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()) {
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) {

View File

@ -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.');
}

View File

@ -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));

View File

@ -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) => {