Journal members: implement revoking access.
parent
a557ec1fd2
commit
85ac4da839
|
@ -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<PropsTypeInner> {
|
||||
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<PropsTypeInner> {
|
|||
(members.length > 0 ?
|
||||
<List>
|
||||
{ members.map((member) => (
|
||||
<ListItem key={member.user} onClick={undefined}>
|
||||
<ListItem key={member.user} onClick={() => this.onRevokeRequest(member.user)}>
|
||||
{member.user}
|
||||
</ListItem>
|
||||
))}
|
||||
|
@ -53,6 +58,16 @@ class JournalMembers extends React.PureComponent<PropsTypeInner> {
|
|||
<LoadingIndicator />
|
||||
}
|
||||
</Container>
|
||||
<ConfirmationDialog
|
||||
title="Remove member"
|
||||
labelOk="OK"
|
||||
open={revokeUser !== null}
|
||||
onOk={this.onRevokeDo}
|
||||
onCancel={() => this.setState({revokeUser: null})}
|
||||
>
|
||||
Would you like to revoke {revokeUser}'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.
|
||||
</ConfirmationDialog>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
@ -73,6 +88,27 @@ class JournalMembers extends React.PureComponent<PropsTypeInner> {
|
|||
});
|
||||
});
|
||||
}
|
||||
|
||||
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);
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue