mirror of
https://github.com/bitwarden/cli
synced 2025-12-14 23:33:35 +00:00
list org-members command
This commit is contained in:
2
jslib
2
jslib
Submodule jslib updated: 034aefa652...83d6b2449c
@@ -26,6 +26,7 @@ import { CipherResponse } from '../models/response/cipherResponse';
|
|||||||
import { CollectionResponse } from '../models/response/collectionResponse';
|
import { CollectionResponse } from '../models/response/collectionResponse';
|
||||||
import { FolderResponse } from '../models/response/folderResponse';
|
import { FolderResponse } from '../models/response/folderResponse';
|
||||||
import { OrganizationResponse } from '../models/response/organizationResponse';
|
import { OrganizationResponse } from '../models/response/organizationResponse';
|
||||||
|
import { OrganizationUserResponse } from '../models/response/organizationUserResponse';
|
||||||
|
|
||||||
import { CliUtils } from '../utils';
|
import { CliUtils } from '../utils';
|
||||||
|
|
||||||
@@ -46,6 +47,8 @@ export class ListCommand {
|
|||||||
return await this.listCollections(cmd);
|
return await this.listCollections(cmd);
|
||||||
case 'org-collections':
|
case 'org-collections':
|
||||||
return await this.listOrganizationCollections(cmd);
|
return await this.listOrganizationCollections(cmd);
|
||||||
|
case 'org-members':
|
||||||
|
return await this.listOrganizationMembers(cmd);
|
||||||
case 'organizations':
|
case 'organizations':
|
||||||
return await this.listOrganizations(cmd);
|
return await this.listOrganizations(cmd);
|
||||||
default:
|
default:
|
||||||
@@ -150,20 +153,54 @@ export class ListCommand {
|
|||||||
return Response.error('Organization not found.');
|
return Response.error('Organization not found.');
|
||||||
}
|
}
|
||||||
|
|
||||||
let response: ApiListResponse<ApiCollectionResponse>;
|
try {
|
||||||
if (organization.isAdmin) {
|
let response: ApiListResponse<ApiCollectionResponse>;
|
||||||
response = await this.apiService.getCollections(cmd.organizationId);
|
if (organization.isAdmin) {
|
||||||
} else {
|
response = await this.apiService.getCollections(cmd.organizationid);
|
||||||
response = await this.apiService.getUserCollections();
|
} 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);
|
private async listOrganizationMembers(cmd: program.Command) {
|
||||||
if (cmd.search != null && cmd.search.trim() !== '') {
|
if (cmd.organizationid == null || cmd.organizationid === '') {
|
||||||
decCollections = CliUtils.searchCollections(decCollections, cmd.search);
|
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) {
|
private async listOrganizations(cmd: program.Command) {
|
||||||
|
|||||||
18
src/models/response/organizationUserResponse.ts
Normal file
18
src/models/response/organizationUserResponse.ts
Normal 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';
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -232,6 +232,8 @@ export class Program extends BaseProgram {
|
|||||||
writeLn(' folders');
|
writeLn(' folders');
|
||||||
writeLn(' collections');
|
writeLn(' collections');
|
||||||
writeLn(' organizations');
|
writeLn(' organizations');
|
||||||
|
writeLn(' org-collections');
|
||||||
|
writeLn(' org-members');
|
||||||
writeLn('');
|
writeLn('');
|
||||||
writeLn(' Notes:');
|
writeLn(' Notes:');
|
||||||
writeLn('');
|
writeLn('');
|
||||||
@@ -249,6 +251,7 @@ export class Program extends BaseProgram {
|
|||||||
writeLn(' bw list items --organizationid notnull');
|
writeLn(' bw list items --organizationid notnull');
|
||||||
writeLn(' bw list items --folderid 60556c31-e649-4b5d-8daf-fc1c391a1bf2 --organizationid notnull');
|
writeLn(' bw list items --folderid 60556c31-e649-4b5d-8daf-fc1c391a1bf2 --organizationid notnull');
|
||||||
writeLn(' bw list folders --search email');
|
writeLn(' bw list folders --search email');
|
||||||
|
writeLn(' bw list org-members --organizationid 60556c31-e649-4b5d-8daf-fc1c391a1bf2');
|
||||||
writeLn('', true);
|
writeLn('', true);
|
||||||
})
|
})
|
||||||
.action(async (object, cmd) => {
|
.action(async (object, cmd) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user