mirror of
https://github.com/bitwarden/browser
synced 2025-12-10 05:13:29 +00:00
[PM-20633] rename personal ownership (#15228)
* sensible renames * renames * clean up comments
This commit is contained in:
@@ -20,5 +20,5 @@ export abstract class DeprecatedVaultFilterService {
|
||||
buildCollapsedFilterNodes: () => Promise<Set<string>>;
|
||||
storeCollapsedFilterNodes: (collapsedFilterNodes: Set<string>) => Promise<void>;
|
||||
checkForSingleOrganizationPolicy: () => Promise<boolean>;
|
||||
checkForPersonalOwnershipPolicy: () => Promise<boolean>;
|
||||
checkForOrganizationDataOwnershipPolicy: () => Promise<boolean>;
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@ export class AddEditComponent implements OnInit, OnDestroy {
|
||||
protected componentName = "";
|
||||
protected destroy$ = new Subject<void>();
|
||||
protected writeableCollections: CollectionView[];
|
||||
private personalOwnershipPolicyAppliesToActiveUser: boolean;
|
||||
private organizationDataOwnershipAppliesToUser: boolean;
|
||||
private previousCipherId: string;
|
||||
|
||||
get fido2CredentialCreationDateValue(): string {
|
||||
@@ -195,10 +195,10 @@ export class AddEditComponent implements OnInit, OnDestroy {
|
||||
.pipe(
|
||||
getUserId,
|
||||
switchMap((userId) =>
|
||||
this.policyService.policyAppliesToUser$(PolicyType.PersonalOwnership, userId),
|
||||
this.policyService.policyAppliesToUser$(PolicyType.OrganizationDataOwnership, userId),
|
||||
),
|
||||
concatMap(async (policyAppliesToActiveUser) => {
|
||||
this.personalOwnershipPolicyAppliesToActiveUser = policyAppliesToActiveUser;
|
||||
this.organizationDataOwnershipAppliesToUser = policyAppliesToActiveUser;
|
||||
await this.init();
|
||||
}),
|
||||
takeUntil(this.destroy$),
|
||||
@@ -218,7 +218,7 @@ export class AddEditComponent implements OnInit, OnDestroy {
|
||||
if (this.ownershipOptions.length) {
|
||||
this.ownershipOptions = [];
|
||||
}
|
||||
if (this.personalOwnershipPolicyAppliesToActiveUser) {
|
||||
if (this.organizationDataOwnershipAppliesToUser) {
|
||||
this.allowPersonal = false;
|
||||
} else {
|
||||
const myEmail = await firstValueFrom(
|
||||
|
||||
@@ -15,7 +15,7 @@ export class OrganizationFilterComponent {
|
||||
@Input() collapsedFilterNodes: Set<string>;
|
||||
@Input() organizations: Organization[];
|
||||
@Input() activeFilter: VaultFilter;
|
||||
@Input() activePersonalOwnershipPolicy: boolean;
|
||||
@Input() activeOrganizationDataOwnership: boolean;
|
||||
@Input() activeSingleOrganizationPolicy: boolean;
|
||||
|
||||
@Output() onNodeCollapseStateChange: EventEmitter<ITreeNodeObject> =
|
||||
@@ -26,12 +26,12 @@ export class OrganizationFilterComponent {
|
||||
let displayMode: DisplayMode = "organizationMember";
|
||||
if (this.organizations == null || this.organizations.length < 1) {
|
||||
displayMode = "noOrganizations";
|
||||
} else if (this.activePersonalOwnershipPolicy && !this.activeSingleOrganizationPolicy) {
|
||||
displayMode = "personalOwnershipPolicy";
|
||||
} else if (!this.activePersonalOwnershipPolicy && this.activeSingleOrganizationPolicy) {
|
||||
} else if (this.activeOrganizationDataOwnership && !this.activeSingleOrganizationPolicy) {
|
||||
displayMode = "organizationDataOwnershipPolicy";
|
||||
} else if (!this.activeOrganizationDataOwnership && this.activeSingleOrganizationPolicy) {
|
||||
displayMode = "singleOrganizationPolicy";
|
||||
} else if (this.activePersonalOwnershipPolicy && this.activeSingleOrganizationPolicy) {
|
||||
displayMode = "singleOrganizationAndPersonalOwnershipPolicies";
|
||||
} else if (this.activeOrganizationDataOwnership && this.activeSingleOrganizationPolicy) {
|
||||
displayMode = "singleOrganizationAndOrganizatonDataOwnershipPolicies";
|
||||
}
|
||||
|
||||
return displayMode;
|
||||
|
||||
@@ -32,7 +32,7 @@ export class VaultFilterComponent implements OnInit {
|
||||
isLoaded = false;
|
||||
collapsedFilterNodes: Set<string>;
|
||||
organizations: Organization[];
|
||||
activePersonalOwnershipPolicy: boolean;
|
||||
activeOrganizationDataOwnershipPolicy: boolean;
|
||||
activeSingleOrganizationPolicy: boolean;
|
||||
collections: DynamicTreeNode<CollectionView>;
|
||||
folders$: Observable<DynamicTreeNode<FolderView>>;
|
||||
@@ -47,8 +47,8 @@ export class VaultFilterComponent implements OnInit {
|
||||
this.collapsedFilterNodes = await this.vaultFilterService.buildCollapsedFilterNodes();
|
||||
this.organizations = await this.vaultFilterService.buildOrganizations();
|
||||
if (this.organizations != null && this.organizations.length > 0) {
|
||||
this.activePersonalOwnershipPolicy =
|
||||
await this.vaultFilterService.checkForPersonalOwnershipPolicy();
|
||||
this.activeOrganizationDataOwnershipPolicy =
|
||||
await this.vaultFilterService.checkForOrganizationDataOwnershipPolicy();
|
||||
this.activeSingleOrganizationPolicy =
|
||||
await this.vaultFilterService.checkForSingleOrganizationPolicy();
|
||||
}
|
||||
@@ -88,8 +88,8 @@ export class VaultFilterComponent implements OnInit {
|
||||
|
||||
async reloadOrganizations() {
|
||||
this.organizations = await this.vaultFilterService.buildOrganizations();
|
||||
this.activePersonalOwnershipPolicy =
|
||||
await this.vaultFilterService.checkForPersonalOwnershipPolicy();
|
||||
this.activeOrganizationDataOwnershipPolicy =
|
||||
await this.vaultFilterService.checkForOrganizationDataOwnershipPolicy();
|
||||
this.activeSingleOrganizationPolicy =
|
||||
await this.vaultFilterService.checkForSingleOrganizationPolicy();
|
||||
}
|
||||
|
||||
@@ -2,5 +2,5 @@ export type DisplayMode =
|
||||
| "noOrganizations"
|
||||
| "organizationMember"
|
||||
| "singleOrganizationPolicy"
|
||||
| "personalOwnershipPolicy"
|
||||
| "singleOrganizationAndPersonalOwnershipPolicies";
|
||||
| "organizationDataOwnershipPolicy"
|
||||
| "singleOrganizationAndOrganizatonDataOwnershipPolicies";
|
||||
|
||||
@@ -123,12 +123,12 @@ export class VaultFilterService implements DeprecatedVaultFilterServiceAbstracti
|
||||
);
|
||||
}
|
||||
|
||||
async checkForPersonalOwnershipPolicy(): Promise<boolean> {
|
||||
async checkForOrganizationDataOwnershipPolicy(): Promise<boolean> {
|
||||
return await firstValueFrom(
|
||||
this.accountService.activeAccount$.pipe(
|
||||
getUserId,
|
||||
switchMap((userId) =>
|
||||
this.policyService.policyAppliesToUser$(PolicyType.PersonalOwnership, userId),
|
||||
this.policyService.policyAppliesToUser$(PolicyType.OrganizationDataOwnership, userId),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -6,7 +6,7 @@ export enum PolicyType {
|
||||
PasswordGenerator = 2, // Sets minimum requirements/default type for generated passwords/passphrases
|
||||
SingleOrg = 3, // Allows users to only be apart of one organization
|
||||
RequireSso = 4, // Requires users to authenticate with SSO
|
||||
PersonalOwnership = 5, // Disables personal vault ownership for adding/cloning items
|
||||
OrganizationDataOwnership = 5, // Enforces organization ownership items added/cloned to the default collection
|
||||
DisableSend = 6, // Disables the ability to create and edit Bitwarden Sends
|
||||
SendOptions = 7, // Sets restrictions or defaults for Bitwarden Sends
|
||||
ResetPassword = 8, // Allows orgs to use reset password : also can enable auto-enrollment during invite flow
|
||||
|
||||
@@ -238,8 +238,8 @@ export class DefaultPolicyService implements PolicyService {
|
||||
case PolicyType.RestrictedItemTypes:
|
||||
// restricted item types policy
|
||||
return false;
|
||||
case PolicyType.PersonalOwnership:
|
||||
// individual vault policy applies to everyone except admins and owners
|
||||
case PolicyType.OrganizationDataOwnership:
|
||||
// organization data ownership policy applies to everyone except admins and owners
|
||||
return organization.isAdmin;
|
||||
default:
|
||||
return organization.canManagePolicies;
|
||||
|
||||
@@ -336,7 +336,7 @@ export class ImportComponent implements OnInit, OnDestroy, AfterViewInit {
|
||||
this.accountService.activeAccount$.pipe(
|
||||
getUserId,
|
||||
switchMap((userId) =>
|
||||
this.policyService.policyAppliesToUser$(PolicyType.PersonalOwnership, userId),
|
||||
this.policyService.policyAppliesToUser$(PolicyType.OrganizationDataOwnership, userId),
|
||||
),
|
||||
),
|
||||
this.organizations$,
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
[label]="'myVault' | i18n"
|
||||
value="myVault"
|
||||
icon="bwi-user"
|
||||
*ngIf="!(disablePersonalOwnershipPolicy$ | async)"
|
||||
*ngIf="!(organizationDataOwnershipPolicy$ | async)"
|
||||
/>
|
||||
<bit-option
|
||||
*ngFor="let o of organizations$ | async"
|
||||
|
||||
@@ -153,7 +153,7 @@ export class ExportComponent implements OnInit, OnDestroy, AfterViewInit {
|
||||
}
|
||||
|
||||
disablePersonalVaultExportPolicy$: Observable<boolean>;
|
||||
disablePersonalOwnershipPolicy$: Observable<boolean>;
|
||||
organizationDataOwnershipPolicy$: Observable<boolean>;
|
||||
|
||||
exportForm = this.formBuilder.group({
|
||||
vaultSelector: [
|
||||
@@ -209,10 +209,10 @@ export class ExportComponent implements OnInit, OnDestroy, AfterViewInit {
|
||||
),
|
||||
);
|
||||
|
||||
this.disablePersonalOwnershipPolicy$ = this.accountService.activeAccount$.pipe(
|
||||
this.organizationDataOwnershipPolicy$ = this.accountService.activeAccount$.pipe(
|
||||
getUserId,
|
||||
switchMap((userId) =>
|
||||
this.policyService.policyAppliesToUser$(PolicyType.PersonalOwnership, userId),
|
||||
this.policyService.policyAppliesToUser$(PolicyType.OrganizationDataOwnership, userId),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -294,21 +294,21 @@ export class ExportComponent implements OnInit, OnDestroy, AfterViewInit {
|
||||
|
||||
combineLatest([
|
||||
this.disablePersonalVaultExportPolicy$,
|
||||
this.disablePersonalOwnershipPolicy$,
|
||||
this.organizationDataOwnershipPolicy$,
|
||||
this.organizations$,
|
||||
])
|
||||
.pipe(
|
||||
tap(([disablePersonalVaultExport, disablePersonalOwnership, organizations]) => {
|
||||
tap(([disablePersonalVaultExport, organizationDataOwnership, organizations]) => {
|
||||
this._disabledByPolicy = disablePersonalVaultExport;
|
||||
|
||||
// When personalOwnership is disabled and we have orgs, set the first org as the selected vault
|
||||
if (disablePersonalOwnership && organizations.length > 0) {
|
||||
// When organizationDataOwnership is enabled and we have orgs, set the first org as the selected vault
|
||||
if (organizationDataOwnership && organizations.length > 0) {
|
||||
this.exportForm.enable();
|
||||
this.exportForm.controls.vaultSelector.setValue(organizations[0].id);
|
||||
}
|
||||
|
||||
// When personalOwnership is disabled and we have no orgs, disable the form
|
||||
if (disablePersonalOwnership && organizations.length === 0) {
|
||||
// When organizationDataOwnership is enabled and we have no orgs, disable the form
|
||||
if (organizationDataOwnership && organizations.length === 0) {
|
||||
this.exportForm.disable();
|
||||
}
|
||||
|
||||
@@ -318,7 +318,7 @@ export class ExportComponent implements OnInit, OnDestroy, AfterViewInit {
|
||||
}
|
||||
|
||||
// When neither policy is enabled, enable the form and set the default vault to "myVault"
|
||||
if (!disablePersonalVaultExport && !disablePersonalOwnership) {
|
||||
if (!disablePersonalVaultExport && !organizationDataOwnership) {
|
||||
this.exportForm.controls.vaultSelector.setValue("myVault");
|
||||
}
|
||||
}),
|
||||
|
||||
@@ -77,7 +77,7 @@ type BaseCipherFormConfig = {
|
||||
* Flag to indicate if the user is allowed to create ciphers in their own Vault. If false, configuration must
|
||||
* supply a list of organizations that the user can create ciphers in.
|
||||
*/
|
||||
allowPersonalOwnership: boolean;
|
||||
organizationDataOwnershipDisabled: boolean;
|
||||
|
||||
/**
|
||||
* The original cipher that is being edited or cloned. This can be undefined when creating a new cipher.
|
||||
@@ -131,18 +131,18 @@ type CreateNewCipherConfig = BaseCipherFormConfig & {
|
||||
type CombinedAddEditConfig = ExistingCipherConfig | CreateNewCipherConfig;
|
||||
|
||||
/**
|
||||
* Configuration object for the cipher form when personal ownership is allowed.
|
||||
* Configuration object for the cipher form when organization data ownership is not allowed.
|
||||
*/
|
||||
type PersonalOwnershipAllowed = CombinedAddEditConfig & {
|
||||
allowPersonalOwnership: true;
|
||||
type OrganizationDataOwnershipDisabled = CombinedAddEditConfig & {
|
||||
organizationDataOwnershipDisabled: true;
|
||||
};
|
||||
|
||||
/**
|
||||
* Configuration object for the cipher form when personal ownership is not allowed.
|
||||
* Configuration object for the cipher form when organization data ownership is allowed.
|
||||
* Organizations must be provided.
|
||||
*/
|
||||
type PersonalOwnershipNotAllowed = CombinedAddEditConfig & {
|
||||
allowPersonalOwnership: false;
|
||||
type OrganizationDataOwnershipEnabled = CombinedAddEditConfig & {
|
||||
organizationDataOwnershipDisabled: false;
|
||||
organizations: Organization[];
|
||||
};
|
||||
|
||||
@@ -150,7 +150,7 @@ type PersonalOwnershipNotAllowed = CombinedAddEditConfig & {
|
||||
* Configuration object for the cipher form.
|
||||
* Determines the behavior of the form and the controls that are displayed/enabled.
|
||||
*/
|
||||
export type CipherFormConfig = PersonalOwnershipAllowed | PersonalOwnershipNotAllowed;
|
||||
export type CipherFormConfig = OrganizationDataOwnershipDisabled | OrganizationDataOwnershipEnabled;
|
||||
|
||||
/**
|
||||
* Service responsible for building the configuration object for the cipher form.
|
||||
|
||||
@@ -57,7 +57,7 @@ const defaultConfig: CipherFormConfig = {
|
||||
mode: "add",
|
||||
cipherType: CipherType.Login,
|
||||
admin: false,
|
||||
allowPersonalOwnership: true,
|
||||
organizationDataOwnershipDisabled: true,
|
||||
collections: [
|
||||
{
|
||||
id: "col1",
|
||||
@@ -354,13 +354,13 @@ export const WithSubmitButton: Story = {
|
||||
},
|
||||
};
|
||||
|
||||
export const NoPersonalOwnership: Story = {
|
||||
export const OrganizationDataOwnershipEnabled: Story = {
|
||||
...Add,
|
||||
args: {
|
||||
config: {
|
||||
...defaultConfig,
|
||||
mode: "add",
|
||||
allowPersonalOwnership: false,
|
||||
organizationDataOwnershipDisabled: false,
|
||||
originalCipher: defaultConfig.originalCipher,
|
||||
organizations: defaultConfig.organizations!,
|
||||
},
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
<bit-label>{{ "owner" | i18n }}</bit-label>
|
||||
<bit-select formControlName="organizationId">
|
||||
<bit-option
|
||||
*ngIf="showPersonalOwnerOption"
|
||||
*ngIf="showOrganizationDataOwnershipOption"
|
||||
[value]="null"
|
||||
[label]="userEmail$ | async"
|
||||
></bit-option>
|
||||
|
||||
@@ -93,8 +93,8 @@ describe("ItemDetailsSectionComponent", () => {
|
||||
});
|
||||
|
||||
describe("ngOnInit", () => {
|
||||
it("should throw an error if no organizations are available for ownership and personal ownership is not allowed", async () => {
|
||||
component.config.allowPersonalOwnership = false;
|
||||
it("should throw an error if no organizations are available for ownership and organization data ownership is enabled", async () => {
|
||||
component.config.organizationDataOwnershipDisabled = false;
|
||||
component.config.organizations = [];
|
||||
await expect(component.ngOnInit()).rejects.toThrow(
|
||||
"No organizations available for ownership.",
|
||||
@@ -102,7 +102,7 @@ describe("ItemDetailsSectionComponent", () => {
|
||||
});
|
||||
|
||||
it("should initialize form with default values if no originalCipher is provided", fakeAsync(async () => {
|
||||
component.config.allowPersonalOwnership = true;
|
||||
component.config.organizationDataOwnershipDisabled = true;
|
||||
component.config.organizations = [{ id: "org1" } as Organization];
|
||||
await component.ngOnInit();
|
||||
tick();
|
||||
@@ -120,7 +120,7 @@ describe("ItemDetailsSectionComponent", () => {
|
||||
}));
|
||||
|
||||
it("should initialize form with values from originalCipher if provided", fakeAsync(async () => {
|
||||
component.config.allowPersonalOwnership = true;
|
||||
component.config.organizationDataOwnershipDisabled = true;
|
||||
component.config.organizations = [{ id: "org1" } as Organization];
|
||||
component.config.collections = [
|
||||
createMockCollection("col1", "Collection 1", "org1") as CollectionView,
|
||||
@@ -150,7 +150,7 @@ describe("ItemDetailsSectionComponent", () => {
|
||||
}));
|
||||
|
||||
it("should disable organizationId control if ownership change is not allowed", async () => {
|
||||
component.config.allowPersonalOwnership = false;
|
||||
component.config.organizationDataOwnershipDisabled = false;
|
||||
component.config.organizations = [{ id: "org1" } as Organization];
|
||||
jest.spyOn(component, "allowOwnershipChange", "get").mockReturnValue(false);
|
||||
|
||||
@@ -188,15 +188,15 @@ describe("ItemDetailsSectionComponent", () => {
|
||||
expect(component.allowOwnershipChange).toBe(false);
|
||||
});
|
||||
|
||||
it("should allow ownership change if personal ownership is allowed and there is at least one organization", () => {
|
||||
component.config.allowPersonalOwnership = true;
|
||||
it("should allow ownership change if organization data ownership is disabled and there is at least one organization", () => {
|
||||
component.config.organizationDataOwnershipDisabled = true;
|
||||
component.config.organizations = [{ id: "org1", name: "org1" } as Organization];
|
||||
fixture.detectChanges();
|
||||
expect(component.allowOwnershipChange).toBe(true);
|
||||
});
|
||||
|
||||
it("should allow ownership change if personal ownership is not allowed but there is more than one organization", () => {
|
||||
component.config.allowPersonalOwnership = false;
|
||||
it("should allow ownership change if organization data ownership is enabled but there is more than one organization", () => {
|
||||
component.config.organizationDataOwnershipDisabled = false;
|
||||
component.config.organizations = [
|
||||
{ id: "org1", name: "org1" } as Organization,
|
||||
{ id: "org2", name: "org2" } as Organization,
|
||||
@@ -207,23 +207,23 @@ describe("ItemDetailsSectionComponent", () => {
|
||||
});
|
||||
|
||||
describe("defaultOwner", () => {
|
||||
it("should return null if personal ownership is allowed", () => {
|
||||
component.config.allowPersonalOwnership = true;
|
||||
it("should return null if organization data ownership is disabled", () => {
|
||||
component.config.organizationDataOwnershipDisabled = true;
|
||||
expect(component.defaultOwner).toBeNull();
|
||||
});
|
||||
|
||||
it("should return the first organization id if personal ownership is not allowed", () => {
|
||||
component.config.allowPersonalOwnership = false;
|
||||
it("should return the first organization id if organization data ownership is enabled", () => {
|
||||
component.config.organizationDataOwnershipDisabled = false;
|
||||
component.config.organizations = [{ id: "org1", name: "Organization 1" } as Organization];
|
||||
fixture.detectChanges();
|
||||
expect(component.defaultOwner).toBe("org1");
|
||||
});
|
||||
});
|
||||
|
||||
describe("showPersonalOwnerOption", () => {
|
||||
it("should show personal ownership when the configuration allows", () => {
|
||||
describe("showOrganizationDataOwnershipOption", () => {
|
||||
it("should show organization data ownership when the configuration allows", () => {
|
||||
component.config.mode = "edit";
|
||||
component.config.allowPersonalOwnership = true;
|
||||
component.config.organizationDataOwnershipDisabled = true;
|
||||
component.originalCipherView = {} as CipherView;
|
||||
component.config.organizations = [{ id: "134-433-22" } as Organization];
|
||||
fixture.detectChanges();
|
||||
@@ -235,9 +235,9 @@ describe("ItemDetailsSectionComponent", () => {
|
||||
expect(label).toBe("test@example.com");
|
||||
});
|
||||
|
||||
it("should show personal ownership when the control is disabled", async () => {
|
||||
it("should show organization data ownership when the control is disabled", async () => {
|
||||
component.config.mode = "edit";
|
||||
component.config.allowPersonalOwnership = false;
|
||||
component.config.organizationDataOwnershipDisabled = false;
|
||||
component.originalCipherView = {} as CipherView;
|
||||
component.config.organizations = [{ id: "134-433-22" } as Organization];
|
||||
await component.ngOnInit();
|
||||
@@ -253,7 +253,7 @@ describe("ItemDetailsSectionComponent", () => {
|
||||
|
||||
describe("showOwnership", () => {
|
||||
it("should return true if ownership change is allowed or in edit mode with at least one organization", () => {
|
||||
component.config.allowPersonalOwnership = true;
|
||||
component.config.organizationDataOwnershipDisabled = true;
|
||||
jest.spyOn(component, "allowOwnershipChange", "get").mockReturnValue(true);
|
||||
expect(component.showOwnership).toBe(true);
|
||||
|
||||
@@ -265,7 +265,7 @@ describe("ItemDetailsSectionComponent", () => {
|
||||
});
|
||||
|
||||
it("should hide the ownership control if showOwnership is false", async () => {
|
||||
component.config.allowPersonalOwnership = true;
|
||||
component.config.organizationDataOwnershipDisabled = true;
|
||||
jest.spyOn(component, "showOwnership", "get").mockReturnValue(false);
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
@@ -276,7 +276,7 @@ describe("ItemDetailsSectionComponent", () => {
|
||||
});
|
||||
|
||||
it("should show the ownership control if showOwnership is true", async () => {
|
||||
component.config.allowPersonalOwnership = true;
|
||||
component.config.organizationDataOwnershipDisabled = true;
|
||||
jest.spyOn(component, "allowOwnershipChange", "get").mockReturnValue(true);
|
||||
fixture.detectChanges();
|
||||
await fixture.whenStable();
|
||||
@@ -293,7 +293,7 @@ describe("ItemDetailsSectionComponent", () => {
|
||||
});
|
||||
|
||||
it("should append '- Clone' to the title if in clone mode", async () => {
|
||||
component.config.allowPersonalOwnership = true;
|
||||
component.config.organizationDataOwnershipDisabled = true;
|
||||
const cipher = {
|
||||
name: "cipher1",
|
||||
organizationId: null,
|
||||
@@ -312,7 +312,7 @@ describe("ItemDetailsSectionComponent", () => {
|
||||
});
|
||||
|
||||
it("does not append clone when the cipher was populated from the cache", async () => {
|
||||
component.config.allowPersonalOwnership = true;
|
||||
component.config.organizationDataOwnershipDisabled = true;
|
||||
const cipher = {
|
||||
name: "from cache cipher",
|
||||
organizationId: null,
|
||||
@@ -332,8 +332,8 @@ describe("ItemDetailsSectionComponent", () => {
|
||||
expect(component.itemDetailsForm.controls.name.value).toBe("from cache cipher");
|
||||
});
|
||||
|
||||
it("should select the first organization if personal ownership is not allowed", async () => {
|
||||
component.config.allowPersonalOwnership = false;
|
||||
it("should select the first organization if organization data ownership is enabled", async () => {
|
||||
component.config.organizationDataOwnershipDisabled = false;
|
||||
component.config.organizations = [
|
||||
{ id: "org1", name: "org1" } as Organization,
|
||||
{ id: "org2", name: "org2" } as Organization,
|
||||
@@ -354,7 +354,7 @@ describe("ItemDetailsSectionComponent", () => {
|
||||
|
||||
describe("collectionOptions", () => {
|
||||
it("should reset and disable/hide collections control when no organization is selected", async () => {
|
||||
component.config.allowPersonalOwnership = true;
|
||||
component.config.organizationDataOwnershipDisabled = true;
|
||||
component.itemDetailsForm.controls.organizationId.setValue(null);
|
||||
|
||||
fixture.detectChanges();
|
||||
@@ -370,7 +370,7 @@ describe("ItemDetailsSectionComponent", () => {
|
||||
});
|
||||
|
||||
it("should enable/show collection control when an organization is selected", async () => {
|
||||
component.config.allowPersonalOwnership = true;
|
||||
component.config.organizationDataOwnershipDisabled = true;
|
||||
component.config.organizations = [{ id: "org1" } as Organization];
|
||||
component.config.collections = [
|
||||
createMockCollection("col1", "Collection 1", "org1") as CollectionView,
|
||||
@@ -421,7 +421,7 @@ describe("ItemDetailsSectionComponent", () => {
|
||||
});
|
||||
|
||||
it("should automatically select the first collection if only one is available", async () => {
|
||||
component.config.allowPersonalOwnership = true;
|
||||
component.config.organizationDataOwnershipDisabled = true;
|
||||
component.config.organizations = [{ id: "org1" } as Organization];
|
||||
component.config.collections = [
|
||||
createMockCollection("col1", "Collection 1", "org1") as CollectionView,
|
||||
@@ -475,7 +475,7 @@ describe("ItemDetailsSectionComponent", () => {
|
||||
|
||||
it("should allow all collections to be altered when `config.admin` is true", async () => {
|
||||
component.config.admin = true;
|
||||
component.config.allowPersonalOwnership = true;
|
||||
component.config.organizationDataOwnershipDisabled = true;
|
||||
component.config.organizations = [{ id: "org1" } as Organization];
|
||||
component.config.collections = [
|
||||
createMockCollection("col1", "Collection 1", "org1", true, false) as CollectionView,
|
||||
@@ -491,7 +491,6 @@ describe("ItemDetailsSectionComponent", () => {
|
||||
expect(component["collectionOptions"].map((c) => c.id)).toEqual(["col1", "col2", "col3"]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("readonlyCollections", () => {
|
||||
beforeEach(() => {
|
||||
component.config.mode = "edit";
|
||||
|
||||
@@ -92,8 +92,8 @@ export class ItemDetailsSectionComponent implements OnInit {
|
||||
return this.config.mode === "partial-edit";
|
||||
}
|
||||
|
||||
get allowPersonalOwnership() {
|
||||
return this.config.allowPersonalOwnership;
|
||||
get organizationDataOwnershipDisabled() {
|
||||
return this.config.organizationDataOwnershipDisabled;
|
||||
}
|
||||
|
||||
get collections(): CollectionView[] {
|
||||
@@ -105,14 +105,17 @@ export class ItemDetailsSectionComponent implements OnInit {
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the personal ownership option in the Owner dropdown when:
|
||||
* - Personal ownership is allowed
|
||||
* Show the organization data ownership option in the Owner dropdown when:
|
||||
* - organization data ownership is disabled
|
||||
* - The `organizationId` control is disabled. This avoids the scenario
|
||||
* where a the dropdown is empty because the user personally owns the cipher
|
||||
* but cannot edit the ownership.
|
||||
*/
|
||||
get showPersonalOwnerOption() {
|
||||
return this.allowPersonalOwnership || !this.itemDetailsForm.controls.organizationId.enabled;
|
||||
get showOrganizationDataOwnershipOption() {
|
||||
return (
|
||||
this.organizationDataOwnershipDisabled ||
|
||||
!this.itemDetailsForm.controls.organizationId.enabled
|
||||
);
|
||||
}
|
||||
|
||||
constructor(
|
||||
@@ -161,7 +164,7 @@ export class ItemDetailsSectionComponent implements OnInit {
|
||||
}
|
||||
|
||||
// If personal ownership is allowed and there is at least one organization, allow ownership change.
|
||||
if (this.allowPersonalOwnership) {
|
||||
if (this.organizationDataOwnershipDisabled) {
|
||||
return this.organizations.length > 0;
|
||||
}
|
||||
|
||||
@@ -180,7 +183,7 @@ export class ItemDetailsSectionComponent implements OnInit {
|
||||
}
|
||||
|
||||
get defaultOwner() {
|
||||
return this.allowPersonalOwnership ? null : this.organizations[0].id;
|
||||
return this.organizationDataOwnershipDisabled ? null : this.organizations[0].id;
|
||||
}
|
||||
|
||||
async ngOnInit() {
|
||||
@@ -188,7 +191,7 @@ export class ItemDetailsSectionComponent implements OnInit {
|
||||
Utils.getSortFunction(this.i18nService, "name"),
|
||||
);
|
||||
|
||||
if (!this.allowPersonalOwnership && this.organizations.length === 0) {
|
||||
if (!this.organizationDataOwnershipDisabled && this.organizations.length === 0) {
|
||||
throw new Error("No organizations available for ownership.");
|
||||
}
|
||||
|
||||
@@ -244,7 +247,7 @@ export class ItemDetailsSectionComponent implements OnInit {
|
||||
);
|
||||
}
|
||||
|
||||
if (!this.allowPersonalOwnership && prefillCipher.organizationId == null) {
|
||||
if (!this.organizationDataOwnershipDisabled && prefillCipher.organizationId == null) {
|
||||
this.itemDetailsForm.controls.organizationId.setValue(this.defaultOwner);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ export class DefaultCipherFormConfigService implements CipherFormConfigService {
|
||||
): Promise<CipherFormConfig> {
|
||||
const activeUserId = await firstValueFrom(this.accountService.activeAccount$.pipe(getUserId));
|
||||
|
||||
const [organizations, collections, allowPersonalOwnership, folders, cipher] =
|
||||
const [organizations, collections, organizationDataOwnershipDisabled, folders, cipher] =
|
||||
await firstValueFrom(
|
||||
combineLatest([
|
||||
this.organizations$(activeUserId),
|
||||
@@ -55,7 +55,7 @@ export class DefaultCipherFormConfigService implements CipherFormConfigService {
|
||||
),
|
||||
),
|
||||
),
|
||||
this.allowPersonalOwnership$,
|
||||
this.organizationDataOwnershipDisabled$,
|
||||
this.folderService.folders$(activeUserId).pipe(
|
||||
switchMap((f) =>
|
||||
this.folderService.folderViews$(activeUserId).pipe(
|
||||
@@ -71,7 +71,7 @@ export class DefaultCipherFormConfigService implements CipherFormConfigService {
|
||||
mode,
|
||||
cipherType: cipher?.type ?? cipherType ?? CipherType.Login,
|
||||
admin: false,
|
||||
allowPersonalOwnership,
|
||||
organizationDataOwnershipDisabled,
|
||||
originalCipher: cipher,
|
||||
collections,
|
||||
organizations,
|
||||
@@ -91,10 +91,10 @@ export class DefaultCipherFormConfigService implements CipherFormConfigService {
|
||||
);
|
||||
}
|
||||
|
||||
private allowPersonalOwnership$ = this.accountService.activeAccount$.pipe(
|
||||
private organizationDataOwnershipDisabled$ = this.accountService.activeAccount$.pipe(
|
||||
getUserId,
|
||||
switchMap((userId) =>
|
||||
this.policyService.policyAppliesToUser$(PolicyType.PersonalOwnership, userId),
|
||||
this.policyService.policyAppliesToUser$(PolicyType.OrganizationDataOwnership, userId),
|
||||
),
|
||||
map((p) => !p),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user