Skip to content

Commit

Permalink
fix: add shareContent group permission and minor hub group clean up (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
vivzhang authored Sep 1, 2023
1 parent 0c98542 commit 9a90b6d
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/common/src/core/types/IHubGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 2 additions & 5 deletions packages/common/src/groups/HubGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
);
}

/**
Expand Down
14 changes: 14 additions & 0 deletions packages/common/src/groups/_internal/GroupBusinessRules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export const GroupPermissions = [
"hub:group:workspace:collaborators",
"hub:group:workspace:content",
"hub:group:workspace:members",
"hub:group:shareContent",
] as const;

/**
Expand Down Expand Up @@ -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",
},
],
},
];
6 changes: 4 additions & 2 deletions packages/common/src/groups/_internal/computeProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ export function computeProps(
"updateitemcontrol"
);

hubGroup.memberType = group.userMembership?.memberType;

hubGroup.membershipAccess = "anyone";
if (group.membershipAccess === "org") {
hubGroup.membershipAccess = "organization";
Expand All @@ -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
Expand Down
14 changes: 14 additions & 0 deletions packages/common/test/groups/_internal/computeProps.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
});
});

0 comments on commit 9a90b6d

Please sign in to comment.