1
0
mirror of https://github.com/bitwarden/directory-connector synced 2026-01-08 19:43:24 +00:00

Manage multiple pages when fetching groups (#14)

This commit is contained in:
Elie Mélois
2019-03-26 11:58:05 +00:00
committed by Kyle Spearrin
parent 9acfaff361
commit d5907477df

View File

@@ -128,19 +128,30 @@ export class GSuiteDirectoryService extends BaseDirectoryService implements Dire
private async getGroups(setFilter: [boolean, Set<string>]): Promise<GroupEntry[]> {
const entries: GroupEntry[] = [];
let nextPageToken;
let p = Object.assign({});
this.logService.info('Querying groups.');
const res = await this.service.groups.list(this.authParams);
if (res.status !== 200) {
throw new Error('Group list API failed: ' + res.statusText);
}
if (res.data.groups != null) {
for (const group of res.data.groups) {
if (!this.filterOutResult(setFilter, group.name)) {
const entry = await this.buildGroup(group);
entries.push(entry);
while(true) {
this.logService.info('Querying groups - nextPageToken:' + nextPageToken);
p = Object.assign({ pageToken: nextPageToken }, this.authParams);
const res = await this.service.groups.list(p);
nextPageToken = res.data.nextPageToken;
if (res.status !== 200) {
throw new Error('Group list API failed: ' + res.statusText);
}
if (res.data.groups != null) {
for (const group of res.data.groups) {
if (!this.filterOutResult(setFilter, group.name)) {
const entry = await this.buildGroup(group);
entries.push(entry);
}
}
}
if (nextPageToken == null) {
break;
}
}
return entries;