diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index 3d9f34f..93b0351 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -4,65 +4,69 @@ import {CatalogComponent} from './pages/catalog/catalog.component' import {AdministrationComponent} from './pages/administration/administration.component' import {MiscComponent} from './pages/others/misc.component' import {CreConfigEditor} from './modules/configuration/config-editor' +import {routes as routesConst} from './routes' const routes: Routes = [{ - path: 'color', + path: routesConst.recipes.route, loadChildren: () => import('./modules/recipes/recipes.module').then(m => m.RecipesModule) }, { - path: 'account', + path: routesConst.accounts.route, loadChildren: () => import('./modules/accounts/accounts.module').then(m => m.AccountsModule) }, { - path: 'catalog', + path: routesConst.catalog.route, component: CatalogComponent, children: [{ - path: 'materialtype', + path: routesConst.catalog.children.materialTypes.simpleRoute, loadChildren: () => import('./modules/material-type/material-type.module').then(m => m.MaterialTypeModule), }, { - path: 'material', + path: routesConst.catalog.children.materials.simpleRoute, loadChildren: () => import('./modules/material/material.module').then(m => m.MaterialModule) }, { - path: 'company', + path: routesConst.catalog.children.companies.simpleRoute, loadChildren: () => import('./modules/company/company.module').then(m => m.CompanyModule) }, { path: '', pathMatch: 'full', - redirectTo: 'materialtype' + redirectTo: routesConst.catalog.children.materials.simpleRoute }] }, { - path: 'admin', + path: routesConst.administration.route, component: AdministrationComponent, children: [ { - path: 'user', + path: routesConst.administration.children.users.simpleRoute, loadChildren: () => import('./modules/users/user.module').then(m => m.UserModule) }, { - path: 'group', + path: routesConst.administration.children.groups.simpleRoute, loadChildren: () => import('./modules/groups/group.module').then(m => m.GroupModule) }, { - path: 'config', + path: routesConst.administration.children.groupTokens.simpleRoute, + loadChildren: () => import('./modules/groupTokens/group-tokens.module').then(m => m.GroupTokensModule) + }, { + path: routesConst.administration.children.configurations.simpleRoute, loadChildren: () => import('./modules/configuration/config.module').then(m => m.ConfigModule), component: CreConfigEditor }, { path: '', pathMatch: 'full', - redirectTo: 'user' + redirectTo: routesConst.administration.children.users.simpleRoute } ] }, { - path: 'misc', + path: routesConst.misc.route, component: MiscComponent, children: [{ - path: 'touch-up-kit', + path: routesConst.misc.children.touchUpKits.simpleRoute, loadChildren: () => import('./modules/touch-up-kit/touch-up-kit.module').then(m => m.TouchUpKitModule) }, { path: '', pathMatch: 'full', - redirectTo: 'touch-up-kit' + redirectTo: routesConst.misc.children.touchUpKits.simpleRoute }] }] @NgModule({ - imports: [RouterModule.forRoot(routes, {relativeLinkResolution: 'legacy'})], + imports: [RouterModule.forRoot(routes)], exports: [RouterModule] }) export class AppRoutingModule { diff --git a/src/app/modules/accounts/accounts.module.ts b/src/app/modules/accounts/accounts.module.ts index 353042f..236563a 100644 --- a/src/app/modules/accounts/accounts.module.ts +++ b/src/app/modules/accounts/accounts.module.ts @@ -3,8 +3,8 @@ import {NgModule} from '@angular/core' import {AccountsRoutingModule} from './accounts-routing.module' import {SharedModule} from '../shared/shared.module' import {Login, Logout} from './accounts' -import {CreInputsModule} from '../shared/components/inputs/inputs.module' -import {CreButtonsModule} from '../shared/components/buttons/buttons.module' +import {CreInputsModule} from "../shared/components/inputs/inputs.module"; +import {CreButtonsModule} from "../shared/components/buttons/buttons.module"; @NgModule({ @@ -16,7 +16,7 @@ import {CreButtonsModule} from '../shared/components/buttons/buttons.module' SharedModule, AccountsRoutingModule, CreInputsModule, - CreButtonsModule, + CreButtonsModule ] }) export class AccountsModule { diff --git a/src/app/modules/accounts/accounts.ts b/src/app/modules/accounts/accounts.ts index 81b477f..48180d6 100644 --- a/src/app/modules/accounts/accounts.ts +++ b/src/app/modules/accounts/accounts.ts @@ -7,6 +7,7 @@ import {ErrorHandler, ErrorService} from '../shared/service/error.service' import {ActivatedRoute, Router} from '@angular/router' import {CreForm, ICreForm} from "../shared/components/forms/forms"; import {AlertService} from "../shared/service/alert.service"; +import {routes} from "../../routes"; @Component({ selector: 'cre-login', @@ -48,8 +49,8 @@ export class Login extends ErrorHandlingComponent { submit() { this.subscribeAndNavigate( - this.accountService.login(this.userIdControl.value, this.passwordControl.value), - '/color/list' + this.accountService.loginAsUser(this.userIdControl.value, this.passwordControl.value), + `/${routes.recipes.route}/list` ) } @@ -79,13 +80,10 @@ export class Logout extends SubscribingComponent { } ngOnInit(): void { - if (!this.appState.isAuthenticated) { - this.urlUtils.navigateTo('/account/login') + if (this.appState.isAuthenticated) { + this.accountService.logout() } - this.subscribeAndNavigate( - this.accountService.logout(), - '/account/login' - ) + this.urlUtils.navigateTo(`/${routes.accounts.route}/login`) } } diff --git a/src/app/modules/accounts/services/account.service.ts b/src/app/modules/accounts/services/account.service.ts index 066973a..f392a25 100644 --- a/src/app/modules/accounts/services/account.service.ts +++ b/src/app/modules/accounts/services/account.service.ts @@ -2,12 +2,11 @@ import {Injectable, OnDestroy} from '@angular/core' import {Observable, Subject} from 'rxjs' import {take, takeUntil} from 'rxjs/operators' import {AppState} from '../../shared/app-state' -import {HttpClient, HttpResponse} from '@angular/common/http' +import {HttpClient} from '@angular/common/http' import {environment} from '../../../../environments/environment' import {ApiService} from '../../shared/service/api.service' -import {Permission, User} from '../../shared/model/user' +import {LoginDto, Permission} from '../../shared/model/account.model' import {ErrorService} from '../../shared/service/error.service' -import {AlertService} from '../../shared/service/alert.service' import {JwtService} from "./jwt.service"; @Injectable({ @@ -21,8 +20,7 @@ export class AccountService implements OnDestroy { private api: ApiService, private appState: AppState, private jwtService: JwtService, - private errorService: ErrorService, - private alertService: AlertService + private errorService: ErrorService ) { } @@ -31,95 +29,58 @@ export class AccountService implements OnDestroy { this.destroy$.complete() } - checkAuthenticationStatus() { - if (!this.appState.isAuthenticated) { - // Try to get current default group user - this.http.get(`${environment.apiUrl}/user/group/currentuser`, {withCredentials: true}) - .pipe( - take(1), - takeUntil(this.destroy$), - ).subscribe( - { - next: user => this.appState.authenticateGroupUser(user), - error: err => { - if (err.status === 404 || err.status === 403) { - console.warn('No default user is defined on this computer') - } else { - this.errorService.handleError(err) - } - } - }) + loginAsGroupIfNotAuthenticated() { + if (this.appState.isAuthenticated) return + + this.loginAsGroup() + } + + loginAsUser(id: number, password: string): Observable { + return this.login(false, {id, password}, error => { + if (error.status !== 403) return false + + this.errorService.handleError({status: error.status, type: 'invalid-credentials', obj: error}) + return true + }) + } + + loginAsGroup(): Observable { + return this.login(true, {}, + error => error.status === 403) // There is no group token, so do nothing + } + + private login(isGroup: boolean, body: LoginBody, errorConsumer: (any) => boolean): Observable { + let url = `${environment.apiUrl}/account/login` + if (isGroup) { + url += '/group' } - } - login(userId: number, password: string): Observable { - const subject = new Subject() + const login$ = this.http.post(url, body, {withCredentials: true}) + .pipe(take(1), takeUntil(this.destroy$)) - this.http.post(`${environment.apiUrl}/login`, {id: userId, password}, { - withCredentials: true, - observe: 'response' as 'body' - }).pipe( - take(1), - takeUntil(this.destroy$) - ).subscribe({ - next: (response: HttpResponse) => { - this.loginUser(response) - - subject.next() - subject.complete() - }, + login$.subscribe({ + next: result => this.appState.authenticateUser(result, isGroup), error: error => { - if (error.status === 403) { - this.alertService.pushError('Les identifiants entrés sont invalides') - } else { - this.errorService.handleError(error) - } + if (errorConsumer(error)) return; - subject.next() - subject.complete() + this.errorService.handleErrorResponse(error) } }) - return subject + return login$ } - private loginUser(response: HttpResponse) { - const authorization = response.headers.get("Authorization") - const user = this.jwtService.parseUser(authorization) - - this.appState.authenticateUser(user) - } - - logout(): Observable { - const subject = new Subject() - - this.api.get('/logout').pipe( - take(1), - takeUntil(this.destroy$) - ).subscribe({ - next: () => { - this.logoutUser() - - subject.next() - subject.complete() - }, - error: error => { - this.errorService.handleError(error) - - subject.next() - subject.complete() - } - }) - - return subject - } - - private logoutUser() { + logout() { this.appState.resetAuthenticatedUser() - this.checkAuthenticationStatus() + this.loginAsGroupIfNotAuthenticated() } hasPermission(permission: Permission): boolean { return this.appState.authenticatedUser && this.appState.authenticatedUser.permissions.indexOf(permission) >= 0 } } + +interface LoginBody { + id?: number + password?: string +} diff --git a/src/app/modules/accounts/services/group-token.service.ts b/src/app/modules/accounts/services/group-token.service.ts new file mode 100644 index 0000000..7eadb61 --- /dev/null +++ b/src/app/modules/accounts/services/group-token.service.ts @@ -0,0 +1,36 @@ +import {Injectable} from "@angular/core"; +import {ApiService} from "../../shared/service/api.service"; +import {Observable} from "rxjs"; +import {GroupToken} from "../../shared/model/account.model"; + +@Injectable({ + providedIn: "root" +}) +export class GroupTokenService { + constructor( + private api: ApiService + ) { + } + + get all(): Observable { + return this.api.get('/account/group/token') + } + + get current(): Observable { + return this.api.get('/account/group/token/current') + } + + save(name: string, groupId: number): Observable { + return this.api.post('/account/group/token', {name, groupId}) + } + + toggle(token: GroupToken): Observable { + return token.enabled ? + this.api.put(`/account/group/token/${token.id}/disable`) : + this.api.put(`/account/group/token/${token.id}/enable`) + } + + delete(id: string): Observable { + return this.api.delete(`/account/group/token/${id}`) + } +} diff --git a/src/app/modules/accounts/services/jwt.service.ts b/src/app/modules/accounts/services/jwt.service.ts index 6f67366..6ec3b0b 100644 --- a/src/app/modules/accounts/services/jwt.service.ts +++ b/src/app/modules/accounts/services/jwt.service.ts @@ -1,12 +1,12 @@ import {Injectable} from "@angular/core"; import jwtDecode from "jwt-decode"; -import { User } from "../../shared/model/user"; +import { AccountModel } from "../../shared/model/account.model"; @Injectable({ providedIn: 'root' }) export class JwtService { - parseUser(jwt: string): User { + parseUser(jwt: string): AccountModel { const decoded = jwtDecode(jwt) as any return JSON.parse(decoded.user) } diff --git a/src/app/modules/company/pages/add/add.component.ts b/src/app/modules/company/pages/add/add.component.ts index 37fbe4c..c239de3 100644 --- a/src/app/modules/company/pages/add/add.component.ts +++ b/src/app/modules/company/pages/add/add.component.ts @@ -5,6 +5,7 @@ import {FormField} from '../../../shared/components/entity-add/entity-add.compon import {ActivatedRoute, Router} from '@angular/router' import {ErrorHandler, ErrorService} from '../../../shared/service/error.service' import {AppState} from '../../../shared/app-state' +import {routes} from "../../../../routes"; @Component({ selector: 'cre-add', @@ -50,7 +51,7 @@ export class AddComponent extends ErrorHandlingComponent { this.submittedValues = values this.subscribeAndNavigate( this.companyService.save(values.name), - '/catalog/company/list' + routes.catalog.children.companies.route + '/list' ) } } diff --git a/src/app/modules/company/pages/edit/edit.component.ts b/src/app/modules/company/pages/edit/edit.component.ts index b536b39..b23cb3e 100644 --- a/src/app/modules/company/pages/edit/edit.component.ts +++ b/src/app/modules/company/pages/edit/edit.component.ts @@ -6,6 +6,7 @@ import {CompanyService} from '../../service/company.service' import {ActivatedRoute, Router} from '@angular/router' import {ErrorHandler, ErrorHandlerComponent, ErrorService} from '../../../shared/service/error.service' import {AppState} from '../../../shared/app-state' +import {routes} from "../../../../routes"; @Component({ selector: 'cre-edit', @@ -29,7 +30,7 @@ export class EditComponent extends ErrorHandlingComponent { errorHandlers: ErrorHandler[] = [{ filter: error => error.type === 'notfound-company-id', - consumer: error => this.urlUtils.navigateTo('/catalog/company/list') + consumer: _ => this.urlUtils.navigateTo(routes.catalog.children.companies.route + '/list') }, { filter: error => error.type === 'exists-company-name', messageProducer: error => `Une bannière avec le nom '${error.name}' existe déjà` @@ -65,14 +66,14 @@ export class EditComponent extends ErrorHandlingComponent { submit(values) { this.subscribeAndNavigate( this.companyService.update(this.company.id, values.name), - '/catalog/company/list' + routes.catalog.children.companies.route + '/list' ) } delete() { this.subscribeAndNavigate( this.companyService.delete(this.company.id), - '/catalog/company/list' + routes.catalog.children.companies.route + '/list' ) } } diff --git a/src/app/modules/company/pages/list/list.component.ts b/src/app/modules/company/pages/list/list.component.ts index 5899e96..4343e6c 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 {Permission} from '../../../shared/model/user' +import {Permission} from '../../../shared/model/account.model' import {ActivatedRoute, Router} from '@angular/router' import {ErrorService} from '../../../shared/service/error.service' import {AppState} from '../../../shared/app-state' diff --git a/src/app/modules/groupTokens/add.html b/src/app/modules/groupTokens/add.html new file mode 100644 index 0000000..bcb62cd --- /dev/null +++ b/src/app/modules/groupTokens/add.html @@ -0,0 +1,10 @@ + + +
+ +
+
+
diff --git a/src/app/modules/groupTokens/group-tokens-routing.module.ts b/src/app/modules/groupTokens/group-tokens-routing.module.ts new file mode 100644 index 0000000..c55971c --- /dev/null +++ b/src/app/modules/groupTokens/group-tokens-routing.module.ts @@ -0,0 +1,17 @@ +import {RouterModule, Routes} from "@angular/router"; +import {GroupTokenList} from "./group-tokens"; +import {NgModule} from "@angular/core"; + +const routes: Routes = [{ + path: 'list', + component: GroupTokenList +}, { + path: '', redirectTo: 'list' +}] + +@NgModule({ + imports: [RouterModule.forChild(routes)], + exports: [RouterModule] +}) +export class GroupTokensRoutingModule { +} diff --git a/src/app/modules/groupTokens/group-tokens.module.ts b/src/app/modules/groupTokens/group-tokens.module.ts new file mode 100644 index 0000000..1f2d324 --- /dev/null +++ b/src/app/modules/groupTokens/group-tokens.module.ts @@ -0,0 +1,28 @@ +import {NgModule} from '@angular/core' + +import {SharedModule} from '../shared/shared.module' +import {CreInputsModule} from '../shared/components/inputs/inputs.module' +import {CreButtonsModule} from '../shared/components/buttons/buttons.module' +import {GroupTokenAdd, GroupTokenList} from "../groupTokens/group-tokens"; +import {GroupTokensRoutingModule} from "./group-tokens-routing.module"; +import {CreTablesModule} from "../shared/components/tables/tables.module"; + + +@NgModule({ + declarations: [ + GroupTokenAdd, + GroupTokenList + ], + exports: [ + GroupTokenAdd + ], + imports: [ + GroupTokensRoutingModule, + SharedModule, + CreInputsModule, + CreButtonsModule, + CreTablesModule + ] +}) +export class GroupTokensModule { +} diff --git a/src/app/modules/groupTokens/group-tokens.ts b/src/app/modules/groupTokens/group-tokens.ts new file mode 100644 index 0000000..6e8a6b9 --- /dev/null +++ b/src/app/modules/groupTokens/group-tokens.ts @@ -0,0 +1,94 @@ +import {Component, EventEmitter, Output, ViewChild} from "@angular/core"; +import {CrePromptDialog} from "../shared/components/dialogs/dialogs"; +import {Group, GroupToken} from "../shared/model/account.model"; +import {FormControl, FormGroup, Validators} from "@angular/forms"; +import {GroupTokenService} from "../accounts/services/group-token.service"; +import {SubscribingComponent} from "../shared/components/subscribing.component"; +import {ErrorService} from "../shared/service/error.service"; +import {ActivatedRoute, Router} from "@angular/router"; +import {tap} from "rxjs/operators"; + +@Component({ + selector: 'cre-group-token-list', + templateUrl: 'list.html' +}) +export class GroupTokenList extends SubscribingComponent { + tokens$ = this.groupTokenService.all.pipe(tap( + tokens => this.tokensEmpty = tokens.length <= 0)) + tokensEmpty = false + + columns = ['id', 'name', 'groupName', 'state', 'stateButton', 'deleteButton'] + + @ViewChild(CrePromptDialog) removePrompt: CrePromptDialog + removePromptToken: GroupToken | null = null + + constructor( + private groupTokenService: GroupTokenService, + errorService: ErrorService, + router: Router, + activatedRoute: ActivatedRoute + ) { + super(errorService, activatedRoute, router) + } + + showRemovePrompt(token: GroupToken) { + this.removePromptToken = token + this.removePrompt.show() + } + + toggle(token: GroupToken) { + this.subscribe( + this.groupTokenService.toggle(token), + _ => window.location.reload() + ) + } + + delete() { + this.subscribe( + this.groupTokenService.delete(this.removePromptToken.id), + _ => window.location.reload() + ) + } +} + +@Component({ + selector: 'cre-group-token-add', + templateUrl: 'add.html' +}) +export class GroupTokenAdd extends SubscribingComponent { + @ViewChild(CrePromptDialog) dialog: CrePromptDialog + + @Output() defaultGroupUpdate = new EventEmitter() + + controls = {name: new FormControl(null, Validators.required)} + form = new FormGroup(this.controls) + + private group: Group | null + + constructor( + private groupTokenService: GroupTokenService, + errorService: ErrorService, + router: Router, + activatedRoute: ActivatedRoute + ) { + super(errorService, activatedRoute, router) + } + + show(group: Group) { + this.group = group + this.dialog.show() + } + + submit() { + if (!this.group) { + console.error("Group token group id was not defined") + return + } + + const name = this.controls.name.value + this.subscribe( + this.groupTokenService.save(name, this.group.id), + groupToken => this.defaultGroupUpdate.emit(groupToken) + ) + } +} diff --git a/src/app/modules/groupTokens/list.html b/src/app/modules/groupTokens/list.html new file mode 100644 index 0000000..c259ef8 --- /dev/null +++ b/src/app/modules/groupTokens/list.html @@ -0,0 +1,54 @@ +
+ + +

Il n'y a aucun ordinateur enregistré dans le système.

+

Vous pouvez en ajouter un en définissant un groupe par défaut ici.

+
+ + + + Identifiant + {{token.id}} + + + + Nom + {{token.name}} + + + + Groupe + {{token.group.name}} + + + + État + {{token.enabled ? 'Activé' : 'Désactivé'}} + + + + + + + Activer + Désactiver + + + + + + + + + Supprimer + + + + + + + + Voulez-vous vraiment retirer l'ordinateur '{{removePromptToken.name}}' du système?
+ Ses utilisateurs ne seront plus connectés automatiquement. +
+
diff --git a/src/app/modules/groups/group.module.ts b/src/app/modules/groups/group.module.ts index 7938a5b..baa7335 100644 --- a/src/app/modules/groups/group.module.ts +++ b/src/app/modules/groups/group.module.ts @@ -5,13 +5,23 @@ import {ListComponent} from './pages/list/list.component'; import {SharedModule} from "../shared/shared.module"; import {AddComponent} from './pages/add/add.component'; import {EditComponent} from './pages/edit/edit.component'; +import {AccountsModule} from "../accounts/accounts.module"; +import {CreActionBarModule} from "../shared/components/action-bar/action-bar.module"; +import {CreButtonsModule} from "../shared/components/buttons/buttons.module"; +import {CreTablesModule} from "../shared/components/tables/tables.module"; +import {GroupTokensModule} from "../groupTokens/group-tokens.module"; @NgModule({ declarations: [ListComponent, AddComponent, EditComponent], - imports: [ - GroupRoutingModule, - SharedModule - ] + imports: [ + GroupRoutingModule, + SharedModule, + AccountsModule, + CreActionBarModule, + CreButtonsModule, + CreTablesModule, + GroupTokensModule + ] }) export class GroupModule { } diff --git a/src/app/modules/groups/pages/add/add.component.ts b/src/app/modules/groups/pages/add/add.component.ts index 4c39fe2..0a69fda 100644 --- a/src/app/modules/groups/pages/add/add.component.ts +++ b/src/app/modules/groups/pages/add/add.component.ts @@ -7,6 +7,7 @@ import {ErrorHandlingComponent} from '../../../shared/components/subscribing.com import {ErrorHandler, ErrorService} from '../../../shared/service/error.service' import {FormField} from '../../../shared/components/entity-add/entity-add.component' import {AppState} from '../../../shared/app-state' +import {routes} from "../../../../routes"; @Component({ selector: 'cre-add', @@ -60,7 +61,7 @@ export class AddComponent extends ErrorHandlingComponent { if (permissionsField.valid()) { this.subscribeAndNavigate( this.groupService.save(values.name, permissionsField.allEnabledPermissions), - '/admin/group/list' + routes.administration.children.groups.route + '/list' ) } } diff --git a/src/app/modules/groups/pages/edit/edit.component.ts b/src/app/modules/groups/pages/edit/edit.component.ts index 57740fa..36f9504 100644 --- a/src/app/modules/groups/pages/edit/edit.component.ts +++ b/src/app/modules/groups/pages/edit/edit.component.ts @@ -1,14 +1,17 @@ import {Component, ViewChild} from '@angular/core' import {ActivatedRoute, Router} from '@angular/router' -import {Group} from '../../../shared/model/user' +import {Group} from '../../../shared/model/account.model' import {GroupService} from '../../services/group.service' import {Validators} from '@angular/forms' -import {currentPermissionsFieldComponent} from '../../../shared/components/permissions-field/permissions-field.component' +import { + currentPermissionsFieldComponent +} from '../../../shared/components/permissions-field/permissions-field.component' import {AccountService} from '../../../accounts/services/account.service' import {ErrorHandlingComponent} from '../../../shared/components/subscribing.component' import {ErrorHandler, ErrorService} from '../../../shared/service/error.service' import {FormField} from '../../../shared/components/entity-add/entity-add.component' import {AppState} from '../../../shared/app-state' +import {routes} from "../../../../routes"; @Component({ selector: 'cre-edit', @@ -38,7 +41,7 @@ export class EditComponent extends ErrorHandlingComponent { errorHandlers: ErrorHandler[] = [{ filter: error => error.type === 'notfound-group-id', - consumer: error => this.urlUtils.navigateTo('/admin/group/list') + consumer: _ => this.urlUtils.navigateTo(routes.administration.children.groups.route + '/list') }, { filter: error => error.type === 'exists-group-name', messageProducer: error => `Un groupe avec le nom '${error.name}' existe déjà` @@ -74,7 +77,7 @@ export class EditComponent extends ErrorHandlingComponent { if (permissionsField.valid()) { this.subscribeAndNavigate( this.groupService.update(this.group.id, values.name, permissionsField.allEnabledPermissions), - '/admin/group/list' + routes.administration.children.groups.route + '/list' ) } } @@ -82,7 +85,7 @@ export class EditComponent extends ErrorHandlingComponent { delete() { this.subscribeAndNavigate( this.groupService.delete(this.group.id), - '/admin/group/list' + routes.administration.children.groups.route + '/list' ) } } diff --git a/src/app/modules/groups/pages/list/list.component.html b/src/app/modules/groups/pages/list/list.component.html index 59ea8dc..1287618 100644 --- a/src/app/modules/groups/pages/list/list.component.html +++ b/src/app/modules/groups/pages/list/list.component.html @@ -1,13 +1,49 @@ - - + + + Ajouter + + - - - + +

Il n'y a actuellement aucun groupe enregistré dans le système.

+

Vous pouvez en créer un ici.

+
+ + + + Nom + {{group.name}} + + + + Nombre de permissions + {{group.permissions.length}} + + + + + + Groupe par défaut + + + + + + + + Définir par défaut + + + + + + + + + Modifier + + + + + + diff --git a/src/app/modules/groups/pages/list/list.component.ts b/src/app/modules/groups/pages/list/list.component.ts index effdcf6..8aba474 100644 --- a/src/app/modules/groups/pages/list/list.component.ts +++ b/src/app/modules/groups/pages/list/list.component.ts @@ -1,12 +1,15 @@ -import {Component} from '@angular/core' +import {Component, ViewChild} from '@angular/core' import {GroupService} from '../../services/group.service' -import {Group, Permission} from '../../../shared/model/user' +import {Group, GroupToken, Permission} from '../../../shared/model/account.model' import {AccountService} from '../../../accounts/services/account.service' import {ErrorHandlingComponent} from '../../../shared/components/subscribing.component' import {ActivatedRoute, Router} from '@angular/router' import {ErrorHandler, ErrorService} from '../../../shared/service/error.service' import {AlertService} from '../../../shared/service/alert.service' import {AppState} from '../../../shared/app-state' +import {GroupTokenService} from "../../../accounts/services/group-token.service"; +import {GroupTokenAdd} from "../../../groupTokens/group-tokens"; +import {tap} from "rxjs/operators"; @Component({ selector: 'cre-groups', @@ -14,29 +17,27 @@ import {AppState} from '../../../shared/app-state' styleUrls: ['./list.component.sass'] }) export class ListComponent extends ErrorHandlingComponent { - groups$ = this.groupService.all - defaultGroup: Group = null - columns = [ - {def: 'name', title: 'Nom', valueFn: g => g.name}, - {def: 'permissionCount', title: 'Nombre de permissions', valueFn: g => g.permissions.length} - ] - buttons = [{ - text: 'Définir par défaut', - clickFn: group => this.setDefaultGroup(group), - disabledFn: group => this.isDefaultGroup(group) - }, { - text: 'Modifier', - linkFn: group => `/admin/group/edit/${group.id}`, - permission: Permission.EDIT_USERS - }] + groups$ = this.groupService.all.pipe(tap( + groups => this.groupsEmpty = groups.length <= 0)) + groupsEmpty = false + currentGroupToken: GroupToken | null + + noDefaultGroupColumns = ['name', 'permissionCount', 'setAsDefaultButton', 'editButton'] + defaultGroupColumns = ['name', 'permissionCount', 'currentDefaultGroup', 'editButton'] errorHandlers: ErrorHandler[] = [{ filter: error => error.type === 'nodefaultgroup', consumer: () => this.alertService.pushWarning('Aucun groupe par défaut n\'a été défini sur cet ordinateur') + }, { + filter: error => error.type === 'exists-grouptoken-name', + messageProducer: error => `Un ordinateur avec le nom '${error.name}' existe déjà` }] + @ViewChild(GroupTokenAdd) groupTokenDialog: GroupTokenAdd + constructor( private groupService: GroupService, + private groupTokenService: GroupTokenService, private accountService: AccountService, private alertService: AlertService, private appState: AppState, @@ -50,21 +51,28 @@ export class ListComponent extends ErrorHandlingComponent { ngOnInit(): void { this.subscribe( - this.groupService.defaultGroup, - group => this.defaultGroup = group, - true + this.groupTokenService.current, + token => this.currentGroupToken = token ) } setDefaultGroup(group: Group) { - this.subscribe( - this.groupService.setDefaultGroup(group), - () => this.defaultGroup = group, - true - ) + this.groupTokenDialog.show(group) } - isDefaultGroup(group: Group): boolean { - return this.defaultGroup && this.defaultGroup.id == group.id + isCurrentGroup(group: Group): boolean { + return this.currentGroupToken && this.currentGroupToken.group.id == group.id + } + + get columns(): string[] { + return this.currentGroupToken ? this.defaultGroupColumns : this.noDefaultGroupColumns + } + + get hasEditPermission(): boolean { + return this.accountService.hasPermission(Permission.EDIT_USERS) + } + + get hasAdminPermission(): boolean { + return this.accountService.hasPermission(Permission.ADMIN) } } diff --git a/src/app/modules/groups/services/group.service.ts b/src/app/modules/groups/services/group.service.ts index 56fbccb..cbf5821 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 {User, Group, Permission} from '../../shared/model/user' +import {AccountModel, Group, Permission} from '../../shared/model/account.model' import {tap} from 'rxjs/operators' @Injectable({ @@ -14,7 +14,7 @@ export class GroupService { } get all(): Observable { - return this.api.get('/user/group') + return this.api.get('/account/group') } get allWithDefault(): Observable { @@ -27,40 +27,40 @@ export class GroupService { } getById(id: number): Observable { - return this.api.get(`/user/group/${id}`) + return this.api.get(`/account/group/${id}`) } get defaultGroup(): Observable { - return this.api.get('/user/group/default') + return this.api.get('/account/group/default') } setDefaultGroup(value: Group): Observable { - return this.api.post(`/user/group/default/${value.id}`, {}) + return this.api.post(`/account/group/default/${value.id}`, {}) } - getUsersForGroup(id: number): Observable { - return this.api.get(`/user/group/${id}/users`) + getUsersForGroup(id: number): Observable { + return this.api.get(`/account/group/${id}/users`) } - addUserToGroup(id: number, user: User): Observable { - return this.api.put(`/user/group/${id}/${user.id}`) + addUserToGroup(id: number, user: AccountModel): Observable { + return this.api.put(`/account/group/${id}/${user.id}`) } - removeUserFromGroup(user: User): Observable { - return this.api.delete(`/user/group/${user.group.id}/${user.id}`) + removeUserFromGroup(user: AccountModel): Observable { + return this.api.delete(`/account/group/${user.group.id}/${user.id}`) } save(name: string, permissions: Permission[]): Observable { const group = {name, permissions} - return this.api.post('/user/group', group) + return this.api.post('/account/group', group) } update(id: number, name: string, permissions: Permission[]): Observable { const group = {id, name, permissions} - return this.api.put('/user/group', group) + return this.api.put('/account/group', group) } delete(id: number): Observable { - return this.api.delete(`/user/group/${id}`) + return this.api.delete(`/account/group/${id}`) } } diff --git a/src/app/modules/material-type/pages/add/add.component.ts b/src/app/modules/material-type/pages/add/add.component.ts index 1c2b1ff..4300ab4 100644 --- a/src/app/modules/material-type/pages/add/add.component.ts +++ b/src/app/modules/material-type/pages/add/add.component.ts @@ -6,6 +6,7 @@ import {ErrorHandlingComponent} from '../../../shared/components/subscribing.com import {ActivatedRoute, Router} from '@angular/router' import {ErrorHandler, ErrorService} from '../../../shared/service/error.service' import {AppState} from '../../../shared/app-state' +import {routes} from "../../../../routes"; @Component({ selector: 'cre-add', @@ -69,7 +70,7 @@ export class AddComponent extends ErrorHandlingComponent { submit(values) { this.subscribeAndNavigate( this.materialTypeService.save(values.name, values.prefix, values.usePercentages), - '/catalog/materialtype/list' + routes.catalog.children.materialTypes.route + '/list' ) } } diff --git a/src/app/modules/material-type/pages/edit/edit.component.ts b/src/app/modules/material-type/pages/edit/edit.component.ts index 8db8933..e005cf7 100644 --- a/src/app/modules/material-type/pages/edit/edit.component.ts +++ b/src/app/modules/material-type/pages/edit/edit.component.ts @@ -7,6 +7,7 @@ import {FormField} from '../../../shared/components/entity-add/entity-add.compon import {Validators} from '@angular/forms' import {ErrorHandler, ErrorService} from '../../../shared/service/error.service' import {AppState} from '../../../shared/app-state' +import {routes} from "../../../../routes"; @Component({ selector: 'cre-edit', @@ -45,7 +46,7 @@ export class EditComponent extends ErrorHandlingComponent { errorHandlers: ErrorHandler[] = [{ filter: error => error.type === 'notfound-materialtype-id', - consumer: error => this.urlUtils.navigateTo('/catalog/materialtype/list') + consumer: _ => this.urlUtils.navigateTo(routes.catalog.children.materialTypes.route + '/list') }, { filter: error => error.type === 'exists-materialtype-name', messageProducer: error => `Un type de produit avec le nom '${error.name}' existe déjà` @@ -84,14 +85,14 @@ export class EditComponent extends ErrorHandlingComponent { submit(values) { this.subscribeAndNavigate( this.materialTypeService.update(this.materialType.id, values.name, values.prefix), - '/catalog/materialtype/list' + routes.catalog.children.materialTypes.route + '/list' ) } delete() { this.subscribeAndNavigate( this.materialTypeService.delete(this.materialType.id), - '/catalog/materialtype/list' + routes.catalog.children.materialTypes.route + '/list' ) } } 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 c25e58f..264db1e 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 {Permission} from '../../../shared/model/user' +import {Permission} from '../../../shared/model/account.model' import {ActivatedRoute, Router} from '@angular/router' import {ErrorService} from '../../../shared/service/error.service' import {AppState} from '../../../shared/app-state' diff --git a/src/app/modules/material/pages/add/add.component.ts b/src/app/modules/material/pages/add/add.component.ts index d5e710a..588d068 100644 --- a/src/app/modules/material/pages/add/add.component.ts +++ b/src/app/modules/material/pages/add/add.component.ts @@ -8,6 +8,7 @@ import {ErrorHandlingComponent} from '../../../shared/components/subscribing.com import {map} from 'rxjs/operators' import {ErrorHandler, ErrorService} from '../../../shared/service/error.service' import {AppState} from '../../../shared/app-state' +import {routes} from "../../../../routes"; @Component({ selector: 'cre-add', @@ -81,7 +82,7 @@ export class AddComponent extends ErrorHandlingComponent { submit(values) { this.subscribeAndNavigate( this.materialService.save(values.name, values.inventoryQuantity, values.materialType, values.simdutFile), - '/catalog/material/list' + routes.catalog.children.materials.route + '/list' ) } } diff --git a/src/app/modules/material/pages/edit/edit.component.ts b/src/app/modules/material/pages/edit/edit.component.ts index fbc2a44..d8a2d7a 100644 --- a/src/app/modules/material/pages/edit/edit.component.ts +++ b/src/app/modules/material/pages/edit/edit.component.ts @@ -9,6 +9,7 @@ import {ErrorHandlingComponent} from '../../../shared/components/subscribing.com import {Material, openSimdut} from '../../../shared/model/material.model' import {ErrorHandler, ErrorService} from '../../../shared/service/error.service' import {AppState} from '../../../shared/app-state' +import {routes} from "../../../../routes"; @Component({ selector: 'cre-edit', @@ -69,7 +70,7 @@ export class EditComponent extends ErrorHandlingComponent { errorHandlers: ErrorHandler[] = [{ filter: error => error.type === 'notfound-material-id', - consumer: error => this.urlUtils.navigateTo('/catalog/material/list') + consumer: _ => this.urlUtils.navigateTo(routes.catalog.children.materials.route + '/list') }, { filter: error => error.type === 'exists-material-name', messageProducer: error => `Un produit avec le nom '${error.name}' existe déjà` @@ -108,14 +109,14 @@ export class EditComponent extends ErrorHandlingComponent { submit(values) { this.subscribeAndNavigate( this.materialService.update(this.material.id, values.name, values.inventoryQuantity, values.materialType, this.selectedSimdutFile), - '/catalog/material/list' + routes.catalog.children.materials.route + '/list' ) } delete() { this.subscribeAndNavigate( this.materialService.delete(this.material.id), - '/catalog/material/list' + routes.catalog.children.materials.route + '/list' ) } diff --git a/src/app/modules/material/pages/inventory/inventory.component.ts b/src/app/modules/material/pages/inventory/inventory.component.ts index 1e53d54..da46d4a 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 {Permission} from '../../../shared/model/user' +import {Permission} from '../../../shared/model/account.model' import {ActivatedRoute, Router} from '@angular/router' import {ErrorService} from '../../../shared/service/error.service' import {Material, materialFilterFieldSeparator, materialMatchesFilter, openSimdut} from '../../../shared/model/material.model' diff --git a/src/app/modules/recipes/components/mix-table/mix-table.component.ts b/src/app/modules/recipes/components/mix-table/mix-table.component.ts index e50128f..7383912 100644 --- a/src/app/modules/recipes/components/mix-table/mix-table.component.ts +++ b/src/app/modules/recipes/components/mix-table/mix-table.component.ts @@ -15,7 +15,7 @@ import {ConfirmBoxComponent} from '../../../shared/components/confirm-box/confir import {ErrorService} from '../../../shared/service/error.service' import {AlertService} from '../../../shared/service/alert.service' import {MaterialService} from '../../../material/service/material.service' -import {Permission} from '../../../shared/model/user' +import {Permission} from '../../../shared/model/account.model' import {AccountService} from '../../../accounts/services/account.service' import {Material, openSimdut} from '../../../shared/model/material.model' diff --git a/src/app/modules/recipes/components/step-table/step-table.component.ts b/src/app/modules/recipes/components/step-table/step-table.component.ts index 1c471b3..7923fa7 100644 --- a/src/app/modules/recipes/components/step-table/step-table.component.ts +++ b/src/app/modules/recipes/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 {Group} from '../../../shared/model/user' +import {Group} from '../../../shared/model/account.model' @Component({ selector: 'cre-step-table', diff --git a/src/app/modules/recipes/explore.ts b/src/app/modules/recipes/explore.ts index dd59d1e..4132cdc 100644 --- a/src/app/modules/recipes/explore.ts +++ b/src/app/modules/recipes/explore.ts @@ -18,10 +18,11 @@ import {ConfirmBoxComponent} from '../shared/components/confirm-box/confirm-box. import {GroupService} from '../groups/services/group.service' import {AppState} from '../shared/app-state' import {AccountService} from '../accounts/services/account.service' -import {Permission} from '../shared/model/user' +import {Permission} from '../shared/model/account.model' import {FormControl} from '@angular/forms'; import {map} from 'rxjs/operators'; import {CreInputEntry} from '../shared/components/inputs/inputs'; +import {routes} from "../../routes"; @Component({ selector: 'cre-recipe-explore', @@ -48,7 +49,7 @@ export class CreRecipeExplore extends ErrorHandlingComponent { errorHandlers: ErrorHandler[] = [{ filter: error => error.type === 'notfound-recipe-id', - consumer: error => this.urlUtils.navigateTo('/color/list') + consumer: _ => this.urlUtils.navigateTo(routes.recipes.route + '/list') }, { filter: error => error.type === 'notenoughinventory-multiple', consumer: error => this.deductErrorBody = {mix: this.deductedMixId, lowQuantities: error.lowQuantities}, @@ -175,7 +176,7 @@ export class CreRecipeExplore extends ErrorHandlingComponent { } get loggedInUserGroupId(): number { - return this.appState.authenticatedUser.group?.id + return this.appState.authenticatedUser.groupId } get selectedGroupNote(): string { diff --git a/src/app/modules/recipes/list.ts b/src/app/modules/recipes/list.ts index 121f6e7..c0d516c 100644 --- a/src/app/modules/recipes/list.ts +++ b/src/app/modules/recipes/list.ts @@ -10,8 +10,9 @@ import {AppState} from '../shared/app-state' import {ErrorService} from '../shared/service/error.service' import {ActivatedRoute, Router} from '@angular/router' import {Config} from '../shared/model/config.model' -import {Permission} from '../shared/model/user' +import {Permission} from '../shared/model/account.model' import {FormControl} from '@angular/forms' +import {routes} from "../../routes"; @Component({ selector: 'cre-recipe-list', @@ -52,7 +53,7 @@ export class RecipeList extends ErrorHandlingComponent { this.configService.get(Config.EMERGENCY_MODE), config => { if (config.content == 'true') { - this.urlUtils.navigateTo('/admin/config/') + this.urlUtils.navigateTo(routes.administration.children.configurations.route) } } ) diff --git a/src/app/modules/recipes/mix/materials-form.ts b/src/app/modules/recipes/mix/materials-form.ts index 47861ef..e1c70d2 100644 --- a/src/app/modules/recipes/mix/materials-form.ts +++ b/src/app/modules/recipes/mix/materials-form.ts @@ -16,7 +16,7 @@ import {FormControl, Validators} from '@angular/forms' import {takeUntil} from 'rxjs/operators' import {CreComboBoxComponent, CreInputEntry} from '../../shared/components/inputs/inputs' import {AccountService} from '../../accounts/services/account.service' -import {Permission} from '../../shared/model/user' +import {Permission} from '../../shared/model/account.model' import {UNIT_MILLILITER} from '../../shared/units' @Component({ diff --git a/src/app/modules/recipes/mix/mix.ts b/src/app/modules/recipes/mix/mix.ts index 9480c20..0d4fed8 100644 --- a/src/app/modules/recipes/mix/mix.ts +++ b/src/app/modules/recipes/mix/mix.ts @@ -15,6 +15,7 @@ import {MaterialService} from '../../material/service/material.service' import {CreForm} from '../../shared/components/forms/forms' import {MixMaterialsForm} from './materials-form' import {MixSaveDto, MixService, MixUpdateDto} from '../services/mix.service' +import {routes} from "../../../routes"; @Directive() abstract class _BaseMixPage extends SubscribingComponent { @@ -74,7 +75,7 @@ export class MixAdd extends _BaseMixPage { submit(dto: MixSaveDto) { this.subscribeAndNavigate( this.mixService.saveDto(dto), - `/color/edit/${this.recipe.id}` + `/${routes.recipes.route}/edit/${this.recipe.id}` ) } } @@ -110,14 +111,14 @@ export class MixEdit extends _BaseMixPage { submit(dto: MixSaveDto) { this.subscribeAndNavigate( this.mixService.updateDto({...dto, id: this.mix.id}), - `/color/edit/${this.recipe.id}` + `/${routes.recipes.route}/edit/${this.recipe.id}` ) } delete() { this.subscribeAndNavigate( this.mixService.delete(this.mixId), - '/color/edit/' + this.recipe.id + `/${routes.recipes.route}/edit/` + this.recipe.id ) } } diff --git a/src/app/modules/recipes/recipes.ts b/src/app/modules/recipes/recipes.ts index e1b6410..f8dcea1 100644 --- a/src/app/modules/recipes/recipes.ts +++ b/src/app/modules/recipes/recipes.ts @@ -11,12 +11,13 @@ import {FormControl, Validators} from '@angular/forms'; import {Component, EventEmitter, Input, Output, ViewChild, ViewEncapsulation} from '@angular/core'; import {Recipe, recipeMixCount, RecipeStep, recipeStepCount} from '../shared/model/recipe.model'; import {AccountService} from '../accounts/services/account.service'; -import {Permission} from '../shared/model/user'; +import {Permission} from '../shared/model/account.model'; import {AlertService} from '../shared/service/alert.service'; import {GroupService} from '../groups/services/group.service'; import {StepTableComponent} from './components/step-table/step-table.component'; import {anyMap} from '../shared/utils/map.utils'; import {CreForm, ICreForm} from '../shared/components/forms/forms'; +import {routes} from "../../routes"; @Component({ selector: 'recipe-form', @@ -117,7 +118,7 @@ export class RecipeAdd extends ErrorHandlingComponent { submit(recipe: Recipe) { this.subscribe( this.recipeService.save(recipe), - recipe => this.urlUtils.navigateTo(`/color/edit/${recipe.id}`) + recipe => this.urlUtils.navigateTo(routes.recipes.route + `/edit/${recipe.id}`) ) } } @@ -137,7 +138,7 @@ export class RecipeEdit extends ErrorHandlingComponent { errorHandlers: ErrorHandler[] = [{ filter: error => error.type === 'notfound-recipe-id', - consumer: _ => this.urlUtils.navigateTo('/color/list') + consumer: _ => this.urlUtils.navigateTo(routes.recipes.route + '/list') }] constructor( @@ -190,19 +191,19 @@ export class RecipeEdit extends ErrorHandlingComponent { this.subscribeAndNavigate( this.recipeService.update(recipe, steps), - '/color/list' + routes.recipes.route + '/list' ) } delete() { this.subscribeAndNavigate( this.recipeService.delete(this.recipe.id), - '/color/list' + routes.recipes.route + '/list' ) } get loggedInUserGroupId(): number { - return this.appState.authenticatedUser.group?.id + return this.appState.authenticatedUser.groupId } private stepsPositionsAreValid(steps: Map): boolean { diff --git a/src/app/modules/shared/app-state.ts b/src/app/modules/shared/app-state.ts index 5b1c93e..15ce7cc 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 {User} from './model/user' +import {LoginDto} from './model/account.model' import {Subject} from 'rxjs' import {Title} from '@angular/platform-browser' @@ -7,11 +7,10 @@ import {Title} from '@angular/platform-browser' providedIn: 'root' }) export class AppState { - private readonly KEY_AUTHENTICATED = 'authenticated' - private readonly KEY_DEFAULT_GROUP_USER_AUTHENTICATED = 'default-group-user-authenticated' - private readonly KEY_LOGGED_IN_USER = 'logged-in-user' + private readonly KEY_AUTHENTICATED_USER = 'authenticated-user' + private readonly KEY_GROUP_USER = 'authenticated-user-group' - authenticatedUser$ = new Subject<{ authenticated: boolean, authenticatedUser: User }>() + authenticatedUser$ = new Subject() serverOnline$ = new Subject() constructor( @@ -19,67 +18,49 @@ export class AppState { ) { } - authenticateUser(user: User) { - this.authenticatedUser = user - this.isAuthenticated = true - } - - authenticateGroupUser(user: User) { - this.authenticatedUser = user - this.isDefaultGroupUserAuthenticated = true + authenticateUser(user: LoginDto, isGroup: boolean) { + this.setAuthenticatedUser(user, isGroup) } resetAuthenticatedUser() { - this.isAuthenticated = false - this.isDefaultGroupUserAuthenticated = false - this.authenticatedUser = null + this.removeAuthenticatedUser() } set isServerOnline(isOnline: boolean) { if (!isOnline) { - this.authenticatedUser = null + this.removeAuthenticatedUser() } this.serverOnline$.next(isOnline) } get isAuthenticated(): boolean { - return sessionStorage.getItem(this.KEY_AUTHENTICATED) === 'true' + return !!this.authenticatedUser } - private set isAuthenticated(value: boolean) { - sessionStorage.setItem(this.KEY_AUTHENTICATED, value.toString()) - this.authenticatedUser$.next({ - authenticated: value, - authenticatedUser: this.authenticatedUser - }) - } - - get isDefaultGroupUserAuthenticated(): boolean { - return sessionStorage.getItem(this.KEY_DEFAULT_GROUP_USER_AUTHENTICATED) === 'true' - } - - private set isDefaultGroupUserAuthenticated(value: boolean) { - sessionStorage.setItem(this.KEY_DEFAULT_GROUP_USER_AUTHENTICATED, value.toString()) - } - - get hasCredentials(): boolean { - return this.isAuthenticated || this.isDefaultGroupUserAuthenticated - } - - get authenticatedUser(): User { - const userString = sessionStorage.getItem(this.KEY_LOGGED_IN_USER) + get authenticatedUser(): LoginDto { + const userString = sessionStorage.getItem(this.KEY_AUTHENTICATED_USER) return userString ? JSON.parse(userString) : null } - private set authenticatedUser(value: User) { - if (value === null) { - // sessionStorage.removeItem(this.KEY_LOGGED_IN_USER) - } else { - sessionStorage.setItem(this.KEY_LOGGED_IN_USER, JSON.stringify(value)) - } + get isGroupUserAuthenticated(): boolean { + return sessionStorage.getItem(this.KEY_GROUP_USER) === 'true' + } + + private setAuthenticatedUser(login: LoginDto, isGroup: boolean) { + sessionStorage.setItem(this.KEY_AUTHENTICATED_USER, JSON.stringify(login)) + sessionStorage.setItem(this.KEY_GROUP_USER, JSON.stringify(isGroup)) this.authenticatedUser$.next({ - authenticated: this.isAuthenticated, - authenticatedUser: value + authenticatedUser: login, + isGroup + }) + } + + private removeAuthenticatedUser() { + sessionStorage.removeItem(this.KEY_AUTHENTICATED_USER) + sessionStorage.removeItem(this.KEY_GROUP_USER) + this.authenticatedUser$.next({ + authenticatedUser: null, + isGroup: false }) } @@ -87,3 +68,8 @@ export class AppState { this.titleService.setTitle(`CRE: ${value}`) } } + +export interface AuthenticationEvent { + authenticatedUser: LoginDto | null + isGroup: boolean +} diff --git a/src/app/modules/shared/components/dialogs/dialogs.ts b/src/app/modules/shared/components/dialogs/dialogs.ts index a06f602..b8bbc48 100644 --- a/src/app/modules/shared/components/dialogs/dialogs.ts +++ b/src/app/modules/shared/components/dialogs/dialogs.ts @@ -58,6 +58,7 @@ abstract class CreDialog { }) export class CrePromptDialog extends CreDialog { @Input() title: string + @Input() continueButtonDisabled = false protected get data(): CrePromptDialogData { return { diff --git a/src/app/modules/shared/components/dialogs/prompt.html b/src/app/modules/shared/components/dialogs/prompt.html index 0d14939..f8c8a10 100644 --- a/src/app/modules/shared/components/dialogs/prompt.html +++ b/src/app/modules/shared/components/dialogs/prompt.html @@ -5,6 +5,6 @@
Annuler - Continuer + Continuer
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 115ad50..91df831 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 {Permission} from '../../model/user' +import {Permission} from '../../model/account.model' import {animate, state, style, transition, trigger} from '@angular/animations' @Component({ diff --git a/src/app/modules/shared/components/header/header.component.ts b/src/app/modules/shared/components/header/header.component.ts index abe4a17..f64ea8a 100644 --- a/src/app/modules/shared/components/header/header.component.ts +++ b/src/app/modules/shared/components/header/header.component.ts @@ -1,7 +1,7 @@ import {Component} from '@angular/core' import {ActivatedRoute, ResolveEnd, Router} from '@angular/router' import {AppState} from '../../app-state' -import {Permission} from '../../model/user' +import {Permission} from '../../model/account.model' import {AccountService} from '../../../accounts/services/account.service' import {SubscribingComponent} from '../subscribing.component' import {ErrorService} from '../../service/error.service' @@ -35,7 +35,7 @@ export class HeaderComponent extends SubscribingComponent { ngOnInit(): void { super.ngOnInit() - this.accountService.checkAuthenticationStatus() + this.accountService.loginAsGroupIfNotAuthenticated() // Gets the current route this.subscribe( @@ -58,10 +58,8 @@ export class HeaderComponent extends SubscribingComponent { } ngOnDestroy(): void { - this.subscribe( - this.accountService.logout(), - () => console.info('Successfully logged out') - ) + this.accountService.logout() + console.info('Successfully logged out') super.ngOnDestroy() } diff --git a/src/app/modules/shared/components/nav/nav.component.html b/src/app/modules/shared/components/nav/nav.component.html index 05e7976..57e917c 100644 --- a/src/app/modules/shared/components/nav/nav.component.html +++ b/src/app/modules/shared/components/nav/nav.component.html @@ -1,9 +1,9 @@