Skip to content

Commit

Permalink
Merge pull request #663 from Esri/f/update-sharing-logic-for-admins
Browse files Browse the repository at this point in the history
feat(portal): add updateGroupMembership, isItemSharedWithGroup
  • Loading branch information
dbouwman authored Mar 1, 2020
2 parents 2fe62ae + 7846b86 commit ab3fefc
Show file tree
Hide file tree
Showing 12 changed files with 1,068 additions and 450 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

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

4 changes: 1 addition & 3 deletions packages/arcgis-rest-feature-layer/test/attachments.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ describe("attachment methods", () => {
expect(fetchMock.called()).toBeTruthy();
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
expect(url).toEqual(
`${requestOptions.url}/${
requestOptions.featureId
}/attachments?f=json&gdbVersion=SDE.DEFAULT`
`${requestOptions.url}/${requestOptions.featureId}/attachments?f=json&gdbVersion=SDE.DEFAULT`
);
expect(options.method).toBe("GET");
expect(getAttachmentsResponse.attachmentInfos.length).toEqual(2);
Expand Down
8 changes: 2 additions & 6 deletions packages/arcgis-rest-feature-layer/test/query.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,7 @@ describe("getFeature() and queryFeatures()", () => {
expect(fetchMock.called()).toBeTruthy();
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
expect(url).toEqual(
`${
requestOptions.url
}/query?f=json&where=Condition%3D'Poor'&outFields=FID%2CTree_ID%2CCmn_Name%2CCondition&geometry=%7B%7D&geometryType=esriGeometryPolygon&orderByFields=test`
`${requestOptions.url}/query?f=json&where=Condition%3D'Poor'&outFields=FID%2CTree_ID%2CCmn_Name%2CCondition&geometry=%7B%7D&geometryType=esriGeometryPolygon&orderByFields=test`
);
expect(options.method).toBe("GET");
// expect(response.attributes.FID).toEqual(42);
Expand All @@ -129,9 +127,7 @@ describe("getFeature() and queryFeatures()", () => {
expect(fetchMock.called()).toBeTruthy();
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
expect(url).toEqual(
`${
requestOptions.url
}/queryRelatedRecords?f=json&definitionExpression=1%3D1&outFields=*&relationshipId=0`
`${requestOptions.url}/queryRelatedRecords?f=json&definitionExpression=1%3D1&outFields=*&relationshipId=0`
);
expect(options.method).toBe("GET");
done();
Expand Down
63 changes: 63 additions & 0 deletions packages/arcgis-rest-portal/src/groups/update-user-membership.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/* Copyright (c) 2017-2018 Environmental Systems Research Institute, Inc.
* Apache-2.0 */
import { IUserRequestOptions } from "@esri/arcgis-rest-auth";
import { getPortalUrl } from "../util/get-portal-url";
import { request } from "@esri/arcgis-rest-request";

export interface IUpdateGroupUsersResult {
/**
* Array of results
*/
results: any[];
}

export interface IUpdateGroupUsersOptions extends IUserRequestOptions {
/**
* Group ID
*/
id: string;
/**
* An array of usernames to be updated
*/
users: string[];
/**
* Membership Type to update to
*/
newMemberType: "member" | "admin";
}

/**
* ```js
* import { updateUserMemberships } from "@esri/arcgis-rest-portal";
* //
* updateUserMemberships({
* id: groupId,
* admins: ["username3"],
* authentication
* })
* .then(response);
* ```
* Change the user membership levels of existing users in a group
*
* @param requestOptions - Options for the request
* @returns A Promise
*/
export function updateUserMemberships(
requestOptions: IUpdateGroupUsersOptions
): Promise<IUpdateGroupUsersResult> {
const url = `${getPortalUrl(requestOptions)}/community/groups/${
requestOptions.id
}/updateUsers`;
const opts: any = {
authentication: requestOptions.authentication,
params: {}
};
// add the correct params depending on the type of membership we are changing to
if (requestOptions.newMemberType === "admin") {
opts.params.admins = requestOptions.users;
} else {
opts.params.users = requestOptions.users;
}
// make the request
return request(url, opts);
}
1 change: 1 addition & 0 deletions packages/arcgis-rest-portal/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export * from "./groups/protect";
export * from "./groups/remove";
export * from "./groups/search";
export * from "./groups/update";
export * from "./groups/update-user-membership";
export * from "./groups/join";

export * from "./users/get-user";
Expand Down
4 changes: 1 addition & 3 deletions packages/arcgis-rest-portal/src/sharing/access.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ export function setItemAccess(
} else {
// if neither, updating the sharing isnt possible
throw Error(
`This item can not be shared by ${
requestOptions.authentication.username
}. They are neither the item owner nor an organization admin.`
`This item can not be shared by ${requestOptions.authentication.username}. They are neither the item owner nor an organization admin.`
);
}
});
Expand Down
Loading

0 comments on commit ab3fefc

Please sign in to comment.