Skip to content

Commit

Permalink
fix(arcgis-rest-portal): do not do any membership adjustments if the …
Browse files Browse the repository at this point in the history
…group is the user's favorites g

AFFECTS PACKAGES:
@esri/arcgis-rest-portal
  • Loading branch information
mjuniper committed Oct 12, 2020
1 parent f388df2 commit 6fc8ada
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 64 deletions.
42 changes: 21 additions & 21 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

79 changes: 40 additions & 39 deletions packages/arcgis-rest-portal/src/sharing/share-item-with-group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,47 +133,48 @@ function getMembershipAdjustments (
requestOptions: IGroupSharingOptions
) {
const membershipGuarantees = [];
if (requestOptions.groupId !== currentUser.favGroupId) {
if (isSharedEditingGroup) {
if (!isAdmin) {
// abort and reject promise
throw Error(`This item can not be shared to shared editing group ${requestOptions.groupId} by ${currentUser.username} as they not the item owner or org admin.`);
}

if (isSharedEditingGroup) {
if (!isAdmin) {
// abort and reject promise
throw Error(`This item can not be shared to shared editing group ${requestOptions.groupId} by ${currentUser.username} as they not the item owner or org admin.`);
}

membershipGuarantees.push(
membershipGuarantees.push(
// admin user must be a group member to share, should be reverted afterwards
ensureMembership(
currentUser,
currentUser,
false,
`Error adding ${currentUser.username} as member to edit group ${requestOptions.groupId}. Consequently item ${requestOptions.id} was not shared to the group.`,
requestOptions
),
// item owner must be a group admin
ensureMembership(
currentUser,
ownerUser,
true,
membership === "none"
? `Error adding user ${ownerUser.username} to edit group ${requestOptions.groupId}. Consequently item ${requestOptions.id} was not shared to the group.`
: `Error promoting user ${ownerUser.username} to admin in edit group ${requestOptions.groupId}. Consequently item ${requestOptions.id} was not shared to the group.`,
requestOptions
)
);
} else if (isAdmin) {
// admin user must be a group member to share, should be reverted afterwards
ensureMembership(
currentUser,
currentUser,
false,
`Error adding ${currentUser.username} as member to edit group ${requestOptions.groupId}. Consequently item ${requestOptions.id} was not shared to the group.`,
requestOptions
),
// item owner must be a group admin
ensureMembership(
currentUser,
ownerUser,
true,
membership === "none"
? `Error adding user ${ownerUser.username} to edit group ${requestOptions.groupId}. Consequently item ${requestOptions.id} was not shared to the group.`
: `Error promoting user ${ownerUser.username} to admin in edit group ${requestOptions.groupId}. Consequently item ${requestOptions.id} was not shared to the group.`,
requestOptions
)
);
} else if (isAdmin) {
// admin user must be a group member to share, should be reverted afterwards
membershipGuarantees.push(
ensureMembership(
currentUser,
currentUser,
false,
`Error adding ${currentUser.username} as member to view group ${requestOptions.groupId}. Consequently item ${requestOptions.id} was not shared to the group.`,
requestOptions
)
);
} else if (membership === "none") {
// all other non-item owners must be a group member
throw new Error(`This item can not be shared by ${currentUser.username} as they are not a member of the specified group ${requestOptions.groupId}.`);
membershipGuarantees.push(
ensureMembership(
currentUser,
currentUser,
false,
`Error adding ${currentUser.username} as member to view group ${requestOptions.groupId}. Consequently item ${requestOptions.id} was not shared to the group.`,
requestOptions
)
);
} else if (membership === "none") {
// all other non-item owners must be a group member
throw new Error(`This item can not be shared by ${currentUser.username} as they are not a member of the specified group ${requestOptions.groupId}.`);
}
}

return membershipGuarantees;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1027,7 +1027,7 @@ describe("shareItemWithGroup() ::", () => {
"https://myorg.maps.arcgis.com/sharing/rest/community/groups/t6b/removeUsers",
{ notRemoved: [] }
);

return shareItemWithGroup({
authentication: MOCK_USER_SESSION,
id: "n3v",
Expand All @@ -1044,7 +1044,7 @@ describe("shareItemWithGroup() ::", () => {
);
expect(shareOptions.body).toContain("groups=t6b");
expect(shareOptions.body).toContain("confirmItemControl=true");

done();
})
.catch(e => {
Expand Down Expand Up @@ -1095,7 +1095,7 @@ describe("shareItemWithGroup() ::", () => {
"https://myorg.maps.arcgis.com/sharing/rest/community/groups/t6b/removeUsers",
{ throws: true }
);

return shareItemWithGroup({
authentication: MOCK_USER_SESSION,
id: "n3v",
Expand All @@ -1112,7 +1112,7 @@ describe("shareItemWithGroup() ::", () => {
);
expect(shareOptions.body).toContain("groups=t6b");
expect(shareOptions.body).toContain("confirmItemControl=true");

done();
})
.catch(e => {
Expand Down Expand Up @@ -1268,4 +1268,58 @@ describe("shareItemWithGroup() ::", () => {
});
});
});
describe("share item to admin user's favorites group ::", () => {
it("should share item", done => {
fetchMock
.once(
"https://myorg.maps.arcgis.com/sharing/rest/community/users/jsmith?f=json&token=fake-token",
{
...OrgAdminUserResponse,
favGroupId: "t6b"
}
)
.once(
"https://myorg.maps.arcgis.com/sharing/rest/search",
NoResultsSearchResponse
)
.get(
"https://myorg.maps.arcgis.com/sharing/rest/community/groups/t6b?f=json&token=fake-token",
GroupOwnerResponse
)
.once(
"https://myorg.maps.arcgis.com/sharing/rest/community/users/casey?f=json&token=fake-token",
{
username: "casey",
orgId: "qWAReEOCnD7eTxOe",
groups: [] as any[]
}
)
.post(
"https://myorg.maps.arcgis.com/sharing/rest/content/items/n3v/share",
{ notSharedWith: [], itemId: "n3v" }
);

shareItemWithGroup({
authentication: MOCK_USER_SESSION,
id: "n3v",
groupId: "t6b",
owner: "casey"
})
.then(result => {
expect(fetchMock.done()).toBeTruthy(
"All fetchMocks should have been called"
);
// verify we shared the item
const shareOptions: RequestInit = fetchMock.lastOptions(
"https://myorg.maps.arcgis.com/sharing/rest/content/items/n3v/share"
);
expect(shareOptions.body).toContain("groups=t6b");

done();
})
.catch(e => {
fail();
});
});
});
});

0 comments on commit 6fc8ada

Please sign in to comment.