Skip to content

Commit

Permalink
feat(portal): searchGroupUsers searches the users in the given group
Browse files Browse the repository at this point in the history
AFFECTS PACKAGES:
@esri/arcgis-rest-portal
  • Loading branch information
mjuniper committed Jul 18, 2019
1 parent 8761888 commit d9151a1
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 36 deletions.
41 changes: 11 additions & 30 deletions package-lock.json

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

55 changes: 52 additions & 3 deletions packages/arcgis-rest-portal/src/groups/get.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
/* Copyright (c) 2017-2018 Environmental Systems Research Institute, Inc.
* Apache-2.0 */

import { request, IRequestOptions } from "@esri/arcgis-rest-request";
import { IPagingParams, IGroup, IItem } from "@esri/arcgis-rest-types";

import {
request,
IRequestOptions,
appendCustomParams
} from "@esri/arcgis-rest-request";
import { IPagingParams, IGroup, IItem, IUser } from "@esri/arcgis-rest-types";
import { getPortalUrl } from "../util/get-portal-url";

export interface IGetGroupContentOptions extends IRequestOptions {
Expand Down Expand Up @@ -97,3 +100,49 @@ export function getGroupUsers(
};
return request(url, options);
}

export interface ISearchGroupUsersOptions
extends IRequestOptions,
IPagingParams {
name?: string;
sortField?: string;
sortOrder?: string;
[key: string]: any;
}

export interface ISearchGroupUsersResult {
total: number;
start: number;
num: number;
nextStart: number;
owner: IUser;
users: any[];
}

/**
* ```js
* import { searchGroupUsers } from "@esri/arcgis-rest-portal";
* //
* searchGroupUsers('abc123')
* .then(response)
* ```
* Search the users in a group. See the [REST Documentation](https://developers.arcgis.com/rest/users-groups-and-items/group-users-list.htm) for more information.
*
* @param id - The group id
* @param searchOptions - Options for the request, including paging parameters.
* @returns A Promise that will resolve with the data from the response.
*/
export function searchGroupUsers(
id: string,
searchOptions: ISearchGroupUsersOptions
): Promise<ISearchGroupUsersResult> {
const url = `${getPortalUrl(searchOptions)}/community/groups/${id}/userlist`;
const options = appendCustomParams<ISearchGroupUsersOptions>(
searchOptions,
["name", "num", "start", "sortField", "sortOrder"],
{
httpMethod: "GET"
}
);
return request(url, options);
}
37 changes: 35 additions & 2 deletions packages/arcgis-rest-portal/test/groups/get.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
/* Copyright (c) 2018 Environmental Systems Research Institute, Inc.
* Apache-2.0 */

import { getGroup, getGroupContent, getGroupUsers } from "../../src/groups/get";
import {
getGroup,
getGroupContent,
getGroupUsers,
searchGroupUsers
} from "../../src/groups/get";

import {
GroupResponse,
GroupContentResponse,
GroupUsersResponse
GroupUsersResponse,
SearchGroupUsersResponse
} from "../mocks/groups/responses";

import * as fetchMock from "fetch-mock";
Expand Down Expand Up @@ -97,5 +103,32 @@ describe("groups", () => {
fail(e);
});
});

it("should search group users", done => {
fetchMock.once("*", SearchGroupUsersResponse);

searchGroupUsers("5bc", {
params: {
name: "jupe",
sortField: "fullname",
sortOrder: "asc",
num: 2,
start: 2
},
...MOCK_REQOPTS
})
.then(response => {
expect(fetchMock.called()).toEqual(true);
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
expect(url).toEqual(
"https://myorg.maps.arcgis.com/sharing/rest/community/groups/5bc/userlist?f=json&name=jupe&sortField=fullname&sortOrder=asc&num=2&start=2&token=fake-token"
);
expect(options.method).toBe("GET");
done();
})
.catch(e => {
fail(e);
});
});
});
});
30 changes: 29 additions & 1 deletion packages/arcgis-rest-portal/test/mocks/groups/responses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import { ISearchResult } from "../../../src/util/search";
import {
IGroupContentResult,
IGroupUsersResult
IGroupUsersResult,
ISearchGroupUsersResult
} from "../../../src/groups/get";

import { IGroup } from "@esri/arcgis-rest-types";
Expand Down Expand Up @@ -142,3 +143,30 @@ export const GroupContentResponse: IGroupContentResult = {
export const GroupNotificationResponse: any = {
success: true
};

export const SearchGroupUsersResponse: ISearchGroupUsersResult = {
total: 4,
start: 1,
num: 2,
nextStart: 3,
owner: {
username: "Vulcan",
fullName: "Spock Vulcan"
},
users: [
{
username: "mjuniper5",
fullName: "Mike Juniper",
memberType: "member",
thumbnail: "ArcGIS-Hub-Glyph-gray.png",
joined: 1561555887000
},
{
username: "mjuniper50",
fullName: "Mike Juniper",
memberType: "member",
thumbnail: null,
joined: 1561555863000
}
]
};

0 comments on commit d9151a1

Please sign in to comment.