Skip to content

fix/AB#71363_inconsistency-in-field-permission #2014

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

Open
wants to merge 2 commits into
base: 2.x.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ <h2>{{ 'common.field.few' | translate }}</h2>
: 'components.role.tooltip.disallowFieldAccessibility'
) | translate : { field: element.name }
"
(click)="onEditFieldAccess(index, element, 'canSee')"
(click)="onEditFieldAccess(element, 'canSee')"
>
</ui-button>
<ui-button
Expand All @@ -65,7 +65,7 @@ <h2>{{ 'common.field.few' | translate }}</h2>
: 'components.role.tooltip.disallowFieldUpdate'
) | translate : { field: element.name }
"
(click)="onEditFieldAccess(index, element, 'canUpdate')"
(click)="onEditFieldAccess(element, 'canUpdate')"
>
</ui-button>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,6 @@ export class ResourceFieldsComponent implements OnInit, OnChanges {
/** Displayed columns */
public displayedColumns: string[] = ['name', 'actions'];

/** Updated field */
private updatedField: { index: number; permission: 'canSee' | 'canUpdate' } =
{ index: -1, permission: 'canSee' };

ngOnInit() {
this.fields = sortBy(this.resource.fields.map(this.hasFieldAccess), 'name');
this.filterId.valueChanges.subscribe((value) => {
Expand All @@ -62,14 +58,11 @@ export class ResourceFieldsComponent implements OnInit, OnChanges {
}

ngOnChanges(changes: SimpleChanges): void {
if (changes.resource && this.updatedField.index !== -1) {
const field = this.fields[this.updatedField.index];
if (this.updatedField.permission === 'canSee') {
field.canSee = !field.canSee;
} else {
field.canUpdate = !field.canUpdate;
}
this.updatedField.index = -1;
if (changes.resource) {
this.fields = sortBy(
this.resource.fields.map(this.hasFieldAccess),
'name'
);
}
}

Expand Down Expand Up @@ -113,17 +106,14 @@ export class ResourceFieldsComponent implements OnInit, OnChanges {
/**
* Emits an event to toggle if field is visible / editable.
*
* @param index Index of the field to toggle permission for.
* @param field Field to toggle permission for.
* @param permission Permission type to toggle.
*/
public onEditFieldAccess(
index: number,
field: ResourceField,
permission: 'canSee' | 'canUpdate'
) {
// Save field updated
this.updatedField = { index, permission };
this.onToggle.emit({
field,
permission,
Expand Down