Skip to content

Commit 50cee3c

Browse files
authored
[PM-22099] expose default collection in clients collection service (#15122)
* Add types * rename types * fix types * fix model and tests
1 parent d8c544f commit 50cee3c

File tree

6 files changed

+28
-4
lines changed

6 files changed

+28
-4
lines changed

libs/admin-console/src/common/collections/models/collection.data.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Jsonify } from "type-fest";
22

33
import { CollectionId, OrganizationId } from "@bitwarden/common/types/guid";
44

5+
import { CollectionType } from "./collection";
56
import { CollectionDetailsResponse } from "./collection.response";
67

78
export class CollectionData {
@@ -12,6 +13,7 @@ export class CollectionData {
1213
readOnly: boolean;
1314
manage: boolean;
1415
hidePasswords: boolean;
16+
type: CollectionType;
1517

1618
constructor(response: CollectionDetailsResponse) {
1719
this.id = response.id;
@@ -21,6 +23,7 @@ export class CollectionData {
2123
this.readOnly = response.readOnly;
2224
this.manage = response.manage;
2325
this.hidePasswords = response.hidePasswords;
26+
this.type = response.type;
2427
}
2528

2629
static fromJSON(obj: Jsonify<CollectionData>) {

libs/admin-console/src/common/collections/models/collection.response.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,22 @@ import { SelectionReadOnlyResponse } from "@bitwarden/common/admin-console/model
22
import { BaseResponse } from "@bitwarden/common/models/response/base.response";
33
import { CollectionId, OrganizationId } from "@bitwarden/common/types/guid";
44

5+
import { CollectionType } from "./collection";
6+
57
export class CollectionResponse extends BaseResponse {
68
id: CollectionId;
79
organizationId: OrganizationId;
810
name: string;
911
externalId: string;
12+
type: CollectionType;
1013

1114
constructor(response: any) {
1215
super(response);
1316
this.id = this.getResponseProperty("Id");
1417
this.organizationId = this.getResponseProperty("OrganizationId");
1518
this.name = this.getResponseProperty("Name");
1619
this.externalId = this.getResponseProperty("ExternalId");
20+
this.type = this.getResponseProperty("Type");
1721
}
1822
}
1923

libs/admin-console/src/common/collections/models/collection.spec.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { makeSymmetricCryptoKey, mockEnc } from "@bitwarden/common/spec";
22
import { CollectionId, OrganizationId } from "@bitwarden/common/types/guid";
33
import { OrgKey } from "@bitwarden/common/types/key";
44

5-
import { Collection } from "./collection";
5+
import { Collection, CollectionTypes } from "./collection";
66
import { CollectionData } from "./collection.data";
77

88
describe("Collection", () => {
@@ -17,6 +17,7 @@ describe("Collection", () => {
1717
readOnly: true,
1818
manage: true,
1919
hidePasswords: true,
20+
type: CollectionTypes.DefaultUserCollection,
2021
};
2122
});
2223

@@ -32,6 +33,7 @@ describe("Collection", () => {
3233
organizationId: null,
3334
readOnly: null,
3435
manage: null,
36+
type: null,
3537
});
3638
});
3739

@@ -46,6 +48,7 @@ describe("Collection", () => {
4648
readOnly: true,
4749
manage: true,
4850
hidePasswords: true,
51+
type: CollectionTypes.DefaultUserCollection,
4952
});
5053
});
5154

@@ -58,6 +61,7 @@ describe("Collection", () => {
5861
collection.readOnly = false;
5962
collection.hidePasswords = false;
6063
collection.manage = true;
64+
collection.type = CollectionTypes.DefaultUserCollection;
6165

6266
const key = makeSymmetricCryptoKey<OrgKey>();
6367

@@ -72,6 +76,7 @@ describe("Collection", () => {
7276
readOnly: false,
7377
manage: true,
7478
assigned: true,
79+
type: CollectionTypes.DefaultUserCollection,
7580
});
7681
});
7782
});

libs/admin-console/src/common/collections/models/collection.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ import { OrgKey } from "@bitwarden/common/types/key";
77
import { CollectionData } from "./collection.data";
88
import { CollectionView } from "./collection.view";
99

10+
export const CollectionTypes = {
11+
SharedCollection: 0,
12+
DefaultUserCollection: 1,
13+
} as const;
14+
15+
export type CollectionType = (typeof CollectionTypes)[keyof typeof CollectionTypes];
16+
1017
export class Collection extends Domain {
1118
id: string;
1219
organizationId: string;
@@ -15,6 +22,7 @@ export class Collection extends Domain {
1522
readOnly: boolean;
1623
hidePasswords: boolean;
1724
manage: boolean;
25+
type: CollectionType;
1826

1927
constructor(obj?: CollectionData) {
2028
super();
@@ -33,8 +41,9 @@ export class Collection extends Domain {
3341
readOnly: null,
3442
hidePasswords: null,
3543
manage: null,
44+
type: null,
3645
},
37-
["id", "organizationId", "readOnly", "hidePasswords", "manage"],
46+
["id", "organizationId", "readOnly", "hidePasswords", "manage", "type"],
3847
);
3948
}
4049

libs/admin-console/src/common/collections/models/collection.view.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { Organization } from "@bitwarden/common/admin-console/models/domain/orga
66
import { View } from "@bitwarden/common/models/view/view";
77
import { ITreeNodeObject } from "@bitwarden/common/vault/models/domain/tree-node";
88

9-
import { Collection } from "./collection";
9+
import { Collection, CollectionType } from "./collection";
1010
import { CollectionAccessDetailsResponse } from "./collection.response";
1111

1212
export const NestingDelimiter = "/";
@@ -21,6 +21,7 @@ export class CollectionView implements View, ITreeNodeObject {
2121
hidePasswords: boolean = null;
2222
manage: boolean = null;
2323
assigned: boolean = null;
24+
type: CollectionType = null;
2425

2526
constructor(c?: Collection | CollectionAccessDetailsResponse) {
2627
if (!c) {
@@ -39,6 +40,7 @@ export class CollectionView implements View, ITreeNodeObject {
3940
if (c instanceof CollectionAccessDetailsResponse) {
4041
this.assigned = c.assigned;
4142
}
43+
this.type = c.type;
4244
}
4345

4446
canEditItems(org: Organization): boolean {

libs/vault/src/cipher-form/components/item-details/item-details-section.component.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { BehaviorSubject } from "rxjs";
77

88
// This import has been flagged as unallowed for this class. It may be involved in a circular dependency loop.
99
// eslint-disable-next-line no-restricted-imports
10-
import { CollectionView } from "@bitwarden/admin-console/common";
10+
import { CollectionTypes, CollectionView } from "@bitwarden/admin-console/common";
1111
import { Organization } from "@bitwarden/common/admin-console/models/domain/organization";
1212
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
1313
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
@@ -35,6 +35,7 @@ const createMockCollection = (
3535
hidePasswords: false,
3636
manage: true,
3737
assigned: true,
38+
type: CollectionTypes.DefaultUserCollection,
3839
canEditItems: jest.fn().mockReturnValue(canEdit),
3940
canEdit: jest.fn(),
4041
canDelete: jest.fn(),

0 commit comments

Comments
 (0)