From 206487e25301211ae6ed5d615c98c59388b6dc48 Mon Sep 17 00:00:00 2001 From: Ian Yenien Serrano <63758389+yenienserrano@users.noreply.github.com> Date: Mon, 12 Jun 2023 12:50:29 +0200 Subject: [PATCH] Remove deprecated code and request in Management (#5485) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Remove deprecated code and request * Add changelog * Update snapshot * remove: remove clusterStatus unused variable * Remove clusterStatus property in groups-main.test.tsx --------- Co-authored-by: Antonio David GutiƩrrez Co-authored-by: Federico Rodriguez (cherry picked from commit 13984520d84bdb07cb0d86f1f315cec4aa39dd84) --- CHANGELOG.md | 2 ++ .../cdblists/components/cdblists-table.tsx | 3 +- .../management/cdblists/main-cdblists.tsx | 4 +-- .../cdblists/views/cdblists-overview.tsx | 2 -- .../management/common/actions-buttons.tsx | 17 ++-------- .../configuration/configuration-switch.js | 13 ++++--- .../__snapshots__/main-decoders.test.tsx.snap | 2 -- .../decoders/components/decoders-table.tsx | 3 +- .../management/decoders/main-decoders.tsx | 4 +-- .../decoders/views/decoders-overview.tsx | 6 ++-- .../__snapshots__/groups-main.test.tsx.snap | 6 ---- .../management/groups/groups-main.test.tsx | 8 ++--- .../components/management/management-main.js | 34 ------------------- .../__snapshots__/main-ruleset.test.tsx.snap | 2 -- .../ruleset/components/ruleset-table.tsx | 7 ++-- .../management/ruleset/main-ruleset.tsx | 4 +-- .../ruleset/views/ruleset-overview.tsx | 3 -- public/controllers/management/management.js | 32 ----------------- public/redux/actions/appStateActions.js | 15 ++------ public/redux/reducers/appStateReducers.js | 15 ++------ 20 files changed, 27 insertions(+), 155 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cae1d85aea..36986e6c76 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. - Changed the title of step 3 of the deploy a new agent section. [#5429](https://github.com/wazuh/wazuh-kibana-app/pull/5429) - Changed the description of step 3 of the deploy a new agent section. [#5429](https://github.com/wazuh/wazuh-kibana-app/pull/5429) - Changed the placeholder of the agent name input of the deploy a new agent section. [#5429](https://github.com/wazuh/wazuh-kibana-app/pull/5429) +- Changed the query to search for an agent in `management/configuration`. [#5485](https://github.com/wazuh/wazuh-kibana-app/pull/5485) - Changed the search bar in management/log to the one used in the rest of the app. [#5476](https://github.com/wazuh/wazuh-kibana-app/pull/5476) ### Fixed @@ -46,6 +47,7 @@ All notable changes to the Wazuh app project will be documented in this file. - Removed repeated and unnecessary requests in security section. [#5500](https://github.com/wazuh/wazuh-kibana-app/pull/5500) - Removed pretty parameter from cron job requests. [#5532](https://github.com/wazuh/wazuh-kibana-app/pull/5532) - Removed unnecessary requests in `Management/Status` section. [#5528](https://github.com/wazuh/wazuh-kibana-app/pull/5528) +- Removed obsolete code that caused duplicate requests to the api in `Management`. [#5485](https://github.com/wazuh/wazuh-kibana-app/pull/5485) ## Wazuh v4.4.3 - Kibana 7.10.2, 7.16.x, 7.17.x - Revision 01 diff --git a/public/controllers/management/components/management/cdblists/components/cdblists-table.tsx b/public/controllers/management/components/management/cdblists/components/cdblists-table.tsx index db27928072..d49792d817 100644 --- a/public/controllers/management/components/management/cdblists/components/cdblists-table.tsx +++ b/public/controllers/management/components/management/cdblists/components/cdblists-table.tsx @@ -153,7 +153,6 @@ function CDBListsTable(props) { { updateRestartClusterManager && updateRestartClusterManager() }} />, ]; @@ -188,4 +187,4 @@ function CDBListsTable(props) { export default compose( withUserPermissions -)(CDBListsTable); \ No newline at end of file +)(CDBListsTable); diff --git a/public/controllers/management/components/management/cdblists/main-cdblists.tsx b/public/controllers/management/components/management/cdblists/main-cdblists.tsx index 1071e38602..cf81b54e4e 100644 --- a/public/controllers/management/components/management/cdblists/main-cdblists.tsx +++ b/public/controllers/management/components/management/cdblists/main-cdblists.tsx @@ -15,7 +15,7 @@ import WzReduxProvider from '../../../../../redux/wz-redux-provider'; import WzCDBListsOverview from './views/cdblists-overview'; import WzListEditor from './views/list-editor'; -export default function WzCDBList({ clusterStatus }) { +export default function WzCDBList() { const [listContent, setListContent] = useState(false); return ( @@ -24,13 +24,11 @@ export default function WzCDBList({ clusterStatus }) { (listContent && ( { setListContent(false) }} updateListContent={(listContent) => { setListContent(listContent) }} /> )) || ( { setListContent(listContent) }} /> ) diff --git a/public/controllers/management/components/management/cdblists/views/cdblists-overview.tsx b/public/controllers/management/components/management/cdblists/views/cdblists-overview.tsx index eb836acea4..374cc479ab 100644 --- a/public/controllers/management/components/management/cdblists/views/cdblists-overview.tsx +++ b/public/controllers/management/components/management/cdblists/views/cdblists-overview.tsx @@ -27,7 +27,6 @@ function WzCDBListsOverview(props) { setShowWarningRestart(showWarningRestart); } - const { clusterStatus } = props; return {showWarningRestart && ( @@ -45,7 +44,6 @@ function WzCDBListsOverview(props) { updateRestartManagers(showWarningRestart)} /> diff --git a/public/controllers/management/components/management/common/actions-buttons.tsx b/public/controllers/management/components/management/common/actions-buttons.tsx index 8222516a6a..7d26f871f6 100644 --- a/public/controllers/management/components/management/common/actions-buttons.tsx +++ b/public/controllers/management/components/management/common/actions-buttons.tsx @@ -58,16 +58,6 @@ async function uploadFiles(files, resource, overwrite) { } } -const getReadPermissionsFiles = (section) => { - const { permissionResource } = resourceDictionary[section]; - return [ - { - action: `${section}:read`, - resource: permissionResource('*'), - }, - ]; -}; - const getUpdatePermissionsFiles = (section) => { const { permissionResource } = resourceDictionary[section]; return [ @@ -125,7 +115,7 @@ export const AddNewCdbListButton = (({ section, updateListContent }) => { // Manage files export const ManageFiles = (({ section, showingFiles, ...props }) => { - + /** * Toggle between files and rules or decoders */ @@ -171,11 +161,10 @@ const uploadFile = async (files, resource, overwrite) => { } }; -export const UploadFilesButton = (({ clusterStatus, section, showingFiles, onSuccess, ...props }) => { - +export const UploadFilesButton = (({ section, showingFiles, onSuccess, ...props }) => { + return ( node.type === 'master').name + nodes.data.data.affected_items.find(node => node.type === 'master') + .name, ); } else { // do nothing if it isn't a cluster @@ -156,9 +157,7 @@ class WzConfigurationSwitch extends Component { // If manager/cluster require agent platform info to filter sections in overview. It isn't coming from props for Management/Configuration try { this.setState({ loadingOverview: true }); - const masterNodeInfo = await WzRequest.apiReq('GET', '/agents', { - params: { q: 'id=000' }, - }); + const masterNodeInfo = await WzRequest.apiReq('GET', '/agents?agents_list=000', {}); this.setState({ masterNodeInfo: masterNodeInfo.data.data.affected_items[0] }); diff --git a/public/controllers/management/components/management/decoders/__snapshots__/main-decoders.test.tsx.snap b/public/controllers/management/components/management/decoders/__snapshots__/main-decoders.test.tsx.snap index ab4c46c446..31886c36ae 100644 --- a/public/controllers/management/components/management/decoders/__snapshots__/main-decoders.test.tsx.snap +++ b/public/controllers/management/components/management/decoders/__snapshots__/main-decoders.test.tsx.snap @@ -18,14 +18,12 @@ exports[`Ruleset component renders correctly to match the snapshot 1`] = ` } > { updateRestartClusterManager && updateRestartClusterManager() }} />); return buttons; diff --git a/public/controllers/management/components/management/decoders/main-decoders.tsx b/public/controllers/management/components/management/decoders/main-decoders.tsx index 7948d2f959..47f48f3152 100644 --- a/public/controllers/management/components/management/decoders/main-decoders.tsx +++ b/public/controllers/management/components/management/decoders/main-decoders.tsx @@ -16,7 +16,7 @@ import WzDecodersOverview from './views/decoders-overview'; import WzFileEditor from '../common/file-editor'; import { SECTION_DECODERS_SECTION } from '../common/constants'; -export default function WzDecoder({ clusterStatus, logtestProps }) { +export default function WzDecoder({ logtestProps }) { const [fileContent, setFileContent] = useState(false); const [addingFile, setAddingFile] = useState(false); @@ -36,13 +36,11 @@ export default function WzDecoder({ clusterStatus, logtestProps }) { fileContent={fileContent} addingFile={addingFile} logtestProps={logtestProps} - clusterStatus={clusterStatus} updateFileContent={(fileContent) => { setFileContent(fileContent) }} cleanEditState={() => cleanEditState()} /> )) || ( { setFileContent(fileContent) }} updateAddingFile={(addingFile) => { setAddingFile(addingFile) }} setShowingFiles={() => { setShowingFiles(!showingFiles) }} diff --git a/public/controllers/management/components/management/decoders/views/decoders-overview.tsx b/public/controllers/management/components/management/decoders/views/decoders-overview.tsx index f47d4498dd..9001328e1d 100644 --- a/public/controllers/management/components/management/decoders/views/decoders-overview.tsx +++ b/public/controllers/management/components/management/decoders/views/decoders-overview.tsx @@ -27,9 +27,8 @@ function WzDecodersOverview(props) { const updateRestartManagers = (showWarningRestart) => { setShowWarningRestart(showWarningRestart); } - - const { clusterStatus } = props; + return {showWarningRestart && ( @@ -42,12 +41,11 @@ function WzDecodersOverview(props) { )} - + updateRestartManagers(showWarningRestart)} /> diff --git a/public/controllers/management/components/management/groups/__snapshots__/groups-main.test.tsx.snap b/public/controllers/management/components/management/groups/__snapshots__/groups-main.test.tsx.snap index 3ae64fbacd..4fd29a949c 100644 --- a/public/controllers/management/components/management/groups/__snapshots__/groups-main.test.tsx.snap +++ b/public/controllers/management/components/management/groups/__snapshots__/groups-main.test.tsx.snap @@ -33,12 +33,6 @@ exports[`Group main component renders correctly to match the snapshot 1`] = ` } > ({ getAngularModule: jest.fn(), getHttp: () => ({ basePath: { - prepend: (str) => str, + prepend: str => str, }, }), })); @@ -55,10 +55,6 @@ const mockProps = { state: { section: '', }, - clusterStatus: { - status: true, - contextConfigServer: 'cluster', - }, }; const mockStore = configureMockStore(); const store = mockStore({}); @@ -68,7 +64,7 @@ describe('Group main component', () => { const wrapper = shallow( - + , ); expect(wrapper).toMatchSnapshot(); diff --git a/public/controllers/management/components/management/management-main.js b/public/controllers/management/components/management/management-main.js index d940694b7b..b71ea77c0c 100644 --- a/public/controllers/management/components/management/management-main.js +++ b/public/controllers/management/components/management/management-main.js @@ -24,8 +24,6 @@ import WzReporting from './reporting/reporting-main'; import WzConfiguration from './configuration/configuration-main'; import WzStatistics from './statistics/statistics-main'; import { connect } from 'react-redux'; -import { clusterReq } from './configuration/utils/wz-fetch'; -import { updateClusterStatus } from '../../../../redux/actions/appStateActions'; import { SECTION_CDBLIST_SECTION, SECTION_DECODERS_SECTION, @@ -46,33 +44,6 @@ class WzManagementMain extends Component { store.dispatch(updateManagementSection('')); } - componentDidMount() { - this.isClusterOrManager(); - } - - isClusterOrManager = async () => { - try { - const clusterStatus = await clusterReq(); - if (clusterStatus.data.data.enabled === 'yes' && clusterStatus.data.data.running === 'yes') { - this.props.updateClusterStatus({ - status: true, - contextConfigServer: 'cluster', - }); - } else { - this.props.updateClusterStatus({ - status: false, - contextConfigServer: 'manager', - }); - } - } catch (error) { - console.warn(`Error when try to get cluster status`, error); - this.props.updateClusterStatus({ - status: false, - contextConfigServer: 'manager', - }); - } - }; - render() { const { section } = this.props; return ( @@ -85,16 +56,13 @@ class WzManagementMain extends Component { (section === 'configuration' && ) || (section === SECTION_DECODERS_SECTION && ) || (section === SECTION_CDBLIST_SECTION && ) || (['ruleset', SECTION_RULES_SECTION].includes(section) && ( ))} @@ -105,14 +73,12 @@ class WzManagementMain extends Component { function mapStateToProps(state) { return { state: state.managementReducers, - clusterStatus: state.appStateReducers.clusterStatus, }; } const mapDispatchToProps = (dispatch) => { return { updateManagementSection: (section) => dispatch(updateManagementSection(section)), - updateClusterStatus: (clusterStatus) => dispatch(updateClusterStatus(clusterStatus)), }; }; diff --git a/public/controllers/management/components/management/ruleset/__snapshots__/main-ruleset.test.tsx.snap b/public/controllers/management/components/management/ruleset/__snapshots__/main-ruleset.test.tsx.snap index ab4c46c446..31886c36ae 100644 --- a/public/controllers/management/components/management/ruleset/__snapshots__/main-ruleset.test.tsx.snap +++ b/public/controllers/management/components/management/ruleset/__snapshots__/main-ruleset.test.tsx.snap @@ -18,14 +18,12 @@ exports[`Ruleset component renders correctly to match the snapshot 1`] = ` } > { updateRestartClusterManager && updateRestartClusterManager() }} />); return buttons; @@ -292,4 +291,4 @@ function RulesetTable({ setShowingFiles, showingFiles, ...props }) { export default compose( withUserPermissions -)(RulesetTable); \ No newline at end of file +)(RulesetTable); diff --git a/public/controllers/management/components/management/ruleset/main-ruleset.tsx b/public/controllers/management/components/management/ruleset/main-ruleset.tsx index 5b95c11e3b..770e383211 100644 --- a/public/controllers/management/components/management/ruleset/main-ruleset.tsx +++ b/public/controllers/management/components/management/ruleset/main-ruleset.tsx @@ -16,7 +16,7 @@ import WzFileEditor from '../common/file-editor'; import { SECTION_RULES_SECTION } from '../common/constants'; -export default function WzRuleset({ clusterStatus, logtestProps }) { +export default function WzRuleset({ logtestProps }) { const [fileContent, setFileContent] = useState(false); const [addingFile, setAddingFile] = useState(false); @@ -36,13 +36,11 @@ export default function WzRuleset({ clusterStatus, logtestProps }) { fileContent={fileContent} addingFile={addingFile} logtestProps={logtestProps} - clusterStatus={clusterStatus} updateFileContent={(fileContent) => { setFileContent(fileContent) }} cleanEditState={() => cleanEditState()} /> )) || ( { setFileContent(fileContent) }} updateAddingFile={(addingFile) => { setAddingFile(addingFile) }} setShowingFiles={() => { setShowingFiles(!showingFiles) }} diff --git a/public/controllers/management/components/management/ruleset/views/ruleset-overview.tsx b/public/controllers/management/components/management/ruleset/views/ruleset-overview.tsx index 62908569d2..377728711b 100644 --- a/public/controllers/management/components/management/ruleset/views/ruleset-overview.tsx +++ b/public/controllers/management/components/management/ruleset/views/ruleset-overview.tsx @@ -27,8 +27,6 @@ function WzRulesetOverview(props) { setShowWarningRestart(showWarningRestart); } - - const { clusterStatus } = props; return {showWarningRestart && ( @@ -46,7 +44,6 @@ function WzRulesetOverview(props) { updateRestartManagers(showWarningRestart)} /> diff --git a/public/controllers/management/management.js b/public/controllers/management/management.js index 59c9dab970..5fcbe60d69 100644 --- a/public/controllers/management/management.js +++ b/public/controllers/management/management.js @@ -368,7 +368,6 @@ export class ManagementController { } this.managementProps.section = this.tab === 'ruleset' ? this.rulesetTab : this.tab; this.$location.search('tab', this.tab); - this.loadNodeList(); } /** @@ -424,37 +423,6 @@ export class ManagementController { this.$scope.$applyAsync(); } - async loadNodeList() { - try { - this.loadingNodes = true; - const clusterInfo = AppState.getClusterInfo() || {}; - const clusterEnabled = clusterInfo.status === 'enabled'; - if (clusterEnabled) { - const response = await WzRequest.apiReq('GET', '/cluster/nodes', {}); - const nodeList = (((response || {}).data || {}).data || {}).items || false; - if (Array.isArray(nodeList) && nodeList.length) { - this.nodeList = nodeList.map((item) => item.name).reverse(); - this.selectedNode = nodeList.filter((item) => item.type === 'master')[0].name; - } - } - } catch (error) { - const errorOptions = { - level: UI_LOGGER_LEVELS.ERROR, - severity: UI_ERROR_SEVERITIES.BUSINESS, - context: `${ManagementController.name}.loadNodeList`, - error: { - error: error, - message: error?.message || '', - title: 'Error loading node list', - }, - }; - - getErrorOrchestrator().handleError(errorOptions); - } - this.loadingNodes = false; - this.$scope.$applyAsync(); - } - openCloseFlyout() { this.logtestOpened = !this.logtestOpened; this.logtestProps.isRuleset = this.tab; diff --git a/public/redux/actions/appStateActions.js b/public/redux/actions/appStateActions.js index e26d7ed3b1..58b6247b64 100644 --- a/public/redux/actions/appStateActions.js +++ b/public/redux/actions/appStateActions.js @@ -170,17 +170,6 @@ export const updateToastNotificationsModal = toastNotification => { }; }; -/** - * Updates ClusterOrManagerConfiguration in the appState store - * @param clusterStatus - */ -export const updateClusterStatus = (clusterStatus) => { - return { - type: 'UPDATE_CLUSTER_STATUS', - clusterStatus, - }; -}; - /** * Updates showFlyoutLogtest in the appState store * @param showFlyout @@ -199,7 +188,7 @@ export const showFlyoutLogtest = (showFlyout) => { export const updateDockedLogtest = (dockedFlyout) => { return { type: 'UPDATE_DOCKED_LOGTEST', - dockedFlyoutLogtest: dockedFlyout + dockedFlyoutLogtest: dockedFlyout }; }; @@ -235,4 +224,4 @@ export const updateLogtestToken = (logtestToken) => { type: 'UPDATE_LOGTEST_TOKEN', logtestToken: logtestToken }; -}; \ No newline at end of file +}; diff --git a/public/redux/reducers/appStateReducers.js b/public/redux/reducers/appStateReducers.js index c69e603300..fdc092e1ac 100644 --- a/public/redux/reducers/appStateReducers.js +++ b/public/redux/reducers/appStateReducers.js @@ -24,10 +24,6 @@ const initialState = { userPermissions: false, userRoles: [], toastNotification: false, - clusterStatus: { - status: false, - contextConfigServer: 'manager', - }, withUserLogged: false, allowedAgents: [], logtestToken: '', @@ -127,19 +123,12 @@ const appStateReducers = (state = initialState, action) => { }; } - if (action.type === 'UPDATE_CLUSTER_STATUS') { - return { - ...state, - clusterStatus: action.clusterStatus, - }; - } - if (action.type === 'UPDATE_WITH_USER_LOGGED') { return { ...state, withUserLogged: action.withUserLogged, }; - } + } if (action.type === 'GET_ALLOWED_AGENTS') { return { @@ -147,7 +136,7 @@ const appStateReducers = (state = initialState, action) => { allowedAgents: action.allowedAgents }; } - + if (action.type === 'UPDATE_LOGTEST_TOKEN') { return { ...state,