From 8845fc933016b379ec617e6579c5ccfdf6ab92dd Mon Sep 17 00:00:00 2001 From: Daniel Maya Date: Tue, 30 Jul 2019 11:20:03 +0200 Subject: [PATCH] item deletion improvements --- .../javascript/pandora_visual_console.js | 98 +++++++++---------- pandora_console/include/rest-api/index.php | 19 +++- .../operation/visual_console/view.php | 30 ++++-- visual_console_client/src/Item.ts | 35 +++++++ visual_console_client/src/VisualConsole.ts | 44 +++++---- 5 files changed, 145 insertions(+), 81 deletions(-) diff --git a/pandora_console/include/javascript/pandora_visual_console.js b/pandora_console/include/javascript/pandora_visual_console.js index 556a273316..892b581a9b 100755 --- a/pandora_console/include/javascript/pandora_visual_console.js +++ b/pandora_console/include/javascript/pandora_visual_console.js @@ -375,57 +375,6 @@ function createVisualConsole( .init(); }); - // VC Item remove. - visualConsole.onItemRemove(function(e) { - var id = e.item.props.id; - var data = { - type: e.item.props.type - }; - var taskId = "visual-console-item-update-" + id; - - // Persist the new position. - asyncTaskManager - .add(taskId, function(done) { - var abortable = removeVisualConsoleItem( - baseUrl, - visualConsole.props.id, - id, - data, - function(error, data) { - if (error || !data) { - console.log( - "[ERROR]", - "[VISUAL-CONSOLE-CLIENT]", - "[API]", - error ? error.message : "Invalid response" - ); - - // Add the item to the list. - visualConsole.elementsById[e.item.props.id] = e.item; - visualConsole.elementIds.push(e.item.props.id); - // Item event handlers. - e.item.onClick(visualConsole.handleElementClick); - e.item.onDblClick(visualConsole.handleElementDblClick); - e.item.onMoved(visualConsole.handleElementMovement); - e.item.onResized(visualConsole.handleElementResizement); - e.item.onRemove(visualConsole.handleElementRemove); - // Add the item to the DOM. - visualConsole.containerRef.append(e.item.elementRef); - } - - done(); - } - ); - - return { - cancel: function() { - abortable.abort(); - } - }; - }) - .init(); - }); - if (updateInterval != null && updateInterval > 0) { // Start an interval to update the Visual Console. updateVisualConsole(props.id, updateInterval, updateInterval); @@ -448,6 +397,48 @@ function createVisualConsole( asyncTaskManager.cancel("visual-console"); asyncTaskManager.cancel("visual-console-start"); } + }, + deleteItem: function(item) { + var aux = item; + var id = item.props.id; + + item.remove(); + + var taskId = "visual-console-item-update-" + id; + + // Persist the new position. + asyncTaskManager + .add(taskId, function(done) { + var abortable = removeVisualConsoleItem( + baseUrl, + visualConsole.props.id, + id, + function(error, data) { + if (error || !data) { + console.log( + "[ERROR]", + "[VISUAL-CONSOLE-CLIENT]", + "[API]", + error ? error.message : "Invalid response" + ); + + // Add the item to the list. + var itemRetrieved = aux.props; + itemRetrieved["receivedAt"] = new Date(); + visualConsole.addElement(itemRetrieved); + } + + done(); + } + ); + + return { + cancel: function() { + abortable.abort(); + } + }; + }) + .init(); } }; } @@ -697,7 +688,7 @@ function getVisualConsoleItem(baseUrl, vcId, vcItemId, callback) { * @return {Object} Cancellable. Object which include and .abort([statusText]) function. */ // eslint-disable-next-line no-unused-vars -function removeVisualConsoleItem(baseUrl, vcId, vcItemId, data, callback) { +function removeVisualConsoleItem(baseUrl, vcId, vcItemId, callback) { // var apiPath = baseUrl + "/include/rest-api"; var apiPath = baseUrl + "/ajax.php"; var jqXHR = null; @@ -742,8 +733,7 @@ function removeVisualConsoleItem(baseUrl, vcId, vcItemId, data, callback) { page: "include/rest-api/index", removeVisualConsoleItem: 1, visualConsoleId: vcId, - visualConsoleItemId: vcItemId, - data: data + visualConsoleItemId: vcItemId }, "json" ) diff --git a/pandora_console/include/rest-api/index.php b/pandora_console/include/rest-api/index.php index cdc92f1c4b..4f89f4dabf 100644 --- a/pandora_console/include/rest-api/index.php +++ b/pandora_console/include/rest-api/index.php @@ -121,9 +121,24 @@ if ($getVisualConsole === true) { return; } + $itemData = $item->toArray(); + $itemAclGroupId = $itemData['aclGroupId']; + + $aclWrite = check_acl($config['id_user'], $itemAclGroupId, 'VW'); + $aclManage = check_acl($config['id_user'], $itemAclGroupId, 'VM'); + + // ACL. + if (!$aclWrite && !$aclManage) { + db_pandora_audit( + 'ACL Violation', + 'Trying to delete visual console item without group access' + ); + http_response_code(403); + return; + } + $data = get_parameter('data'); - $class = VisualConsole::getItemClass((int) $data['type']); - $result = $class::delete($itemId); + $result = $item::delete($itemId); echo $result; return; } diff --git a/pandora_console/operation/visual_console/view.php b/pandora_console/operation/visual_console/view.php index a57f644424..b2d61aae61 100644 --- a/pandora_console/operation/visual_console/view.php +++ b/pandora_console/operation/visual_console/view.php @@ -167,7 +167,7 @@ if ($pure === false) { echo '