From 2dd557e66df5898bec52c07490332b2b1dc18722 Mon Sep 17 00:00:00 2001 From: Luciano Gorza Date: Wed, 20 Mar 2024 16:22:53 -0300 Subject: [PATCH 1/5] Remove groups.js angular controller --- .../groups/actions-buttons-agents.js | 33 ++-- .../management/groups/groups-main.js | 25 +-- .../public/controllers/management/groups.js | 180 ------------------ .../public/controllers/management/index.js | 2 - .../templates/management/management.html | 19 -- 5 files changed, 26 insertions(+), 233 deletions(-) delete mode 100644 plugins/main/public/controllers/management/groups.js diff --git a/plugins/main/public/controllers/management/components/management/groups/actions-buttons-agents.js b/plugins/main/public/controllers/management/components/management/groups/actions-buttons-agents.js index 39e04635a5..fa3ffc0a7d 100644 --- a/plugins/main/public/controllers/management/components/management/groups/actions-buttons-agents.js +++ b/plugins/main/public/controllers/management/components/management/groups/actions-buttons-agents.js @@ -15,9 +15,7 @@ import { EuiFlexItem, EuiButtonEmpty } from '@elastic/eui'; import { connect } from 'react-redux'; -import { - updateShowAddAgents, -} from '../../../../../redux/actions/groupsActions'; +import { updateShowAddAgents } from '../../../../../redux/actions/groupsActions'; import GroupsHandler from './utils/groups-handler'; import { ExportConfiguration } from '../../../../agent/components/export-configuration'; @@ -30,22 +28,21 @@ class WzGroupsActionButtonsAgents extends Component { super(props); this.reportingService = new ReportingService(); - this.groupsHandler = GroupsHandler; } - showManageAgents() { - const { itemDetail } = this.props.state; - - this.props.groupsProps.showAddingAgents(true, itemDetail); this.props.updateShowAddAgents(true); } render() { // Add new group button const manageAgentsButton = ( - this.showManageAgents()}> + this.showManageAgents()} + > Manage agents ); @@ -53,14 +50,14 @@ class WzGroupsActionButtonsAgents extends Component { // Export PDF button const exportPDFButton = ( + exportConfiguration={enabledComponents => this.reportingService.startConfigReport( this.props.state.itemDetail, 'groupConfig', - enabledComponents + enabledComponents, ) } - type="group" + type='group' /> ); @@ -73,16 +70,20 @@ class WzGroupsActionButtonsAgents extends Component { } } -const mapStateToProps = (state) => { +const mapStateToProps = state => { return { state: state.groupsReducers, }; }; -const mapDispatchToProps = (dispatch) => { +const mapDispatchToProps = dispatch => { return { - updateShowAddAgents: (showAddAgents) => dispatch(updateShowAddAgents(showAddAgents)), + updateShowAddAgents: showAddAgents => + dispatch(updateShowAddAgents(showAddAgents)), }; }; -export default connect(mapStateToProps, mapDispatchToProps)(WzGroupsActionButtonsAgents); +export default connect( + mapStateToProps, + mapDispatchToProps, +)(WzGroupsActionButtonsAgents); diff --git a/plugins/main/public/controllers/management/components/management/groups/groups-main.js b/plugins/main/public/controllers/management/components/management/groups/groups-main.js index 3898978ec3..83cf53c972 100644 --- a/plugins/main/public/controllers/management/components/management/groups/groups-main.js +++ b/plugins/main/public/controllers/management/components/management/groups/groups-main.js @@ -30,6 +30,7 @@ import { getErrorOrchestrator } from '../../../../../react-services/common-servi import { compose } from 'redux'; import { withGlobalBreadcrumb } from '../../../../../components/common/hocs'; import { endpointGroups } from '../../../../../utils/applications'; +import { MultipleAgentSelector } from '../../../../../components/management/groups/multiple-agent-selector'; class WzGroups extends Component { constructor(props) { @@ -71,29 +72,15 @@ class WzGroups extends Component { } UNSAFE_componentWillReceiveProps(nextProps) { - if ( - nextProps.groupsProps.closeAddingAgents && - this.props.state.showAddAgents - ) { + if (this.props.state.showAddAgents) { this.props.updateShowAddAgents(false); } - if ( - nextProps.groupsProps.selectedGroup && - nextProps.groupsProps.selectedGroup !== - this.props.groupsProps.selectedGroup - ) { - store.dispatch(updateGroupDetail(nextProps.groupsProps.selectedGroup)); - } } componentWillUnmount() { // When the component is going to be unmounted the groups state is reset this.props.resetGroup(); } - componentDidUpdate() { - if (this.props.groupsProps.selectedGroup) { - this.props.groupsProps.updateProps(); - } - } + render() { const { itemDetail, showAddAgents, fileContent } = this.props.state; return ( @@ -101,6 +88,12 @@ class WzGroups extends Component { {!showAddAgents && ((itemDetail && !fileContent && ) || (fileContent && ) || )} + {showAddAgents && itemDetail && ( + this.props.updateShowAddAgents(false)} + /> + )} ); } diff --git a/plugins/main/public/controllers/management/groups.js b/plugins/main/public/controllers/management/groups.js deleted file mode 100644 index caf3bf29f1..0000000000 --- a/plugins/main/public/controllers/management/groups.js +++ /dev/null @@ -1,180 +0,0 @@ -/* - * Wazuh app - Management groups controller - * Copyright (C) 2015-2022 Wazuh, Inc. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * Find more information about this on the LICENSE file. - */ -import { WazuhConfig } from '../../react-services/wazuh-config'; -import { WzRequest } from '../../react-services/wz-request'; -import { ShareAgent } from '../../factories/share-agent'; -import { GroupHandler } from '../../react-services/group-handler'; -import { ErrorHandler } from '../../react-services/error-handler'; -import { ReportingService } from '../../react-services/reporting'; - -export class GroupsController { - constructor($scope, $location, errorHandler) { - this.scope = $scope; - this.location = $location; - this.errorHandler = errorHandler; - this.shareAgent = new ShareAgent(); - this.groupHandler = GroupHandler; - this.wazuhConfig = new WazuhConfig(); - this.reportingService = new ReportingService(); - } - - async $onInit() { - try { - this.mctrl = this.scope.mctrl; - this.addingGroup = false; - this.load = false; - await this.loadGroups(); - - // Listeners - - // Resetting the factory configuration - this.scope.$on('$destroy', () => {}); - - this.scope.$watch('lookingGroup', value => { - this.addingAgents = false; - if (!value) { - this.file = false; - this.filename = false; - } - }); - - // Props - this.exportConfigurationProps = { - exportConfiguration: enabledComponents => - this.exportConfiguration(enabledComponents), - type: 'group', - }; - - this.filesInGroupTableProps = { - exportConfigurationProps: this.exportConfigurationProps, - }; - - return; - } catch (error) { - ErrorHandler.handle(error, 'Groups'); - } - } - - /** - * Loads the initial information - */ - async loadGroups() { - try { - // If come from agents - // Store a boolean variable to check if come from agents - this.globalAgent = this.shareAgent.getAgent(); - if (this.globalAgent || this.location.search()?.group) { - const globalGroup = - this.shareAgent.getSelectedGroup() || this.location.search().group; - // Get ALL groups - const data = await WzRequest.apiReq('GET', '/groups', {}); - const filtered = data.data.data.affected_items.filter( - group => group.name === globalGroup, - ); - if (Array.isArray(filtered) && filtered.length) { - // Load that our group - this.buildGroupsTableProps(data.data.data.items, { - group: filtered[0], - }); - } else { - throw Error(`Group ${globalGroup} not found`); - } - - this.shareAgent.deleteAgent(); - } else { - const loadedGroups = await WzRequest.apiReq('GET', '/groups', {}); - this.buildGroupsTableProps(loadedGroups.data.data.affected_items); - this.load = false; - } - this.scope.$applyAsync(); - } catch (error) { - return Promise.reject(error); - } - } - - toggle() { - this.lookingGroup = true; - } - - /** - * This navigate to a selected agent - * @param {Number} agentId - */ - showAgent(agent) { - this.shareAgent.setAgent(agent); - this.location.search('tab', null); - this.location.path('/agents'); - this.scope.$applyAsync(); - } - - /** - * - * @param {Object} enabledComponents - */ - exportConfiguration(enabledComponents, group) { - this.reportingService.startConfigReport( - group, - 'groupConfig', - enabledComponents, - ); - } - - async cancelButton() { - this.mctrl.managementProps.groupsProps.closeAddingAgents = true; - this.addingAgents = false; - } - - switchAddingGroup() { - this.addingGroup = !this.addingGroup; - } - - buildGroupsTableProps(items, params = {}) { - this.redirectGroup = params.group || false; - this.groupsTableProps = { - items, - closeAddingAgents: false, - showAddingAgents: (status, group) => { - this.showAddingAgents(status, group); - }, - exportConfigurationProps: { - exportConfiguration: (enabledComponents, group) => - this.exportConfiguration(enabledComponents, group), - type: 'group', - }, - currentGroup: group => { - this.currentGroup = group; - }, - updateProps: () => { - this.loadGroups(); - }, - showAgent: agent => { - this.showAgent(agent); - }, - selectedGroup: this.redirectGroup, - }; - this.mctrl.managementProps.groupsProps = this.groupsTableProps; - } - - async showAddingAgents(status, group) { - this.load = true; - this.mctrl.managementProps.groupsProps.closeAddingAgents = false; - this.currentGroup = group; - this.lookingGroup = true; - this.addingAgents = status; - this.load = false; - this.multipleAgentSelectorProps = { - currentGroup: this.currentGroup, - cancelButton: () => this.cancelButton(), - }; - this.scope.$applyAsync(); - } -} diff --git a/plugins/main/public/controllers/management/index.js b/plugins/main/public/controllers/management/index.js index 6ed7e0517c..f879da31d1 100644 --- a/plugins/main/public/controllers/management/index.js +++ b/plugins/main/public/controllers/management/index.js @@ -10,7 +10,6 @@ * Find more information about this on the LICENSE file. */ -import { GroupsController } from './groups'; import { ManagementController } from './management'; import { ClusterController } from './monitoring'; import WzManagement from './components/management/management-provider'; @@ -24,7 +23,6 @@ WzManagementConfiguration.displayName = 'WzManagementConfiguration'; app .controller('managementController', ManagementController) - .controller('groupsPreviewController', GroupsController) .controller('clusterController', ClusterController) .value('WzManagement', WzManagement) .value('WzManagementConfiguration', WzManagementConfiguration); diff --git a/plugins/main/public/templates/management/management.html b/plugins/main/public/templates/management/management.html index 8bfc57911f..efa961dc3a 100644 --- a/plugins/main/public/templates/management/management.html +++ b/plugins/main/public/templates/management/management.html @@ -555,23 +555,4 @@

> - -
- -
- -
-
- From 195110518ed783e2746e4aa8ddad5a6319739d66 Mon Sep 17 00:00:00 2001 From: Luciano Gorza Date: Wed, 20 Mar 2024 16:26:49 -0300 Subject: [PATCH 2/5] Update CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b1f91bd870..da06b6845d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ All notable changes to the Wazuh app project will be documented in this file. - Change the view of API is down and check connection to Server APIs application [#6337](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6337) - Changed the usage of the endpoint GET /groups/{group_id}/files/{file_name} [#6385](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6385) - Refactoring and redesign endpoints summary visualizations [#6268](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6268) +- Remove AngularJS controller for manage groups [#6543](https://github.com/wazuh/wazuh-dashboard-plugins/pull/6543) ### Fixed From 7ef40ea2e5accc5714fac26b456eec03a04847a5 Mon Sep 17 00:00:00 2001 From: Luciano Gorza Date: Wed, 20 Mar 2024 17:33:55 -0300 Subject: [PATCH 3/5] Fix unit test --- .../__snapshots__/groups-main.test.tsx.snap | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/plugins/main/public/controllers/management/components/management/groups/__snapshots__/groups-main.test.tsx.snap b/plugins/main/public/controllers/management/components/management/groups/__snapshots__/groups-main.test.tsx.snap index 2923c94f31..792a26b3e0 100644 --- a/plugins/main/public/controllers/management/components/management/groups/__snapshots__/groups-main.test.tsx.snap +++ b/plugins/main/public/controllers/management/components/management/groups/__snapshots__/groups-main.test.tsx.snap @@ -33,23 +33,6 @@ exports[`Group main component renders correctly to match the snapshot 1`] = ` }, } } - groupsProps={ - Object { - "closeAddingAgents": false, - "exportConfigurationProps": Object { - "type": "group", - }, - "items": Array [ - Object { - "configSum": "ab73af41699f13fdd81903b5f23d8d00", - "count": 1, - "mergedSum": "2c45c95db2954d2c7d0ea533f09e81a5", - "name": "default", - }, - ], - "selectedGroup": false, - } - } logtestProps={ Object { "onFlyout": true, From c0a9fbb902a8e45a1ce4579c5d7176ee54203c83 Mon Sep 17 00:00:00 2001 From: Luciano Gorza Date: Wed, 20 Mar 2024 17:58:48 -0300 Subject: [PATCH 4/5] Update unit test snapshot --- .../__snapshots__/groups-main.test.tsx.snap | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/plugins/main/public/controllers/management/components/management/groups/__snapshots__/groups-main.test.tsx.snap b/plugins/main/public/controllers/management/components/management/groups/__snapshots__/groups-main.test.tsx.snap index 792a26b3e0..2923c94f31 100644 --- a/plugins/main/public/controllers/management/components/management/groups/__snapshots__/groups-main.test.tsx.snap +++ b/plugins/main/public/controllers/management/components/management/groups/__snapshots__/groups-main.test.tsx.snap @@ -33,6 +33,23 @@ exports[`Group main component renders correctly to match the snapshot 1`] = ` }, } } + groupsProps={ + Object { + "closeAddingAgents": false, + "exportConfigurationProps": Object { + "type": "group", + }, + "items": Array [ + Object { + "configSum": "ab73af41699f13fdd81903b5f23d8d00", + "count": 1, + "mergedSum": "2c45c95db2954d2c7d0ea533f09e81a5", + "name": "default", + }, + ], + "selectedGroup": false, + } + } logtestProps={ Object { "onFlyout": true, From 29513d205304b1bc46842b2c546c7045c7bbc201 Mon Sep 17 00:00:00 2001 From: Luciano Gorza Date: Thu, 21 Mar 2024 11:47:51 -0300 Subject: [PATCH 5/5] Fix WzButtonPermissions --- .../components/common/permissions/button.tsx | 1 + .../__snapshots__/groups-main.test.tsx.snap | 17 ----------------- .../management/groups/groups-main.test.tsx | 15 --------------- 3 files changed, 1 insertion(+), 32 deletions(-) diff --git a/plugins/main/public/components/common/permissions/button.tsx b/plugins/main/public/components/common/permissions/button.tsx index 419477fc2e..fb0acc4f72 100644 --- a/plugins/main/public/components/common/permissions/button.tsx +++ b/plugins/main/public/components/common/permissions/button.tsx @@ -70,6 +70,7 @@ export const WzButtonPermissions = ({ return additionalProps; }} + {...rest} >