1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-10 13:23:34 +00:00

[PM-15938] - Restrict viewing hidden input based on permission (#13016)

* allow string or boolean disabled prop in input directive

* fix tests

* add test

* disable custom fields in partial edit

* disable custom fields in partial edit

* manually disable inputs

* revert changes to directive

* revert other changes

* remove unnecessary check for partial-edit
This commit is contained in:
Jordan Aasen
2025-02-04 12:59:25 -08:00
committed by GitHub
parent 327aed9763
commit a9f24b6d24
2 changed files with 36 additions and 14 deletions

View File

@@ -115,7 +115,13 @@ describe("CustomFieldsComponent", () => {
value: true,
newField: false,
},
{ linkedId: 1, name: "linked label", type: FieldType.Linked, value: null, newField: false },
{
linkedId: 1,
name: "linked label",
type: FieldType.Linked,
value: null,
newField: false,
},
]);
});
@@ -132,6 +138,19 @@ describe("CustomFieldsComponent", () => {
expect(button).toBeFalsy();
});
it("should disable the hidden field input when `viewPassword` is false", () => {
originalCipherView.viewPassword = false;
originalCipherView.fields = mockFieldViews;
component.ngOnInit();
fixture.detectChanges();
const input = fixture.debugElement.query(By.css('[data-testid="custom-hidden-field"]'));
expect(input.nativeElement.disabled).toBe(true);
});
it("when `viewPassword` is true the user can see the view toggle option", () => {
originalCipherView.viewPassword = true;
originalCipherView.fields = mockFieldViews;

View File

@@ -158,20 +158,23 @@ export class CustomFieldsComponent implements OnInit, AfterViewInit {
value = field.value === "true" ? true : false;
}
this.fields.push(
this.formBuilder.group<CustomField>({
type: field.type,
name: field.name,
value: value,
linkedId: field.linkedId,
newField: false,
}),
);
});
const customField = this.formBuilder.group<CustomField>({
type: field.type,
name: field.name,
value: value,
linkedId: field.linkedId,
newField: false,
});
if (!this.cipherFormContainer.originalCipherView?.viewPassword) {
this.customFieldsForm.disable();
}
if (
field.type === FieldType.Hidden &&
!this.cipherFormContainer.originalCipherView?.viewPassword
) {
customField.controls.value.disable();
}
this.fields.push(customField);
});
// Disable the form if in partial-edit mode
// Must happen after the initial fields are populated