From fe24003145d7c0cebbe0d92f0eaea2c8c7b837bb Mon Sep 17 00:00:00 2001 From: Damien <damien.burel@maarch.org> Date: Fri, 26 Oct 2018 11:30:13 +0200 Subject: [PATCH] FEAT #8732 [home] Notification when document out of perimeter --- rest/index.php | 2 + .../resource/controllers/ResController.php | 9 +++ src/frontend/app/home.component.ts | 57 +++++++++++-------- src/frontend/lang/lang-en.ts | 2 + src/frontend/lang/lang-fr.ts | 2 + 5 files changed, 48 insertions(+), 24 deletions(-) diff --git a/rest/index.php b/rest/index.php index 2b958046d62..eaa517ada83 100755 --- a/rest/index.php +++ b/rest/index.php @@ -241,6 +241,8 @@ $app->put('/res/externalInfos', \Resource\controllers\ResController::class . ':u $app->get('/categories', \Resource\controllers\ResController::class . ':getCategories'); $app->get('/natures', \Resource\controllers\ResController::class . ':getNatures'); $app->get('/resources/groups/{groupSerialId}/baskets/{basketId}', \Resource\controllers\ResController::class . ':getResourcesByBasket'); +$app->get('/resources/{resId}/isAllowed', \Resource\controllers\ResController::class . ':isAllowedForCurrentUser'); + //Attachments $app->post('/attachments', \Attachment\controllers\AttachmentController::class . ':create'); diff --git a/src/app/resource/controllers/ResController.php b/src/app/resource/controllers/ResController.php index 7aeea0c588e..6e2d3b617bf 100755 --- a/src/app/resource/controllers/ResController.php +++ b/src/app/resource/controllers/ResController.php @@ -668,4 +668,13 @@ class ResController { return $response->withJson(['natures' => ResModel::getNatures()]); } + + public function isAllowedForCurrentUser(Request $request, Response $response, array $aArgs) + { + if (!Validator::intVal()->validate($aArgs['resId']) || !ResController::hasRightByResId(['resId' => $aArgs['resId'], 'userId' => $GLOBALS['userId']])) { + return $response->withJson(['isAllowed' => false]); + } + + return $response->withJson(['isAllowed' => true]); + } } diff --git a/src/frontend/app/home.component.ts b/src/frontend/app/home.component.ts index b13b0aacd08..f5d094fbaf1 100755 --- a/src/frontend/app/home.component.ts +++ b/src/frontend/app/home.component.ts @@ -19,30 +19,30 @@ declare var angularGlobals: any; }) export class HomeComponent extends AutoCompletePlugin implements OnInit { - private _mobileQueryListener: () => void; - mobileQuery: MediaQueryList; - mobileMode: boolean = false; - coreUrl: string; - thumbnailUrl: string; - lang: any = LANG; + private _mobileQueryListener : () => void; + mobileQuery : MediaQueryList; + mobileMode : boolean = false; - loading: boolean = false; - docUrl : string = ''; - public innerHtml: SafeHtml; + coreUrl : string; + lang : any = LANG; + loading : boolean = false; + + thumbnailUrl : string; + docUrl : string = ''; + homeData : any; + homeMessage : string; + dataSource : any; + currentDate : string = ""; + + + public innerHtml : SafeHtml; + displayedColumns : string[] = ['res_id', 'subject', 'creation_date']; @ViewChild('snav') snav: MatSidenav; @ViewChild('snav2') sidenavRight: MatSidenav; - - @ViewChildren(MatExpansionPanel) viewPanels: QueryList<MatExpansionPanel>; - homeData: any; - homeMessage: string; - dataSource: any; - displayedColumns: string[] = ['res_id', 'subject', 'creation_date']; - - currentDate : string = ""; - constructor(changeDetectorRef: ChangeDetectorRef, media: MediaMatcher, public http: HttpClient, public dialog: MatDialog, private sanitizer: DomSanitizer) { + constructor(changeDetectorRef: ChangeDetectorRef, media: MediaMatcher, public http: HttpClient, public dialog: MatDialog, private sanitizer: DomSanitizer, private notify: NotificationService) { super(http, ['users']); this.mobileMode = angularGlobals.mobileMode; $j("link[href='merged_css.php']").remove(); @@ -66,9 +66,9 @@ export class HomeComponent extends AutoCompletePlugin implements OnInit { this.currentDate = event.toLocaleDateString('fr-FR', options); this.http.get(this.coreUrl + "rest/home") - .subscribe((data: any) => { - this.homeData = data; - this.homeMessage = data['homeMessage'] + .subscribe((data: any) => { + this.homeData = data; + this.homeMessage = data['homeMessage'] }); } @@ -82,7 +82,7 @@ export class HomeComponent extends AutoCompletePlugin implements OnInit { }); } - goTo(row:any){ + goTo(row:any) { if (this.docUrl == this.coreUrl+'rest/res/'+row.res_id+'/content' && this.sidenavRight.opened) { this.sidenavRight.close(); } else { @@ -105,7 +105,16 @@ export class HomeComponent extends AutoCompletePlugin implements OnInit { $j('#listContent').css({"overflow":"auto"}); } - goToDetail(row:any){ - location.href = "index.php?page=details&dir=indexing_searching&id="+row.res_id; + goToDetail(row:any) { + this.http.get(this.coreUrl + "rest/resources/" + row.res_id + "/isAllowed") + .subscribe((data: any) => { + if (data['isAllowed']) { + location.href = "index.php?page=details&dir=indexing_searching&id=" + row.res_id; + } else { + this.notify.error(this.lang.documentOutOfPerimeter); + } + }, () => { + this.notify.error(this.lang.errorOccured); + }); } } diff --git a/src/frontend/lang/lang-en.ts b/src/frontend/lang/lang-en.ts index 81a275d8ad4..5136f3392da 100755 --- a/src/frontend/lang/lang-en.ts +++ b/src/frontend/lang/lang-en.ts @@ -686,4 +686,6 @@ export const LANG_EN = { "toRange" : "to", "redirectUserListDiff" : "Change destination user of diffusion list model", "chooseNewDest" : "is to <b>recipient</b> of following diffusion list model, please choose a <b>replacement</b> user", + "errorOccured" : "An error occured", + "documentOutOfPerimeter" : "This document is out of perimeter", }; diff --git a/src/frontend/lang/lang-fr.ts b/src/frontend/lang/lang-fr.ts index f2eaa199d1a..86f402c9215 100755 --- a/src/frontend/lang/lang-fr.ts +++ b/src/frontend/lang/lang-fr.ts @@ -711,4 +711,6 @@ export const LANG_FR = { "toRange" : "à ", "redirectUserListDiff" : "Changement de destinataire des modèles de liste de diffusion", "chooseNewDest" : "est en <b>destinataire</b> des modèles de liste de difffusion suivants, veuillez choisir un utilisateur de <b>remplacement</b>", + "errorOccured" : "Une erreur s'est produite", + "documentOutOfPerimeter" : "Ce document est en dehors de votre périmètre", }; -- GitLab