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

Fix problem with adding new permissions #505

Merged
merged 2 commits into from
Oct 7, 2024
Merged
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 @@ -43,7 +43,7 @@ <h1 mat-dialog-title>{{ data.Name }}</h1>
</div>

<div class="row tw-p-2 tw-mx-4 tw-gap-4 tw-w-fit tw-border-b last:tw-border-0"
*ngFor="let element of obj.filter | rightsFilter : obj.rights ?? []">
*ngFor="let element of obj.filter | rightsFilter : obj.rights ?? []; index as index">
<button mat-icon-button
[disabled]="element.IsVirtual"
[matMenuTriggerFor]="menu">
Expand All @@ -52,12 +52,12 @@ <h1 mat-dialog-title>{{ data.Name }}</h1>
<mat-menu #menu="matMenu">
<button *ngIf="allContexts$ | async as allContexts"
mat-menu-item
(click)="grantRightsDialogService.edit(element, allContexts)">
(click)="grantRightsDialogService.edit(element, index)">
<mat-icon>edit</mat-icon>
<span>Edit</span>
</button>
<button mat-menu-item
(click)="grantRightsDialogService.remove(element)">
(click)="grantRightsDialogService.remove(index)">
<mat-icon>delete</mat-icon>
<span>Delete</span>
</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class GrantRightsDialogService {
});
}

public remove(permission: IPermissionDto): void {
public remove(elementIndex: number): void {
this.dialog
.open(ConfirmDialogComponent, {
data: { title: 'Are you sure you want to delete this role?', button: 'Yes, delete' },
Expand All @@ -65,44 +65,19 @@ export class GrantRightsDialogService {
return;
}
const rights = this.rightsInternalSubject.value;
rights.Permissions = rights.Permissions.filter((x) => x.Id != permission.Id);
rights.Permissions.splice(elementIndex, 1);
this.rightsInternalSubject.next(rights);
}),
takeUntil(this.destroy$)
)
.subscribe();
}

public edit(permissionDto: IPermissionDto, units: IRoleContext[]): void {
const permission = this.mapPermission(permissionDto, this.rolesSubject.value, this.allContextsSubject.value);
public edit(permissionDto: IPermissionDto, elementIndex: number): void {
const allContexts = this.allContextsSubject.value;
const permission = this.mapPermission(permissionDto, this.rolesSubject.value, allContexts);

this.dialog
.open(PermissionEditDialogComponent, {
maxHeight: '90vh',
maxWidth: '90vw',
data: { permission, units },
})
.afterClosed()
.pipe(
tap((result) => {
if (result) {
const rights = this.rightsInternalSubject.value;
const findIndex = rights.Permissions.findIndex((x) => x.Id === result.Id);
if (findIndex > -1) {
rights.Permissions[findIndex] = result;
} else {
rights.Permissions.unshift(result);
}
this.rightsInternalSubject.next(rights);
}
// TODO: fix next three lines
const filterValue = this.filter.value;
this.filter.next({ ...filterValue, comment: '' });
this.filter.next({ ...filterValue });
}),
takeUntil(this.destroy$)
)
.subscribe();
this.openPermissionEditDialog(permission, (permissions, permission) => (permissions[elementIndex] = permission));
}

public addPermission(): void {
Expand All @@ -123,7 +98,38 @@ export class GrantRightsDialogService {
Comment: '',
Contexts: [],
};
this.edit(permission, this.allContextsSubject.value);
this.openPermissionEditDialog(permission, (permissions, permission) => permissions.push(permission));
}),
takeUntil(this.destroy$)
)
.subscribe();
}

private openPermissionEditDialog<TPermission extends IPermissionDto>(
permissionDto: IPermissionDto,
updPermissionsAction: (existingPermissions: IPermissionDto[], newPermission: TPermission) => void
): void {
const allContexts = this.allContextsSubject.value;
const permission = this.mapPermission(permissionDto, this.rolesSubject.value, allContexts);

this.dialog
.open(PermissionEditDialogComponent, {
maxHeight: '90vh',
maxWidth: '90vw',
data: { permission, allContexts },
})
.afterClosed()
.pipe(
tap((result) => {
if (result) {
const rights = this.rightsInternalSubject.value;
updPermissionsAction(rights.Permissions, result);
this.rightsInternalSubject.next(rights);
}
// TODO: fix next three lines
const filterValue = this.filter.value;
this.filter.next({ ...filterValue, comment: '' });
this.filter.next({ ...filterValue });
}),
takeUntil(this.destroy$)
)
Expand Down
6 changes: 3 additions & 3 deletions src/__SolutionItems/CommonAssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
[assembly: AssemblyCompany("Luxoft")]
[assembly: AssemblyCopyright("Copyright © Luxoft 2009-2024")]

[assembly: AssemblyVersion("22.3.16.0")]
[assembly: AssemblyFileVersion("22.3.16.0")]
[assembly: AssemblyInformationalVersion("22.3.16.0")]
[assembly: AssemblyVersion("22.3.17.0")]
[assembly: AssemblyFileVersion("22.3.17.0")]
[assembly: AssemblyInformationalVersion("22.3.17.0")]

#if DEBUG
[assembly: AssemblyConfiguration("Debug")]
Expand Down
Loading