mirror of
https://github.com/bitwarden/browser
synced 2025-12-13 14:53:33 +00:00
delete org collection command
This commit is contained in:
@@ -1,14 +1,17 @@
|
||||
import * as program from 'commander';
|
||||
|
||||
import { ApiService } from 'jslib/abstractions/api.service';
|
||||
import { CipherService } from 'jslib/abstractions/cipher.service';
|
||||
import { FolderService } from 'jslib/abstractions/folder.service';
|
||||
import { UserService } from 'jslib/abstractions/user.service';
|
||||
|
||||
import { Response } from 'jslib/cli/models/response';
|
||||
|
||||
import { Utils } from 'jslib/misc/utils';
|
||||
|
||||
export class DeleteCommand {
|
||||
constructor(private cipherService: CipherService, private folderService: FolderService,
|
||||
private userService: UserService) { }
|
||||
private userService: UserService, private apiService: ApiService) { }
|
||||
|
||||
async run(object: string, id: string, cmd: program.Command): Promise<Response> {
|
||||
if (id != null) {
|
||||
@@ -22,6 +25,8 @@ export class DeleteCommand {
|
||||
return await this.deleteAttachment(id, cmd);
|
||||
case 'folder':
|
||||
return await this.deleteFolder(id);
|
||||
case 'org-collection':
|
||||
return await this.deleteOrganizationCollection(id, cmd);
|
||||
default:
|
||||
return Response.badRequest('Unknown object.');
|
||||
}
|
||||
@@ -86,4 +91,22 @@ export class DeleteCommand {
|
||||
return Response.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
private async deleteOrganizationCollection(id: string, cmd: program.Command) {
|
||||
if (cmd.organizationid == null || cmd.organizationid === '') {
|
||||
return Response.badRequest('--organizationid <organizationid> required.');
|
||||
}
|
||||
if (!Utils.isGuid(id)) {
|
||||
return Response.error('`' + id + '` is not a GUID.');
|
||||
}
|
||||
if (!Utils.isGuid(cmd.organizationid)) {
|
||||
return Response.error('`' + cmd.organizationid + '` is not a GUID.');
|
||||
}
|
||||
try {
|
||||
await this.apiService.deleteCollection(cmd.organizationid, id);
|
||||
return Response.success();
|
||||
} catch (e) {
|
||||
return Response.error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user