mirror of
https://github.com/bitwarden/browser
synced 2025-12-15 07:43:35 +00:00
[PM-24269] Enable ownership field for personal items (#16069)
* remove global check for personal ownership as `setFormState` now handles it * ensure that the organizationId is disabled for new ciphers * only check for personal ownership change for enabling/disabling the entire form - this ensure that it is only applied when the data ownership policy is applied - The bug was caused by a regular user that wasn't in an organization, their form was getting fully disabled when it shouldn't. * fix type checking * do not disable organization id after an organization is selected
This commit is contained in:
@@ -225,10 +225,9 @@ export class ItemDetailsSectionComponent implements OnInit {
|
||||
});
|
||||
await this.updateCollectionOptions(this.initialValues?.collectionIds);
|
||||
}
|
||||
|
||||
this.setFormState();
|
||||
if (!this.allowOwnershipChange) {
|
||||
this.itemDetailsForm.controls.organizationId.disable();
|
||||
}
|
||||
|
||||
this.itemDetailsForm.controls.organizationId.valueChanges
|
||||
.pipe(
|
||||
takeUntilDestroyed(this.destroyRef),
|
||||
@@ -241,22 +240,28 @@ export class ItemDetailsSectionComponent implements OnInit {
|
||||
}
|
||||
|
||||
/**
|
||||
* When the cipher does not belong to an organization but the user's organization
|
||||
* requires all ciphers to be owned by an organization, disable the entire form
|
||||
* until the user selects an organization. Once the organization is set, enable the form.
|
||||
* Ensure to properly set the collections control state when the form is enabled.
|
||||
* Updates the global form and organizationId control states.
|
||||
*/
|
||||
private setFormState() {
|
||||
if (this.config.originalCipher && !this.allowPersonalOwnership) {
|
||||
// When editing a cipher and the user cannot have personal ownership
|
||||
// and the cipher is is not within the organization - force the user to
|
||||
// move the cipher within the organization first before editing any other field
|
||||
if (this.itemDetailsForm.controls.organizationId.value === null) {
|
||||
this.cipherFormContainer.disableFormFields();
|
||||
this.itemDetailsForm.controls.organizationId.enable();
|
||||
this.favoriteButtonDisabled = true;
|
||||
} else {
|
||||
// The "after" from the above: When editing a cipher and the user cannot have personal ownership
|
||||
// and the organization is populated - re-enable the global form.
|
||||
this.cipherFormContainer.enableFormFields();
|
||||
this.favoriteButtonDisabled = false;
|
||||
this.setCollectionControlState();
|
||||
}
|
||||
} else if (!this.allowOwnershipChange) {
|
||||
// When the user cannot change the organization field, disable the organizationId control.
|
||||
// This could be because they aren't a part of an organization
|
||||
this.itemDetailsForm.controls.organizationId.disable({ emitEvent: false });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user