Collection members: show admins in the member list.

master
Tom Hacohen 4 years ago
parent aed7862cab
commit 9f426bf2c8

@ -9,6 +9,7 @@ import { List, ListItem } from "../widgets/List";
import IconMemberAdd from "@material-ui/icons/PersonAdd"; import IconMemberAdd from "@material-ui/icons/PersonAdd";
import VisibilityIcon from "@material-ui/icons/Visibility"; import VisibilityIcon from "@material-ui/icons/Visibility";
import AdminIcon from "@material-ui/icons/SupervisedUserCircle";
import AppBarOverride from "../widgets/AppBarOverride"; import AppBarOverride from "../widgets/AppBarOverride";
import Container from "../widgets/Container"; import Container from "../widgets/Container";
@ -28,13 +29,15 @@ interface PropsType {
export default function CollectionMembers(props: PropsType) { export default function CollectionMembers(props: PropsType) {
const etebase = useCredentials()!; const etebase = useCredentials()!;
const [members_, setMembers] = React.useState<Etebase.CollectionMember[]>(); const [members, setMembers] = React.useState<Etebase.CollectionMember[]>();
const [revokeUser, setRevokeUser] = React.useState<string | null>(null); const [revokeUser, setRevokeUser] = React.useState<Etebase.CollectionMember | null>(null);
const [addMemberOpen, setAddMemberOpen] = React.useState(false); const [addMemberOpen, setAddMemberOpen] = React.useState(false);
const [error, setError] = React.useState<Error>(); const [error, setError] = React.useState<Error>();
const { collection, metadata } = props.collection; const { collection, metadata } = props.collection;
const revokeUserIsAdmin = revokeUser?.accessLevel === Etebase.CollectionAccessLevel.Admin;
async function fetchMembers() { async function fetchMembers() {
const colMgr = getCollectionManager(etebase); const colMgr = getCollectionManager(etebase);
const memberManager = colMgr.getMemberManager(collection); const memberManager = colMgr.getMemberManager(collection);
@ -62,14 +65,10 @@ export default function CollectionMembers(props: PropsType) {
fetchMembers(); fetchMembers();
}, []); }, []);
function onRevokeRequest(user: string) {
setRevokeUser(user);
}
async function onRevokeDo() { async function onRevokeDo() {
const colMgr = getCollectionManager(etebase); const colMgr = getCollectionManager(etebase);
const memberManager = colMgr.getMemberManager(collection); const memberManager = colMgr.getMemberManager(collection);
await memberManager.remove(revokeUser!); await memberManager.remove(revokeUser!.username);
await fetchMembers(); await fetchMembers();
setRevokeUser(null); setRevokeUser(null);
} }
@ -81,8 +80,6 @@ export default function CollectionMembers(props: PropsType) {
setAddMemberOpen(false); setAddMemberOpen(false);
} }
const members = members_?.filter((x) => x.username !== etebase.user.username);
return ( return (
<> <>
<AppBarOverride title={`${metadata.name} - Members`} /> <AppBarOverride title={`${metadata.name} - Members`} />
@ -98,15 +95,23 @@ export default function CollectionMembers(props: PropsType) {
Invite user Invite user
</ListItem> </ListItem>
{(members.length > 0 ? {(members.length > 0 ?
members.map((member) => ( members.map((member) => {
<ListItem let rightIcon: React.ReactElement | undefined = undefined;
key={member.username} if (member.accessLevel === Etebase.CollectionAccessLevel.ReadOnly) {
onClick={() => onRevokeRequest(member.username)} rightIcon = (<div title="Read Only"><VisibilityIcon /></div>);
rightIcon={(member.accessLevel === Etebase.CollectionAccessLevel.ReadOnly) ? (<VisibilityIcon />) : undefined} } else if (member.accessLevel === Etebase.CollectionAccessLevel.Admin) {
> rightIcon = (<div title="Admin"><AdminIcon /></div>);
{member.username} }
</ListItem> return (
)) <ListItem
key={member.username}
onClick={() => setRevokeUser(member)}
rightIcon={rightIcon}
>
{member.username}
</ListItem>
);
})
: :
<ListItem> <ListItem>
No members No members
@ -121,11 +126,19 @@ export default function CollectionMembers(props: PropsType) {
title="Remove member" title="Remove member"
labelOk="OK" labelOk="OK"
open={revokeUser !== null} open={revokeUser !== null}
onOk={onRevokeDo} onOk={(revokeUserIsAdmin) ? () => setRevokeUser(null) : onRevokeDo}
onCancel={() => setRevokeUser(null)} onCancel={() => setRevokeUser(null)}
> >
Would you like to revoke {revokeUser}'s access?<br /> {(revokeUserIsAdmin) ? (
Please be advised that a malicious user would potentially be able to retain access to encryption keys. Please refer to the FAQ for more information. <p>
Revoking admin access is not allowed.
</p>
) : (
<p>
Would you like to revoke {revokeUser?.username}'s access?<br />
Please be advised that a malicious user would potentially be able to retain access to encryption keys. Please refer to the FAQ for more information.
</p>
)}
</ConfirmationDialog> </ConfirmationDialog>
{addMemberOpen && {addMemberOpen &&

Loading…
Cancel
Save