From 49f643a29171b1753dc7d4e98cbac5abea8bd3c4 Mon Sep 17 00:00:00 2001 From: Adri Valle Date: Mon, 3 Jun 2019 16:44:30 +0200 Subject: [PATCH 1/2] Fix adminMode in several controllers --- .../js/config/routes/management-states.js | 30 +++++++++++++++++++ .../decoders/managerDecodersIdCtrl.js | 5 ++-- .../management/groups/groupsCtrl.js | 6 ++-- .../management/rules/managerRulesetIdCtrl.js | 5 ++-- 4 files changed, 39 insertions(+), 7 deletions(-) diff --git a/SplunkAppForWazuh/appserver/static/js/config/routes/management-states.js b/SplunkAppForWazuh/appserver/static/js/config/routes/management-states.js index dda3957c4..35ea2a9c6 100644 --- a/SplunkAppForWazuh/appserver/static/js/config/routes/management-states.js +++ b/SplunkAppForWazuh/appserver/static/js/config/routes/management-states.js @@ -129,6 +129,16 @@ define(['../module'], function(module) { return false } } + ], + isAdmin: [ + '$currentDataService', + async $currentDataService => { + try { + return await $currentDataService.isAdmin() + } catch (error) { + return false + } + } ] } }) @@ -190,6 +200,16 @@ define(['../module'], function(module) { return false } } + ], + isAdmin: [ + '$currentDataService', + async $currentDataService => { + try { + return await $currentDataService.isAdmin() + } catch (error) { + return false + } + } ] } }) @@ -282,6 +302,16 @@ define(['../module'], function(module) { return false } } + ], + isAdmin: [ + '$currentDataService', + async $currentDataService => { + try { + return await $currentDataService.isAdmin() + } catch (error) { + return false + } + } ] } }) diff --git a/SplunkAppForWazuh/appserver/static/js/controllers/management/decoders/managerDecodersIdCtrl.js b/SplunkAppForWazuh/appserver/static/js/controllers/management/decoders/managerDecodersIdCtrl.js index 1f6275cf0..0dbf216fe 100644 --- a/SplunkAppForWazuh/appserver/static/js/controllers/management/decoders/managerDecodersIdCtrl.js +++ b/SplunkAppForWazuh/appserver/static/js/controllers/management/decoders/managerDecodersIdCtrl.js @@ -25,7 +25,8 @@ define(['../../module', '../rules/ruleset'], function(controllers, Ruleset) { extensions, $fileEditor, $restartService, - $requestService + $requestService, + isAdmin ) { super( $scope, @@ -43,6 +44,7 @@ define(['../../module', '../rules/ruleset'], function(controllers, Ruleset) { this.restartService = $restartService this.requestService = $requestService this.currentDecoder = currentDecoder + this.scope.adminMode = isAdmin } /** @@ -59,7 +61,6 @@ define(['../../module', '../rules/ruleset'], function(controllers, Ruleset) { this.scope.downloadCsv = (path, name) => this.downloadCsv(path, name) this.scope.addDetailFilter = (name, value) => this.addDetailFilter(name, value) - this.scope.adminMode = this.extensions['admin'] === 'true' this.scope.isLocal = this.scope.currentDecoder.path === 'etc/decoders' this.scope.saveDecoderConfig = fileName => this.saveDecoderConfig(fileName) diff --git a/SplunkAppForWazuh/appserver/static/js/controllers/management/groups/groupsCtrl.js b/SplunkAppForWazuh/appserver/static/js/controllers/management/groups/groupsCtrl.js index 04882e972..5498a2391 100644 --- a/SplunkAppForWazuh/appserver/static/js/controllers/management/groups/groupsCtrl.js +++ b/SplunkAppForWazuh/appserver/static/js/controllers/management/groups/groupsCtrl.js @@ -24,7 +24,8 @@ define(['../../module', 'FileSaver'], function(controllers) { $beautifierJson, $notificationService, $groupHandler, - extensions + extensions, + isAdmin ) { this.scope = $scope this.state = $state @@ -60,6 +61,7 @@ define(['../../module', 'FileSaver'], function(controllers) { } }) this.extensions = extensions + this.scope.adminMode = isAdmin this.scope.addingGroup = false this.scope.addingAgents = false this.scope.$on('groupsIsReloaded', () => { @@ -230,8 +232,6 @@ define(['../../module', 'FileSaver'], function(controllers) { this.scope.saveGroupAgentConfig = content => this.saveGroupAgentConfig(content) - this.scope.adminMode = this.extensions['admin'] === 'true' - this.scope.$applyAsync() } catch (err) { console.error('err ', err) diff --git a/SplunkAppForWazuh/appserver/static/js/controllers/management/rules/managerRulesetIdCtrl.js b/SplunkAppForWazuh/appserver/static/js/controllers/management/rules/managerRulesetIdCtrl.js index 388754882..796ec45fd 100644 --- a/SplunkAppForWazuh/appserver/static/js/controllers/management/rules/managerRulesetIdCtrl.js +++ b/SplunkAppForWazuh/appserver/static/js/controllers/management/rules/managerRulesetIdCtrl.js @@ -26,7 +26,8 @@ define(['../../module', './ruleset'], function(controllers, Ruleset) { extensions, $fileEditor, $restartService, - $requestService + $requestService, + isAdmin ) { super( $scope, @@ -43,6 +44,7 @@ define(['../../module', './ruleset'], function(controllers, Ruleset) { this.fileEditor = $fileEditor this.restartService = $restartService this.requestService = $requestService + this.scope.adminMode = isAdmin try { this.filters = JSON.parse(window.localStorage.ruleset) || [] } catch (err) { @@ -72,7 +74,6 @@ define(['../../module', './ruleset'], function(controllers, Ruleset) { this.scope.downloadCsv = (path, name) => this.downloadCsv(path, name) this.scope.addDetailFilter = (name, value) => this.addDetailFilter(name, value) - this.scope.adminMode = this.extensions['admin'] === 'true' this.scope.isLocal = this.scope.ruleInfo.path === 'etc/rules' this.scope.saveRuleConfig = fileName => this.saveRuleConfig(fileName) this.scope.closeEditingFile = () => this.closeEditingFile() From 26aa9f420306b59140abc00df38aa3616f000e5f Mon Sep 17 00:00:00 2001 From: Adri Valle Date: Thu, 6 Jun 2019 13:15:49 +0200 Subject: [PATCH 2/2] Remove duplicated functions --- .../js/config/routes/management-states.js | 92 ++++--------------- 1 file changed, 20 insertions(+), 72 deletions(-) diff --git a/SplunkAppForWazuh/appserver/static/js/config/routes/management-states.js b/SplunkAppForWazuh/appserver/static/js/config/routes/management-states.js index 35ea2a9c6..a3e4cadaa 100644 --- a/SplunkAppForWazuh/appserver/static/js/config/routes/management-states.js +++ b/SplunkAppForWazuh/appserver/static/js/config/routes/management-states.js @@ -1,10 +1,18 @@ -define(['../module'], function(module) { +define(['../module'], function (module) { 'use strict' + const checkAdmin = async $currentDataService => { + try { + return await $currentDataService.isAdmin() + } catch (error) { + return false + } + } + module.config([ '$stateProvider', 'BASE_URL', - function($stateProvider, BASE_URL) { + function ($stateProvider, BASE_URL) { $stateProvider // Manager .state('manager', { @@ -84,13 +92,7 @@ define(['../module'], function(module) { resolve: { isAdmin: [ '$currentDataService', - async $currentDataService => { - try { - return await $currentDataService.isAdmin() - } catch (error) { - return false - } - } + async $currentDataService => { return await checkAdmin($currentDataService) } ] } }) @@ -132,13 +134,7 @@ define(['../module'], function(module) { ], isAdmin: [ '$currentDataService', - async $currentDataService => { - try { - return await $currentDataService.isAdmin() - } catch (error) { - return false - } - } + async $currentDataService => { return await checkAdmin($currentDataService) } ] } }) @@ -155,13 +151,7 @@ define(['../module'], function(module) { resolve: { isAdmin: [ '$currentDataService', - async $currentDataService => { - try { - return await $currentDataService.isAdmin() - } catch (error) { - return false - } - } + async $currentDataService => { return await checkAdmin($currentDataService) } ] } }) @@ -203,13 +193,7 @@ define(['../module'], function(module) { ], isAdmin: [ '$currentDataService', - async $currentDataService => { - try { - return await $currentDataService.isAdmin() - } catch (error) { - return false - } - } + async $currentDataService => { return await checkAdmin($currentDataService) } ] } }) @@ -227,13 +211,7 @@ define(['../module'], function(module) { resolve: { isAdmin: [ '$currentDataService', - async $currentDataService => { - try { - return await $currentDataService.isAdmin() - } catch (error) { - return false - } - } + async $currentDataService => { return await checkAdmin($currentDataService) } ] } }) @@ -251,13 +229,7 @@ define(['../module'], function(module) { resolve: { isAdmin: [ '$currentDataService', - async $currentDataService => { - try { - return await $currentDataService.isAdmin() - } catch (error) { - return false - } - } + async $currentDataService => { return await checkAdmin($currentDataService) } ], cdbInfo: [ '$cdbEditor', @@ -305,13 +277,7 @@ define(['../module'], function(module) { ], isAdmin: [ '$currentDataService', - async $currentDataService => { - try { - return await $currentDataService.isAdmin() - } catch (error) { - return false - } - } + async $currentDataService => { return await checkAdmin($currentDataService) } ] } }) @@ -328,13 +294,7 @@ define(['../module'], function(module) { resolve: { isAdmin: [ '$currentDataService', - async $currentDataService => { - try { - return await $currentDataService.isAdmin() - } catch (error) { - return false - } - } + async $currentDataService => { return await checkAdmin($currentDataService) } ], clusterInfo: [ '$requestService', @@ -380,13 +340,7 @@ define(['../module'], function(module) { resolve: { isAdmin: [ '$currentDataService', - async $currentDataService => { - try { - return await $currentDataService.isAdmin() - } catch (error) { - return false - } - } + async $currentDataService => { return await checkAdmin($currentDataService) } ], clusterInfo: [ '$requestService', @@ -432,13 +386,7 @@ define(['../module'], function(module) { resolve: { isAdmin: [ '$currentDataService', - async $currentDataService => { - try { - return await $currentDataService.isAdmin() - } catch (error) { - return false - } - } + async $currentDataService => { return await checkAdmin($currentDataService) } ], statusData: [ '$requestService',