1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-15 07:43:35 +00:00

[PM-24304][PM-24305] - [Defect] Some fields are not disabled when editing an item from My Vault (#15982)

* disable all remaining form fields for editing personally owned My Items

* fix failing tests

* ensure collection field is also properly disabled

* clean up logic

* fix failing test

* fix test

* refactor variable to avoid using `is` prefix

* directly reference parent form for status rather than subscribe to it

* refactor subscription for form status changes

* use observable as an Output

* disable attachment button on desktop vault when the form

* disable custom field components when custom fields already exist and parent form is disabled

* disable attachments button in the browser when the edit form is disabled

* grab icon button instance for disabled state

---------

Co-authored-by: Nick Krantz <nick@livefront.com>
This commit is contained in:
Jordan Aasen
2025-08-25 15:48:00 -07:00
committed by GitHub
parent e10d13faa8
commit 9ed69ef4b8
22 changed files with 224 additions and 36 deletions

View File

@@ -82,6 +82,8 @@ export class ItemDetailsSectionComponent implements OnInit {
protected userId: UserId;
protected favoriteButtonDisabled = false;
@Input({ required: true })
config: CipherFormConfig;
@@ -241,15 +243,19 @@ 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.
* 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.
*/
private setFormState() {
if (this.config.originalCipher && !this.allowPersonalOwnership) {
if (this.itemDetailsForm.controls.organizationId.value === null) {
this.cipherFormContainer.disableFormFields();
this.itemDetailsForm.controls.organizationId.enable();
this.favoriteButtonDisabled = true;
} else {
this.cipherFormContainer.enableFormFields();
this.favoriteButtonDisabled = false;
this.setCollectionControlState();
}
}
}
@@ -305,7 +311,6 @@ export class ItemDetailsSectionComponent implements OnInit {
});
const orgId = this.itemDetailsForm.controls.organizationId.value as OrganizationId;
const organization = this.organizations.find((o) => o.id === orgId);
const initializedWithCachedCipher = this.cipherFormContainer.initializedWithCachedCipher();
// Configure form for clone mode.
@@ -327,9 +332,7 @@ export class ItemDetailsSectionComponent implements OnInit {
await this.updateCollectionOptions(prefillCollections);
if (!organization?.canEditAllCiphers && !prefillCipher.canAssignToCollections) {
this.itemDetailsForm.controls.collectionIds.disable();
}
this.setCollectionControlState();
if (this.partialEdit) {
this.itemDetailsForm.disable();
@@ -344,22 +347,34 @@ export class ItemDetailsSectionComponent implements OnInit {
c.readOnly &&
this.originalCipherView.collectionIds.includes(c.id as CollectionId),
);
// When Owners/Admins access setting is turned on.
// Disable Collections Options if Owner/Admin does not have Edit/Manage permissions on item
// Disable Collections Options if Custom user does not have Edit/Manage permissions on item
if (
(organization?.allowAdminAccessToAllCollectionItems &&
(!this.originalCipherView.viewPassword || !this.originalCipherView.edit)) ||
(organization?.type === OrganizationUserType.Custom &&
!this.originalCipherView.viewPassword)
) {
this.itemDetailsForm.controls.collectionIds.disable();
}
}
}
}
private setCollectionControlState() {
const initialCipherView = this.cipherFormContainer.getInitialCipherView();
const orgId = this.itemDetailsForm.controls.organizationId.value as OrganizationId;
const organization = this.organizations.find((o) => o.id === orgId);
if (!organization || !initialCipherView) {
return;
}
// Disable the collection control if either of the following apply:
// 1. The organization does not allow editing all ciphers and the existing cipher cannot be assigned to
// collections
// 2. When Owners/Admins access setting is turned on.
// AND either:
// a. Disable Collections Options if Owner/Admin does not have Edit/Manage permissions on item
// b. Disable Collections Options if Custom user does not have Edit/Manage permissions on item
if (
(!organization.canEditAllCiphers && !initialCipherView.canAssignToCollections) ||
(organization.allowAdminAccessToAllCollectionItems &&
(!initialCipherView.viewPassword || !initialCipherView.edit)) ||
(organization.type === OrganizationUserType.Custom && !initialCipherView.viewPassword)
) {
this.itemDetailsForm.controls.collectionIds.disable();
}
}
/**
* Updates the collection options based on the selected organization.
* @param startingSelection - Optional starting selection of collectionIds to be automatically selected.