From 2d888dc6338511a43940343b469741bcb5aff4ee Mon Sep 17 00:00:00 2001 From: Jeremie BRISON <ext.sopra.jbrison@grandlyon.com> Date: Mon, 18 Jan 2021 18:07:57 +0100 Subject: [PATCH 1/6] fix(editstructure) : fix condition display btn --- .../structure-details/structure-details.component.html | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/app/structure-list/components/structure-details/structure-details.component.html b/src/app/structure-list/components/structure-details/structure-details.component.html index 8fb67057c..a617a7dd0 100644 --- a/src/app/structure-list/components/structure-details/structure-details.component.html +++ b/src/app/structure-list/components/structure-details/structure-details.component.html @@ -12,8 +12,11 @@ <button (click)="claimStructure()">Revendiquer</button> </div> <div fxLayout="row" fxLayoutAlign="center center"> - <button *ngIf="profileService.isLinkedToStructure(structure._id)" (click)="editStructure()"> - Modifier ma structure + <button + *ngIf="profileService.isLinkedToStructure(structure._id) || profileService.isAdmin()" + (click)="editStructure()" + > + Modifier la structure </button> </div> <div fxLayout="row" fxLayoutAlign="end center"> -- GitLab From 680dd5db97b3413373e67e55b63c445fb873e130 Mon Sep 17 00:00:00 2001 From: Jeremie BRISON <ext.sopra.jbrison@grandlyon.com> Date: Mon, 18 Jan 2021 18:08:39 +0100 Subject: [PATCH 2/6] fix(claim) : fix api parameter --- src/app/form/form.component.ts | 12 +++++------- src/app/services/structure.service.ts | 4 ++-- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/app/form/form.component.ts b/src/app/form/form.component.ts index 3e931beda..93ab67f33 100644 --- a/src/app/form/form.component.ts +++ b/src/app/form/form.component.ts @@ -253,13 +253,11 @@ export class FormComponent implements OnInit { } public onSubmitClaimWithAccount(): void { - this.structureService - .claimStructureWithAccount(this.structureId, this.profile.email) - .subscribe((structuresLinked) => { - this.profile.pendingStructuresLink = structuresLinked; - this.profileService.setProfile(this.profile); - this.closeEvent.emit(this.structureForm.value); - }); + this.structureService.claimStructureWithAccount(this.structureId, this.profile).subscribe((structuresLinked) => { + this.profile.pendingStructuresLink = structuresLinked; + this.profileService.setProfile(this.profile); + this.closeEvent.emit(this.structureForm.value); + }); } public onSubmit(structureForm: FormGroup): void { if (structureForm.valid) { diff --git a/src/app/services/structure.service.ts b/src/app/services/structure.service.ts index e28d78f8f..5b928a6a5 100644 --- a/src/app/services/structure.service.ts +++ b/src/app/services/structure.service.ts @@ -35,8 +35,8 @@ export class StructureService { return this.http.get(`${this.baseUrl}/${id}/isClaimed`); } - public claimStructureWithAccount(id: string, email: string): Observable<string[]> { - return this.http.post<any>(`${this.baseUrl}/${id}/claim`, { email }); + public claimStructureWithAccount(id: string, user: User): Observable<string[]> { + return this.http.post<any>(`${this.baseUrl}/${id}/claim`, user); } public getStructure(id: string): Observable<Structure> { -- GitLab From ef99f774acc87a5dbca530410d4f8e4599e022eb Mon Sep 17 00:00:00 2001 From: Jeremie BRISON <ext.sopra.jbrison@grandlyon.com> Date: Mon, 18 Jan 2021 18:09:29 +0100 Subject: [PATCH 3/6] fix(admin) : fix isAdmin bug when user not logged --- src/app/profile/services/profile.service.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/app/profile/services/profile.service.ts b/src/app/profile/services/profile.service.ts index 87c91ca9f..79abef7df 100644 --- a/src/app/profile/services/profile.service.ts +++ b/src/app/profile/services/profile.service.ts @@ -4,6 +4,7 @@ import { Observable } from 'rxjs'; import { User } from '../../models/user.model'; import decode from 'jwt-decode'; import { UserRole } from '../../shared/enum/userRole.enum'; +import { AuthService } from '../../services/auth.service'; @Injectable({ providedIn: 'root', @@ -11,7 +12,7 @@ import { UserRole } from '../../shared/enum/userRole.enum'; export class ProfileService { private readonly baseUrl = 'api/users'; private currentProfile: User = null; - constructor(private http: HttpClient) { + constructor(private http: HttpClient, private authService: AuthService) { this.getProfile(); } @@ -45,14 +46,15 @@ export class ProfileService { } public isAdmin(): boolean { - const user = JSON.parse(localStorage.getItem('user')); - if (user) { + if (this.authService.isLoggedIn()) { + const user = this.authService.userValue; const token = user.accessToken; // decode the token to get its payload const tokenPayload: User = decode(token); if (tokenPayload.role == UserRole.admin) { return true; } + return false; } return false; } -- GitLab From 3703f33ff883a29cebeb027bd55361b920268ce4 Mon Sep 17 00:00:00 2001 From: Jeremie BRISON <ext.sopra.jbrison@grandlyon.com> Date: Mon, 18 Jan 2021 18:07:57 +0100 Subject: [PATCH 4/6] fix(editstructure) : fix condition display btn --- .../structure-details/structure-details.component.html | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/app/structure-list/components/structure-details/structure-details.component.html b/src/app/structure-list/components/structure-details/structure-details.component.html index 2fe93a904..1d401c6c5 100644 --- a/src/app/structure-list/components/structure-details/structure-details.component.html +++ b/src/app/structure-list/components/structure-details/structure-details.component.html @@ -12,8 +12,11 @@ <button (click)="claimStructure()">Revendiquer</button> </div> <div fxLayout="row" fxLayoutAlign="center center"> - <button *ngIf="profileService.isLinkedToStructure(structure._id)" (click)="editStructure()"> - Modifier ma structure + <button + *ngIf="profileService.isLinkedToStructure(structure._id) || profileService.isAdmin()" + (click)="editStructure()" + > + Modifier la structure </button> </div> <div fxLayout="row" fxLayoutAlign="end center"> -- GitLab From 422ac4e4884b6c67cc959896c2c060eec8cdf676 Mon Sep 17 00:00:00 2001 From: Jeremie BRISON <ext.sopra.jbrison@grandlyon.com> Date: Mon, 18 Jan 2021 18:08:39 +0100 Subject: [PATCH 5/6] fix(claim) : fix api parameter --- src/app/form/form.component.ts | 12 +++++------- src/app/services/structure.service.ts | 4 ++-- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/app/form/form.component.ts b/src/app/form/form.component.ts index 3e931beda..93ab67f33 100644 --- a/src/app/form/form.component.ts +++ b/src/app/form/form.component.ts @@ -253,13 +253,11 @@ export class FormComponent implements OnInit { } public onSubmitClaimWithAccount(): void { - this.structureService - .claimStructureWithAccount(this.structureId, this.profile.email) - .subscribe((structuresLinked) => { - this.profile.pendingStructuresLink = structuresLinked; - this.profileService.setProfile(this.profile); - this.closeEvent.emit(this.structureForm.value); - }); + this.structureService.claimStructureWithAccount(this.structureId, this.profile).subscribe((structuresLinked) => { + this.profile.pendingStructuresLink = structuresLinked; + this.profileService.setProfile(this.profile); + this.closeEvent.emit(this.structureForm.value); + }); } public onSubmit(structureForm: FormGroup): void { if (structureForm.valid) { diff --git a/src/app/services/structure.service.ts b/src/app/services/structure.service.ts index e28d78f8f..5b928a6a5 100644 --- a/src/app/services/structure.service.ts +++ b/src/app/services/structure.service.ts @@ -35,8 +35,8 @@ export class StructureService { return this.http.get(`${this.baseUrl}/${id}/isClaimed`); } - public claimStructureWithAccount(id: string, email: string): Observable<string[]> { - return this.http.post<any>(`${this.baseUrl}/${id}/claim`, { email }); + public claimStructureWithAccount(id: string, user: User): Observable<string[]> { + return this.http.post<any>(`${this.baseUrl}/${id}/claim`, user); } public getStructure(id: string): Observable<Structure> { -- GitLab From 8d09372ccc8e833e1417e84a0569b5f8eb6095a4 Mon Sep 17 00:00:00 2001 From: Jeremie BRISON <ext.sopra.jbrison@grandlyon.com> Date: Mon, 18 Jan 2021 18:09:29 +0100 Subject: [PATCH 6/6] fix(admin) : fix isAdmin bug when user not logged --- src/app/profile/services/profile.service.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/app/profile/services/profile.service.ts b/src/app/profile/services/profile.service.ts index 87c91ca9f..79abef7df 100644 --- a/src/app/profile/services/profile.service.ts +++ b/src/app/profile/services/profile.service.ts @@ -4,6 +4,7 @@ import { Observable } from 'rxjs'; import { User } from '../../models/user.model'; import decode from 'jwt-decode'; import { UserRole } from '../../shared/enum/userRole.enum'; +import { AuthService } from '../../services/auth.service'; @Injectable({ providedIn: 'root', @@ -11,7 +12,7 @@ import { UserRole } from '../../shared/enum/userRole.enum'; export class ProfileService { private readonly baseUrl = 'api/users'; private currentProfile: User = null; - constructor(private http: HttpClient) { + constructor(private http: HttpClient, private authService: AuthService) { this.getProfile(); } @@ -45,14 +46,15 @@ export class ProfileService { } public isAdmin(): boolean { - const user = JSON.parse(localStorage.getItem('user')); - if (user) { + if (this.authService.isLoggedIn()) { + const user = this.authService.userValue; const token = user.accessToken; // decode the token to get its payload const tokenPayload: User = decode(token); if (tokenPayload.role == UserRole.admin) { return true; } + return false; } return false; } -- GitLab