From 55def97d66caa685e6df99903a6470046ab8c612 Mon Sep 17 00:00:00 2001 From: Daniel Barbero Martin Date: Mon, 15 Apr 2019 15:10:58 +0200 Subject: [PATCH] Add ACL for all item and item groups, fixed minor error show elements type item groups in VC Former-commit-id: 04e1d5736dbfd0da47df7d3948969621b2c8faf1 --- .../models/VisualConsole/Container.php | 29 +++++++++++++++++-- visual_console_client/src/items/Group.ts | 8 +++-- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/pandora_console/include/rest-api/models/VisualConsole/Container.php b/pandora_console/include/rest-api/models/VisualConsole/Container.php index 9845969dfd..7710121cb4 100644 --- a/pandora_console/include/rest-api/models/VisualConsole/Container.php +++ b/pandora_console/include/rest-api/models/VisualConsole/Container.php @@ -324,10 +324,28 @@ final class Container extends Model int $layoutId, array $aclUserGroups=[] ): array { - $filter = ['id_layout' => $layoutId]; // If is empty array user view all groups. if (count($aclUserGroups) > 0) { - $filter['element_group'] = $aclUserGroups; + // Filter group for elements groups. + $filterCondition = ['id_layout' => $layoutId]; + $filterCondition['element_group'] = $aclUserGroups; + // Format filter mysql. + $filter[0] = db_format_array_where_clause_sql( + $filterCondition + ); + + // Filter groups for type groups. + // Only true condition if type is GROUP_ITEM. + $filterGroup = []; + $filterGroup['type'] = GROUP_ITEM; + $filterGroup['id_group'] = $aclUserGroups; + + // Format filter mysql. + $filter[1] = '('.db_format_array_where_clause_sql( + $filterGroup + ).')'; + } else { + $filter = ['id_layout' => $layoutId]; } $fields = [ @@ -335,7 +353,12 @@ final class Container extends Model 'type', ]; - $rows = \db_get_all_rows_filter('tlayout_data', $filter, $fields); + $rows = \db_get_all_rows_filter( + 'tlayout_data', + $filter, + $fields, + 'OR' + ); if ($rows === false) { $rows = []; diff --git a/visual_console_client/src/items/Group.ts b/visual_console_client/src/items/Group.ts index c40a2475be..f1f080c140 100644 --- a/visual_console_client/src/items/Group.ts +++ b/visual_console_client/src/items/Group.ts @@ -1,11 +1,12 @@ import { LinkedVisualConsoleProps, UnknownObject } from "../types"; -import { linkedVCPropsDecoder, parseIntOr } from "../lib"; +import { linkedVCPropsDecoder, parseIntOr, notEmptyStringOr } from "../lib"; import Item, { ItemProps, itemBasePropsDecoder, ItemType } from "../Item"; export type GroupProps = { type: ItemType.GROUP_ITEM; imageSrc: string; // URL? groupId: number; + statusImageSrc: string | null; } & ItemProps & LinkedVisualConsoleProps; @@ -31,6 +32,7 @@ export function groupPropsDecoder(data: UnknownObject): GroupProps | never { type: ItemType.GROUP_ITEM, imageSrc: data.imageSrc, groupId: parseInt(data.groupId), + statusImageSrc: notEmptyStringOr(data.statusImageSrc, null), ...linkedVCPropsDecoder(data) // Object spread. It will merge the properties of the two objects. }; } @@ -39,7 +41,9 @@ export default class Group extends Item { public createDomElement(): HTMLElement { const img: HTMLImageElement = document.createElement("img"); img.className = "group"; - img.src = this.props.imageSrc; + if (this.props.statusImageSrc != null) { + img.src = this.props.statusImageSrc; + } return img; }