1
Fork 0
mirror of https://github.com/pds-nest/nest.git synced 2024-11-25 06:24:19 +00:00

Complete repository share

This commit is contained in:
Steffo 2021-05-23 17:56:25 +02:00
parent 1928435f6f
commit 7b0b028a50
Signed by: steffo
GPG key ID: 6965406171929D01
5 changed files with 24 additions and 8 deletions

View file

@ -54,11 +54,17 @@ export default {
emptyMenu: "Non c'è nulla qui.", emptyMenu: "Non c'è nulla qui.",
delete: "Elimina", delete: "Elimina",
share: "Condividi", share: "Condividi",
unshare: "Rimuovi",
archive: "Archivia", archive: "Archivia",
edit: "Modifica", edit: "Modifica",
created: "Creata", created: "Creata",
archived: "Archiviata", archived: "Archiviata",
// TODO: migliorare, maybe?
repoShare: "Condivisioni",
availableUsers: "Utenti disponibili",
sharingWith: "In condivisione con",
alerts: "Allarmi", alerts: "Allarmi",
alertTitle: "I tuoi allarmi", alertTitle: "I tuoi allarmi",
alertCreate: "Crea un allarme", alertCreate: "Crea un allarme",

View file

@ -1,8 +1,9 @@
import React from "react" import React, { useContext } from "react"
import BoxFullScrollable from "../base/BoxFullScrollable" import BoxFullScrollable from "../base/BoxFullScrollable"
import Loading from "../base/Loading" import Loading from "../base/Loading"
import SummaryRepository from "./SummaryRepository" import SummaryRepository from "./SummaryRepository"
import Empty from "./Empty" import Empty from "./Empty"
import ContextUser from "../../contexts/ContextUser"
/** /**
@ -34,6 +35,8 @@ export default function BoxRepositories(
...props ...props
}) })
{ {
const {user} = useContext(ContextUser)
let contents let contents
if(loading) { if(loading) {
contents = <Loading/> contents = <Loading/>
@ -47,7 +50,7 @@ export default function BoxRepositories(
key={repo["id"]} key={repo["id"]}
repo={repo} repo={repo}
view={view ? () => view(repo["id"]) : null} view={view ? () => view(repo["id"]) : null}
share={share ? () => share(repo["id"]) : null} share={(share && user["email"] === repo["owner"]["email"]) ? () => share(repo["id"]) : null}
archive={archive ? () => archive(repo["id"]) : null} archive={archive ? () => archive(repo["id"]) : null}
edit={edit ? () => edit(repo["id"]) : null} edit={edit ? () => edit(repo["id"]) : null}
destroy={destroy ? () => destroy(repo["id"]) : null} destroy={destroy ? () => destroy(repo["id"]) : null}

View file

@ -7,6 +7,7 @@ import SummaryLabels from "../base/summary/SummaryLabels"
import SummaryButton from "../base/summary/SummaryButton" import SummaryButton from "../base/summary/SummaryButton"
import SummaryRight from "../base/summary/SummaryRight" import SummaryRight from "../base/summary/SummaryRight"
import {FontAwesomeIcon} from "@fortawesome/react-fontawesome" import {FontAwesomeIcon} from "@fortawesome/react-fontawesome"
import ContextUser from "../../contexts/ContextUser"
/** /**
@ -23,6 +24,7 @@ import {FontAwesomeIcon} from "@fortawesome/react-fontawesome"
*/ */
export default function SummaryUser({ user, shareWithUser, unshareWithUser, destroyUser, running, ...props }) { export default function SummaryUser({ user, shareWithUser, unshareWithUser, destroyUser, running, ...props }) {
const { strings } = useContext(ContextLanguage) const { strings } = useContext(ContextLanguage)
const {user: loggedUser} = useContext(ContextUser)
return ( return (
<SummaryBase {...props}> <SummaryBase {...props}>
@ -36,7 +38,7 @@ export default function SummaryUser({ user, shareWithUser, unshareWithUser, dest
upperLabel={strings.type} upperLabel={strings.type}
upperValue={user.isAdmin ? strings.admin : strings.user} upperValue={user.isAdmin ? strings.admin : strings.user}
/> />
{shareWithUser ? {(shareWithUser && loggedUser["email"] !== user["email"]) ?
<SummaryButton <SummaryButton
color={"Green"} color={"Green"}
icon={faShare} icon={faShare}
@ -49,7 +51,7 @@ export default function SummaryUser({ user, shareWithUser, unshareWithUser, dest
{strings.share} {strings.share}
</SummaryButton> </SummaryButton>
: null} : null}
{unshareWithUser ? {(unshareWithUser && loggedUser["email"] !== user["email"]) ?
<SummaryButton <SummaryButton
color={"Red"} color={"Red"}
icon={<FontAwesomeIcon icon={faShare} flip={"horizontal"}/>} icon={<FontAwesomeIcon icon={faShare} flip={"horizontal"}/>}

View file

@ -5,6 +5,7 @@ import useBackendViewset from "../hooks/useBackendViewset"
import BoxRepositories from "../components/interactive/BoxRepositories" import BoxRepositories from "../components/interactive/BoxRepositories"
import { useHistory } from "react-router" import { useHistory } from "react-router"
import ContextLanguage from "../contexts/ContextLanguage" import ContextLanguage from "../contexts/ContextLanguage"
import ContextUser from "../contexts/ContextUser"
export default function PageRepositories({ children, className, ...props }) { export default function PageRepositories({ children, className, ...props }) {

View file

@ -6,12 +6,14 @@ import Style from "./PageShare.module.css"
import BoxUserList from "../components/interactive/BoxUserList" import BoxUserList from "../components/interactive/BoxUserList"
import useBackendViewset from "../hooks/useBackendViewset" import useBackendViewset from "../hooks/useBackendViewset"
import { useParams } from "react-router" import { useParams } from "react-router"
import ContextUser from "../contexts/ContextUser"
export default function PageShare({ className, ...props }) { export default function PageShare({ className, ...props }) {
const { strings } = useContext(ContextLanguage) const { strings } = useContext(ContextLanguage)
const {user: loggedUser} = useContext(ContextUser)
const { id } = useParams() const { id } = useParams()
const {resources: users} = useBackendViewset( const {resources: users, running: usersBvRunning} = useBackendViewset(
"/api/v1/users/", "/api/v1/users/",
"email", "email",
{ {
@ -24,7 +26,7 @@ export default function PageShare({ className, ...props }) {
action: false, action: false,
} }
) )
const {resources: authorizations, createResource: createAuthorization, destroyResource: destroyAuthorization} = useBackendViewset( const {resources: authorizations, createResource: createAuthorization, destroyResource: destroyAuthorization, running: authBvRunning} = useBackendViewset(
`/api/v1/repositories/${id}/authorizations/`, `/api/v1/repositories/${id}/authorizations/`,
"email", "email",
{ {
@ -61,15 +63,17 @@ export default function PageShare({ className, ...props }) {
</BoxHeader> </BoxHeader>
<BoxUserList <BoxUserList
className={Style.UserList} className={Style.UserList}
users={users.filter(user => !authorizations.map(a => a.email).includes(user.email))} users={users.filter(user => user["email"] !== loggedUser["email"] && !authorizations.map(a => a.email).includes(user.email))}
shareWithUser={shareWith} shareWithUser={shareWith}
header={strings.availableUsers} header={strings.availableUsers}
running={usersBvRunning && authBvRunning}
/> />
<BoxUserList <BoxUserList
className={Style.SharingWith} className={Style.SharingWith}
users={users.filter(user => authorizations.map(a => a.email).includes(user.email))} users={users.filter(user => user["email"] === loggedUser["email"] || authorizations.map(a => a.email).includes(user.email))}
unshareWithUser={unshareWith} unshareWithUser={unshareWith}
header={strings.sharingWith} header={strings.sharingWith}
running={usersBvRunning && authBvRunning}
/> />
</div> </div>
) )