feat: Read-only users (#1955)
* Introduce isViewer field * Update policies * Make users read-only feature * Remove not demoting current user validation * Update tests * Catch the unhandled promise rejection * Hide unnecessary ui elements for read-only user * Update app/scenes/Settings/People.js Co-authored-by: Tom Moor <tom.moor@gmail.com> * Remove redundant logic for admin only policies * Use can logic * Update snapshot * Remove lint error * Update snapshot * Minor fix * Update app/menus/UserMenu.js Co-authored-by: Tom Moor <tom.moor@gmail.com> * Update server/api/users.js Co-authored-by: Tom Moor <tom.moor@gmail.com> * Update app/components/DocumentListItem.js Co-authored-by: Tom Moor <tom.moor@gmail.com> * Update app/stores/UsersStore.js Co-authored-by: Tom Moor <tom.moor@gmail.com> * Use useCurrentTeam hook in functional component * Update translation * Update ternary * Remove punctuation * Move the functions to User model * Update share policy and shareMenu * Rename makeAdmin to promote * Create updateCounts function and Rank enum * Update tests * Remove enum * Use async await, remove enum and create computed accessor * Remove unused variable * Fix lint issues * Hide templates * Create shared/types and use rank type from it * Delete shared/utils/rank type file Co-authored-by: Tom Moor <tom.moor@gmail.com>
This commit is contained in:
@ -37,7 +37,7 @@ function UserMenu({ user }: Props) {
|
||||
[users, user, t]
|
||||
);
|
||||
|
||||
const handleDemote = React.useCallback(
|
||||
const handleMember = React.useCallback(
|
||||
(ev: SyntheticEvent<>) => {
|
||||
ev.preventDefault();
|
||||
if (
|
||||
@ -49,7 +49,27 @@ function UserMenu({ user }: Props) {
|
||||
) {
|
||||
return;
|
||||
}
|
||||
users.demote(user);
|
||||
users.demote(user, "Member");
|
||||
},
|
||||
[users, user, t]
|
||||
);
|
||||
|
||||
const handleViewer = React.useCallback(
|
||||
(ev: SyntheticEvent<>) => {
|
||||
ev.preventDefault();
|
||||
if (
|
||||
!window.confirm(
|
||||
t(
|
||||
"Are you sure you want to make {{ userName }} a read-only viewer? They will not be able to edit any content",
|
||||
{
|
||||
userName: user.name,
|
||||
}
|
||||
)
|
||||
)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
users.demote(user, "Viewer");
|
||||
},
|
||||
[users, user, t]
|
||||
);
|
||||
@ -95,18 +115,25 @@ function UserMenu({ user }: Props) {
|
||||
{...menu}
|
||||
items={[
|
||||
{
|
||||
title: t("Make {{ userName }} a member…", {
|
||||
title: t("Make {{ userName }} a member", {
|
||||
userName: user.name,
|
||||
}),
|
||||
onClick: handleDemote,
|
||||
visible: can.demote,
|
||||
onClick: handleMember,
|
||||
visible: can.demote && user.rank !== "Member",
|
||||
},
|
||||
{
|
||||
title: t("Make {{ userName }} a viewer", {
|
||||
userName: user.name,
|
||||
}),
|
||||
onClick: handleViewer,
|
||||
visible: can.demote && user.rank !== "Viewer",
|
||||
},
|
||||
{
|
||||
title: t("Make {{ userName }} an admin…", {
|
||||
userName: user.name,
|
||||
}),
|
||||
onClick: handlePromote,
|
||||
visible: can.promote,
|
||||
visible: can.promote && user.rank !== "Admin",
|
||||
},
|
||||
{
|
||||
type: "separator",
|
||||
|
Reference in New Issue
Block a user