diff --git a/jslib b/jslib index 2f6426deb4..43c0cbce45 160000 --- a/jslib +++ b/jslib @@ -1 +1 @@ -Subproject commit 2f6426deb470b71838b51c52587929ac64d428bf +Subproject commit 43c0cbce452daff9bcc4c70866a56c8cbd548b4a diff --git a/src/commands/edit.command.ts b/src/commands/edit.command.ts index 1947758fc1..35e4b9ecd6 100644 --- a/src/commands/edit.command.ts +++ b/src/commands/edit.command.ts @@ -39,6 +39,8 @@ export class EditCommand { switch (object.toLowerCase()) { case 'item': return await this.editCipher(id, req); + case 'item-collections': + return await this.editCipherCollections(id, req); case 'folder': return await this.editFolder(id, req); default: @@ -66,6 +68,24 @@ export class EditCommand { } } + private async editCipherCollections(id: string, req: string[]) { + const cipher = await this.cipherService.get(id); + if (cipher == null) { + return Response.notFound(); + } + + cipher.collectionIds = req; + try { + await this.cipherService.saveCollectionsWithServer(cipher); + const updatedCipher = await this.cipherService.get(cipher.id); + const decCipher = await updatedCipher.decrypt(); + const res = new CipherResponse(decCipher); + return Response.success(res); + } catch (e) { + return Response.error(e); + } + } + private async editFolder(id: string, req: Folder) { const folder = await this.folderService.get(id); if (folder == null) { diff --git a/src/commands/get.command.ts b/src/commands/get.command.ts index f850903f50..28c4e9b6ba 100644 --- a/src/commands/get.command.ts +++ b/src/commands/get.command.ts @@ -364,6 +364,9 @@ export class GetCommand { case 'collection': template = Collection.template(); break; + case 'item-collections': + template = ['collection-id1', 'collection-id2']; + break; default: return Response.badRequest('Unknown template object.'); } diff --git a/src/models/response/cipherResponse.ts b/src/models/response/cipherResponse.ts index a481016cc7..87202d4da2 100644 --- a/src/models/response/cipherResponse.ts +++ b/src/models/response/cipherResponse.ts @@ -14,6 +14,7 @@ export class CipherResponse extends Cipher implements BaseResponse { attachments: AttachmentResponse[]; revisionDate: Date; passwordHistory: PasswordHistoryResponse[]; + collectionIds: string[]; constructor(o: CipherView) { super(); @@ -23,6 +24,7 @@ export class CipherResponse extends Cipher implements BaseResponse { if (o.attachments != null) { this.attachments = o.attachments.map((a) => new AttachmentResponse(a)); } + this.collectionIds = o.collectionIds; this.revisionDate = o.revisionDate; if (o.passwordHistory != null) { this.passwordHistory = o.passwordHistory.map((h) => new PasswordHistoryResponse(h)); diff --git a/src/program.ts b/src/program.ts index 09ae0e995c..017d3e40b2 100644 --- a/src/program.ts +++ b/src/program.ts @@ -317,6 +317,7 @@ export class Program { writeLn('\n Objects:'); writeLn(''); writeLn(' item'); + writeLn(' item-collections'); writeLn(' folder'); writeLn(''); writeLn(' Id:'); @@ -332,6 +333,8 @@ export class Program { writeLn(' bw edit folder 5cdfbd80-d99f-409b-915b-f4c5d0241b02 eyJuYW1lIjoiTXkgRm9sZGVyMiJ9Cg=='); writeLn(' echo \'eyJuYW1lIjoiTXkgRm9sZGVyMiJ9Cg==\' | ' + 'bw edit folder 5cdfbd80-d99f-409b-915b-f4c5d0241b02'); + writeLn(' bw edit item-collections 78307355-fd25-416b-88b8-b33fd0e88c82 ' + + 'WyI5NzQwNTNkMC0zYjMzLTRiOTgtODg2ZS1mZWNmNWM4ZGJhOTYiXQ=='); writeLn('', true); }) .action(async (object, id, encodedJson, cmd) => {