Employee -> User

This commit is contained in:
FyloZ 2021-05-05 23:49:34 -04:00
parent 68e0238023
commit 89b7865096
43 changed files with 344 additions and 345 deletions

View File

@ -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<Employee>(`${environment.apiUrl}/employee/current`, {withCredentials: true})
this.http.get<User>(`${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<any>) => {
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>('/employee/current', true)
private setLoggedInUserFromApi() {
this.api.get<User>('/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()
},

View File

@ -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() {

View File

@ -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) {

View File

@ -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<EmployeeGroup[]>
@Input() groups$: Observable<Group[]>
@Input() selectedGroupId: number | null
hoveredStep: RecipeStep | null

View File

@ -52,7 +52,7 @@
#stepTable
[recipe]="recipe"
[groups$]="groups$"
[selectedGroupId]="loggedInEmployeeGroupId">
[selectedGroupId]="loggedInUserGroupId">
</cre-step-table>
</div>

View File

@ -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<number, RecipeStep[]>): boolean {

View File

@ -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<number, string> {

View File

@ -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) {

View File

@ -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(

View File

@ -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à`
}]

View File

@ -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à`
}]

View File

@ -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
}
}

View File

@ -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<EmployeeGroup[]> {
return this.api.get<EmployeeGroup[]>('/employee/group')
get all(): Observable<Group[]> {
return this.api.get<Group[]>('/user/group')
}
get allWithDefault(): Observable<EmployeeGroup[]> {
get allWithDefault(): Observable<Group[]> {
return this.all
.pipe(tap(groups => groups.unshift({
id: -1,
@ -26,41 +26,41 @@ export class GroupService {
})))
}
getById(id: number): Observable<EmployeeGroup> {
return this.api.get<EmployeeGroup>(`/employee/group/${id}`)
getById(id: number): Observable<Group> {
return this.api.get<Group>(`/user/group/${id}`)
}
get defaultGroup(): Observable<EmployeeGroup> {
return this.api.get<EmployeeGroup>('/employee/group/default')
get defaultGroup(): Observable<Group> {
return this.api.get<Group>('/user/group/default')
}
setDefaultGroup(value: EmployeeGroup): Observable<void> {
return this.api.post<void>(`/employee/group/default/${value.id}`, {})
setDefaultGroup(value: Group): Observable<void> {
return this.api.post<void>(`/user/group/default/${value.id}`, {})
}
getEmployeesForGroup(id: number): Observable<Employee[]> {
return this.api.get<Employee[]>(`/employee/group/${id}/employees`)
getUsersForGroup(id: number): Observable<User[]> {
return this.api.get<User[]>(`/user/group/${id}/users`)
}
addEmployeeToGroup(id: number, employee: Employee): Observable<void> {
return this.api.put<void>(`/employee/group/${id}/${employee.id}`)
addUserToGroup(id: number, user: User): Observable<void> {
return this.api.put<void>(`/user/group/${id}/${user.id}`)
}
removeEmployeeFromGroup(employee: Employee): Observable<void> {
return this.api.delete<void>(`/employee/group/${employee.group.id}/${employee.id}`)
removeUserFromGroup(user: User): Observable<void> {
return this.api.delete<void>(`/user/group/${user.group.id}/${user.id}`)
}
save(name: string, permissions: EmployeePermission[]): Observable<EmployeeGroup> {
save(name: string, permissions: Permission[]): Observable<Group> {
const group = {name, permissions}
return this.api.post<EmployeeGroup>('/employee/group', group)
return this.api.post<Group>('/user/group', group)
}
update(id: number, name: string, permissions: EmployeePermission[]): Observable<EmployeeGroup> {
update(id: number, name: string, permissions: Permission[]): Observable<Group> {
const group = {id, name, permissions}
return this.api.put<EmployeeGroup>('/employee/group', group)
return this.api.put<Group>('/user/group', group)
}
delete(id: number): Observable<EmployeeGroup> {
return this.api.delete<EmployeeGroup>(`/employee/group/${id}`)
delete(id: number): Observable<Group> {
return this.api.delete<Group>(`/user/group/${id}`)
}
}

View File

@ -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
}
]

View File

@ -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)
}
}

View File

@ -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<boolean>()
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,

View File

@ -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<any>()

View File

@ -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<T> {
@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<T> {
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
) {
}

View File

@ -16,7 +16,7 @@
</div>
</nav>
<cre-employee-menu></cre-employee-menu>
<cre-user-menu></cre-user-menu>
<img
class="flex-grow-0"
src="assets/logo.png"

View File

@ -1,7 +1,7 @@
import {Component} from '@angular/core'
import {ActivatedRoute, ResolveEnd, Router} from '@angular/router'
import {AppState} from '../../app-state'
import {Employee, EmployeePermission} from '../../model/employee'
import {Permission} from '../../model/user'
import {AccountService} from '../../../accounts/services/account.service'
import {SubscribingComponent} from '../subscribing.component'
import {ErrorService} from '../../service/error.service'
@ -13,10 +13,10 @@ import {ErrorService} from '../../service/error.service'
})
export class HeaderComponent extends SubscribingComponent {
links: HeaderLink[] = [
{route: '/color', title: 'Couleurs', requiredPermission: EmployeePermission.VIEW_RECIPES},
{route: '/catalog', title: 'Catalogue', requiredPermission: EmployeePermission.VIEW_CATALOG},
{route: '/color', title: 'Couleurs', requiredPermission: Permission.VIEW_RECIPES},
{route: '/catalog', title: 'Catalogue', requiredPermission: Permission.VIEW_CATALOG},
{route: '/misc', title: 'Autres', enabled: true},
{route: '/admin', title: 'Administration', requiredPermission: EmployeePermission.VIEW_USERS},
{route: '/admin', title: 'Administration', requiredPermission: Permission.VIEW_USERS},
]
_activeLink = this.links[0].route
@ -78,7 +78,7 @@ export class HeaderComponent extends SubscribingComponent {
}
if (l.route === '/misc') {
l.enabled = this.accountService.hasPermission(EmployeePermission.GENERATE_TOUCH_UP_KIT)
l.enabled = this.accountService.hasPermission(Permission.GENERATE_TOUCH_UP_KIT)
}
})
}
@ -88,7 +88,7 @@ class HeaderLink {
constructor(
public route: string,
public title: string,
public requiredPermission?: EmployeePermission,
public requiredPermission?: Permission,
public enabled?
) {
}

View File

@ -1,5 +1,5 @@
import {Component, Input, OnDestroy, OnInit} from '@angular/core';
import {Employee, EmployeePermission} from "../../model/employee";
import {User, Permission} from "../../model/user";
import {AccountService} from "../../../accounts/services/account.service";
import {ActivatedRoute, Router} from "@angular/router";
import {takeUntil} from "rxjs/operators";
@ -27,7 +27,7 @@ export class NavComponent implements OnInit, OnDestroy {
ngOnInit(): void {
this._activeLink = this.router.url
this.updateEnabledLinks(this.appState.authenticatedEmployee)
this.updateEnabledLinks(this.appState.authenticatedUser)
this.appState.authenticatedUser$
.pipe(takeUntil(this._destroy$))
@ -54,10 +54,10 @@ export class NavComponent implements OnInit, OnDestroy {
return this._activeLink
}
private updateEnabledLinks(employee: Employee) {
private updateEnabledLinks(user: User) {
this.links.forEach(l => {
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?
) {
}

View File

@ -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]
}

View File

@ -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)
}
}

View File

@ -1,43 +1,43 @@
<div class="employee-menu-wrapper">
<div *ngIf="employee" class="employee-info-wrapper d-flex flex-column" (click)="menuEnabled = !menuEnabled">
<div class="user-menu-wrapper">
<div *ngIf="user" class="user-info-wrapper d-flex flex-column" (click)="menuEnabled = !menuEnabled">
<labeled-icon
*ngIf="authenticated"
icon="account"
label="{{employee.firstName}} {{employee.lastName}}">
label="{{user.firstName}} {{user.lastName}}">
</labeled-icon>
<div class="d-flex flex-row">
<labeled-icon
*ngIf="authenticated"
icon="pound"
[label]="employee.id.toString()">
[label]="user.id.toString()">
</labeled-icon>
<labeled-icon
*ngIf="employeeInGroup"
class="employee-info-group"
*ngIf="userInGroup"
class="user-info-group"
icon="account-multiple"
[label]="employee.group.name">
[label]="user.group.name">
</labeled-icon>
</div>
</div>
<button
*ngIf="!authenticated && !employeeInGroup"
*ngIf="!authenticated && !userInGroup"
(click)="openLogout()">
Connexion
</button>
<mat-action-list *ngIf="menuEnabled">
<button
*ngIf="!authenticated && employeeInGroup"
*ngIf="!authenticated && userInGroup"
mat-list-item
class="employee-menu-item-login"
class="user-menu-item-login"
(click)="openLogin()">
Connexion
</button>
<button
*ngIf="authenticated"
mat-list-item
class="employee-menu-item-logout"
class="user-menu-item-logout"
(click)="openLogout()">
Déconnexion
</button>

View File

@ -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

View File

@ -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<boolean>()
@ -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
}
}
}

View File

@ -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]
}]
}

View File

@ -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[]
) {

View File

@ -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]
}]
}

View File

@ -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() {

View File

@ -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,

View File

@ -1,6 +1,6 @@
<cre-entity-add
title="Création d'un utilisateur"
backButtonLink="/employee/list"
backButtonLink="/user/list"
[formFields]="formFields"
(submit)="submit($event)">
</cre-entity-add>

View File

@ -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'

View File

@ -1,15 +1,15 @@
<cre-entity-edit
*ngIf="employee"
title="Modification de l'utilisateur #{{employee.id}}"
backButtonLink="/employee/list"
*ngIf="user"
title="Modification de l'utilisateur #{{user.id}}"
backButtonLink="/user/list"
deletePermission="REMOVE_USERS"
deleteConfirmMessage="Voulez-vous vraiment supprimer l'utilisateur #{{employee.id}}?"
[entity]="employee"
deleteConfirmMessage="Voulez-vous vraiment supprimer l'utilisateur #{{user.id}}?"
[entity]="user"
[formFields]="formFields"
(submit)="submit($event)"
(delete)="delete()">
</cre-entity-edit>
<ng-template #permissionsTemplateRef>
<cre-permissions-field [enabledPermissions]="employee.explicitPermissions"></cre-permissions-field>
<cre-permissions-field [enabledPermissions]="user.explicitPermissions"></cre-permissions-field>
</ng-template>

View File

@ -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'
)
}

View File

@ -1,13 +1,13 @@
<cre-entity-list
addLink="/admin/user/add"
addPermission="EDIT_USERS"
[entities$]="employees$"
[entities$]="users$"
[columns]="columns"
[buttons]="buttons"
[expandable]="true"
[rowDetailsTemplate]="employeeDetailsTemplate">
[rowDetailsTemplate]="userDetailsTemplate">
</cre-entity-list>
<ng-template #employeeDetailsTemplate let-employee="entity">
<cre-permissions-list [employee]="employee" class="w-100"></cre-permissions-list>
<ng-template #userDetailsTemplate let-user="entity">
<cre-permissions-list [user]="user" class="w-100"></cre-permissions-list>
</ng-template>

View File

@ -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<Employee[]>
users$: Observable<User[]>
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) {

View File

@ -1,7 +1,7 @@
<mat-card *ngIf="employee" class="x-centered mt-5">
<mat-card *ngIf="user" class="x-centered mt-5">
<form [formGroup]="form">
<mat-card-header>
<mat-card-title>Modification du mot de passe de l'utilisateur #{{employee.id}}</mat-card-title>
<mat-card-title>Modification du mot de passe de l'utilisateur #{{user.id}}</mat-card-title>
</mat-card-header>
<mat-card-content>
<mat-form-field>
@ -15,7 +15,7 @@
</mat-form-field>
</mat-card-content>
<mat-card-actions>
<button mat-raised-button color="primary" routerLink="/employee/list">Retour</button>
<button mat-raised-button color="primary" routerLink="/user/list">Retour</button>
<button mat-raised-button color="accent" [disabled]="form.invalid" (click)="submit()">Enregistrer</button>
</mat-card-actions>
</form>

View File

@ -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'
)
}

View File

@ -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<Employee[]> {
return this.api.get<Employee[]>('/employee')
get all(): Observable<User[]> {
return this.api.get<User[]>('/user')
}
getById(id: number): Observable<Employee> {
return this.api.get<Employee>(`/employee/${id}`)
getById(id: number): Observable<User> {
return this.api.get<User>(`/user/${id}`)
}
save(id: number, firstName: string, lastName: string, password: string, group: number, permissions: EmployeePermission[]): Observable<Employee> {
const employee = {id, firstName, lastName, password, groupId: group, permissions}
return this.api.post<Employee>('/employee', employee)
save(id: number, firstName: string, lastName: string, password: string, group: number, permissions: Permission[]): Observable<User> {
const user = {id, firstName, lastName, password, groupId: group >= 0 ? group : null, permissions}
return this.api.post<User>('/user', user)
}
update(id: number, firstName: string, lastName: string, group: number, permissions: EmployeePermission[]): Observable<void> {
const employee = {id, firstName, lastName, groupId: group, permissions}
return this.api.put<void>('/employee', employee)
update(id: number, firstName: string, lastName: string, group: number, permissions: Permission[]): Observable<void> {
const user = {id, firstName, lastName, groupId: group >= 0 ? group : null, permissions}
return this.api.put<void>('/user', user)
}
updatePassword(id: number, password: string): Observable<void> {
return this.api.put<void>(`/employee/${id}/password`, password, true, {contentType: 'text/plain'})
return this.api.put<void>(`/user/${id}/password`, password, true, {contentType: 'text/plain'})
}
delete(id: number): Observable<void> {
return this.api.delete<void>(`/employee/${id}`)
return this.api.delete<void>(`/user/${id}`)
}
}

View File

@ -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},
]
}

View File

@ -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}
]
}

View File

@ -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}
]
}