diff --git a/src/app/modules/accounts/services/account.service.ts b/src/app/modules/accounts/services/account.service.ts index 3af265f..dbf3362 100644 --- a/src/app/modules/accounts/services/account.service.ts +++ b/src/app/modules/accounts/services/account.service.ts @@ -5,7 +5,7 @@ import {AppState} from '../../shared/app-state' import {HttpClient, HttpResponse} from '@angular/common/http' import {environment} from '../../../../environments/environment' import {ApiService} from '../../shared/service/api.service' -import {Employee, EmployeePermission} from '../../shared/model/employee' +import {User, Permission} from '../../shared/model/user' import {ErrorService} from '../../shared/service/error.service' import {globalLoadingWheel} from '../../shared/components/loading-wheel/loading-wheel.component' import {AlertService} from '../../shared/service/alert.service' @@ -35,15 +35,15 @@ export class AccountService implements OnDestroy { } checkAuthenticationStatus() { - if (!this.appState.authenticatedEmployee) { + if (!this.appState.authenticatedUser) { // Try to get current default group user - this.http.get(`${environment.apiUrl}/employee/current`, {withCredentials: true}) + this.http.get(`${environment.apiUrl}/user/current`, {withCredentials: true}) .pipe( take(1), takeUntil(this.destroy$), ).subscribe( { - next: employee => this.appState.authenticatedEmployee = employee, + next: user => this.appState.authenticatedUser = user, error: err => { if (err.status === 404 || err.status === 403) { console.warn('No default user is defined on this computer') @@ -70,7 +70,7 @@ export class AccountService implements OnDestroy { next: (response: HttpResponse) => { this.appState.authenticationExpiration = parseInt(response.headers.get('X-Authentication-Expiration')) this.appState.isAuthenticated = true - this.setLoggedInEmployeeFromApi() + this.setLoggedInUserFromApi() success() }, error: err => { @@ -91,7 +91,7 @@ export class AccountService implements OnDestroy { ) .subscribe({ next: () => { - this.appState.resetAuthenticatedEmployee() + this.appState.resetAuthenticatedUser() this.checkAuthenticationStatus() success() }, @@ -99,19 +99,19 @@ export class AccountService implements OnDestroy { }) } - hasPermission(permission: EmployeePermission): boolean { - return this.appState.authenticatedEmployee && this.appState.authenticatedEmployee.permissions.indexOf(permission) >= 0 + hasPermission(permission: Permission): boolean { + return this.appState.authenticatedUser && this.appState.authenticatedUser.permissions.indexOf(permission) >= 0 } - private setLoggedInEmployeeFromApi() { - this.api.get('/employee/current', true) + private setLoggedInUserFromApi() { + this.api.get('/user/current', true) .pipe( take(1), takeUntil(this.destroy$) ) .subscribe({ - next: employee => { - this.appState.authenticatedEmployee = employee + next: user => { + this.appState.authenticatedUser = user // At this point the loading wheel should be visible globalLoadingWheel.hide() }, diff --git a/src/app/modules/colors/components/mix-editor/mix-editor.component.ts b/src/app/modules/colors/components/mix-editor/mix-editor.component.ts index 1ebd7bc..2c0ec3c 100644 --- a/src/app/modules/colors/components/mix-editor/mix-editor.component.ts +++ b/src/app/modules/colors/components/mix-editor/mix-editor.component.ts @@ -19,7 +19,7 @@ import {MatTable} from '@angular/material/table' import {ActivatedRoute, Router} from '@angular/router' import {ConfirmBoxComponent} from '../../../shared/components/confirm-box/confirm-box.component' import {AccountService} from '../../../accounts/services/account.service' -import {EmployeePermission} from '../../../shared/model/employee' +import {Permission} from '../../../shared/model/user' import {ErrorService} from '../../../shared/service/error.service' @Component({ @@ -191,7 +191,7 @@ export class MixEditorComponent extends ErrorHandlingComponent { } get canDeleteMix() { - return this.accountService.hasPermission(EmployeePermission.REMOVE_RECIPES) + return this.accountService.hasPermission(Permission.REMOVE_RECIPES) } private generateForm() { diff --git a/src/app/modules/colors/components/mix-table/mix-table.component.ts b/src/app/modules/colors/components/mix-table/mix-table.component.ts index fa8da6d..853c054 100644 --- a/src/app/modules/colors/components/mix-table/mix-table.component.ts +++ b/src/app/modules/colors/components/mix-table/mix-table.component.ts @@ -10,7 +10,7 @@ import {ErrorService} from '../../../shared/service/error.service' import {AlertService} from '../../../shared/service/alert.service' import {environment} from '../../../../../environments/environment' import {MaterialService} from '../../../material/service/material.service' -import {EmployeePermission} from '../../../shared/model/employee' +import {Permission} from '../../../shared/model/user' import {AccountService} from '../../../accounts/services/account.service' import {Material, openSimdut} from '../../../shared/model/material.model' @@ -175,15 +175,15 @@ export class MixTableComponent extends SubscribingComponent { } get canPrintMixes(): boolean { - return this.accountService.hasPermission(EmployeePermission.PRINT_MIXES) + return this.accountService.hasPermission(Permission.PRINT_MIXES) } get canDeductFromInventory(): boolean { - return this.accountService.hasPermission(EmployeePermission.DEDUCT_FROM_INVENTORY) + return this.accountService.hasPermission(Permission.DEDUCT_FROM_INVENTORY) } get canEditRecipesPublicData(): boolean { - return this.accountService.hasPermission(EmployeePermission.EDIT_RECIPES_PUBLIC_DATA) + return this.accountService.hasPermission(Permission.EDIT_RECIPES_PUBLIC_DATA) } private emitQuantityChangeEvent(index: number) { diff --git a/src/app/modules/colors/components/step-table/step-table.component.ts b/src/app/modules/colors/components/step-table/step-table.component.ts index 3d92d34..1c471b3 100644 --- a/src/app/modules/colors/components/step-table/step-table.component.ts +++ b/src/app/modules/colors/components/step-table/step-table.component.ts @@ -2,7 +2,7 @@ import {Component, Input} from '@angular/core' import {Recipe, RecipeStep, recipeStepsForGroupId, sortRecipeSteps} from '../../../shared/model/recipe.model' import {MatTable} from '@angular/material/table' import {Observable} from 'rxjs' -import {EmployeeGroup} from '../../../shared/model/employee' +import {Group} from '../../../shared/model/user' @Component({ selector: 'cre-step-table', @@ -13,7 +13,7 @@ export class StepTableComponent { readonly columns = ['position', 'buttonsPosition', 'message', 'buttonRemove'] @Input() recipe: Recipe - @Input() groups$: Observable + @Input() groups$: Observable @Input() selectedGroupId: number | null hoveredStep: RecipeStep | null diff --git a/src/app/modules/colors/pages/edit/edit.component.html b/src/app/modules/colors/pages/edit/edit.component.html index 6e15d0a..c22a493 100644 --- a/src/app/modules/colors/pages/edit/edit.component.html +++ b/src/app/modules/colors/pages/edit/edit.component.html @@ -52,7 +52,7 @@ #stepTable [recipe]="recipe" [groups$]="groups$" - [selectedGroupId]="loggedInEmployeeGroupId"> + [selectedGroupId]="loggedInUserGroupId"> diff --git a/src/app/modules/colors/pages/edit/edit.component.ts b/src/app/modules/colors/pages/edit/edit.component.ts index 5382f21..3bca40e 100644 --- a/src/app/modules/colors/pages/edit/edit.component.ts +++ b/src/app/modules/colors/pages/edit/edit.component.ts @@ -7,7 +7,7 @@ import {Validators} from '@angular/forms' import {Subject} from 'rxjs' import {UNIT_GALLON, UNIT_LITER, UNIT_MILLILITER} from '../../../shared/units' import {AccountService} from '../../../accounts/services/account.service' -import {EmployeePermission} from '../../../shared/model/employee' +import {Permission} from '../../../shared/model/user' import {EntityEditComponent} from '../../../shared/components/entity-edit/entity-edit.component' import {ImagesEditorComponent} from '../../components/images-editor/images-editor.component' import {ErrorHandler, ErrorService} from '../../../shared/service/error.service' @@ -169,11 +169,11 @@ export class EditComponent extends ErrorHandlingComponent { } get hasDeletePermission(): boolean { - return this.accountService.hasPermission(EmployeePermission.REMOVE_RECIPES) + return this.accountService.hasPermission(Permission.REMOVE_RECIPES) } - get loggedInEmployeeGroupId(): number { - return this.appState.authenticatedEmployee.group?.id + get loggedInUserGroupId(): number { + return this.appState.authenticatedUser.group?.id } private stepsPositionsAreValid(steps: Map): boolean { diff --git a/src/app/modules/colors/pages/explore/explore.component.ts b/src/app/modules/colors/pages/explore/explore.component.ts index e112d4b..89665ec 100644 --- a/src/app/modules/colors/pages/explore/explore.component.ts +++ b/src/app/modules/colors/pages/explore/explore.component.ts @@ -12,7 +12,7 @@ import {ConfirmBoxComponent} from '../../../shared/components/confirm-box/confir import {GroupService} from '../../../groups/services/group.service' import {AppState} from '../../../shared/app-state' import {AccountService} from '../../../accounts/services/account.service' -import {EmployeePermission} from '../../../shared/model/employee' +import {Permission} from '../../../shared/model/user' @Component({ selector: 'cre-explore', @@ -60,7 +60,7 @@ export class ExploreComponent extends ErrorHandlingComponent { super.ngOnInit() GlobalAlertHandlerComponent.extraTopMarginMultiplier = 2.5 - this.selectedGroupId = this.loggedInEmployeeGroupId + this.selectedGroupId = this.loggedInUserGroupId const id = parseInt(this.activatedRoute.snapshot.paramMap.get('id')) this.subscribeEntityById( @@ -132,8 +132,8 @@ export class ExploreComponent extends ErrorHandlingComponent { ) } - get loggedInEmployeeGroupId(): number { - return this.appState.authenticatedEmployee.group?.id + get loggedInUserGroupId(): number { + return this.appState.authenticatedUser.group?.id } get selectedGroupNote(): string { @@ -148,7 +148,7 @@ export class ExploreComponent extends ErrorHandlingComponent { } get canEditRecipesPublicData(): boolean { - return this.accountService.hasPermission(EmployeePermission.EDIT_RECIPES_PUBLIC_DATA) + return this.accountService.hasPermission(Permission.EDIT_RECIPES_PUBLIC_DATA) } private get mappedUpdatedNotes(): Map { diff --git a/src/app/modules/colors/pages/list/list.component.ts b/src/app/modules/colors/pages/list/list.component.ts index 1b42eb4..b713a5e 100644 --- a/src/app/modules/colors/pages/list/list.component.ts +++ b/src/app/modules/colors/pages/list/list.component.ts @@ -1,7 +1,7 @@ import {ChangeDetectorRef, Component} from '@angular/core' import {ErrorHandlingComponent} from '../../../shared/components/subscribing.component' import {RecipeService} from '../../services/recipe.service' -import {EmployeePermission} from '../../../shared/model/employee' +import {Permission} from '../../../shared/model/user' import {AccountService} from '../../../accounts/services/account.service' import {getRecipeLuma, Recipe, recipeApprobationExpired} from '../../../shared/model/recipe.model' import {ActivatedRoute, Router} from '@angular/router' @@ -63,7 +63,7 @@ export class ListComponent extends ErrorHandlingComponent { } get hasEditPermission(): boolean { - return this.accountService.hasPermission(EmployeePermission.EDIT_RECIPES) + return this.accountService.hasPermission(Permission.EDIT_RECIPES) } private recipeMatchesSearchQuery(recipe: Recipe) { diff --git a/src/app/modules/company/pages/list/list.component.ts b/src/app/modules/company/pages/list/list.component.ts index d817a86..7ab4045 100644 --- a/src/app/modules/company/pages/list/list.component.ts +++ b/src/app/modules/company/pages/list/list.component.ts @@ -1,7 +1,7 @@ import {Component} from '@angular/core' import {ErrorHandlingComponent} from '../../../shared/components/subscribing.component' import {CompanyService} from '../../service/company.service' -import {EmployeePermission} from '../../../shared/model/employee' +import {Permission} from '../../../shared/model/user' import {ActivatedRoute, Router} from '@angular/router' import {ErrorService} from '../../../shared/service/error.service' @@ -18,7 +18,7 @@ export class ListComponent extends ErrorHandlingComponent { buttons = [{ text: 'Modifier', linkFn: t => `/catalog/company/edit/${t.id}`, - permission: EmployeePermission.EDIT_COMPANIES + permission: Permission.EDIT_COMPANIES }] constructor( diff --git a/src/app/modules/groups/pages/add/add.component.ts b/src/app/modules/groups/pages/add/add.component.ts index e632fb9..85e98ee 100644 --- a/src/app/modules/groups/pages/add/add.component.ts +++ b/src/app/modules/groups/pages/add/add.component.ts @@ -33,7 +33,7 @@ export class AddComponent extends ErrorHandlingComponent { }] errorHandlers: ErrorHandler[] = [{ - filter: error => error.type === 'exists-employeegroup-name', + filter: error => error.type === 'exists-group-name', messageProducer: error => `Un groupe avec le nom '${error.name}' existe déjà` }] diff --git a/src/app/modules/groups/pages/edit/edit.component.ts b/src/app/modules/groups/pages/edit/edit.component.ts index 0b4c121..90d0057 100644 --- a/src/app/modules/groups/pages/edit/edit.component.ts +++ b/src/app/modules/groups/pages/edit/edit.component.ts @@ -1,6 +1,6 @@ import {Component, ViewChild} from '@angular/core' import {ActivatedRoute, Router} from '@angular/router' -import {EmployeeGroup} from '../../../shared/model/employee' +import {Group} from '../../../shared/model/user' import {GroupService} from '../../services/group.service' import {Validators} from '@angular/forms' import {currentPermissionsFieldComponent} from '../../../shared/components/permissions-field/permissions-field.component' @@ -33,13 +33,13 @@ export class EditComponent extends ErrorHandlingComponent { label: 'Permissions', type: 'permissions' }] - group: EmployeeGroup | null + group: Group | null errorHandlers: ErrorHandler[] = [{ - filter: error => error.type === 'notfound-employeegroup-id', + filter: error => error.type === 'notfound-group-id', consumer: error => this.urlUtils.navigateTo('/admin/group/list') }, { - filter: error => error.type === 'exists-employeegroup-name', + filter: error => error.type === 'exists-group-name', messageProducer: error => `Un groupe avec le nom '${error.name}' existe déjà` }] diff --git a/src/app/modules/groups/pages/list/list.component.ts b/src/app/modules/groups/pages/list/list.component.ts index d8a08e9..ba22fdf 100644 --- a/src/app/modules/groups/pages/list/list.component.ts +++ b/src/app/modules/groups/pages/list/list.component.ts @@ -1,6 +1,6 @@ import {Component} from '@angular/core' import {GroupService} from '../../services/group.service' -import {EmployeeGroup, EmployeePermission} from '../../../shared/model/employee' +import {Group, Permission} from '../../../shared/model/user' import {AccountService} from '../../../accounts/services/account.service' import {ErrorHandlingComponent} from '../../../shared/components/subscribing.component' import {ActivatedRoute, Router} from '@angular/router' @@ -14,7 +14,7 @@ import {AlertService} from '../../../shared/service/alert.service' }) export class ListComponent extends ErrorHandlingComponent { groups$ = this.groupService.all - defaultGroup: EmployeeGroup = null + defaultGroup: Group = null columns = [ {def: 'name', title: 'Nom', valueFn: g => g.name}, {def: 'permissionCount', title: 'Nombre de permissions', valueFn: g => g.permissions.length} @@ -26,7 +26,7 @@ export class ListComponent extends ErrorHandlingComponent { }, { text: 'Modifier', linkFn: group => `/admin/group/edit/${group.id}`, - permission: EmployeePermission.EDIT_USERS + permission: Permission.EDIT_USERS }] errorHandlers: ErrorHandler[] = [{ @@ -53,7 +53,7 @@ export class ListComponent extends ErrorHandlingComponent { ) } - setDefaultGroup(group: EmployeeGroup) { + setDefaultGroup(group: Group) { this.subscribe( this.groupService.setDefaultGroup(group), () => this.defaultGroup = group, @@ -61,7 +61,7 @@ export class ListComponent extends ErrorHandlingComponent { ) } - isDefaultGroup(group: EmployeeGroup): boolean { + isDefaultGroup(group: Group): boolean { return this.defaultGroup && this.defaultGroup.id == group.id } } diff --git a/src/app/modules/groups/services/group.service.ts b/src/app/modules/groups/services/group.service.ts index 565332c..56fbccb 100644 --- a/src/app/modules/groups/services/group.service.ts +++ b/src/app/modules/groups/services/group.service.ts @@ -1,7 +1,7 @@ import {Injectable} from '@angular/core' import {ApiService} from '../../shared/service/api.service' import {Observable} from 'rxjs' -import {Employee, EmployeeGroup, EmployeePermission} from '../../shared/model/employee' +import {User, Group, Permission} from '../../shared/model/user' import {tap} from 'rxjs/operators' @Injectable({ @@ -13,11 +13,11 @@ export class GroupService { ) { } - get all(): Observable { - return this.api.get('/employee/group') + get all(): Observable { + return this.api.get('/user/group') } - get allWithDefault(): Observable { + get allWithDefault(): Observable { return this.all .pipe(tap(groups => groups.unshift({ id: -1, @@ -26,41 +26,41 @@ export class GroupService { }))) } - getById(id: number): Observable { - return this.api.get(`/employee/group/${id}`) + getById(id: number): Observable { + return this.api.get(`/user/group/${id}`) } - get defaultGroup(): Observable { - return this.api.get('/employee/group/default') + get defaultGroup(): Observable { + return this.api.get('/user/group/default') } - setDefaultGroup(value: EmployeeGroup): Observable { - return this.api.post(`/employee/group/default/${value.id}`, {}) + setDefaultGroup(value: Group): Observable { + return this.api.post(`/user/group/default/${value.id}`, {}) } - getEmployeesForGroup(id: number): Observable { - return this.api.get(`/employee/group/${id}/employees`) + getUsersForGroup(id: number): Observable { + return this.api.get(`/user/group/${id}/users`) } - addEmployeeToGroup(id: number, employee: Employee): Observable { - return this.api.put(`/employee/group/${id}/${employee.id}`) + addUserToGroup(id: number, user: User): Observable { + return this.api.put(`/user/group/${id}/${user.id}`) } - removeEmployeeFromGroup(employee: Employee): Observable { - return this.api.delete(`/employee/group/${employee.group.id}/${employee.id}`) + removeUserFromGroup(user: User): Observable { + return this.api.delete(`/user/group/${user.group.id}/${user.id}`) } - save(name: string, permissions: EmployeePermission[]): Observable { + save(name: string, permissions: Permission[]): Observable { const group = {name, permissions} - return this.api.post('/employee/group', group) + return this.api.post('/user/group', group) } - update(id: number, name: string, permissions: EmployeePermission[]): Observable { + update(id: number, name: string, permissions: Permission[]): Observable { const group = {id, name, permissions} - return this.api.put('/employee/group', group) + return this.api.put('/user/group', group) } - delete(id: number): Observable { - return this.api.delete(`/employee/group/${id}`) + delete(id: number): Observable { + return this.api.delete(`/user/group/${id}`) } } diff --git a/src/app/modules/material-type/pages/list/list.component.ts b/src/app/modules/material-type/pages/list/list.component.ts index c729638..364242a 100644 --- a/src/app/modules/material-type/pages/list/list.component.ts +++ b/src/app/modules/material-type/pages/list/list.component.ts @@ -1,7 +1,7 @@ import {Component} from '@angular/core' import {MaterialTypeService} from '../../service/material-type.service' import {ErrorHandlingComponent} from '../../../shared/components/subscribing.component' -import {EmployeePermission} from '../../../shared/model/employee' +import {Permission} from '../../../shared/model/user' import {ActivatedRoute, Router} from '@angular/router' import {ErrorService} from '../../../shared/service/error.service' @@ -21,7 +21,7 @@ export class ListComponent extends ErrorHandlingComponent { { text: 'Modifier', linkFn: t => `/catalog/materialtype/edit/${t.id}`, - permission: EmployeePermission.EDIT_MATERIAL_TYPES, + permission: Permission.EDIT_MATERIAL_TYPES, disabledFn: t => t.systemType } ] diff --git a/src/app/modules/material/pages/inventory/inventory.component.ts b/src/app/modules/material/pages/inventory/inventory.component.ts index f706215..3ad3e11 100644 --- a/src/app/modules/material/pages/inventory/inventory.component.ts +++ b/src/app/modules/material/pages/inventory/inventory.component.ts @@ -1,7 +1,7 @@ import {Component, ViewChild} from '@angular/core' import {ErrorHandlingComponent} from '../../../shared/components/subscribing.component' import {MaterialService} from '../../service/material.service' -import {EmployeePermission} from '../../../shared/model/employee' +import {Permission} from '../../../shared/model/user' import {ActivatedRoute, Router} from '@angular/router' import {ErrorService} from '../../../shared/service/error.service' import {Material, openSimdut} from '../../../shared/model/material.model' @@ -116,10 +116,10 @@ export class InventoryComponent extends ErrorHandlingComponent { } get canEditMaterial(): boolean { - return this.accountService.hasPermission(EmployeePermission.EDIT_MATERIALS) + return this.accountService.hasPermission(Permission.EDIT_MATERIALS) } get canAddToInventory(): boolean { - return this.accountService.hasPermission(EmployeePermission.ADD_TO_INVENTORY) + return this.accountService.hasPermission(Permission.ADD_TO_INVENTORY) } } diff --git a/src/app/modules/shared/app-state.ts b/src/app/modules/shared/app-state.ts index 772bd25..a9c7716 100644 --- a/src/app/modules/shared/app-state.ts +++ b/src/app/modules/shared/app-state.ts @@ -1,5 +1,5 @@ import {Injectable} from "@angular/core"; -import {Employee} from "./model/employee"; +import {User} from "./model/user"; import {Subject} from "rxjs"; @Injectable({ @@ -8,20 +8,20 @@ import {Subject} from "rxjs"; export class AppState { private readonly KEY_AUTHENTICATED = "authenticated" private readonly KEY_AUTHENTICATION_EXPIRATION = "authentication-expiration" - private readonly KEY_LOGGED_IN_EMPLOYEE = "logged-in-employee" + private readonly KEY_LOGGED_IN_USER = "logged-in-user" - authenticatedUser$ = new Subject<{ authenticated: boolean, authenticatedUser: Employee }>() + authenticatedUser$ = new Subject<{ authenticated: boolean, authenticatedUser: User }>() serverOnline$ = new Subject() - resetAuthenticatedEmployee() { + resetAuthenticatedUser() { this.isAuthenticated = false this.authenticationExpiration = -1 - this.authenticatedEmployee = null + this.authenticatedUser = null } set isServerOnline(isOnline: boolean) { - if (!isOnline) this.authenticatedEmployee = null + if (!isOnline) this.authenticatedUser = null this.serverOnline$.next(isOnline); } @@ -33,7 +33,7 @@ export class AppState { sessionStorage.setItem(this.KEY_AUTHENTICATED, value.toString()) this.authenticatedUser$.next({ authenticated: value, - authenticatedUser: this.authenticatedEmployee + authenticatedUser: this.authenticatedUser }) } @@ -45,16 +45,16 @@ export class AppState { sessionStorage.setItem(this.KEY_AUTHENTICATION_EXPIRATION, value.toString()) } - get authenticatedEmployee(): Employee { - const employeeString = sessionStorage.getItem(this.KEY_LOGGED_IN_EMPLOYEE) - return employeeString ? JSON.parse(employeeString) : null + get authenticatedUser(): User { + const userString = sessionStorage.getItem(this.KEY_LOGGED_IN_USER) + return userString ? JSON.parse(userString) : null } - set authenticatedEmployee(value: Employee) { + set authenticatedUser(value: User) { if (value === null) { - sessionStorage.removeItem(this.KEY_LOGGED_IN_EMPLOYEE) + sessionStorage.removeItem(this.KEY_LOGGED_IN_USER) } else { - sessionStorage.setItem(this.KEY_LOGGED_IN_EMPLOYEE, JSON.stringify(value)) + sessionStorage.setItem(this.KEY_LOGGED_IN_USER, JSON.stringify(value)) } this.authenticatedUser$.next({ authenticated: this.isAuthenticated, diff --git a/src/app/modules/shared/components/entity-edit/entity-edit.component.ts b/src/app/modules/shared/components/entity-edit/entity-edit.component.ts index 41864b1..239f96c 100644 --- a/src/app/modules/shared/components/entity-edit/entity-edit.component.ts +++ b/src/app/modules/shared/components/entity-edit/entity-edit.component.ts @@ -1,7 +1,7 @@ import {ChangeDetectorRef, Component, EventEmitter, Input, Output} from '@angular/core' import {FormBuilder, FormControl, FormGroup} from '@angular/forms' import {FormField} from '../entity-add/entity-add.component' -import {EmployeePermission} from '../../model/employee' +import {Permission} from '../../model/user' import {AccountService} from '../../../accounts/services/account.service' @Component({ @@ -15,7 +15,7 @@ export class EntityEditComponent { @Input() deleteConfirmMessage: string @Input() backButtonLink: string @Input() formFields: FormField[] - @Input() deletePermission: EmployeePermission + @Input() deletePermission: Permission @Input() disableButtons: boolean @Input() noTopMargin = false @Output() submit = new EventEmitter() diff --git a/src/app/modules/shared/components/entity-list/entity-list.component.ts b/src/app/modules/shared/components/entity-list/entity-list.component.ts index d5ddb0f..115ad50 100644 --- a/src/app/modules/shared/components/entity-list/entity-list.component.ts +++ b/src/app/modules/shared/components/entity-list/entity-list.component.ts @@ -1,7 +1,7 @@ import {Component, Input} from '@angular/core' import {Observable} from 'rxjs' import {AccountService} from '../../../accounts/services/account.service' -import {EmployeePermission} from '../../model/employee' +import {Permission} from '../../model/user' import {animate, state, style, transition, trigger} from '@angular/animations' @Component({ @@ -22,7 +22,7 @@ export class EntityListComponent { @Input() icons: TableIcon[] @Input() buttons?: TableButton[] @Input() addLink: string - @Input() addPermission: EmployeePermission + @Input() addPermission: Permission @Input() expandable = false @Input() rowDetailsTemplate @@ -38,7 +38,7 @@ export class EntityListComponent { return !button.permission || this.hasPermission(button.permission) } - hasPermission(permission: EmployeePermission): boolean { + hasPermission(permission: Permission): boolean { return this.accountService.hasPermission(permission) } @@ -119,7 +119,7 @@ export class TableButton { public link: string | { externalLink: string } | null, public linkFn: (T) => string | { externalLink: string } | null, public clickFn: (T) => void, - public permission: EmployeePermission | null, + public permission: Permission | null, public disabledFn: (T) => boolean | null ) { } diff --git a/src/app/modules/shared/components/header/header.component.html b/src/app/modules/shared/components/header/header.component.html index 51aabfa..7a2bb30 100644 --- a/src/app/modules/shared/components/header/header.component.html +++ b/src/app/modules/shared/components/header/header.component.html @@ -16,7 +16,7 @@ - + { if (l.permission) { - l.enabled = employee && employee.permissions.indexOf(l.permission) >= 0; + l.enabled = user && user.permissions.indexOf(l.permission) >= 0; } }) } @@ -67,7 +67,7 @@ export class NavLink { constructor( public route: string, public title: string, - public permission?: EmployeePermission, + public permission?: Permission, public enabled? ) { } diff --git a/src/app/modules/shared/components/permissions-field/permissions-field.component.ts b/src/app/modules/shared/components/permissions-field/permissions-field.component.ts index 5a265c6..0fa898d 100644 --- a/src/app/modules/shared/components/permissions-field/permissions-field.component.ts +++ b/src/app/modules/shared/components/permissions-field/permissions-field.component.ts @@ -1,9 +1,9 @@ import {Component, Input, OnInit, ViewChild} from '@angular/core'; -import {EmployeePermission, mapped_permissions} from "../../model/employee"; +import {Permission, mapped_permissions} from "../../model/user"; import {FormControl} from "@angular/forms"; import {AccountService} from "../../../accounts/services/account.service"; -// The current permissions field component. Workaround to be able to access a permission field in template. (See employee/AddComponent) +// The current permissions field component. Workaround to be able to access a permission field in template. (See user/AddComponent) // This workaround prevent the use of several permissions field component at the same time. export let currentPermissionsFieldComponent: PermissionsFieldComponent | null @@ -13,7 +13,7 @@ export let currentPermissionsFieldComponent: PermissionsFieldComponent | null styleUrls: ['./permissions-field.component.sass'] }) export class PermissionsFieldComponent implements OnInit { - @Input() enabledPermissions: EmployeePermission[] + @Input() enabledPermissions: Permission[] @Input() title = 'Permissions' @Input() required = true @@ -34,7 +34,7 @@ export class PermissionsFieldComponent implements OnInit { if (this.enabledPermissions) { this.enabledPermissions.forEach(p => { - if (EmployeePermission[p]) { + if (Permission[p]) { const control = this.findPermissionControl(p) control.control.setValue(true) this.togglePermission(control, true) @@ -74,7 +74,7 @@ export class PermissionsFieldComponent implements OnInit { return false } - get allEnabledPermissions(): EmployeePermission[] { + get allEnabledPermissions(): Permission[] { return this.allPermissionControls().filter(p => p.control.value).map(p => p.permission) } @@ -96,7 +96,7 @@ export class PermissionsFieldComponent implements OnInit { return Object.values(this.permissionControls).flatMap(p => p) } - private findPermissionControl(permission: EmployeePermission): any { + private findPermissionControl(permission: Permission): any { return this.allPermissionControls().filter(p => p.permission === permission)[0] } diff --git a/src/app/modules/shared/components/permissions-list/permissions-list.component.ts b/src/app/modules/shared/components/permissions-list/permissions-list.component.ts index b63ac16..18ddb0e 100644 --- a/src/app/modules/shared/components/permissions-list/permissions-list.component.ts +++ b/src/app/modules/shared/components/permissions-list/permissions-list.component.ts @@ -1,5 +1,5 @@ import {Component, Input, OnInit} from '@angular/core' -import {Employee, EmployeeGroup, EmployeePermission, mapped_permissions} from '../../model/employee' +import {User, Group, Permission, mapped_permissions} from '../../model/user' @Component({ selector: 'cre-permissions-list', @@ -7,8 +7,8 @@ import {Employee, EmployeeGroup, EmployeePermission, mapped_permissions} from '. styleUrls: ['./permissions-list.component.sass'] }) export class PermissionsListComponent { - @Input() employee: Employee - @Input() group: EmployeeGroup + @Input() user: User + @Input() group: Group // @ts-ignore private _permissions = Object.values(mapped_permissions).flatMap(p => p) @@ -16,12 +16,12 @@ export class PermissionsListComponent { constructor() { } - get permissions(): EmployeePermission[] { + get permissions(): Permission[] { // @ts-ignore - return this.filterPermissions(this.employee ? this.employee.permissions : this.group.permissions) + return this.filterPermissions(this.user ? this.user.permissions : this.group.permissions) } - private filterPermissions(permissions: EmployeePermission[]) { + private filterPermissions(permissions: Permission[]) { return this._permissions.filter(p => permissions.indexOf(p.permission) >= 0).map(p => p.description) } } diff --git a/src/app/modules/shared/components/employee-info/employee-menu.component.html b/src/app/modules/shared/components/user-info/user-menu.component.html similarity index 55% rename from src/app/modules/shared/components/employee-info/employee-menu.component.html rename to src/app/modules/shared/components/user-info/user-menu.component.html index 4830558..d758d48 100644 --- a/src/app/modules/shared/components/employee-info/employee-menu.component.html +++ b/src/app/modules/shared/components/user-info/user-menu.component.html @@ -1,43 +1,43 @@ -
-
+
+ diff --git a/src/app/modules/shared/components/employee-info/employee-menu.component.sass b/src/app/modules/shared/components/user-info/user-menu.component.sass similarity index 93% rename from src/app/modules/shared/components/employee-info/employee-menu.component.sass rename to src/app/modules/shared/components/user-info/user-menu.component.sass index 7da5a0c..d3ffcd7 100644 --- a/src/app/modules/shared/components/employee-info/employee-menu.component.sass +++ b/src/app/modules/shared/components/user-info/user-menu.component.sass @@ -4,14 +4,14 @@ p, labeled-icon margin: 0 color: $light-primary-text -.employee-info-wrapper +.user-info-wrapper margin: 1rem 1rem 0 cursor: pointer &:hover labeled-icon text-decoration: underline -.employee-info-group +.user-info-group margin-left: 0.7rem mat-action-list diff --git a/src/app/modules/shared/components/employee-info/employee-menu.component.ts b/src/app/modules/shared/components/user-info/user-menu.component.ts similarity index 70% rename from src/app/modules/shared/components/employee-info/employee-menu.component.ts rename to src/app/modules/shared/components/user-info/user-menu.component.ts index 70263c3..d04c28a 100644 --- a/src/app/modules/shared/components/employee-info/employee-menu.component.ts +++ b/src/app/modules/shared/components/user-info/user-menu.component.ts @@ -1,20 +1,20 @@ import {Component, OnDestroy, OnInit} from '@angular/core' import {AppState} from '../../app-state' -import {Employee} from '../../model/employee' +import {User} from '../../model/user' import {Subject} from 'rxjs' import {takeUntil} from 'rxjs/operators' import {UrlUtils} from '../../utils/url.utils' import {ActivatedRoute, Router} from '@angular/router' @Component({ - selector: 'cre-employee-menu', - templateUrl: './employee-menu.component.html', - styleUrls: ['./employee-menu.component.sass'] + selector: 'cre-user-menu', + templateUrl: './user-menu.component.html', + styleUrls: ['./user-menu.component.sass'] }) -export class EmployeeMenuComponent implements OnInit, OnDestroy { +export class UserMenuComponent implements OnInit, OnDestroy { authenticated = false - employee: Employee = null - employeeInGroup = false + user: User = null + userInGroup = false menuEnabled = false private destroy$ = new Subject() @@ -29,7 +29,7 @@ export class EmployeeMenuComponent implements OnInit, OnDestroy { } ngOnInit(): void { - this.authenticationState(this.appState.isAuthenticated, this.appState.authenticatedEmployee) + this.authenticationState(this.appState.isAuthenticated, this.appState.authenticatedUser) this.appState.authenticatedUser$ .pipe(takeUntil(this.destroy$)) .subscribe({ @@ -52,11 +52,11 @@ export class EmployeeMenuComponent implements OnInit, OnDestroy { this.menuEnabled = false } - private authenticationState(authenticated: boolean, employee: Employee) { + private authenticationState(authenticated: boolean, user: User) { this.authenticated = authenticated - this.employee = employee - if (this.employee != null) { - this.employeeInGroup = this.employee.group != null + this.user = user + if (this.user != null) { + this.userInGroup = this.user.group != null } } } diff --git a/src/app/modules/shared/model/employee.ts b/src/app/modules/shared/model/employee.ts deleted file mode 100644 index 601676a..0000000 --- a/src/app/modules/shared/model/employee.ts +++ /dev/null @@ -1,132 +0,0 @@ -export class Employee { - constructor( - public id: number, - public firstName: string, - public lastName: string, - public explicitPermissions: EmployeePermission[], - public permissions: EmployeePermission[], - public group?: EmployeeGroup, - public lastLoginTime?: Date - ) { - } -} - -export class EmployeeGroup { - constructor( - public id: number, - public name: string, - public permissions: EmployeePermission[] - ) { - } -} - -export enum EmployeePermission { - VIEW_RECIPES = 'VIEW_RECIPES', - VIEW_USERS = 'VIEW_USERS', - VIEW_CATALOG = 'VIEW_CATALOG', - - EDIT_RECIPES_PUBLIC_DATA = 'EDIT_RECIPES_PUBLIC_DATA', - EDIT_RECIPES = 'EDIT_RECIPES', - EDIT_MATERIALS = 'EDIT_MATERIALS', - EDIT_MATERIAL_TYPES = 'EDIT_MATERIAL_TYPES', - EDIT_COMPANIES = 'EDIT_COMPANIES', - EDIT_USERS = 'EDIT_USERS', - EDIT_CATALOG = 'EDIT_CATALOG', - - REMOVE_RECIPES = 'REMOVE_RECIPES', - REMOVE_MATERIALS = 'REMOVE_MATERIALS', - REMOVE_MATERIAL_TYPES = 'REMOVE_MATERIAL_TYPES', - REMOVE_COMPANIES = 'REMOVE_COMPANIES', - REMOVE_USERS = 'REMOVE_USERS', - REMOVE_CATALOG = 'REMOVE_CATALOG', - - PRINT_MIXES = 'PRINT_MIXES', - ADD_TO_INVENTORY = 'ADD_TO_INVENTORY', - DEDUCT_FROM_INVENTORY = 'DEDUCT_FROM_INVENTORY', - GENERATE_TOUCH_UP_KIT = 'GENERATE_TOUCH_UP_KIT', - - ADMIN = 'ADMIN' -} - -export const mapped_permissions = { - view: [ - {permission: EmployeePermission.VIEW_RECIPES, description: 'Voir les recettes', impliedPermissions: []}, - {permission: EmployeePermission.VIEW_CATALOG, description: 'Voir le catalogue', impliedPermissions: []}, - {permission: EmployeePermission.VIEW_USERS, description: 'Voir les utilisateurs', impliedPermissions: []}, - ], - edit: [{ - permission: EmployeePermission.EDIT_RECIPES_PUBLIC_DATA, - description: 'Modifier les données publiques des recettes', - impliedPermissions: [EmployeePermission.VIEW_RECIPES] - }, { - permission: EmployeePermission.EDIT_RECIPES, - description: 'Modifier les recettes', - impliedPermissions: [EmployeePermission.EDIT_RECIPES_PUBLIC_DATA] - }, { - permission: EmployeePermission.EDIT_MATERIALS, - description: 'Modifier les produits', - impliedPermissions: [EmployeePermission.VIEW_CATALOG] - }, { - permission: EmployeePermission.EDIT_MATERIAL_TYPES, - description: 'Modifier les types de produit', - impliedPermissions: [EmployeePermission.VIEW_CATALOG] - }, { - permission: EmployeePermission.EDIT_COMPANIES, - description: 'Modifier les bannières', - impliedPermissions: [EmployeePermission.VIEW_CATALOG] - }, { - permission: EmployeePermission.EDIT_CATALOG, - description: 'Modifier le catalogue', - impliedPermissions: [EmployeePermission.EDIT_MATERIALS, EmployeePermission.EDIT_MATERIAL_TYPES, EmployeePermission.EDIT_COMPANIES] - }, { - permission: EmployeePermission.EDIT_USERS, - description: 'Modifier les utilisateurs', - impliedPermissions: [EmployeePermission.VIEW_USERS] - }], - remove: [{ - permission: EmployeePermission.REMOVE_RECIPES, - description: 'Supprimer des recettes', - impliedPermissions: [EmployeePermission.EDIT_RECIPES] - }, { - permission: EmployeePermission.REMOVE_MATERIALS, - description: 'Supprimer des produits', - impliedPermissions: [EmployeePermission.EDIT_MATERIALS] - }, { - permission: EmployeePermission.REMOVE_MATERIAL_TYPES, - description: 'Supprimer des types de produit', - impliedPermissions: [EmployeePermission.EDIT_MATERIAL_TYPES] - }, { - permission: EmployeePermission.REMOVE_COMPANIES, - description: 'Supprimer des bannières', - impliedPermissions: [EmployeePermission.EDIT_COMPANIES] - }, { - permission: EmployeePermission.REMOVE_CATALOG, - description: 'Supprimer dans le catalogue', - impliedPermissions: [EmployeePermission.REMOVE_MATERIALS, EmployeePermission.REMOVE_MATERIAL_TYPES, EmployeePermission.REMOVE_COMPANIES] - }, { - permission: EmployeePermission.REMOVE_USERS, - description: 'Supprimer des utilisateurs', - impliedPermissions: [EmployeePermission.EDIT_USERS] - }], - other: [{ - permission: EmployeePermission.PRINT_MIXES, - description: 'Imprimer les mélanges (bPac)', - impliedPermissions: [EmployeePermission.VIEW_RECIPES] - }, { - permission: EmployeePermission.ADD_TO_INVENTORY, - description: 'Ajouter dans l\'inventaire', - impliedPermissions: [EmployeePermission.VIEW_CATALOG] - }, { - permission: EmployeePermission.DEDUCT_FROM_INVENTORY, - description: 'Déduire dans l\'inventaire', - impliedPermissions: [EmployeePermission.VIEW_RECIPES] - }, { - permission: EmployeePermission.GENERATE_TOUCH_UP_KIT, - description: 'Générer un PDF de kit de retouche', - impliedPermissions: [] - }, { - permission: EmployeePermission.ADMIN, - description: 'Administrateur', - impliedPermissions: [EmployeePermission.EDIT_CATALOG, EmployeePermission.REMOVE_RECIPES, EmployeePermission.REMOVE_USERS, EmployeePermission.REMOVE_CATALOG, EmployeePermission.PRINT_MIXES, EmployeePermission.ADD_TO_INVENTORY, EmployeePermission.DEDUCT_FROM_INVENTORY] - }] -} diff --git a/src/app/modules/shared/model/recipe.model.ts b/src/app/modules/shared/model/recipe.model.ts index 7e84e00..f48ec29 100644 --- a/src/app/modules/shared/model/recipe.model.ts +++ b/src/app/modules/shared/model/recipe.model.ts @@ -1,7 +1,7 @@ import {Material} from './material.model' import {LocalDate} from 'js-joda' import {Company} from './company.model' -import {EmployeeGroup} from './employee' +import {Group} from './user' export class Recipe { constructor( @@ -24,7 +24,7 @@ export class Recipe { export class RecipeGroupInformation { constructor( public id: number, - public group: EmployeeGroup, + public group: Group, public note: string, public steps: RecipeStep[] ) { diff --git a/src/app/modules/shared/model/user.ts b/src/app/modules/shared/model/user.ts new file mode 100644 index 0000000..273c579 --- /dev/null +++ b/src/app/modules/shared/model/user.ts @@ -0,0 +1,132 @@ +export class User { + constructor( + public id: number, + public firstName: string, + public lastName: string, + public explicitPermissions: Permission[], + public permissions: Permission[], + public group?: Group, + public lastLoginTime?: Date + ) { + } +} + +export class Group { + constructor( + public id: number, + public name: string, + public permissions: Permission[] + ) { + } +} + +export enum Permission { + VIEW_RECIPES = 'VIEW_RECIPES', + VIEW_USERS = 'VIEW_USERS', + VIEW_CATALOG = 'VIEW_CATALOG', + + EDIT_RECIPES_PUBLIC_DATA = 'EDIT_RECIPES_PUBLIC_DATA', + EDIT_RECIPES = 'EDIT_RECIPES', + EDIT_MATERIALS = 'EDIT_MATERIALS', + EDIT_MATERIAL_TYPES = 'EDIT_MATERIAL_TYPES', + EDIT_COMPANIES = 'EDIT_COMPANIES', + EDIT_USERS = 'EDIT_USERS', + EDIT_CATALOG = 'EDIT_CATALOG', + + REMOVE_RECIPES = 'REMOVE_RECIPES', + REMOVE_MATERIALS = 'REMOVE_MATERIALS', + REMOVE_MATERIAL_TYPES = 'REMOVE_MATERIAL_TYPES', + REMOVE_COMPANIES = 'REMOVE_COMPANIES', + REMOVE_USERS = 'REMOVE_USERS', + REMOVE_CATALOG = 'REMOVE_CATALOG', + + PRINT_MIXES = 'PRINT_MIXES', + ADD_TO_INVENTORY = 'ADD_TO_INVENTORY', + DEDUCT_FROM_INVENTORY = 'DEDUCT_FROM_INVENTORY', + GENERATE_TOUCH_UP_KIT = 'GENERATE_TOUCH_UP_KIT', + + ADMIN = 'ADMIN' +} + +export const mapped_permissions = { + view: [ + {permission: Permission.VIEW_RECIPES, description: 'Voir les recettes', impliedPermissions: []}, + {permission: Permission.VIEW_CATALOG, description: 'Voir le catalogue', impliedPermissions: []}, + {permission: Permission.VIEW_USERS, description: 'Voir les utilisateurs', impliedPermissions: []}, + ], + edit: [{ + permission: Permission.EDIT_RECIPES_PUBLIC_DATA, + description: 'Modifier les données publiques des recettes', + impliedPermissions: [Permission.VIEW_RECIPES] + }, { + permission: Permission.EDIT_RECIPES, + description: 'Modifier les recettes', + impliedPermissions: [Permission.EDIT_RECIPES_PUBLIC_DATA] + }, { + permission: Permission.EDIT_MATERIALS, + description: 'Modifier les produits', + impliedPermissions: [Permission.VIEW_CATALOG] + }, { + permission: Permission.EDIT_MATERIAL_TYPES, + description: 'Modifier les types de produit', + impliedPermissions: [Permission.VIEW_CATALOG] + }, { + permission: Permission.EDIT_COMPANIES, + description: 'Modifier les bannières', + impliedPermissions: [Permission.VIEW_CATALOG] + }, { + permission: Permission.EDIT_CATALOG, + description: 'Modifier le catalogue', + impliedPermissions: [Permission.EDIT_MATERIALS, Permission.EDIT_MATERIAL_TYPES, Permission.EDIT_COMPANIES] + }, { + permission: Permission.EDIT_USERS, + description: 'Modifier les utilisateurs', + impliedPermissions: [Permission.VIEW_USERS] + }], + remove: [{ + permission: Permission.REMOVE_RECIPES, + description: 'Supprimer des recettes', + impliedPermissions: [Permission.EDIT_RECIPES] + }, { + permission: Permission.REMOVE_MATERIALS, + description: 'Supprimer des produits', + impliedPermissions: [Permission.EDIT_MATERIALS] + }, { + permission: Permission.REMOVE_MATERIAL_TYPES, + description: 'Supprimer des types de produit', + impliedPermissions: [Permission.EDIT_MATERIAL_TYPES] + }, { + permission: Permission.REMOVE_COMPANIES, + description: 'Supprimer des bannières', + impliedPermissions: [Permission.EDIT_COMPANIES] + }, { + permission: Permission.REMOVE_CATALOG, + description: 'Supprimer dans le catalogue', + impliedPermissions: [Permission.REMOVE_MATERIALS, Permission.REMOVE_MATERIAL_TYPES, Permission.REMOVE_COMPANIES] + }, { + permission: Permission.REMOVE_USERS, + description: 'Supprimer des utilisateurs', + impliedPermissions: [Permission.EDIT_USERS] + }], + other: [{ + permission: Permission.PRINT_MIXES, + description: 'Imprimer les mélanges (bPac)', + impliedPermissions: [Permission.VIEW_RECIPES] + }, { + permission: Permission.ADD_TO_INVENTORY, + description: 'Ajouter dans l\'inventaire', + impliedPermissions: [Permission.VIEW_CATALOG] + }, { + permission: Permission.DEDUCT_FROM_INVENTORY, + description: 'Déduire dans l\'inventaire', + impliedPermissions: [Permission.VIEW_RECIPES] + }, { + permission: Permission.GENERATE_TOUCH_UP_KIT, + description: 'Générer un PDF de kit de retouche', + impliedPermissions: [] + }, { + permission: Permission.ADMIN, + description: 'Administrateur', + impliedPermissions: [Permission.EDIT_CATALOG, Permission.REMOVE_RECIPES, Permission.REMOVE_USERS, Permission.REMOVE_CATALOG, Permission.PRINT_MIXES, Permission.ADD_TO_INVENTORY, Permission.DEDUCT_FROM_INVENTORY, Permission.GENERATE_TOUCH_UP_KIT] + }] +} diff --git a/src/app/modules/shared/service/api.service.ts b/src/app/modules/shared/service/api.service.ts index 5389e7d..7c39b28 100644 --- a/src/app/modules/shared/service/api.service.ts +++ b/src/app/modules/shared/service/api.service.ts @@ -78,7 +78,7 @@ export class ApiService implements OnDestroy { console.error('httpOptions need to be specified to use credentials in HTTP methods.') } } else { - this.appState.resetAuthenticatedEmployee() + this.appState.resetAuthenticatedUser() this.navigateToLogin() } } @@ -92,7 +92,7 @@ export class ApiService implements OnDestroy { private checkAuthenticated(): boolean { return (this.appState.isAuthenticated && Date.now() <= this.appState.authenticationExpiration) || - (this.appState.authenticatedEmployee && this.appState.authenticatedEmployee.group != null) + (this.appState.authenticatedUser && this.appState.authenticatedUser.group != null) } private navigateToLogin() { diff --git a/src/app/modules/shared/shared.module.ts b/src/app/modules/shared/shared.module.ts index 549c6a8..b1391c7 100644 --- a/src/app/modules/shared/shared.module.ts +++ b/src/app/modules/shared/shared.module.ts @@ -7,7 +7,7 @@ import {MatFormFieldModule} from '@angular/material/form-field' import {MatInputModule} from '@angular/material/input' import {MatIconModule} from '@angular/material/icon' import {FormsModule, ReactiveFormsModule} from '@angular/forms' -import {EmployeeMenuComponent} from './components/employee-info/employee-menu.component' +import {UserMenuComponent} from './components/user-info/user-menu.component' import {LabeledIconComponent} from './components/labeled-icon/labeled-icon.component' import {MatTableModule} from '@angular/material/table' import {CommonModule} from '@angular/common' @@ -35,7 +35,7 @@ import {MatProgressSpinnerModule} from '@angular/material/progress-spinner' @NgModule({ - declarations: [HeaderComponent, EmployeeMenuComponent, LabeledIconComponent, ConfirmBoxComponent, PermissionsListComponent, PermissionsFieldComponent, NavComponent, EntityListComponent, EntityAddComponent, EntityEditComponent, FileButtonComponent, GlobalAlertHandlerComponent, SliderFieldComponent, LoadingWheelComponent], + declarations: [HeaderComponent, UserMenuComponent, LabeledIconComponent, ConfirmBoxComponent, PermissionsListComponent, PermissionsFieldComponent, NavComponent, EntityListComponent, EntityAddComponent, EntityEditComponent, FileButtonComponent, GlobalAlertHandlerComponent, SliderFieldComponent, LoadingWheelComponent], exports: [ CommonModule, HttpClientModule, diff --git a/src/app/modules/users/pages/add/add.component.html b/src/app/modules/users/pages/add/add.component.html index 8175a1f..72e0f60 100644 --- a/src/app/modules/users/pages/add/add.component.html +++ b/src/app/modules/users/pages/add/add.component.html @@ -1,6 +1,6 @@ diff --git a/src/app/modules/users/pages/add/add.component.ts b/src/app/modules/users/pages/add/add.component.ts index 44d8a71..a40b343 100644 --- a/src/app/modules/users/pages/add/add.component.ts +++ b/src/app/modules/users/pages/add/add.component.ts @@ -73,15 +73,15 @@ export class AddComponent extends ErrorHandlingComponent { }] errorHandlers: ErrorHandler[] = [{ - filter: error => error.type === 'exists-employee-id', + filter: error => error.type === 'exists-user-id', messageProducer: error => `Un utilisateur avec l'identifiant ${error.id} existe déjà` }, { - filter: error => error.type === 'exists-employee-fullName', + filter: error => error.type === 'exists-user-fullName', messageProducer: error => `Un utilisateur nommé '${error.fullName}' existe déjà` }] constructor( - private employeeService: UserService, + private userService: UserService, private groupService: GroupService, errorService: ErrorService, router: Router, @@ -99,14 +99,13 @@ export class AddComponent extends ErrorHandlingComponent { submit(values) { const permissionsField = currentPermissionsFieldComponent if (permissionsField.valid()) { - const groupId = values.groupId >= 0 ? values.groupId : null this.subscribeAndNavigate( - this.employeeService.save( + this.userService.save( values.id, values.firstName, values.lastName, values.password, - groupId, + values.groupId, permissionsField.allEnabledPermissions ), '/admin/user/list' diff --git a/src/app/modules/users/pages/edit/edit.component.html b/src/app/modules/users/pages/edit/edit.component.html index 2ab4d53..8b80939 100644 --- a/src/app/modules/users/pages/edit/edit.component.html +++ b/src/app/modules/users/pages/edit/edit.component.html @@ -1,15 +1,15 @@ - + diff --git a/src/app/modules/users/pages/edit/edit.component.ts b/src/app/modules/users/pages/edit/edit.component.ts index f835a4a..af82f21 100644 --- a/src/app/modules/users/pages/edit/edit.component.ts +++ b/src/app/modules/users/pages/edit/edit.component.ts @@ -3,7 +3,7 @@ import {currentPermissionsFieldComponent} from '../../../shared/components/permi import {UserService} from '../../services/user.service' import {GroupService} from '../../../groups/services/group.service' import {ActivatedRoute, Router} from '@angular/router' -import {Employee} from '../../../shared/model/employee' +import {User} from '../../../shared/model/user' import {AccountService} from '../../../accounts/services/account.service' import {ErrorHandlingComponent} from '../../../shared/components/subscribing.component' import {ErrorHandler, ErrorService} from '../../../shared/service/error.service' @@ -18,7 +18,7 @@ import {map} from 'rxjs/operators' export class EditComponent extends ErrorHandlingComponent { @ViewChild('permissionsTemplateRef', {static: true}) permissionsTemplateRef - employee: Employee | null + user: User | null formFields: FormField[] = [{ name: 'id', label: 'Numéro d\'utilisateur', @@ -48,7 +48,7 @@ export class EditComponent extends ErrorHandlingComponent { label: 'Groupe', icon: 'account-multiple', type: 'select', - valueFn: employee => employee.group ? employee.group.id : -1, + valueFn: user => user.group ? user.group.id : -1, options$: this.groupService.allWithDefault.pipe(map(groups => groups.map(g => { return {value: g.id, label: g.name} }))) @@ -59,16 +59,16 @@ export class EditComponent extends ErrorHandlingComponent { }] errorHandlers: ErrorHandler[] = [{ - filter: error => error.type === 'notfound-employee-id', + filter: error => error.type === 'notfound-user-id', consumer: error => this.urlUtils.navigateTo('/admin/user/list') }, { - filter: error => error.type === 'exists-employee-fullName', + filter: error => error.type === 'exists-user-fullName', messageProducer: error => `Un utilisateur nommé '${error.fullName}' existe déjà` }] constructor( private accountService: AccountService, - private employeeService: UserService, + private userService: UserService, private groupService: GroupService, errorService: ErrorService, router: Router, @@ -80,9 +80,9 @@ export class EditComponent extends ErrorHandlingComponent { ngOnInit(): void { const id = parseInt(this.activatedRoute.snapshot.paramMap.get('id')) this.subscribeEntityById( - this.employeeService, + this.userService, id, - employee => this.employee = employee + user => this.user = user ) this.formFields[this.formFields.length - 1].template = this.permissionsTemplateRef @@ -92,7 +92,7 @@ export class EditComponent extends ErrorHandlingComponent { const permissionsField = currentPermissionsFieldComponent if (permissionsField.valid()) { this.subscribe( - this.employeeService.update( + this.userService.update( parseInt(values.id), values.firstName, values.lastName, @@ -108,7 +108,7 @@ export class EditComponent extends ErrorHandlingComponent { delete() { this.subscribeAndNavigate( - this.employeeService.delete(this.employee.id), + this.userService.delete(this.user.id), '/admin/user/list' ) } diff --git a/src/app/modules/users/pages/list/list.component.html b/src/app/modules/users/pages/list/list.component.html index bb5d917..8d99f7f 100644 --- a/src/app/modules/users/pages/list/list.component.html +++ b/src/app/modules/users/pages/list/list.component.html @@ -1,13 +1,13 @@ + [rowDetailsTemplate]="userDetailsTemplate"> - - + + diff --git a/src/app/modules/users/pages/list/list.component.ts b/src/app/modules/users/pages/list/list.component.ts index dd680dd..389f77e 100644 --- a/src/app/modules/users/pages/list/list.component.ts +++ b/src/app/modules/users/pages/list/list.component.ts @@ -1,7 +1,7 @@ import {Component} from '@angular/core' import {Observable} from 'rxjs' import {UserService} from '../../services/user.service' -import {Employee, EmployeePermission} from '../../../shared/model/employee' +import {User, Permission} from '../../../shared/model/user' import {takeUntil} from 'rxjs/operators' import {AccountService} from '../../../accounts/services/account.service' import {animate, state, style, transition, trigger} from '@angular/animations' @@ -10,7 +10,7 @@ import {ActivatedRoute, Router} from '@angular/router' import {ErrorService} from '../../../shared/service/error.service' @Component({ - selector: 'cre-employees', + selector: 'cre-users', templateUrl: './list.component.html', styleUrls: ['./list.component.sass'], animations: [ @@ -22,7 +22,7 @@ import {ErrorService} from '../../../shared/service/error.service' ] }) export class ListComponent extends ErrorHandlingComponent { - employees$: Observable + users$: Observable columns = [ {def: 'id', title: 'Numéro d\'utilisateur', valueFn: e => e.id}, {def: 'name', title: 'Nom', valueFn: e => `${e.firstName} ${e.lastName}`}, @@ -32,16 +32,16 @@ export class ListComponent extends ErrorHandlingComponent { ] buttons = [{ text: 'Modifier', - linkFn: employee => `/admin/user/edit/${employee.id}`, - permission: EmployeePermission.EDIT_USERS + linkFn: user => `/admin/user/edit/${user.id}`, + permission: Permission.EDIT_USERS }, { text: 'Modifier mot de passe', - linkFn: employee => `/admin/user/password/edit/${employee.id}`, - permission: EmployeePermission.EDIT_USERS + linkFn: user => `/admin/user/password/edit/${user.id}`, + permission: Permission.EDIT_USERS }] constructor( - private employeeService: UserService, + private userService: UserService, private accountService: AccountService, errorService: ErrorService, router: Router, @@ -51,7 +51,7 @@ export class ListComponent extends ErrorHandlingComponent { } ngOnInit(): void { - this.employees$ = this.employeeService.all.pipe(takeUntil(this.destroy$)) + this.users$ = this.userService.all.pipe(takeUntil(this.destroy$)) } getDate(dateString: string) { diff --git a/src/app/modules/users/pages/password-edit/password-edit.component.html b/src/app/modules/users/pages/password-edit/password-edit.component.html index 8f2d735..c522191 100644 --- a/src/app/modules/users/pages/password-edit/password-edit.component.html +++ b/src/app/modules/users/pages/password-edit/password-edit.component.html @@ -1,7 +1,7 @@ - +
- Modification du mot de passe de l'utilisateur #{{employee.id}} + Modification du mot de passe de l'utilisateur #{{user.id}} @@ -15,7 +15,7 @@ - +
diff --git a/src/app/modules/users/pages/password-edit/password-edit.component.ts b/src/app/modules/users/pages/password-edit/password-edit.component.ts index 65684c8..293fa78 100644 --- a/src/app/modules/users/pages/password-edit/password-edit.component.ts +++ b/src/app/modules/users/pages/password-edit/password-edit.component.ts @@ -1,7 +1,7 @@ import {Component} from '@angular/core' import {ErrorHandlingComponent} from '../../../shared/components/subscribing.component' import {UserService} from '../../services/user.service' -import {Employee} from '../../../shared/model/employee' +import {User} from '../../../shared/model/user' import {ActivatedRoute, Router} from '@angular/router' import {FormBuilder, FormControl, FormGroup, Validators} from '@angular/forms' import {ErrorHandler, ErrorService} from '../../../shared/service/error.service' @@ -12,18 +12,18 @@ import {ErrorHandler, ErrorService} from '../../../shared/service/error.service' styleUrls: ['./password-edit.component.sass'] }) export class PasswordEditComponent extends ErrorHandlingComponent { - employee: Employee | null + user: User | null form: FormGroup passwordControl = new FormControl(null, Validators.compose([Validators.required, Validators.minLength(8)])) errorHandlers: ErrorHandler[] = [{ - filter: error => error.type === 'notfound-employee-id', + filter: error => error.type === 'notfound-user-id', consumer: error => this.urlUtils.navigateTo('/admin/user/list') }] constructor( - private employeeService: UserService, + private userService: UserService, private formBuilder: FormBuilder, errorService: ErrorService, router: Router, @@ -35,9 +35,9 @@ export class PasswordEditComponent extends ErrorHandlingComponent { ngOnInit(): void { const id = parseInt(this.activatedRoute.snapshot.paramMap.get('id')) this.subscribeEntityById( - this.employeeService, + this.userService, id, - employee => this.employee = employee + user => this.user = user ) this.form = this.formBuilder.group({ @@ -48,7 +48,7 @@ export class PasswordEditComponent extends ErrorHandlingComponent { submit() { if (this.form.valid) { this.subscribeAndNavigate( - this.employeeService.updatePassword(this.employee.id, this.passwordControl.value), + this.userService.updatePassword(this.user.id, this.passwordControl.value), '/admin/user/list' ) } diff --git a/src/app/modules/users/services/user.service.ts b/src/app/modules/users/services/user.service.ts index 3047bb6..4a93cf0 100644 --- a/src/app/modules/users/services/user.service.ts +++ b/src/app/modules/users/services/user.service.ts @@ -1,6 +1,6 @@ import {Injectable} from '@angular/core'; import {ApiService} from "../../shared/service/api.service"; -import {Employee, EmployeePermission} from "../../shared/model/employee"; +import {User, Permission} from "../../shared/model/user"; import {Observable} from "rxjs"; @Injectable({ @@ -12,29 +12,29 @@ export class UserService { ) { } - get all(): Observable { - return this.api.get('/employee') + get all(): Observable { + return this.api.get('/user') } - getById(id: number): Observable { - return this.api.get(`/employee/${id}`) + getById(id: number): Observable { + return this.api.get(`/user/${id}`) } - save(id: number, firstName: string, lastName: string, password: string, group: number, permissions: EmployeePermission[]): Observable { - const employee = {id, firstName, lastName, password, groupId: group, permissions} - return this.api.post('/employee', employee) + save(id: number, firstName: string, lastName: string, password: string, group: number, permissions: Permission[]): Observable { + const user = {id, firstName, lastName, password, groupId: group >= 0 ? group : null, permissions} + return this.api.post('/user', user) } - update(id: number, firstName: string, lastName: string, group: number, permissions: EmployeePermission[]): Observable { - const employee = {id, firstName, lastName, groupId: group, permissions} - return this.api.put('/employee', employee) + update(id: number, firstName: string, lastName: string, group: number, permissions: Permission[]): Observable { + const user = {id, firstName, lastName, groupId: group >= 0 ? group : null, permissions} + return this.api.put('/user', user) } updatePassword(id: number, password: string): Observable { - return this.api.put(`/employee/${id}/password`, password, true, {contentType: 'text/plain'}) + return this.api.put(`/user/${id}/password`, password, true, {contentType: 'text/plain'}) } delete(id: number): Observable { - return this.api.delete(`/employee/${id}`) + return this.api.delete(`/user/${id}`) } } diff --git a/src/app/pages/administration/administration.component.ts b/src/app/pages/administration/administration.component.ts index 44683f8..3406db0 100644 --- a/src/app/pages/administration/administration.component.ts +++ b/src/app/pages/administration/administration.component.ts @@ -1,7 +1,7 @@ import {Component} from '@angular/core' import {SubMenuComponent} from '../../modules/shared/components/sub-menu/sub-menu.component' import {NavLink} from '../../modules/shared/components/nav/nav.component' -import {EmployeePermission} from '../../modules/shared/model/employee' +import {Permission} from '../../modules/shared/model/user' @Component({ selector: 'cre-administration', @@ -10,7 +10,7 @@ import {EmployeePermission} from '../../modules/shared/model/employee' }) export class AdministrationComponent extends SubMenuComponent { links: NavLink[] = [ - {route: '/admin/user', title: 'Utilisateurs', permission: EmployeePermission.VIEW_USERS}, - {route: '/admin/group', title: 'Groupes', permission: EmployeePermission.VIEW_USERS}, + {route: '/admin/user', title: 'Utilisateurs', permission: Permission.VIEW_USERS}, + {route: '/admin/group', title: 'Groupes', permission: Permission.VIEW_USERS}, ] } diff --git a/src/app/pages/catalog/catalog.component.ts b/src/app/pages/catalog/catalog.component.ts index 30981b0..2ad1840 100644 --- a/src/app/pages/catalog/catalog.component.ts +++ b/src/app/pages/catalog/catalog.component.ts @@ -1,6 +1,6 @@ import {Component} from '@angular/core' import {NavLink} from '../../modules/shared/components/nav/nav.component' -import {EmployeePermission} from '../../modules/shared/model/employee' +import {Permission} from '../../modules/shared/model/user' import {SubMenuComponent} from '../../modules/shared/components/sub-menu/sub-menu.component' @Component({ @@ -10,8 +10,8 @@ import {SubMenuComponent} from '../../modules/shared/components/sub-menu/sub-men }) export class CatalogComponent extends SubMenuComponent { links: NavLink[] = [ - {route: '/catalog/materialtype', title: 'Types de produit', permission: EmployeePermission.VIEW_CATALOG}, - {route: '/catalog/material', title: 'Inventaire', permission: EmployeePermission.VIEW_CATALOG}, - {route: '/catalog/company', title: 'Bannières', permission: EmployeePermission.VIEW_CATALOG} + {route: '/catalog/materialtype', title: 'Types de produit', permission: Permission.VIEW_CATALOG}, + {route: '/catalog/material', title: 'Inventaire', permission: Permission.VIEW_CATALOG}, + {route: '/catalog/company', title: 'Bannières', permission: Permission.VIEW_CATALOG} ] } diff --git a/src/app/pages/others/misc.component.ts b/src/app/pages/others/misc.component.ts index d6f99ea..567849a 100644 --- a/src/app/pages/others/misc.component.ts +++ b/src/app/pages/others/misc.component.ts @@ -1,7 +1,7 @@ import {Component} from '@angular/core' import {SubMenuComponent} from '../../modules/shared/components/sub-menu/sub-menu.component' import {NavLink} from '../../modules/shared/components/nav/nav.component' -import {EmployeePermission} from '../../modules/shared/model/employee' +import {Permission} from '../../modules/shared/model/user' @Component({ selector: 'cre-others', @@ -10,6 +10,6 @@ import {EmployeePermission} from '../../modules/shared/model/employee' }) export class MiscComponent extends SubMenuComponent{ links: NavLink[] = [ - {route: '/misc/touchupkit', title: 'Kits de retouche', permission: EmployeePermission.GENERATE_TOUCH_UP_KIT} + {route: '/misc/touchupkit', title: 'Kits de retouche', permission: Permission.GENERATE_TOUCH_UP_KIT} ] }