list org-members command

This commit is contained in:
Kyle Spearrin 2019-10-07 09:58:19 -04:00
parent 1de6c2884b
commit e781de9f34
4 changed files with 71 additions and 13 deletions

2
jslib

@ -1 +1 @@
Subproject commit 034aefa652459c9ed5a660fe13593e314ee368dc
Subproject commit 83d6b2449cba8390912b692d882f400723c01dc1

View File

@ -26,6 +26,7 @@ import { CipherResponse } from '../models/response/cipherResponse';
import { CollectionResponse } from '../models/response/collectionResponse';
import { FolderResponse } from '../models/response/folderResponse';
import { OrganizationResponse } from '../models/response/organizationResponse';
import { OrganizationUserResponse } from '../models/response/organizationUserResponse';
import { CliUtils } from '../utils';
@ -46,6 +47,8 @@ export class ListCommand {
return await this.listCollections(cmd);
case 'org-collections':
return await this.listOrganizationCollections(cmd);
case 'org-members':
return await this.listOrganizationMembers(cmd);
case 'organizations':
return await this.listOrganizations(cmd);
default:
@ -150,20 +153,54 @@ export class ListCommand {
return Response.error('Organization not found.');
}
let response: ApiListResponse<ApiCollectionResponse>;
if (organization.isAdmin) {
response = await this.apiService.getCollections(cmd.organizationId);
} else {
response = await this.apiService.getUserCollections();
try {
let response: ApiListResponse<ApiCollectionResponse>;
if (organization.isAdmin) {
response = await this.apiService.getCollections(cmd.organizationid);
} else {
response = await this.apiService.getUserCollections();
}
const collections = response.data.filter((c) => c.organizationId === cmd.organizationid).map((r) =>
new Collection(new CollectionData(r as ApiCollectionDetailsResponse)));
let decCollections = await this.collectionService.decryptMany(collections);
if (cmd.search != null && cmd.search.trim() !== '') {
decCollections = CliUtils.searchCollections(decCollections, cmd.search);
}
const res = new ListResponse(decCollections.map((o) => new CollectionResponse(o)));
return Response.success(res);
} catch (e) {
return Response.error(e);
}
const collections = response.data.filter((c) => c.organizationId === cmd.organizationId).map((r) =>
new Collection(new CollectionData(r as ApiCollectionDetailsResponse)));
let decCollections = await this.collectionService.decryptMany(collections);
if (cmd.search != null && cmd.search.trim() !== '') {
decCollections = CliUtils.searchCollections(decCollections, cmd.search);
}
private async listOrganizationMembers(cmd: program.Command) {
if (cmd.organizationid == null || cmd.organizationid === '') {
return Response.badRequest('--organizationid <organizationid> required.');
}
if (!Utils.isGuid(cmd.organizationid)) {
return Response.error('`' + cmd.organizationid + '` is not a GUID.');
}
const organization = await this.userService.getOrganization(cmd.organizationid);
if (organization == null) {
return Response.error('Organization not found.');
}
try {
const response = await this.apiService.getOrganizationUsers(cmd.organizationid);
const res = new ListResponse(response.data.map((r) => {
const u = new OrganizationUserResponse();
u.email = r.email;
u.name = r.name;
u.id = r.id;
u.status = r.status;
u.type = r.type;
u.twoFactorEnabled = r.twoFactorEnabled;
return u;
}));
return Response.success(res);
} catch (e) {
return Response.error(e);
}
const res = new ListResponse(decCollections.map((o) => new CollectionResponse(o)));
return Response.success(res);
}
private async listOrganizations(cmd: program.Command) {

View File

@ -0,0 +1,18 @@
import { BaseResponse } from 'jslib/cli/models/response/baseResponse';
import { OrganizationUserStatusType } from 'jslib/enums/organizationUserStatusType';
import { OrganizationUserType } from 'jslib/enums/organizationUserType';
export class OrganizationUserResponse implements BaseResponse {
object: string;
id: string;
email: string;
name: string;
status: OrganizationUserStatusType;
type: OrganizationUserType;
twoFactorEnabled: boolean;
constructor() {
this.object = 'org-member';
}
}

View File

@ -232,6 +232,8 @@ export class Program extends BaseProgram {
writeLn(' folders');
writeLn(' collections');
writeLn(' organizations');
writeLn(' org-collections');
writeLn(' org-members');
writeLn('');
writeLn(' Notes:');
writeLn('');
@ -249,6 +251,7 @@ export class Program extends BaseProgram {
writeLn(' bw list items --organizationid notnull');
writeLn(' bw list items --folderid 60556c31-e649-4b5d-8daf-fc1c391a1bf2 --organizationid notnull');
writeLn(' bw list folders --search email');
writeLn(' bw list org-members --organizationid 60556c31-e649-4b5d-8daf-fc1c391a1bf2');
writeLn('', true);
})
.action(async (object, cmd) => {