diff --git a/src/Journals/JournalMembers.tsx b/src/Journals/JournalMembers.tsx index fb8f280..bfcc4cd 100644 --- a/src/Journals/JournalMembers.tsx +++ b/src/Journals/JournalMembers.tsx @@ -7,6 +7,7 @@ import { Theme, withTheme } from '@material-ui/core/styles'; import AppBarOverride from '../widgets/AppBarOverride'; import Container from '../widgets/Container'; import LoadingIndicator from '../widgets/LoadingIndicator'; +import ConfirmationDialog from '../widgets/ConfirmationDialog'; import * as EteSync from '../api/EteSync'; import { CredentialsData } from '../store'; @@ -23,15 +24,19 @@ interface PropsTypeInner extends PropsType { class JournalMembers extends React.PureComponent { public state = { members: null as EteSync.JournalMemberJson[] | null, + revokeUser: null as string | null, }; constructor(props: PropsTypeInner) { super(props); + + this.onRevokeRequest = this.onRevokeRequest.bind(this); + this.onRevokeDo = this.onRevokeDo.bind(this); } public render() { const { info } = this.props; - const { members } = this.state; + const { members, revokeUser } = this.state; return ( <> @@ -41,7 +46,7 @@ class JournalMembers extends React.PureComponent { (members.length > 0 ? { members.map((member) => ( - + this.onRevokeRequest(member.user)}> {member.user} ))} @@ -53,6 +58,16 @@ class JournalMembers extends React.PureComponent { } + this.setState({revokeUser: null})} + > + Would you like to revoke {revokeUser}'s access?
+ 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. +
); } @@ -73,6 +88,27 @@ class JournalMembers extends React.PureComponent { }); }); } + + private onRevokeRequest(user: string) { + this.setState({ + revokeUser: user, + }); + } + + private onRevokeDo() { + const { etesync, info } = this.props; + const { revokeUser } = this.state; + + const creds = etesync.credentials; + const apiBase = etesync.serviceApiUrl; + const journalMembersManager = new EteSync.JournalMembersManager(creds, apiBase, info.uid); + journalMembersManager.delete({ user: revokeUser!, key: '' }).then(() => { + this.fetchMembers(); + }); + this.setState({ + revokeUser: null, + }); + } } export default withTheme()(JournalMembers); diff --git a/src/api/EteSync.ts b/src/api/EteSync.ts index 33bac81..182ec65 100644 --- a/src/api/EteSync.ts +++ b/src/api/EteSync.ts @@ -529,6 +529,23 @@ export class JournalMembersManager extends BaseManager { }); }); } + + public create(journalMember: JournalMemberJson): Promise<{}> { + const extra = { + method: 'post', + body: JSON.stringify(journalMember), + }; + + return this.newCall([], extra); + } + + public delete(journalMember: JournalMemberJson): Promise<{}> { + const extra = { + method: 'delete', + }; + + return this.newCall([journalMember.user, ''], extra); + } } export class UserInfoManager extends BaseManager {