From ea3106536acb0479052df13cddd752fb9028ad67 Mon Sep 17 00:00:00 2001
From: Guillaume Heurtier <guillaume.heurtier@maarch.org>
Date: Fri, 10 Jan 2020 16:18:50 +0100
Subject: [PATCH] FEAT #12764 TIME 0:40 hiding private templates in get,
 displaying them in available circuits

---
 .../controllers/ListTemplateController.php    | 31 ++++++-------------
 ...iffusionModels-administration.component.ts |  2 +-
 2 files changed, 11 insertions(+), 22 deletions(-)

diff --git a/src/app/entity/controllers/ListTemplateController.php b/src/app/entity/controllers/ListTemplateController.php
index 448d7a15d2c..7a3290550ed 100755
--- a/src/app/entity/controllers/ListTemplateController.php
+++ b/src/app/entity/controllers/ListTemplateController.php
@@ -33,27 +33,11 @@ class ListTemplateController
 {
     public function get(Request $request, Response $response)
     {
-        $queryParams = $request->getQueryParams();
-
-        if (empty($queryParams['admin'])) {
-            $where = ['owner is null or owner = ?'];
-            $data = [$GLOBALS['id']];
-        } else {
-            $where = ['owner is null'];
-            $data = [];
-        }
-
         $listTemplates = ListTemplateModel::get([
-            'select' => ['id', 'type', 'entity_id as "entityId"', 'title', 'description', 'owner'],
-            'where'  => $where,
-            'data'   => $data
+            'select' => ['id', 'type', 'entity_id as "entityId"', 'title', 'description'],
+            'where'  => ['owner is null']
         ]);
 
-        foreach ($listTemplates as $key => $listTemplate) {
-            $listTemplates[$key]['isPrivate'] = $listTemplates[$key]['owner'] != null;
-            unset($listTemplates[$key]['owner']);
-        }
-
         return $response->withJson(['listTemplates' => $listTemplates]);
     }
 
@@ -619,8 +603,8 @@ class ListTemplateController
         $circuit = $queryParams['circuit'] == 'opinion' ? 'opinionCircuit' : 'visaCircuit';
         $resource = ResModel::getById(['resId' => $args['resId'], 'select' => ['destination']]);
 
-        $where = ['type = ?'];
-        $data = [$circuit];
+        $where = ['type = ?', 'owner is null or owner = ?'];
+        $data = [$circuit, $GLOBALS['id']];
         if (!empty($resource['destination'])) {
             $entity = EntityModel::getByEntityId(['entityId' => $resource['destination'], 'select' => ['id']]);
             $where[] = '(entity_id is null OR entity_id = ?)';
@@ -631,7 +615,12 @@ class ListTemplateController
             $orderBy = ['title'];
         }
 
-        $circuits = ListTemplateModel::get(['select' => ['*'], 'where' => $where, 'data' => $data, 'orderBy' => $orderBy]);
+        $circuits = ListTemplateModel::get([
+            'select'  => ['id', 'type', 'entity_id as "entityId"', 'title', 'description', "case when owner is null then false else true end as private"],
+            'where'   => $where,
+            'data'    => $data,
+            'orderBy' => $orderBy
+        ]);
 
         return $response->withJson(['circuits' => $circuits]);
     }
diff --git a/src/frontend/app/administration/diffusionModel/diffusionModels-administration.component.ts b/src/frontend/app/administration/diffusionModel/diffusionModels-administration.component.ts
index 07e58a382f0..0ab53293594 100755
--- a/src/frontend/app/administration/diffusionModel/diffusionModels-administration.component.ts
+++ b/src/frontend/app/administration/diffusionModel/diffusionModels-administration.component.ts
@@ -59,7 +59,7 @@ export class DiffusionModelsAdministrationComponent implements OnInit {
 
         this.loading = true;
 
-        this.http.get("../../rest/listTemplates?admin=true")
+        this.http.get("../../rest/listTemplates")
             .subscribe((data: any) => {
                 data['listTemplates'].forEach((template: any) => {
                     if ((template.type.indexOf('visaCircuit') != -1 || template.type.indexOf('opinionCircuit') != -1) && template.entityId == null) {
-- 
GitLab