From 10d3c8d93182bf891361dc861ae203db6f50b585 Mon Sep 17 00:00:00 2001 From: Henry Taeschner Date: Sat, 17 Feb 2024 19:07:13 +0100 Subject: [PATCH] feat: load permissions --- .../app-detail/app-detail.component.html | 18 +--- .../app-detail/app-detail.component.ts | 96 +++++++++++++------ src/assets/i18n/de.json | 8 +- src/assets/i18n/en.json | 8 +- 4 files changed, 80 insertions(+), 50 deletions(-) diff --git a/src/app/permission/app-detail/app-detail.component.html b/src/app/permission/app-detail/app-detail.component.html index 0913ccd..bd507af 100644 --- a/src/app/permission/app-detail/app-detail.component.html +++ b/src/app/permission/app-detail/app-detail.component.html @@ -401,10 +401,10 @@ readonly type="text" class="w-full" - id="app_detail_create_permission_appName" - formControlName="appName" + id="app_detail_create_permission_app_id" + formControlName="appId" /> - -
- - - - -
resource#action + roles: RoleAssignments +} @Component({ templateUrl: './app-detail.component.html', @@ -125,10 +116,9 @@ export class AppDetailComponent implements OnInit, OnDestroy { if (userService.hasPermission('PERMISSION#DELETE')) this.myPermissions.push('PERMISSION#DELETE') this.formGroupPermission = new FormGroup({ - appName: new FormControl({ value: null, disabled: true }, [Validators.required]), + appId: new FormControl({ value: null, disabled: true }, [Validators.required]), resource: new FormControl(null, [Validators.required, Validators.minLength(2), Validators.maxLength(50)]), action: new FormControl(null, [Validators.required, Validators.minLength(2), Validators.maxLength(50)]), - name: new FormControl(null), description: new FormControl(null) }) this.formGroupRole = new FormGroup({ @@ -264,6 +254,8 @@ export class AppDetailComponent implements OnInit, OnDestroy { this.currentApp = { ...result.stream[0], type: 'APP' } as App this.log('loadApp => App:', this.currentApp) this.prepareActionButtons() + this.permissionRows = [] + this.preparePermissionTable(this.currentApp) } else { this.loadingServerIssue = true this.loadingExceptionKey = 'EXCEPTIONS.HTTP_STATUS_0.APPS' @@ -302,6 +294,54 @@ export class AppDetailComponent implements OnInit, OnDestroy { }) } + /* 1. Prepare rows of the table: permissions of the as Map + * key (resource#action): 'PERMISSION#READ' + * value: {resource: 'PERMISSION', action: 'READ', key: 'PERMISSION#READ', name: 'View permission matrix' + */ + private preparePermissionTable(app: App): void { + const permissionRows: Map = new Map() + // get permissions for the app + this.permApi + .searchPermissions({ permissionSearchCriteria: { appId: this.currentApp.appId } }) + .pipe(catchError((error) => of(error))) + .subscribe((result) => { + if (result instanceof HttpErrorResponse) { + this.loadingServerIssue = true + this.loadingExceptionKey = 'EXCEPTIONS.HTTP_STATUS_' + result.status + '.PERMISSIONS' + console.error('searchPermissions() result:', result) + } else if (result instanceof Object) { + for (const permission of result.stream) { + permissionRows.set(permission.resource + '#' + permission.action, { + ...permission, + key: permission.resource + '#' + permission.action, + roles: {} + }) + } + this.roles.sort(this.sortRoleByName) + this.log('loadPermissions:', permissionRows) + + // add permission rows of this app to permission table + this.permissionRows = this.permissionRows.concat( + Array.from(permissionRows.values()).sort(this.sortPermissionRowByKey) + ) + this.loading = false + } else { + this.loadingServerIssue = true + this.loadingExceptionKey = 'EXCEPTIONS.HTTP_STATUS_0.ROLES' + console.error('searchPermissions() => unknown response:', result) + } + }) + /* + // Fill permission rows with role assignments of the current application + permissionRows.forEach((row) => { + this.currentApp?.assignments?.forEach((ra) => { + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + row.roles[ra.role!] = ra.permissionKeys?.includes(row.key) || false + }) + }) +*/ + } + /********************************************* * Table Filter */ @@ -343,7 +383,6 @@ export class AppDetailComponent implements OnInit, OnDestroy { this.workspaceAppFilterValue = undefined this.onSortPermissionTable() this.permissionTable?.clear() - //this.preparePermissionTable() } public onSortPermissionTable() { if (this.appSortIcon) this.appSortIcon.nativeElement.className = 'pi pi-fw pi-sort-alt' // reset icon @@ -408,32 +447,27 @@ export class AppDetailComponent implements OnInit, OnDestroy { * Create a new PERMISSION */ public onCopyPermission(ev: MouseEvent, permRow: PermissionViewRow): void { - //this.onEditPermission(ev, permRow) - //this.changeMode = 'CREATE' + this.onEditPermission(ev, permRow) + this.changeMode = 'CREATE' } public onCreatePermission(): void { - /* this.formGroupPermission.reset() - this.formGroupPermission.controls['appName'].patchValue(this.urlParamAppId) + this.formGroupPermission.controls['appId'].patchValue(this.currentApp.appId) this.changeMode = 'CREATE' this.permissionRow = { key: '' } as PermissionViewRow this.showPermissionDetailDialog = true - */ } /** * View and Edit a PERMISSION */ public onEditPermission(ev: MouseEvent, permRow: PermissionViewRow): void { - /* + this.formGroupPermission.controls['appId'].patchValue(this.currentApp.appId) this.formGroupPermission.controls['resource'].patchValue(permRow.resource) this.formGroupPermission.controls['action'].patchValue(permRow.action) - this.formGroupPermission.controls['name'].patchValue(permRow.name) this.formGroupPermission.controls['description'].patchValue(permRow.description) - this.formGroupPermission.controls['appName'].patchValue(permRow.applicationId) this.changeMode = 'EDIT' this.permissionRow = permRow this.showPermissionDetailDialog = true - */ } /** * Save a PERMISSION @@ -573,13 +607,13 @@ export class AppDetailComponent implements OnInit, OnDestroy { return (a.key ? (a.key as string).toUpperCase() : '').localeCompare(b.key ? (b.key as string).toUpperCase() : '') } private sortPermissionRowByAppIdAsc(a: PermissionViewRow, b: PermissionViewRow): number { - return (a.applicationId ? (a.applicationId as string).toUpperCase() : '').localeCompare( - b.applicationId ? (b.applicationId as string).toUpperCase() : '' + return (a.appId ? (a.appId as string).toUpperCase() : '').localeCompare( + b.appId ? (b.appId as string).toUpperCase() : '' ) } private sortPermissionRowByAppIdDesc(b: PermissionViewRow, a: PermissionViewRow): number { - return (a.applicationId ? (a.applicationId as string).toUpperCase() : '').localeCompare( - b.applicationId ? (b.applicationId as string).toUpperCase() : '' + return (a.appId ? (a.appId as string).toUpperCase() : '').localeCompare( + b.appId ? (b.appId as string).toUpperCase() : '' ) } private sortRoleByName(a: Role, b: Role): number { diff --git a/src/assets/i18n/de.json b/src/assets/i18n/de.json index 7e54bad..0e779fd 100644 --- a/src/assets/i18n/de.json +++ b/src/assets/i18n/de.json @@ -220,10 +220,13 @@ "HTTP_STATUS_0": { "APPS": "Unbekanntes Problem beim Abrufen von Apps - Bitte versuchen sie es noch einmal.", "ROLES": "Unbekanntes Problem beim Abrufen von Rollen - Bitte versuchen sie es noch einmal.", + "PERMISSIONS": "Unbekanntes Problem beim Abrufen von Berechtigungen - Bitte versuchen sie es noch einmal.", "WORKSPACES": "Unbekanntes Problem beim Abrufen von Workspace Daten - Bitte versuchen sie es noch einmal." }, "HTTP_STATUS_403": { "APPS": "Sie haben keine Rechte um Apps zu sehen.", + "ROLES": "Sie haben keine Rechte um Rollen zu sehen.", + "PERMISSIONS": "Sie haben keine Rechte um Berechtigungen zu sehen.", "WORKSPACES": "Sie haben keine Rechte um Workspaces zu sehen." }, "HTTP_STATUS_404": { @@ -231,14 +234,15 @@ "APPS": "Es konnten keine Apps gefunden werden.", "ROLE": "Die Rolle konnte nicht gefunden werden.", "ROLES": "Es konnten keine Rollen gefunden werden.", + "PERMISSIONS": "Es konnten keine Berechtigungen gefunden werden.", "WORKSPACE": "Der Workspace konnte nicht gefunden werden.", "WORKSPACES": "Es konnten keine Workspaces gefunden werden." }, "HTTP_STATUS_500": { "APPS": "Unbekanntes Server-Problem beim Abrufen von Apps - Bitte versuchen sie es noch einmal.", "ROLES": "Unbekanntes Server-Problem beim Abrufen von Rollen - Bitte versuchen sie es noch einmal.", + "PERMISSIONS": "Unbekanntes Server-Problem beim Abrufen von Berechtigungen - Bitte versuchen sie es noch einmal.", "WORKSPACES": "Unbekanntes Server-Problem beim Abrufen von Workspace Daten - Bitte versuchen sie es noch einmal." - }, - "NO_APPLICATION_OR_APPLICATION_ROLE_FOUND": "Rolle konnte nicht gelöscht werden da sie nicht gefunden wurde" + } } } diff --git a/src/assets/i18n/en.json b/src/assets/i18n/en.json index 1c63650..60a6ee3 100644 --- a/src/assets/i18n/en.json +++ b/src/assets/i18n/en.json @@ -221,10 +221,13 @@ "HTTP_STATUS_0": { "APPS": "Unknown problem retrieving App data - please try again.", "ROLES": "Unknown problem retrieving Role data - please try again.", + "PERMISSIONS": "Unknown problem retrieving Permission data - please try again.", "WORKSPACES": "Unknown problem retrieving Workspace data - please try again." }, "HTTP_STATUS_403": { "APPS": "You have no permissions to see Apps.", + "ROLES": "You have no permissions to see Roles.", + "PERMISSIONS": "You have no permissions to see Permissions.", "WORKSPACES": "You have no permissions to see Workspaces." }, "HTTP_STATUS_404": { @@ -232,14 +235,15 @@ "APPS": "No Apps could be found.", "ROLE": "Role could not be found.", "ROLES": "No Roles could be found.", + "PERMISSIONS": "No Permissions could be found.", "WORKSPACE": "Workspace could not be found.", "WORKSPACES": "No Workspaces could be found." }, "HTTP_STATUS_500": { "APPS": "Unknown server problem retrieving App data - please try again.", "ROLES": "Unknown server problem retrieving Role data - please try again.", + "PERMISSIONS": "Unknown server problem retrieving Permission data - please try again.", "WORKSPACES": "Unknown server problem retrieving Workspace data - please try again." - }, - "NO_APPLICATION_OR_APPLICATION_ROLE_FOUND": "Role could not be deleted because it was not found" + } } }