From 2b47f097b19988ea65537f35cd16b98356dd605f Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Wed, 13 Oct 2021 03:52:06 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=A5=20Disallow=20group=20members=20fro?= =?UTF-8?q?m=20editing=20group=20`name`=20and=20`description`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/sophon/core/models.py | 7 +- .../src/components/group/GroupCreateBox.tsx | 71 ++++++++++++------- 2 files changed, 49 insertions(+), 29 deletions(-) diff --git a/backend/sophon/core/models.py b/backend/sophon/core/models.py index 70fbbd6..0930a58 100644 --- a/backend/sophon/core/models.py +++ b/backend/sophon/core/models.py @@ -374,14 +374,13 @@ class ResearchGroup(SophonGroupModel): @classmethod def get_editable_fields(cls) -> set[str]: - return { - "name", - "description", - } + return {} @classmethod def get_administrable_fields(cls) -> set[str]: return { + "name", + "description", "members", "access", } diff --git a/frontend/src/components/group/GroupCreateBox.tsx b/frontend/src/components/group/GroupCreateBox.tsx index 823589d..0bcde31 100644 --- a/frontend/src/components/group/GroupCreateBox.tsx +++ b/frontend/src/components/group/GroupCreateBox.tsx @@ -6,8 +6,20 @@ import {ManagedResource, ManagedViewSet} from "../../hooks/useManagedViewSet" import {SophonResearchGroup} from "../../types/SophonTypes" +/** + * The props of {@link GroupCreateBox}. + * + * Only one between `viewSet` and `resource` should be defined. + */ export interface GroupCreateBoxProps { + /** + * The viewSet to use to create new resources. + */ viewSet?: ManagedViewSet, + + /** + * The resource to be edited. + */ resource?: ManagedResource, } @@ -69,21 +81,6 @@ export function GroupCreateBox({viewSet, resource}: GroupCreateBoxProps): JSX.El [viewSet, resource, name, slug, description, members, access], ) - const trueMembers = - React.useMemo( - () => resource ? [...new Set([resource.value.owner, ...resource.value.members])] : undefined, - [resource], - ) - - const canEdit = - React.useMemo( - () => !resource || - ( - authorization && authorization.state.user && trueMembers?.includes(authorization.state.user.id) - ), - [authorization, resource, trueMembers], - ) - const canAdministrate = React.useMemo( () => !resource || @@ -107,10 +104,12 @@ export function GroupCreateBox({viewSet, resource}: GroupCreateBoxProps): JSX.El )) { return null } - if(!canEdit) { + if(!canAdministrate) { return null } + const hasError = viewSet?.operationError || resource?.error + return (
@@ -119,14 +118,35 @@ export function GroupCreateBox({viewSet, resource}: GroupCreateBoxProps): JSX.El
- - 0 ? true : undefined}/> - - - + + 0 ? true : undefined} + /> + + + {resource ? "Edit" : "Create"}