1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-24 12:06:15 +01:00

edit item collections

This commit is contained in:
Kyle Spearrin 2018-10-23 17:31:59 -04:00
parent 8f857988ca
commit e0b9d84ad5
5 changed files with 29 additions and 1 deletions

2
jslib

@ -1 +1 @@
Subproject commit 2f6426deb470b71838b51c52587929ac64d428bf Subproject commit 43c0cbce452daff9bcc4c70866a56c8cbd548b4a

View File

@ -39,6 +39,8 @@ export class EditCommand {
switch (object.toLowerCase()) { switch (object.toLowerCase()) {
case 'item': case 'item':
return await this.editCipher(id, req); return await this.editCipher(id, req);
case 'item-collections':
return await this.editCipherCollections(id, req);
case 'folder': case 'folder':
return await this.editFolder(id, req); return await this.editFolder(id, req);
default: 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) { private async editFolder(id: string, req: Folder) {
const folder = await this.folderService.get(id); const folder = await this.folderService.get(id);
if (folder == null) { if (folder == null) {

View File

@ -364,6 +364,9 @@ export class GetCommand {
case 'collection': case 'collection':
template = Collection.template(); template = Collection.template();
break; break;
case 'item-collections':
template = ['collection-id1', 'collection-id2'];
break;
default: default:
return Response.badRequest('Unknown template object.'); return Response.badRequest('Unknown template object.');
} }

View File

@ -14,6 +14,7 @@ export class CipherResponse extends Cipher implements BaseResponse {
attachments: AttachmentResponse[]; attachments: AttachmentResponse[];
revisionDate: Date; revisionDate: Date;
passwordHistory: PasswordHistoryResponse[]; passwordHistory: PasswordHistoryResponse[];
collectionIds: string[];
constructor(o: CipherView) { constructor(o: CipherView) {
super(); super();
@ -23,6 +24,7 @@ export class CipherResponse extends Cipher implements BaseResponse {
if (o.attachments != null) { if (o.attachments != null) {
this.attachments = o.attachments.map((a) => new AttachmentResponse(a)); this.attachments = o.attachments.map((a) => new AttachmentResponse(a));
} }
this.collectionIds = o.collectionIds;
this.revisionDate = o.revisionDate; this.revisionDate = o.revisionDate;
if (o.passwordHistory != null) { if (o.passwordHistory != null) {
this.passwordHistory = o.passwordHistory.map((h) => new PasswordHistoryResponse(h)); this.passwordHistory = o.passwordHistory.map((h) => new PasswordHistoryResponse(h));

View File

@ -317,6 +317,7 @@ export class Program {
writeLn('\n Objects:'); writeLn('\n Objects:');
writeLn(''); writeLn('');
writeLn(' item'); writeLn(' item');
writeLn(' item-collections');
writeLn(' folder'); writeLn(' folder');
writeLn(''); writeLn('');
writeLn(' Id:'); writeLn(' Id:');
@ -332,6 +333,8 @@ export class Program {
writeLn(' bw edit folder 5cdfbd80-d99f-409b-915b-f4c5d0241b02 eyJuYW1lIjoiTXkgRm9sZGVyMiJ9Cg=='); writeLn(' bw edit folder 5cdfbd80-d99f-409b-915b-f4c5d0241b02 eyJuYW1lIjoiTXkgRm9sZGVyMiJ9Cg==');
writeLn(' echo \'eyJuYW1lIjoiTXkgRm9sZGVyMiJ9Cg==\' | ' + writeLn(' echo \'eyJuYW1lIjoiTXkgRm9sZGVyMiJ9Cg==\' | ' +
'bw edit folder 5cdfbd80-d99f-409b-915b-f4c5d0241b02'); 'bw edit folder 5cdfbd80-d99f-409b-915b-f4c5d0241b02');
writeLn(' bw edit item-collections 78307355-fd25-416b-88b8-b33fd0e88c82 ' +
'WyI5NzQwNTNkMC0zYjMzLTRiOTgtODg2ZS1mZWNmNWM4ZGJhOTYiXQ==');
writeLn('', true); writeLn('', true);
}) })
.action(async (object, id, encodedJson, cmd) => { .action(async (object, id, encodedJson, cmd) => {