Ajout des permissions pour le bouton ajouter dans l'interface Angular.

This commit is contained in:
FyloZ 2021-01-11 14:05:03 -05:00
parent 66cec621ac
commit b3facdc7db
6 changed files with 31 additions and 9 deletions

View File

@ -2,5 +2,6 @@
[entities$]="companies$"
[columns]="columns"
[buttons]="buttons"
addLink="/catalog/company/add">
addLink="/catalog/company/add"
addPermission="EDIT_COMPANY">
</cre-entity-list>

View File

@ -2,5 +2,6 @@
[entities$]="materialTypes$"
[columns]="columns"
[buttons]="buttons"
addLink="/catalog/materialtype/add">
addLink="/catalog/materialtype/add"
addPermission="EDIT_MATERIAL_TYPE">
</cre-entity-list>

View File

@ -3,5 +3,6 @@
[columns]="columns"
[icons]="icons"
[buttons]="buttons"
addLink="/catalog/material/add">
addLink="/catalog/material/add"
addPermission="EDIT_MATERIAL">
</cre-entity-list>

View File

@ -1,5 +1,5 @@
<div class="action-bar">
<button mat-raised-button color="accent" [routerLink]="addLink">Ajouter</button>
<button *ngIf="hasPermission(addPermission)" mat-raised-button color="accent" [routerLink]="addLink">Ajouter</button>
</div>
<table class="mx-auto" *ngIf="entities$ | async as entities" mat-table [dataSource]="entities">

View File

@ -15,6 +15,7 @@ export class EntityListComponent<T> extends SubscribingComponent {
@Input() icons: TableIcon[]
@Input() buttons?: TableButton[]
@Input() addLink: string
@Input() addPermission: EmployeePermission
constructor(
private accountService: AccountService
@ -23,7 +24,11 @@ export class EntityListComponent<T> extends SubscribingComponent {
}
hasPermissionToUseButton(button: TableButton): boolean {
return !button.permission || this.accountService.hasPermission(button.permission)
return !button.permission || this.hasPermission(button.permission)
}
hasPermission(permission: EmployeePermission): boolean {
return this.accountService.hasPermission(permission)
}
openExternalLink(button: TableButton, entity: T) {

View File

@ -24,6 +24,7 @@ export enum EmployeePermission {
VIEW_MATERIAL = 'VIEW_MATERIAL',
VIEW_MATERIAL_TYPE = 'VIEW_MATERIAL_TYPE',
VIEW_COMPANY = 'VIEW_COMPANY',
VIEW_RECIPE = 'VIEW_RECIPE',
VIEW = 'VIEW',
VIEW_EMPLOYEE = 'VIEW_EMPLOYEE',
VIEW_EMPLOYEE_GROUP = 'VIEW_EMPLOYEE_GROUP',
@ -31,6 +32,7 @@ export enum EmployeePermission {
EDIT_MATERIAL = 'EDIT_MATERIAL',
EDIT_MATERIAL_TYPE = 'EDIT_MATERIAL_TYPE',
EDIT_COMPANY = 'EDIT_COMPANY',
EDIT_RECIPE = 'EDIT_RECIPE',
EDIT = 'EDIT',
EDIT_EMPLOYEE = 'EDIT_EMPLOYEE',
EDIT_EMPLOYEE_PASSWORD = 'EDIT_EMPLOYEE_PASSWORD',
@ -39,6 +41,7 @@ export enum EmployeePermission {
REMOVE_MATERIAL = 'REMOVE_MATERIAL',
REMOVE_MATERIAL_TYPE = 'REMOVE_MATERIAL_TYPE',
REMOVE_COMPANY = 'REMOVE_COMPANY',
REMOVE_RECIPE = 'REMOVE_RECIPE',
REMOVE = 'REMOVE',
REMOVE_EMPLOYEE = 'REMOVE_EMPLOYEE',
REMOVE_EMPLOYEE_GROUP = 'REMOVE_EMPLOYEE_GROUP',
@ -56,10 +59,11 @@ export const mapped_permissions = {
impliedPermissions: []
},
{permission: EmployeePermission.VIEW_COMPANY, description: 'Voir les bannières', impliedPermissions: []},
{permission: EmployeePermission.VIEW_RECIPE, description: 'Voir les couleurs', impliedPermissions: []},
{
permission: EmployeePermission.VIEW,
description: 'Voir',
impliedPermissions: [EmployeePermission.VIEW_MATERIAL, EmployeePermission.VIEW_MATERIAL_TYPE, EmployeePermission.VIEW_COMPANY]
impliedPermissions: [EmployeePermission.VIEW_MATERIAL, EmployeePermission.VIEW_MATERIAL_TYPE, EmployeePermission.VIEW_COMPANY, EmployeePermission.VIEW_RECIPE]
},
{permission: EmployeePermission.VIEW_EMPLOYEE, description: 'Voir les employés', impliedPermissions: []},
{permission: EmployeePermission.VIEW_EMPLOYEE_GROUP, description: 'Voir les groupes', impliedPermissions: []},
@ -80,15 +84,20 @@ export const mapped_permissions = {
description: 'Modifier les bannières',
impliedPermissions: [EmployeePermission.VIEW_COMPANY]
},
{
permission: EmployeePermission.EDIT_RECIPE,
description: 'Modifier les couleurs',
impliedPermissions: [EmployeePermission.VIEW_RECIPE]
},
{
permission: EmployeePermission.EDIT,
description: 'Modifier',
impliedPermissions: [EmployeePermission.EDIT_MATERIAL, EmployeePermission.EDIT_MATERIAL_TYPE, EmployeePermission.EDIT_COMPANY, EmployeePermission.VIEW]
impliedPermissions: [EmployeePermission.EDIT_MATERIAL, EmployeePermission.EDIT_MATERIAL_TYPE, EmployeePermission.EDIT_COMPANY, EmployeePermission.EDIT_RECIPE, EmployeePermission.VIEW]
},
{
permission: EmployeePermission.EDIT_EMPLOYEE,
description: 'Modifier les employés',
impliedPermissions: [EmployeePermission.EDIT_EMPLOYEE]
impliedPermissions: [EmployeePermission.VIEW_EMPLOYEE]
},
{
permission: EmployeePermission.EDIT_EMPLOYEE_PASSWORD,
@ -117,10 +126,15 @@ export const mapped_permissions = {
description: 'Supprimer des bannières',
impliedPermissions: [EmployeePermission.EDIT_COMPANY]
},
{
permission: EmployeePermission.REMOVE_RECIPE,
description: 'Supprimer des couleurs',
impliedPermissions: [EmployeePermission.EDIT_RECIPE]
},
{
permission: EmployeePermission.REMOVE,
description: 'Supprimer',
impliedPermissions: [EmployeePermission.REMOVE_MATERIAL, EmployeePermission.REMOVE_MATERIAL_TYPE, EmployeePermission.REMOVE_COMPANY, EmployeePermission.EDIT]
impliedPermissions: [EmployeePermission.REMOVE_MATERIAL, EmployeePermission.REMOVE_MATERIAL_TYPE, EmployeePermission.REMOVE_COMPANY, EmployeePermission.REMOVE_RECIPE, EmployeePermission.EDIT]
},
{
permission: EmployeePermission.REMOVE_EMPLOYEE,