Skip to content
Snippets Groups Projects
Commit ea310653 authored by Guillaume Heurtier's avatar Guillaume Heurtier
Browse files

FEAT #12764 TIME 0:40 hiding private templates in get, displaying them in available circuits

parent 03e46dc8
No related branches found
No related tags found
No related merge requests found
......@@ -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]);
}
......
......@@ -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) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment