()
| 18 | |
| 19 | /** Form for managing and viewing rights for this resource */ |
| 20 | export function ShareRoute(): JSX.Element { |
| 21 | const [subject] = useCurrentSubject(); |
| 22 | const resource = useResource(subject); |
| 23 | const title = useTitle(resource); |
| 24 | const store = useStore(); |
| 25 | const [canWrite] = useCanWrite(resource); |
| 26 | const [showInviteForm, setShowInviteForm] = useState(false); |
| 27 | |
| 28 | const [writers, setWriters] = useArray(resource, urls.properties.write); |
| 29 | const [readers, setReaders] = useArray(resource, urls.properties.read); |
| 30 | |
| 31 | const [inheritedRights, setInheritedRights] = useState<Right[]>([]); |
| 32 | |
| 33 | useEffect(() => { |
| 34 | async function getTheRights() { |
| 35 | const allRights = await resource.getRights(store); |
| 36 | const inherited = allRights.filter(r => r.setIn !== subject); |
| 37 | |
| 38 | // Make sure the public agent is always the top of the list |
| 39 | const sorted = inherited.sort((a, b) => { |
| 40 | return a.for === urls.instances.publicAgent ? -1 : 1; |
| 41 | }); |
| 42 | |
| 43 | setInheritedRights(sorted); |
| 44 | } |
| 45 | |
| 46 | getTheRights(); |
| 47 | }, [resource]); |
| 48 | |
| 49 | function handleSetRight( |
| 50 | agent: string, |
| 51 | write: boolean, |
| 52 | setToTrue: boolean, |
| 53 | ): void { |
| 54 | let agents = write ? writers : readers; |
| 55 | if (setToTrue) { |
| 56 | // remove previous occurence |
| 57 | agents = agents.filter(s => s !== agent); |
| 58 | agents.push(agent); |
| 59 | } else { |
| 60 | agents = agents.filter(s => s !== agent); |
| 61 | } |
| 62 | if (write) { |
| 63 | setWriters(agents); |
| 64 | } else { |
| 65 | setReaders(agents); |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | function constructAgentProps(): AgentRight[] { |
| 70 | const rightsMap: Map<string, RightBools> = new Map(); |
| 71 | |
| 72 | // Always show the public agent |
| 73 | rightsMap.set(urls.instances.publicAgent, { read: false, write: false }); |
| 74 | |
| 75 | readers.map(agent => { |
| 76 | rightsMap.set(agent, { |
| 77 | read: true, |
nothing calls this directly
no test coverage detected