diff --git a/jslib b/jslib index 034aefa652..83d6b2449c 160000 --- a/jslib +++ b/jslib @@ -1 +1 @@ -Subproject commit 034aefa652459c9ed5a660fe13593e314ee368dc +Subproject commit 83d6b2449cba8390912b692d882f400723c01dc1 diff --git a/src/commands/list.command.ts b/src/commands/list.command.ts index dbe99d69b0..847bf55f08 100644 --- a/src/commands/list.command.ts +++ b/src/commands/list.command.ts @@ -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; - if (organization.isAdmin) { - response = await this.apiService.getCollections(cmd.organizationId); - } else { - response = await this.apiService.getUserCollections(); + try { + let response: ApiListResponse; + 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 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) { diff --git a/src/models/response/organizationUserResponse.ts b/src/models/response/organizationUserResponse.ts new file mode 100644 index 0000000000..690e3630f3 --- /dev/null +++ b/src/models/response/organizationUserResponse.ts @@ -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'; + } +} diff --git a/src/program.ts b/src/program.ts index 4378a98896..e068974c8a 100644 --- a/src/program.ts +++ b/src/program.ts @@ -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) => {