Skip to content

Commit

Permalink
fix(:bug:): allow for group sharing of public items outside an organi…
Browse files Browse the repository at this point in the history
…zation

AFFECTS PACKAGES:
@esri/arcgis-rest-sharing

ISSUES CLOSED: 454
  • Loading branch information
jgravois committed Feb 11, 2019
1 parent 8be88a3 commit e47a772
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
16 changes: 9 additions & 7 deletions packages/arcgis-rest-sharing/src/group-sharing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,16 @@ function changeGroupSharing(
requestOptions.action === "share" ? "notSharedWith" : "notUnsharedFrom";
// check if the item has already been shared with the group...
return isItemSharedWithGroup(requestOptions).then(result => {
// console.log(admin);
// if we are sharing and result is true OR we are unsharing and result is false... short circuit
if (
(requestOptions.action === "share" && result === true) ||
(requestOptions.action === "unshare" && result === false)
) {
// and send back the same response structure ArcGIS Online would
const response = { itemId: requestOptions.id, shortcut: true } as any;
// and send back the same response ArcGIS Online would
const response = {
itemId: requestOptions.id,
shortcut: true
} as ISharingResponse;
response[resultProp] = [];
return response;
} else {
Expand All @@ -106,16 +108,16 @@ function changeGroupSharing(
}.`
);
} else {
// if orgAdmin or owner (and member of group) share using the owner url
if (owner === username || admin) {
// if owner (and member of group) share using the owner url
if (owner === username) {
return `${getPortalUrl(
requestOptions
)}/content/users/${owner}/items/${requestOptions.id}/${
requestOptions.action
}`;
} else {
// if they are a group admin/owner, use the bare item url
if (membership === "admin" || membership === "owner") {
// if org admin, group admin/owner, use the bare item url
if (membership === "admin" || membership === "owner" || admin) {
return `${getPortalUrl(requestOptions)}/content/items/${
requestOptions.id
}/${requestOptions.action}`;
Expand Down
12 changes: 6 additions & 6 deletions packages/arcgis-rest-sharing/test/group-sharing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ describe("shareItemWithGroup() ::", () => {
);

fetchMock.once(
"https://myorg.maps.arcgis.com/sharing/rest/content/users/casey/items/n3v/share",
"https://myorg.maps.arcgis.com/sharing/rest/content/items/n3v/share",
SharingResponse
);

Expand All @@ -214,10 +214,10 @@ describe("shareItemWithGroup() ::", () => {
"All fetchMocks should have been called"
);
const [url, options]: [string, RequestInit] = fetchMock.lastCall(
"https://myorg.maps.arcgis.com/sharing/rest/content/users/casey/items/n3v/share"
"https://myorg.maps.arcgis.com/sharing/rest/content/items/n3v/share"
);
expect(url).toBe(
"https://myorg.maps.arcgis.com/sharing/rest/content/users/casey/items/n3v/share"
"https://myorg.maps.arcgis.com/sharing/rest/content/items/n3v/share"
);
expect(options.method).toBe("POST");
expect(response).toEqual(SharingResponse);
Expand Down Expand Up @@ -455,7 +455,7 @@ describe("unshareItemWithGroup() ::", () => {
);

fetchMock.once(
"https://myorg.maps.arcgis.com/sharing/rest/content/users/casey/items/a5b/unshare",
"https://myorg.maps.arcgis.com/sharing/rest/content/items/a5b/unshare",
UnsharingResponse
);

Expand All @@ -472,10 +472,10 @@ describe("unshareItemWithGroup() ::", () => {
})
.then(response => {
const [url, options]: [string, RequestInit] = fetchMock.lastCall(
"https://myorg.maps.arcgis.com/sharing/rest/content/users/casey/items/a5b/unshare"
"https://myorg.maps.arcgis.com/sharing/rest/content/items/a5b/unshare"
);
expect(url).toBe(
"https://myorg.maps.arcgis.com/sharing/rest/content/users/casey/items/a5b/unshare"
"https://myorg.maps.arcgis.com/sharing/rest/content/items/a5b/unshare"
);
expect(options.method).toBe("POST");
expect(response).toEqual(UnsharingResponse);
Expand Down

0 comments on commit e47a772

Please sign in to comment.