1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-11 22:03:36 +00:00

[PM-22099] expose default collection in clients collection service (#15122)

* Add types

* rename types

* fix types

* fix model and tests
This commit is contained in:
Brandon Treston
2025-06-11 11:39:47 -04:00
committed by GitHub
parent d8c544fd65
commit 50cee3cd9a
6 changed files with 28 additions and 4 deletions

View File

@@ -2,6 +2,7 @@ import { Jsonify } from "type-fest";
import { CollectionId, OrganizationId } from "@bitwarden/common/types/guid"; import { CollectionId, OrganizationId } from "@bitwarden/common/types/guid";
import { CollectionType } from "./collection";
import { CollectionDetailsResponse } from "./collection.response"; import { CollectionDetailsResponse } from "./collection.response";
export class CollectionData { export class CollectionData {
@@ -12,6 +13,7 @@ export class CollectionData {
readOnly: boolean; readOnly: boolean;
manage: boolean; manage: boolean;
hidePasswords: boolean; hidePasswords: boolean;
type: CollectionType;
constructor(response: CollectionDetailsResponse) { constructor(response: CollectionDetailsResponse) {
this.id = response.id; this.id = response.id;
@@ -21,6 +23,7 @@ export class CollectionData {
this.readOnly = response.readOnly; this.readOnly = response.readOnly;
this.manage = response.manage; this.manage = response.manage;
this.hidePasswords = response.hidePasswords; this.hidePasswords = response.hidePasswords;
this.type = response.type;
} }
static fromJSON(obj: Jsonify<CollectionData>) { static fromJSON(obj: Jsonify<CollectionData>) {

View File

@@ -2,11 +2,14 @@ import { SelectionReadOnlyResponse } from "@bitwarden/common/admin-console/model
import { BaseResponse } from "@bitwarden/common/models/response/base.response"; import { BaseResponse } from "@bitwarden/common/models/response/base.response";
import { CollectionId, OrganizationId } from "@bitwarden/common/types/guid"; import { CollectionId, OrganizationId } from "@bitwarden/common/types/guid";
import { CollectionType } from "./collection";
export class CollectionResponse extends BaseResponse { export class CollectionResponse extends BaseResponse {
id: CollectionId; id: CollectionId;
organizationId: OrganizationId; organizationId: OrganizationId;
name: string; name: string;
externalId: string; externalId: string;
type: CollectionType;
constructor(response: any) { constructor(response: any) {
super(response); super(response);
@@ -14,6 +17,7 @@ export class CollectionResponse extends BaseResponse {
this.organizationId = this.getResponseProperty("OrganizationId"); this.organizationId = this.getResponseProperty("OrganizationId");
this.name = this.getResponseProperty("Name"); this.name = this.getResponseProperty("Name");
this.externalId = this.getResponseProperty("ExternalId"); this.externalId = this.getResponseProperty("ExternalId");
this.type = this.getResponseProperty("Type");
} }
} }

View File

@@ -2,7 +2,7 @@ import { makeSymmetricCryptoKey, mockEnc } from "@bitwarden/common/spec";
import { CollectionId, OrganizationId } from "@bitwarden/common/types/guid"; import { CollectionId, OrganizationId } from "@bitwarden/common/types/guid";
import { OrgKey } from "@bitwarden/common/types/key"; import { OrgKey } from "@bitwarden/common/types/key";
import { Collection } from "./collection"; import { Collection, CollectionTypes } from "./collection";
import { CollectionData } from "./collection.data"; import { CollectionData } from "./collection.data";
describe("Collection", () => { describe("Collection", () => {
@@ -17,6 +17,7 @@ describe("Collection", () => {
readOnly: true, readOnly: true,
manage: true, manage: true,
hidePasswords: true, hidePasswords: true,
type: CollectionTypes.DefaultUserCollection,
}; };
}); });
@@ -32,6 +33,7 @@ describe("Collection", () => {
organizationId: null, organizationId: null,
readOnly: null, readOnly: null,
manage: null, manage: null,
type: null,
}); });
}); });
@@ -46,6 +48,7 @@ describe("Collection", () => {
readOnly: true, readOnly: true,
manage: true, manage: true,
hidePasswords: true, hidePasswords: true,
type: CollectionTypes.DefaultUserCollection,
}); });
}); });
@@ -58,6 +61,7 @@ describe("Collection", () => {
collection.readOnly = false; collection.readOnly = false;
collection.hidePasswords = false; collection.hidePasswords = false;
collection.manage = true; collection.manage = true;
collection.type = CollectionTypes.DefaultUserCollection;
const key = makeSymmetricCryptoKey<OrgKey>(); const key = makeSymmetricCryptoKey<OrgKey>();
@@ -72,6 +76,7 @@ describe("Collection", () => {
readOnly: false, readOnly: false,
manage: true, manage: true,
assigned: true, assigned: true,
type: CollectionTypes.DefaultUserCollection,
}); });
}); });
}); });

View File

@@ -7,6 +7,13 @@ import { OrgKey } from "@bitwarden/common/types/key";
import { CollectionData } from "./collection.data"; import { CollectionData } from "./collection.data";
import { CollectionView } from "./collection.view"; import { CollectionView } from "./collection.view";
export const CollectionTypes = {
SharedCollection: 0,
DefaultUserCollection: 1,
} as const;
export type CollectionType = (typeof CollectionTypes)[keyof typeof CollectionTypes];
export class Collection extends Domain { export class Collection extends Domain {
id: string; id: string;
organizationId: string; organizationId: string;
@@ -15,6 +22,7 @@ export class Collection extends Domain {
readOnly: boolean; readOnly: boolean;
hidePasswords: boolean; hidePasswords: boolean;
manage: boolean; manage: boolean;
type: CollectionType;
constructor(obj?: CollectionData) { constructor(obj?: CollectionData) {
super(); super();
@@ -33,8 +41,9 @@ export class Collection extends Domain {
readOnly: null, readOnly: null,
hidePasswords: null, hidePasswords: null,
manage: null, manage: null,
type: null,
}, },
["id", "organizationId", "readOnly", "hidePasswords", "manage"], ["id", "organizationId", "readOnly", "hidePasswords", "manage", "type"],
); );
} }

View File

@@ -6,7 +6,7 @@ import { Organization } from "@bitwarden/common/admin-console/models/domain/orga
import { View } from "@bitwarden/common/models/view/view"; import { View } from "@bitwarden/common/models/view/view";
import { ITreeNodeObject } from "@bitwarden/common/vault/models/domain/tree-node"; import { ITreeNodeObject } from "@bitwarden/common/vault/models/domain/tree-node";
import { Collection } from "./collection"; import { Collection, CollectionType } from "./collection";
import { CollectionAccessDetailsResponse } from "./collection.response"; import { CollectionAccessDetailsResponse } from "./collection.response";
export const NestingDelimiter = "/"; export const NestingDelimiter = "/";
@@ -21,6 +21,7 @@ export class CollectionView implements View, ITreeNodeObject {
hidePasswords: boolean = null; hidePasswords: boolean = null;
manage: boolean = null; manage: boolean = null;
assigned: boolean = null; assigned: boolean = null;
type: CollectionType = null;
constructor(c?: Collection | CollectionAccessDetailsResponse) { constructor(c?: Collection | CollectionAccessDetailsResponse) {
if (!c) { if (!c) {
@@ -39,6 +40,7 @@ export class CollectionView implements View, ITreeNodeObject {
if (c instanceof CollectionAccessDetailsResponse) { if (c instanceof CollectionAccessDetailsResponse) {
this.assigned = c.assigned; this.assigned = c.assigned;
} }
this.type = c.type;
} }
canEditItems(org: Organization): boolean { canEditItems(org: Organization): boolean {

View File

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