diff --git a/rest/index.php b/rest/index.php index 9bd791017c4a022bedb01cbfcc271890ca2a649a..a2e307f3f2dfb61076120739269017b0e91b8911 100755 --- a/rest/index.php +++ b/rest/index.php @@ -56,6 +56,7 @@ $app->add(function (\Slim\Http\Request $request, \Slim\Http\Response $response, $app->get('/authenticationInformations', \SrcCore\controllers\AuthenticationController::class . ':getInformations'); $app->post('/authenticate', \SrcCore\controllers\AuthenticationController::class . ':authenticate'); $app->get('/authenticate/token', \SrcCore\controllers\AuthenticationController::class . ':getRefreshedToken'); +$app->get('/authenticate/logout', \SrcCore\controllers\AuthenticationController::class . ':logout'); //Attachments $app->get('/attachments/{id}', \Attachment\controllers\AttachmentController::class . ':getById'); @@ -113,6 +114,9 @@ $app->put('/languages', \SrcCore\controllers\LanguageController::class . ':gener $app->get('/passwordRules', \SrcCore\controllers\PasswordController::class . ':get'); $app->put('/passwordRules', \SrcCore\controllers\PasswordController::class . ':updateRules'); +// Privileges +$app->get('/privileges', \Group\controllers\PrivilegeController::class . ':getPrivileges'); + //Users $app->post('/users', \User\controllers\UserController::class . ':create'); $app->get('/users', \User\controllers\UserController::class . ':get'); diff --git a/src/app/group/controllers/PrivilegeController.php b/src/app/group/controllers/PrivilegeController.php index d31f0699c22f920cd177ee013042a33a0a49b058..21583e6c5ae051d5547b0e0397117e4ba8a10149 100755 --- a/src/app/group/controllers/PrivilegeController.php +++ b/src/app/group/controllers/PrivilegeController.php @@ -14,6 +14,8 @@ namespace Group\controllers; +use Slim\Http\Request; +use Slim\Http\Response; use SrcCore\models\ValidatorModel; use User\models\UserGroupModel; use Group\models\GroupPrivilegeModel; @@ -31,6 +33,11 @@ class PrivilegeController ['id' => 'indexation', 'type' => 'simple'] ]; + public function getPrivileges(Request $request, Response $response) + { + return $response->withJson(['privileges' => PrivilegeController::PRIVILEGES]); + } + public static function getPrivilegesByUserId(array $args) { ValidatorModel::notEmpty($args, ['userId', 'type']); diff --git a/src/core/controllers/AuthenticationController.php b/src/core/controllers/AuthenticationController.php index 10ff61166bbfe293d10dcbb2657ed075fb527bf3..929ad2e9d36d9ea7e74a0da27cf54504e4afe998 100755 --- a/src/core/controllers/AuthenticationController.php +++ b/src/core/controllers/AuthenticationController.php @@ -236,6 +236,19 @@ class AuthenticationController return $response->withJson(['token' => AuthenticationController::getJWT()]); } + public function logout(Request $request, Response $response) + { + HistoryController::add([ + 'code' => 'OK', + 'objectType' => 'users', + 'objectId' => $GLOBALS['id'], + 'type' => 'LOGOUT', + 'message' => '{userLogOut}' + ]); + + $response->withStatus(204); + } + public static function getJWT() { $sessionTime = AuthenticationController::MAX_DURATION_TOKEN; diff --git a/src/frontend/app/administration/history/history-list.component.ts b/src/frontend/app/administration/history/history-list.component.ts index 41a735c676f39ced7f331e3f50a837f03163768e..ec5eb4f117e0119ebc64ce312d788d8925aee245 100644 --- a/src/frontend/app/administration/history/history-list.component.ts +++ b/src/frontend/app/administration/history/history-list.component.ts @@ -57,10 +57,13 @@ export class HistoryListComponent { 'EMAIL': 'mail-outline', 'SUPPRESSION': 'trash-bin-outline', 'MODIFICATION': 'create-outline', - 'LOGIN': 'log-in-outline' + 'LOGIN': 'log-in-outline', + 'LOGOUT': 'log-out-outline' }; actions: any[] = []; + privileges: any[] = []; + @ViewChild('rightContent', { static: true }) rightContent: TemplateRef<any>; constructor( @@ -87,18 +90,19 @@ export class HistoryListComponent { this.menu.open('right-menu'); } - ionViewWillEnter() { + async ionViewWillEnter() { this.filters.messageTypes = []; this.filters.user = ''; this.filters.date.start = this.filters.date.end = null; this.menu.enable(true, 'left-menu'); this.menu.enable(true, 'right-menu'); this.signaturesService.initTemplate(this.rightContent, this.viewContainerRef, 'rightContent'); - this.gesActions(); + this.getActions(); this.getDatas(); + await this.getPrivileges(); } - gesActions() { + getActions() { this.http.get(`../rest/history/messageTypes`, this.filters) .pipe( tap((data: any) => { @@ -108,7 +112,7 @@ export class HistoryListComponent { label: this.translate.instant('lang.' + item) }; }); - this.actions = this.sortPipe.transform(this.actions, 'label'); + this.actions = this.sortPipe.transform(this.actions, 'label'); }), catchError((err: any) => { this.notificationService.handleErrors(err); @@ -117,6 +121,26 @@ export class HistoryListComponent { ).subscribe(); } + async getPrivileges() { + return new Promise(resolve => { + this.http.get(`../rest/privileges`) + .pipe( + tap((data: any) => { + this.privileges = data.privileges; + this.privileges.forEach((privilege, index) => { + this.privileges[index].label = this.translate.instant('lang.' + privilege.id + 'Admin'); + }); + resolve(true); + }), + catchError((err: any) => { + this.notificationService.handleErrors(err); + resolve(false); + return of(false); + }) + ).subscribe(); + }); + } + getDatas() { this.resources = []; this.offset = 0; @@ -125,7 +149,16 @@ export class HistoryListComponent { .pipe( tap((data: any) => { this.resources = data.history; - this.count = data.total; + this.resources.forEach((history, index) => { + this.privileges.forEach(privilege => { + if (history.message.includes(privilege.id)) { + this.resources[index].message = this.resources[index].message.replace(privilege.id, privilege.label); + } + }); + this.resources[index].message = this.resources[index].message.replace('VAL', this.translate.instant('lang.validate')); + this.resources[index].message = this.resources[index].message.replace('REF', this.translate.instant('lang.reject')); + }); + this.count = data.total; resolve(true); }), catchError((err: any) => { @@ -151,6 +184,15 @@ export class HistoryListComponent { this.http.post('../rest/history?limit=' + this.limit + '&offset=' + this.offset, this.filters).pipe( tap((data: any) => { this.resources = this.resources.concat(data.history); + this.resources.forEach((history, index) => { + this.privileges.forEach(privilege => { + if (history.message.includes(privilege.id)) { + this.resources[index].message = this.resources[index].message.replace(privilege.id, privilege.label); + } + }); + this.resources[index].message = this.resources[index].message.replace('VAL', this.translate.instant('lang.validate')); + this.resources[index].message = this.resources[index].message.replace('REF', this.translate.instant('lang.reject')); + }); event.target.complete(); if (this.count === this.resources.length) { event.target.disabled = true; diff --git a/src/frontend/app/service/auth.service.ts b/src/frontend/app/service/auth.service.ts index 86e726773354a28be968c85d4f9aa4e2965f43bf..1267711d24b3a96c73d36a0457fcd257efd10f18 100755 --- a/src/frontend/app/service/auth.service.ts +++ b/src/frontend/app/service/auth.service.ts @@ -5,6 +5,8 @@ import { NotificationService } from './notification.service'; import { SignaturesContentService } from './signatures.service'; import { LocalStorageService } from './local-storage.service'; import { NavController } from '@ionic/angular'; +import { catchError, tap } from 'rxjs/operators'; +import { of } from 'rxjs'; @Injectable({ providedIn: 'root' @@ -46,8 +48,17 @@ export class AuthService { } logout() { - this.clearTokens(); - this.navCtrl.navigateRoot('/login'); + this.http.get('../rest/authenticate/logout') + .pipe( + tap(() => { + this.clearTokens(); + this.navCtrl.navigateRoot('/login'); + }), + catchError((err: any) => { + this.notificationService.handleErrors(err); + return of(false); + }) + ).subscribe(); // this.router.navigate(['/login']); }