From 9a90b6df4ff8da6c0a4de2a8f92bc1a8c63289dd Mon Sep 17 00:00:00 2001 From: Vivian Zhang Date: Fri, 1 Sep 2023 11:21:34 -0700 Subject: [PATCH] fix: add shareContent group permission and minor hub group clean up (#1194) --- packages/common/src/core/types/IHubGroup.ts | 2 +- packages/common/src/groups/HubGroup.ts | 7 ++----- .../src/groups/_internal/GroupBusinessRules.ts | 14 ++++++++++++++ .../common/src/groups/_internal/computeProps.ts | 6 ++++-- .../test/groups/_internal/computeProps.test.ts | 14 ++++++++++++++ 5 files changed, 35 insertions(+), 8 deletions(-) diff --git a/packages/common/src/core/types/IHubGroup.ts b/packages/common/src/core/types/IHubGroup.ts index 70735175314..b2f9595da13 100644 --- a/packages/common/src/core/types/IHubGroup.ts +++ b/packages/common/src/core/types/IHubGroup.ts @@ -79,7 +79,7 @@ export interface IHubGroup extends IHubEntityBase, IWithPermissions { owner?: string; /** - * Whether the group is protect or not + * Whether the group is protected or not * the group cannot be deleted if protected */ protected: boolean; diff --git a/packages/common/src/groups/HubGroup.ts b/packages/common/src/groups/HubGroup.ts index 445a41db33e..dbb0daeb03d 100644 --- a/packages/common/src/groups/HubGroup.ts +++ b/packages/common/src/groups/HubGroup.ts @@ -54,15 +54,12 @@ export class HubGroup * only the owner or admins of the group can */ get canEdit(): boolean { - if ( + return ( (this.entity.memberType && (this.entity.memberType === "owner" || this.entity.memberType === "admin")) || this.entity.owner === this.context.currentUser.username - ) { - return true; - } - return false; + ); } /** diff --git a/packages/common/src/groups/_internal/GroupBusinessRules.ts b/packages/common/src/groups/_internal/GroupBusinessRules.ts index 2d53b02887b..5729212c2f8 100644 --- a/packages/common/src/groups/_internal/GroupBusinessRules.ts +++ b/packages/common/src/groups/_internal/GroupBusinessRules.ts @@ -19,6 +19,7 @@ export const GroupPermissions = [ "hub:group:workspace:collaborators", "hub:group:workspace:content", "hub:group:workspace:members", + "hub:group:shareContent", ] as const; /** @@ -74,4 +75,17 @@ export const GroupPermissionPolicies: IPermissionPolicy[] = [ permission: "hub:group:workspace:members", dependencies: ["hub:group:view"], }, + { + permission: "hub:group:shareContent", + dependencies: ["hub:group"], + authenticated: true, + privileges: ["portal:user:shareToGroup"], + assertions: [ + { + property: "context:currentUser", + type: "is-group-member", + value: "entity:id", + }, + ], + }, ]; diff --git a/packages/common/src/groups/_internal/computeProps.ts b/packages/common/src/groups/_internal/computeProps.ts index 9ed583e783f..edeb7b0497a 100644 --- a/packages/common/src/groups/_internal/computeProps.ts +++ b/packages/common/src/groups/_internal/computeProps.ts @@ -47,6 +47,8 @@ export function computeProps( "updateitemcontrol" ); + hubGroup.memberType = group.userMembership?.memberType; + hubGroup.membershipAccess = "anyone"; if (group.membershipAccess === "org") { hubGroup.membershipAccess = "organization"; @@ -56,8 +58,8 @@ export function computeProps( } hubGroup.canEdit = - group.userMembership.memberType === "owner" || - group.userMembership.memberType === "admin"; + group.userMembership?.memberType === "owner" || + group.userMembership?.memberType === "admin"; hubGroup.canDelete = hubGroup.canEdit; // cast b/c this takes a partial but returns a full group diff --git a/packages/common/test/groups/_internal/computeProps.test.ts b/packages/common/test/groups/_internal/computeProps.test.ts index b6406ca2563..e57236e0376 100644 --- a/packages/common/test/groups/_internal/computeProps.test.ts +++ b/packages/common/test/groups/_internal/computeProps.test.ts @@ -86,6 +86,20 @@ describe("groups: computeProps:", () => { "https://org.maps.arcgis.com/sharing/rest/community/groups/3ef/info/group.jpg" ); }); + it("computes the correct props when no userMembership", () => { + group = { + id: "3ef", + name: "Test group", + } as unknown as IGroup; + const chk = computeProps( + group, + hubGroup, + authdCtxMgr.context.requestOptions + ); + expect(chk.memberType).toBeFalsy(); + expect(chk.canEdit).toBeFalsy(); + expect(chk.canDelete).toBeFalsy(); + }); }); }); });