1
0
mirror of https://github.com/bitwarden/cli synced 2025-12-15 15:53:44 +00:00

list and get organizations

This commit is contained in:
Kyle Spearrin
2018-05-18 15:26:59 -04:00
parent 7c33af769e
commit 2e8d0aaf53
6 changed files with 87 additions and 7 deletions

View File

@@ -1,20 +1,22 @@
import * as program from 'commander';
import { CipherService } from 'jslib/abstractions/cipher.service';
import { CollectionService } from 'jslib/services/collection.service';
import { FolderService } from 'jslib/services/folder.service';
import { CollectionService } from 'jslib/abstractions/collection.service';
import { FolderService } from 'jslib/abstractions/folder.service';
import { UserService } from 'jslib/abstractions/user.service';
import { Response } from '../models/response';
import { CipherResponse } from '../models/response/cipherResponse';
import { CollectionResponse } from '../models/response/collectionResponse';
import { FolderResponse } from '../models/response/folderResponse';
import { ListResponse } from '../models/response/listResponse';
import { OrganizationResponse } from '../models/response/organizationResponse';
import { CliUtils } from '../utils';
export class ListCommand {
constructor(private cipherService: CipherService, private folderService: FolderService,
private collectionService: CollectionService) { }
private collectionService: CollectionService, private userService: UserService) { }
async run(object: string, cmd: program.Command): Promise<Response> {
switch (object.toLowerCase()) {
@@ -24,6 +26,8 @@ export class ListCommand {
return await this.listFolders(cmd);
case 'collections':
return await this.listCollections(cmd);
case 'organizations':
return await this.listOrganizations(cmd);
default:
return Response.badRequest('Unknown object.');
}
@@ -108,4 +112,15 @@ export class ListCommand {
const res = new ListResponse(collections.map((o) => new CollectionResponse(o)));
return Response.success(res);
}
private async listOrganizations(cmd: program.Command) {
let organizations = await this.userService.getAllOrganizations();
if (cmd.search != null && cmd.search.trim() !== '') {
organizations = CliUtils.searchOrganizations(organizations, cmd.search);
}
const res = new ListResponse(organizations.map((o) => new OrganizationResponse(o)));
return Response.success(res);
}
}