Skip to content

Commit

Permalink
feat: added role management
Browse files Browse the repository at this point in the history
  • Loading branch information
HenryT-CG committed Feb 17, 2024
1 parent 55e8770 commit 59b8786
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 53 deletions.
18 changes: 7 additions & 11 deletions src/app/permission/app-detail/app-detail.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@
<button
pbutton
type="button"
*ngIf="myPermissions.includes('ROLE#DELETE') && role.appId === urlParamAppId"
*ngIf="myPermissions.includes('ROLE#DELETE')"
[id]="'app_detail_permission_table_col_' + role.name + '_delete_action'"
(click)="onDeleteRole($event, role)"
[title]="'ROLE.DELETE' | translate"
Expand All @@ -228,7 +228,7 @@
<button
pbutton
type="button"
*ngIf="myPermissions.includes('ROLE#EDIT') && role.appId === urlParamAppId"
*ngIf="myPermissions.includes('ROLE#EDIT')"
[id]="'app_detail_permission_table_col_' + role.id + '_edit_action'"
(click)="onEditRole($event, role)"
[title]="'ROLE.EDIT' | translate"
Expand All @@ -239,11 +239,7 @@
<button
pbutton
type="button"
*ngIf="
myPermissions.includes('ROLE#EDIT') &&
role.appId === urlParamAppId &&
permissionTable.totalRecords > 0
"
*ngIf="myPermissions.includes('ROLE#EDIT') && permissionTable.totalRecords > 0"
[id]="'app_detail_permission_table_col_' + role.id + '_set_all_action'"
(click)="onGrantAllPermissions($event, role)"
[title]="'PERMISSION.SET_ALL_PERMISSIONS' | translate"
Expand Down Expand Up @@ -551,9 +547,9 @@
>
<form [formGroup]="formGroupRole" errorTailor>
<div class="flex flex-wrap flex-column gap-4 justify-content-between">
<div>
<div class="mt-1">
<span class="p-float-label" controlErrorAnchor>
<input pInputText type="text" class="w-full" id="app_detail_create_role_name" formControlName="roleName" />
<input pInputText type="text" class="w-full" id="app_detail_create_role_name" formControlName="name" />
<label class="ocx-required-label" for="app_detail_create_role_name"> {{ 'ROLE.NAME' | translate }} </label>
</span>
</div>
Expand All @@ -578,7 +574,7 @@
autofocus
type="button"
class="m-0"
id="app_detail_create_role_cancel"
id="app_detail_create_role_button_cancel"
icon="pi pi-times"
iconPos="left"
[label]="'ACTIONS.CANCEL' | translate"
Expand All @@ -588,7 +584,7 @@
pButton
type="button"
class="m-0"
id="app_detail_create_role_save"
id="app_detail_create_role_button_save"
icon="pi pi-save"
iconPos="left"
[label]="'ACTIONS.SAVE' | translate"
Expand Down
96 changes: 85 additions & 11 deletions src/app/permission/app-detail/app-detail.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ import { Action, PortalMessageService, UserService } from '@onecx/portal-integra

import {
Role,
CreateRoleRequest,
UpdateRoleRequest,
/* RolePageResult,
RoleSearchCriteria,
CreateRoleRequest,
UpdateRoleRequest,
Permission,
PermissionSearchCriteria,
Assignment,
Expand Down Expand Up @@ -131,8 +132,8 @@ export class AppDetailComponent implements OnInit, OnDestroy {
description: new FormControl(null)
})
this.formGroupRole = new FormGroup({
roleId: new FormControl(null),
roleName: new FormControl(null, [Validators.required, Validators.minLength(2), Validators.maxLength(50)]),
id: new FormControl(null),
name: new FormControl(null, [Validators.required, Validators.minLength(2), Validators.maxLength(50)]),
description: new FormControl(null)
})
this.filterMode = FilterMatchMode.CONTAINS
Expand Down Expand Up @@ -219,7 +220,10 @@ export class AppDetailComponent implements OnInit, OnDestroy {
this.loadApp()
}
private log(text: string, obj?: object): void {
if (this.debug) console.log('app detail: ' + text, obj)
if (this.debug) {
if (obj) console.log('app detail: ' + text, obj)
else console.log('app detail: ' + text)
}
}

private loadApp(): void {
Expand Down Expand Up @@ -254,15 +258,15 @@ export class AppDetailComponent implements OnInit, OnDestroy {
.subscribe((result) => {
if (result instanceof HttpErrorResponse) {
this.loadingServerIssue = true
this.loadingExceptionKey = 'EXCEPTIONS.HTTP_STATUS_' + result.status + '.APPLICATION'
this.loadingExceptionKey = 'EXCEPTIONS.HTTP_STATUS_' + result.status + '.APP'
console.error('searchApplications() result:', result)
} else if (result instanceof Object) {
this.currentApp = { ...result.stream[0], type: 'APP' } as App
this.log('loadApp => App:', this.currentApp)
this.prepareActionButtons()
} else {
this.loadingServerIssue = true
this.loadingExceptionKey = 'EXCEPTIONS.HTTP_STATUS_0.APPLICATIONS'
this.loadingExceptionKey = 'EXCEPTIONS.HTTP_STATUS_0.APPS'
console.error('getApplicationById() => unknown response:', result)
}
this.loading = false
Expand All @@ -281,21 +285,21 @@ export class AppDetailComponent implements OnInit, OnDestroy {
.subscribe((result) => {
if (result instanceof HttpErrorResponse) {
this.loadingServerIssue = true
this.loadingExceptionKey = 'EXCEPTIONS.HTTP_STATUS_' + result.status + '.APPLICATION'
console.error('searchApplications() result:', result)
this.loadingExceptionKey = 'EXCEPTIONS.HTTP_STATUS_' + result.status + '.ROLES'
console.error('searchRoles() result:', result)
} else if (result instanceof Object) {
for (const role of result.stream) {
this.roles.push({ ...role })
this.permissionDefaultRoles[role.name] = false
}
this.roles.sort(this.sortRoleByName)
this.log('loadRoles:', this.roles)
} else {
this.loadingServerIssue = true
this.loadingExceptionKey = 'EXCEPTIONS.HTTP_STATUS_0.APPLICATIONS'
this.loadingExceptionKey = 'EXCEPTIONS.HTTP_STATUS_0.ROLES'
console.error('searchRoles() => unknown response:', result)
}
})
this.roles.sort(this.sortRoleByName)
}

/*********************************************
Expand Down Expand Up @@ -459,7 +463,7 @@ export class AppDetailComponent implements OnInit, OnDestroy {
* View and Edit a ROLE
*/
public onEditRole(ev: MouseEvent, role: AppRole): void {
this.formGroupRole.controls['roleName'].patchValue(role.name)
this.formGroupRole.controls['name'].patchValue(role.name)
this.formGroupRole.controls['description'].patchValue(role.description)
this.changeMode = 'EDIT'
this.role = role
Expand All @@ -470,13 +474,83 @@ export class AppDetailComponent implements OnInit, OnDestroy {
*/
public onSaveRole(): void {
this.log('onSaveRole()')
if (this.formGroupRole.valid) {
const roleExists =
this.roles.filter(
(r) =>
r.name === this.formGroupRole.controls['name'].value &&
(this.changeMode === 'CREATE' ? true : r.id ? r.id !== this.role?.id : true)
).length > 0
if (roleExists) {
this.msgService.error({
summaryKey: 'ROLE.' + this.changeMode + '_HEADER',
detailKey: 'VALIDATION.ERRORS.ROLE.' + this.changeMode + '_ALREADY_EXISTS'
})
return
}
if (this.changeMode === 'CREATE') {
const role = {
name: this.formGroupRole.controls['name'].value,
description: this.formGroupRole.controls['description'].value
} as CreateRoleRequest
this.roleApi
.createRole({
createRoleRequest: role
})
.subscribe({
next: () => {
this.msgService.success({ summaryKey: 'ACTIONS.' + this.changeMode + '.MESSAGE.ROLE_OK' })
this.loadApp()
},
error: (err) => {
this.msgService.error({ summaryKey: 'ACTIONS.' + this.changeMode + '.MESSAGE.ROLE_NOK' })
console.error(err)
}
})
} else {
const roleNameChanged = this.formGroupRole.controls['name'].value !== this.role?.name
const role = {
modificationCount: this.role?.modificationCount,
name: this.formGroupRole.controls['name'].value,
description: this.formGroupRole.controls['description'].value
} as UpdateRoleRequest
this.roleApi.updateRole({ id: this.role?.id ?? '', updateRoleRequest: role }).subscribe({
next: () => {
this.msgService.success({ summaryKey: 'ACTIONS.EDIT.MESSAGE.ROLE_OK' })
if (roleNameChanged) this.loadApp() // reload all to avoid any mistakes
else {
this.roles.forEach((r) => {
if (r.id === this.role?.id) r.description = role.description
})
}
},
error: (err) => {
this.msgService.error({ summaryKey: 'ACTIONS.EDIT.MESSAGE.ROLE_NOK' })
console.error(err)
}
})
}
this.showRoleDetailDialog = false
}
}

public onDeleteRole(ev: MouseEvent, role: AppRole): void {
this.role = role
this.showRoleDeleteDialog = true
}
public onDeleteRoleExecute() {
this.log('onDeleteRoleExecute()')
this.roleApi.deleteRole({ id: this.role?.id ?? '' }).subscribe({
next: () => {
this.msgService.success({ summaryKey: 'ACTIONS.DELETE.MESSAGE.ROLE_OK' })
this.loadApp()
},
error: (err) => {
this.msgService.error({ summaryKey: 'ACTIONS.DELETE.MESSAGE.ROLE_NOK' })
console.error(err.error)
}
})
this.showRoleDeleteDialog = false
}

public onAssignPermission(ev: MouseEvent, permRow: PermissionViewRow, role: AppRole, silent?: boolean): void {
Expand Down
2 changes: 1 addition & 1 deletion src/app/permission/app-search/app-search.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export class AppSearchComponent implements OnInit, OnDestroy {
if (!this.dataAccessIssue) {
if (apps instanceof HttpErrorResponse) {
this.dataAccessIssue = true
this.exceptionKey = 'EXCEPTIONS.HTTP_STATUS_' + apps.status + '.APPLICATIONS'
this.exceptionKey = 'EXCEPTIONS.HTTP_STATUS_' + apps.status + '.APPS'
console.error('searchApplications():', apps)
} else if (apps.stream instanceof Array) {
for (const app of apps.stream) {
Expand Down
33 changes: 18 additions & 15 deletions src/assets/i18n/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -188,13 +188,10 @@
}
},
"ROLE": {
"LABEL.APP": "App Rollen",
"LABEL.WORKSPACE": "Workspace Rollen",
"TOOLTIP": "Alle Rollen die der App zugeordnet sind. Neue Rollen können nur für Workspaces erzeugt werden.",
"TOOLTIP": "Für den Workspace erstellte Rollen, als Auswahl der für den Mandaten definierten Rollen, die dem Benutzer zugeordnet werden können.",
"NAME": "Name",
"DESCRIPTION": "Beschreibung",
"APP_ID.WORKSPACE": "Workspace Name",
"APP_ID.APP": "App",
"CREATE": "Neue Rolle erstellen",
"CREATE_HEADER": "Rolle erstellen",
"DELETE": "Rolle einschließlich aller Berechtigungen löschen",
Expand All @@ -208,8 +205,10 @@
"FORMAT_URL": "Format: "
},
"ERRORS": {
"CREATE_ALREADY_EXISTS": "Berechtigung konnte nicht erstellt werden, da sie bereits existiert",
"EDIT_ALREADY_EXISTS": "Berechtigung konnte nicht geändert werden, da sie bereits existiert",
"PERMISSION.CREATE_ALREADY_EXISTS": "Die Berechtigung konnte nicht erstellt werden, da eine Berechtigung mit diesem Namen bereits existiert.",
"PERMISSION.EDIT_ALREADY_EXISTS": "Berechtigung konnte nicht geändert werden, da eine Berechtigung mit diesem Namen bereits existiert.",
"ROLE.CREATE_ALREADY_EXISTS": "Rolle konnte nicht erstellt werden, da eine Rolle mit diesem Namen bereits existiert.",
"ROLE.EDIT_ALREADY_EXISTS": "Rolle konnte nicht geändert werden, da eine Rolle mit diesem Namen bereits existiert.",
"INTERNAL_ERROR": "Interner Fehler",
"EMPTY_REQUIRED_FIELD": "Dieses Feld ist ein Pflichtfeld.",
"MAXIMUM_LENGTH": "Es sind nur {{chars}} Zeichen erlaubt.",
Expand All @@ -219,22 +218,26 @@
},
"EXCEPTIONS": {
"HTTP_STATUS_0": {
"WORKSPACES": "Unbekanntes Problem beim Abrufen von Workspace Daten - Bitte versuchen sie es noch einmal.",
"APPLICATIONS": "Unbekanntes Problem beim Abrufen von App-Daten - Bitte versuchen sie es noch einmal."
"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.",
"WORKSPACES": "Unbekanntes Problem beim Abrufen von Workspace Daten - Bitte versuchen sie es noch einmal."
},
"HTTP_STATUS_403": {
"WORKSPACES": "Sie haben keine Rechte um Workspaces zu sehen.",
"APPLICATIONS": "Sie haben keine Rechte um Apps zu sehen."
"APPS": "Sie haben keine Rechte um Apps zu sehen.",
"WORKSPACES": "Sie haben keine Rechte um Workspaces zu sehen."
},
"HTTP_STATUS_404": {
"APP": "Die App konnte nicht gefunden werden.",
"APPS": "Es konnten keine Apps gefunden werden.",
"ROLE": "Die Rolle konnte nicht gefunden werden.",
"ROLES": "Es konnten keine Rollen gefunden werden.",
"WORKSPACE": "Der Workspace konnte nicht gefunden werden.",
"WORKSPACES": "Es konnten keine Workspaces gefunden werden.",
"APPLICATION": "Die App konnte nicht gefunden werden.",
"APPLICATIONS": "Es konnten keine Apps gefunden werden."
"WORKSPACES": "Es konnten keine Workspaces gefunden werden."
},
"HTTP_STATUS_500": {
"WORKSPACES": "Unbekanntes Server-Problem beim Abrufen von Workspace Daten - Bitte versuchen sie es noch einmal.",
"APPLICATIONS": "Unbekanntes Server-Problem beim Abrufen von App-Daten - Bitte versuchen sie es noch einmal."
"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.",
"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"
}
Expand Down
33 changes: 18 additions & 15 deletions src/assets/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,10 @@
}
},
"ROLE": {
"LABEL.APP": "App Roles",
"LABEL.WORKSPACE": "Workspace Roles",
"TOOLTIP": "All roles assigned to the App. New roles can be created only for Workspaces.",
"TOOLTIP": "Roles created for the workspace, as a selection of the roles defined for the tenant that can be assigned to the user.",
"NAME": "Name",
"DESCRIPTION": "Description",
"APP_ID.WORKSPACE": "Workspace Name",
"APP_ID.APP": "App",
"CREATE": "Create new Role",
"CREATE_HEADER": "Create Role",
"DELETE": "Delete Role including all existing Permissions",
Expand All @@ -209,8 +206,10 @@
"FORMAT_URL": "Format: "
},
"ERRORS": {
"CREATE_ALREADY_EXISTS": "Couldn't create permission because it already exists",
"EDIT_ALREADY_EXISTS": "Couldn't change permission because it already exists",
"PERMISSION.CREATE_ALREADY_EXISTS": "Couldn't create permission because it already exists",
"PERMISSION.EDIT_ALREADY_EXISTS": "Couldn't change permission because it already exists",
"ROLE.CREATE_ALREADY_EXISTS": "Couldn't create permission because it already exists",
"ROLE.EDIT_ALREADY_EXISTS": "Couldn't change permission because it already exists",
"INTERNAL_ERROR": "Internal error",
"EMPTY_REQUIRED_FIELD": "This field is required.",
"MAXIMUM_LENGTH": "Only {{chars}} characters are allowed.",
Expand All @@ -220,22 +219,26 @@
},
"EXCEPTIONS": {
"HTTP_STATUS_0": {
"WORKSPACES": "Unknown problem retrieving Workspace data - please try again.",
"APPLICATIONS": "Unknown problem retrieving App data - please try again."
"APPS": "Unknown problem retrieving App data - please try again.",
"ROLES": "Unknown problem retrieving Role data - please try again.",
"WORKSPACES": "Unknown problem retrieving Workspace data - please try again."
},
"HTTP_STATUS_403": {
"WORKSPACES": "You have no permissions to see Workspaces.",
"APPLICATIONS": "You have no permissions to see Apps."
"APPS": "You have no permissions to see Apps.",
"WORKSPACES": "You have no permissions to see Workspaces."
},
"HTTP_STATUS_404": {
"APP": "App could not be found.",
"APPS": "No Apps could be found.",
"ROLE": "Role could not be found.",
"ROLES": "No Roles could be found.",
"WORKSPACE": "Workspace could not be found.",
"WORKSPACES": "No Workspaces could be found.",
"APPLICATION": "App could not be found.",
"APPLICATIONS": "No Apps could be found."
"WORKSPACES": "No Workspaces could be found."
},
"HTTP_STATUS_500": {
"WORKSPACES": "Unknown server problem retrieving Workspace data - please try again.",
"APPLICATIONS": "Unknown server problem retrieving App data - please try again."
"APPS": "Unknown server problem retrieving App data - please try again.",
"ROLES": "Unknown server problem retrieving Role 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"
}
Expand Down

0 comments on commit 59b8786

Please sign in to comment.