Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
]);
});

Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading