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"}