1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-16 08:13:42 +00:00

add support for syncing collections

This commit is contained in:
Kyle Spearrin
2017-11-22 13:17:59 -05:00
parent 04cfd8040c
commit 2d81466d25
11 changed files with 231 additions and 3 deletions

View File

@@ -28,6 +28,7 @@ class CipherData {
identity?: IdentityData;
fields?: FieldData[];
attachments?: AttachmentData[];
collectionIds?: string[];
constructor(response: CipherResponse, userId: string) {
this.id = response.id;
@@ -39,6 +40,7 @@ class CipherData {
this.favorite = response.favorite;
this.revisionDate = response.revisionDate;
this.type = response.type;
this.collectionIds = response.collectionIds;
this.name = response.data.Name;
this.notes = response.data.Notes;

View File

@@ -0,0 +1,16 @@
import { CollectionResponse } from '../response/collectionResponse';
class CollectionData {
id: string;
organizationId: string;
name: string;
constructor(response: CollectionResponse) {
this.id = response.id;
this.organizationId = response.organizationId;
this.name = response.name;
}
}
export { CollectionData };
(window as any).CollectionData = CollectionData;

View File

@@ -30,6 +30,7 @@ class Cipher extends Domain {
secureNote: SecureNote;
attachments: Attachment[];
fields: Field[];
collectionIds: string[];
private utilsService: UtilsService;
@@ -51,6 +52,7 @@ class Cipher extends Domain {
this.favorite = obj.favorite;
this.organizationUseTotp = obj.organizationUseTotp;
this.edit = obj.edit;
this.collectionIds = obj.collectionIds;
this.localData = localData;
switch (this.type) {
@@ -104,6 +106,7 @@ class Cipher extends Domain {
subTitle: null as string,
attachments: null as any[],
fields: null as any[],
collectionIds: this.collectionIds,
};
await this.decryptObj(model, {

View File

@@ -0,0 +1,37 @@
import { CollectionData } from '../data/collectionData';
import { CipherString } from './cipherString';
import Domain from './domain';
class Collection extends Domain {
id: string;
organizationId: string;
name: CipherString;
constructor(obj?: CollectionData, alreadyEncrypted: boolean = false) {
super();
if (obj == null) {
return;
}
this.buildDomainModel(this, obj, {
id: null,
organizationId: null,
name: null,
}, alreadyEncrypted, ['id', 'organizationId']);
}
decrypt(): Promise<any> {
const model = {
id: this.id,
organizationId: this.organizationId,
};
return this.decryptObj(model, {
name: null,
}, this.organizationId);
}
}
export { Collection };
(window as any).Collection = Collection;

View File

@@ -11,6 +11,7 @@ class CipherResponse {
data: any;
revisionDate: string;
attachments: AttachmentResponse[];
collectionIds: string[];
constructor(response: any) {
this.id = response.Id;
@@ -29,6 +30,13 @@ class CipherResponse {
this.attachments.push(new AttachmentResponse(attachment));
});
}
if (response.CollectionIds) {
this.collectionIds = [];
response.CollectionIds.forEach((id: string) => {
this.collectionIds.push(id);
});
}
}
}

View File

@@ -0,0 +1,14 @@
class CollectionResponse {
id: string;
organizationId: string;
name: string;
constructor(response: any) {
this.id = response.Id;
this.organizationId = response.OrganizationId;
this.name = response.Name;
}
}
export { CollectionResponse };
(window as any).CollectionResponse = CollectionResponse;

View File

@@ -1,4 +1,5 @@
import { CipherResponse } from './cipherResponse';
import { CollectionResponse } from './collectionResponse';
import { DomainsResponse } from './domainsResponse';
import { FolderResponse } from './folderResponse';
import { ProfileResponse } from './profileResponse';
@@ -6,6 +7,7 @@ import { ProfileResponse } from './profileResponse';
class SyncResponse {
profile?: ProfileResponse;
folders: FolderResponse[] = [];
collections: CollectionResponse[] = [];
ciphers: CipherResponse[] = [];
domains?: DomainsResponse;
@@ -20,6 +22,12 @@ class SyncResponse {
});
}
if (response.Collections) {
response.Collections.forEach((collection: any) => {
this.collections.push(new CollectionResponse(collection));
});
}
if (response.Ciphers) {
response.Ciphers.forEach((cipher: any) => {
this.ciphers.push(new CipherResponse(cipher));