Verified Commit 00c57845 authored by Alex ORLUC's avatar Alex ORLUC

FEAT #1730 TIME 4:30 hide admin button when no admin + add guard + interceptor +…

FEAT #1730 TIME 4:30 hide admin button when no admin + add guard + interceptor + remove access profile in admin
parent ab13c3f4
......@@ -24,24 +24,5 @@ export class AppComponent {
this.cookieService.set( 'maarchParapheurLang', 'fr' );
translate.setDefaultLang('fr');
}
if (this.cookieService.check('maarchParapheurAuth')) {
const cookieInfo = JSON.parse(atob(this.cookieService.get('maarchParapheurAuth')));
this.http.get('../rest/users/' + cookieInfo.id)
.subscribe((data: any) => {
this.signaturesService.userLogged = data.user;
if (this.signaturesService.signaturesList.length === 0) {
this.http.get('../rest/users/' + this.signaturesService.userLogged.id + '/signatures')
.subscribe((dataSign: any) => {
this.signaturesService.signaturesList = dataSign.signatures;
});
}
this.translate.use(this.signaturesService.userLogged.preferences.lang);
},
(err: any) => {
this.notificationService.handleErrors(err);
});
}
}
}
import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { HttpClientModule, HttpClient } from '@angular/common/http';
import { HttpClientModule, HttpClient, HTTP_INTERCEPTORS } from '@angular/common/http';
import { RouterModule } from '@angular/router';
import { NgModule } from '@angular/core';
import { HammerGestureConfig, HAMMER_GESTURE_CONFIG } from '@angular/platform-browser';
import { AuthGuard } from './service/auth.guard';
import { AuthInterceptor } from './service/auth-interceptor.service';
// import ngx-translate and the http loader
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
import { TranslateHttpLoader } from '@ngx-translate/http-loader';
......@@ -119,12 +122,12 @@ import { ConfirmComponent } from './plugins/confirm.component';
AngularDraggableModule,
AppMaterialModule,
RouterModule.forRoot([
{ path: 'administration', component: AdministrationComponent },
{ path: 'administration/users', component: UsersListComponent },
{ path: 'administration/users/new', component: UserComponent },
{ path: 'administration/users/:id', component: UserComponent },
{ path: 'administration', canActivate: [AuthGuard], component: AdministrationComponent },
{ path: 'administration/users', canActivate: [AuthGuard], component: UsersListComponent },
{ path: 'administration/users/new', canActivate: [AuthGuard], component: UserComponent },
{ path: 'administration/users/:id', canActivate: [AuthGuard], component: UserComponent },
{ path: 'documents/:id', component: DocumentComponent },
{ path: 'documents', component: DocumentComponent },
{ path: 'documents', canActivate: [AuthGuard], component: DocumentComponent },
{ path: 'login', component: LoginComponent },
{ path: 'forgot-password', component: ForgotPasswordComponent },
{ path: 'update-password', component: UpdatePasswordComponent },
......@@ -140,7 +143,9 @@ import { ConfirmComponent } from './plugins/confirm.component';
SignaturesComponent,
ConfirmComponent
],
providers: [SignaturesContentService,
providers: [
{ provide: HTTP_INTERCEPTORS, useClass: AuthInterceptor, multi: true },
SignaturesContentService,
FiltersService,
NotificationService,
{
......
......@@ -143,10 +143,6 @@ export class DocumentComponent implements OnInit {
private cookieService: CookieService,
private sanitizer: DomSanitizer, public dialog: MatDialog, private bottomSheet: MatBottomSheet) {
this.draggable = false;
if (!this.cookieService.check('maarchParapheurAuth')) {
this.router.navigate(['/login']);
}
}
ngOnInit(): void {
......
import { Injectable } from '@angular/core';
import { HttpEvent, HttpHandler, HttpInterceptor, HttpRequest } from '@angular/common/http';
import { Observable } from 'rxjs';
@Injectable()
export class AuthInterceptor implements HttpInterceptor {
constructor() {}
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
return next.handle(req);
}
}
import { Injectable } from '@angular/core';
import { ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot } from '@angular/router';
import { Observable, BehaviorSubject } from 'rxjs';
import { tap } from 'rxjs/operators';
import { CookieService } from 'ngx-cookie-service';
import { HttpClient } from '@angular/common/http';
import { SignaturesContentService } from './signatures.service';
@Injectable({
providedIn: 'root'
})
export class AuthGuard implements CanActivate {
constructor(public http: HttpClient, private router: Router, public signaturesService: SignaturesContentService, private cookieService: CookieService) { }
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
if (this.cookieService.check('maarchParapheurAuth')) {
console.log('Cookie ok !');
if (this.signaturesService.userLogged.id === undefined) {
const cookieInfo = JSON.parse(atob(this.cookieService.get('maarchParapheurAuth')));
this.http.get('../rest/users/' + cookieInfo.id)
.subscribe((data: any) => {
this.signaturesService.userLogged = data.user;
if (this.signaturesService.signaturesList.length === 0) {
this.http.get('../rest/users/' + this.signaturesService.userLogged.id + '/signatures')
.subscribe((dataSign: any) => {
this.signaturesService.signaturesList = dataSign.signatures;
});
}
},
(err: any) => {
this.router.navigateByUrl('/login');
});
return true;
} else {
return true;
}
} else {
console.log('auth failed !');
this.router.navigateByUrl('/login');
return false;
}
}
}
......@@ -14,8 +14,7 @@
{{signaturesService.userLogged.firstname}} {{signaturesService.userLogged.lastname}}
</div>
<div *ngIf="signaturesService.userLogged.picture" class="avatar"
[ngStyle]="{'background': 'url(' + signaturesService.userLogged.picture + ') no-repeat scroll center center / cover'}"
(click)="openProfile()">
[ngStyle]="{'background': 'url(' + signaturesService.userLogged.picture + ') no-repeat scroll center center / cover'}">
</div>
</header>
<header class="sidebar-header">
......
......@@ -36,7 +36,6 @@
}
.avatar {
cursor: pointer;
position: absolute;
width: 65px;
height: 65px;
......@@ -46,11 +45,6 @@
background-size: cover;
background-repeat: no-repeat;
background-position: center;
transition: all 0.2s;
}
.avatar:hover {
box-shadow: 0px 0px 5px 0px #656565;
}
.user {
......
......@@ -45,18 +45,6 @@ export class AdminSidebarComponent implements OnInit {
});
}
openProfile() {
this.signaturesService.sideNavRigtDatas = {
mode : 'profile',
width : '650px',
locked : true,
};
if (this.signaturesService.mobileMode) {
this.snavLeftComponent.close();
this.snavRightComponent.open();
}
}
openHome() {
this.router.navigate(['/documents/']);
if (this.signaturesService.mobileMode) {
......
......@@ -4,7 +4,7 @@
<button class="logout-button" mat-icon-button (click)="logout()">
<mat-icon fontSet="fas" fontIcon="fa-power-off"></mat-icon>
</button>
<button class="admin-button" mat-icon-button (click)="openAdmin()">
<button *ngIf="signaturesService.userLogged.hasAdmin" class="admin-button" mat-icon-button (click)="openAdmin()">
<mat-icon fontSet="fas" fontIcon="fa-tools"></mat-icon>
</button>
<button *ngIf="checkClose()" class="closePanel"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment