mirror of
https://github.com/bitwarden/browser
synced 2025-01-19 16:00:53 +01:00
delete org collection command
This commit is contained in:
parent
6df7d2a2f2
commit
abcd43b4ba
2
jslib
2
jslib
@ -1 +1 @@
|
|||||||
Subproject commit 53d08067df953e7a66ebf0b972e6443e1f275d86
|
Subproject commit 034aefa652459c9ed5a660fe13593e314ee368dc
|
@ -1,14 +1,17 @@
|
|||||||
import * as program from 'commander';
|
import * as program from 'commander';
|
||||||
|
|
||||||
|
import { ApiService } from 'jslib/abstractions/api.service';
|
||||||
import { CipherService } from 'jslib/abstractions/cipher.service';
|
import { CipherService } from 'jslib/abstractions/cipher.service';
|
||||||
import { FolderService } from 'jslib/abstractions/folder.service';
|
import { FolderService } from 'jslib/abstractions/folder.service';
|
||||||
import { UserService } from 'jslib/abstractions/user.service';
|
import { UserService } from 'jslib/abstractions/user.service';
|
||||||
|
|
||||||
import { Response } from 'jslib/cli/models/response';
|
import { Response } from 'jslib/cli/models/response';
|
||||||
|
|
||||||
|
import { Utils } from 'jslib/misc/utils';
|
||||||
|
|
||||||
export class DeleteCommand {
|
export class DeleteCommand {
|
||||||
constructor(private cipherService: CipherService, private folderService: FolderService,
|
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> {
|
async run(object: string, id: string, cmd: program.Command): Promise<Response> {
|
||||||
if (id != null) {
|
if (id != null) {
|
||||||
@ -22,6 +25,8 @@ export class DeleteCommand {
|
|||||||
return await this.deleteAttachment(id, cmd);
|
return await this.deleteAttachment(id, cmd);
|
||||||
case 'folder':
|
case 'folder':
|
||||||
return await this.deleteFolder(id);
|
return await this.deleteFolder(id);
|
||||||
|
case 'org-collection':
|
||||||
|
return await this.deleteOrganizationCollection(id, cmd);
|
||||||
default:
|
default:
|
||||||
return Response.badRequest('Unknown object.');
|
return Response.badRequest('Unknown object.');
|
||||||
}
|
}
|
||||||
@ -86,4 +91,22 @@ export class DeleteCommand {
|
|||||||
return Response.error(e);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -96,7 +96,7 @@ export class GetCommand {
|
|||||||
|
|
||||||
private async getCipherView(id: string): Promise<CipherView | string[]> {
|
private async getCipherView(id: string): Promise<CipherView | string[]> {
|
||||||
let decCipher: CipherView = null;
|
let decCipher: CipherView = null;
|
||||||
if (this.isGuid(id)) {
|
if (Utils.isGuid(id)) {
|
||||||
const cipher = await this.cipherService.get(id);
|
const cipher = await this.cipherService.get(id);
|
||||||
if (cipher != null) {
|
if (cipher != null) {
|
||||||
decCipher = await cipher.decrypt();
|
decCipher = await cipher.decrypt();
|
||||||
@ -285,7 +285,7 @@ export class GetCommand {
|
|||||||
|
|
||||||
private async getFolder(id: string) {
|
private async getFolder(id: string) {
|
||||||
let decFolder: FolderView = null;
|
let decFolder: FolderView = null;
|
||||||
if (this.isGuid(id)) {
|
if (Utils.isGuid(id)) {
|
||||||
const folder = await this.folderService.get(id);
|
const folder = await this.folderService.get(id);
|
||||||
if (folder != null) {
|
if (folder != null) {
|
||||||
decFolder = await folder.decrypt();
|
decFolder = await folder.decrypt();
|
||||||
@ -310,7 +310,7 @@ export class GetCommand {
|
|||||||
|
|
||||||
private async getCollection(id: string) {
|
private async getCollection(id: string) {
|
||||||
let decCollection: CollectionView = null;
|
let decCollection: CollectionView = null;
|
||||||
if (this.isGuid(id)) {
|
if (Utils.isGuid(id)) {
|
||||||
const collection = await this.collectionService.get(id);
|
const collection = await this.collectionService.get(id);
|
||||||
if (collection != null) {
|
if (collection != null) {
|
||||||
decCollection = await collection.decrypt();
|
decCollection = await collection.decrypt();
|
||||||
@ -337,10 +337,10 @@ export class GetCommand {
|
|||||||
if (cmd.organizationid == null || cmd.organizationid === '') {
|
if (cmd.organizationid == null || cmd.organizationid === '') {
|
||||||
return Response.badRequest('--organizationid <organizationid> required.');
|
return Response.badRequest('--organizationid <organizationid> required.');
|
||||||
}
|
}
|
||||||
if (!this.isGuid(id)) {
|
if (!Utils.isGuid(id)) {
|
||||||
return Response.error('`' + id + '` is not a GUID.');
|
return Response.error('`' + id + '` is not a GUID.');
|
||||||
}
|
}
|
||||||
if (!this.isGuid(cmd.organizationid)) {
|
if (!Utils.isGuid(cmd.organizationid)) {
|
||||||
return Response.error('`' + cmd.organizationid + '` is not a GUID.');
|
return Response.error('`' + cmd.organizationid + '` is not a GUID.');
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
@ -364,7 +364,7 @@ export class GetCommand {
|
|||||||
|
|
||||||
private async getOrganization(id: string) {
|
private async getOrganization(id: string) {
|
||||||
let org: Organization = null;
|
let org: Organization = null;
|
||||||
if (this.isGuid(id)) {
|
if (Utils.isGuid(id)) {
|
||||||
org = await this.userService.getOrganization(id);
|
org = await this.userService.getOrganization(id);
|
||||||
} else if (id.trim() !== '') {
|
} else if (id.trim() !== '') {
|
||||||
let orgs = await this.userService.getAllOrganizations();
|
let orgs = await this.userService.getAllOrganizations();
|
||||||
@ -384,10 +384,6 @@ export class GetCommand {
|
|||||||
return Response.success(res);
|
return Response.success(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
private isGuid(id: string) {
|
|
||||||
return RegExp(/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/, 'i').test(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
private async getTemplate(id: string) {
|
private async getTemplate(id: string) {
|
||||||
let template: any = null;
|
let template: any = null;
|
||||||
switch (id.toLowerCase()) {
|
switch (id.toLowerCase()) {
|
||||||
@ -436,7 +432,7 @@ export class GetCommand {
|
|||||||
let fingerprint: string[] = null;
|
let fingerprint: string[] = null;
|
||||||
if (id === 'me') {
|
if (id === 'me') {
|
||||||
fingerprint = await this.cryptoService.getFingerprint(await this.userService.getUserId());
|
fingerprint = await this.cryptoService.getFingerprint(await this.userService.getUserId());
|
||||||
} else if (this.isGuid(id)) {
|
} else if (Utils.isGuid(id)) {
|
||||||
try {
|
try {
|
||||||
const response = await this.apiService.getUserPublicKey(id);
|
const response = await this.apiService.getUserPublicKey(id);
|
||||||
const pubKey = Utils.fromB64ToArray(response.publicKey);
|
const pubKey = Utils.fromB64ToArray(response.publicKey);
|
||||||
|
@ -277,6 +277,7 @@ export class Program extends BaseProgram {
|
|||||||
writeLn(' attachment');
|
writeLn(' attachment');
|
||||||
writeLn(' folder');
|
writeLn(' folder');
|
||||||
writeLn(' collection');
|
writeLn(' collection');
|
||||||
|
writeLn(' org-collection');
|
||||||
writeLn(' organization');
|
writeLn(' organization');
|
||||||
writeLn(' template');
|
writeLn(' template');
|
||||||
writeLn(' fingerprint');
|
writeLn(' fingerprint');
|
||||||
@ -319,6 +320,7 @@ export class Program extends BaseProgram {
|
|||||||
writeLn(' item');
|
writeLn(' item');
|
||||||
writeLn(' attachment');
|
writeLn(' attachment');
|
||||||
writeLn(' folder');
|
writeLn(' folder');
|
||||||
|
writeLn(' org-collection');
|
||||||
writeLn('');
|
writeLn('');
|
||||||
writeLn(' Notes:');
|
writeLn(' Notes:');
|
||||||
writeLn('');
|
writeLn('');
|
||||||
@ -377,6 +379,7 @@ export class Program extends BaseProgram {
|
|||||||
program
|
program
|
||||||
.command('delete <object> <id>')
|
.command('delete <object> <id>')
|
||||||
.option('--itemid <itemid>', 'Attachment\'s item id.')
|
.option('--itemid <itemid>', 'Attachment\'s item id.')
|
||||||
|
.option('--organizationid <organizationid>', 'Organization id for an organization object.')
|
||||||
.description('Delete an object from the vault.')
|
.description('Delete an object from the vault.')
|
||||||
.on('--help', () => {
|
.on('--help', () => {
|
||||||
writeLn('\n Objects:');
|
writeLn('\n Objects:');
|
||||||
@ -384,6 +387,7 @@ export class Program extends BaseProgram {
|
|||||||
writeLn(' item');
|
writeLn(' item');
|
||||||
writeLn(' attachment');
|
writeLn(' attachment');
|
||||||
writeLn(' folder');
|
writeLn(' folder');
|
||||||
|
writeLn(' org-collection');
|
||||||
writeLn('');
|
writeLn('');
|
||||||
writeLn(' Id:');
|
writeLn(' Id:');
|
||||||
writeLn('');
|
writeLn('');
|
||||||
@ -399,7 +403,7 @@ export class Program extends BaseProgram {
|
|||||||
.action(async (object, id, cmd) => {
|
.action(async (object, id, cmd) => {
|
||||||
await this.exitIfLocked();
|
await this.exitIfLocked();
|
||||||
const command = new DeleteCommand(this.main.cipherService, this.main.folderService,
|
const command = new DeleteCommand(this.main.cipherService, this.main.folderService,
|
||||||
this.main.userService);
|
this.main.userService, this.main.apiService);
|
||||||
const response = await command.run(object, id, cmd);
|
const response = await command.run(object, id, cmd);
|
||||||
this.processResponse(response);
|
this.processResponse(response);
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user