Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Miscellaneous to tab into Configuration App #5830

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 49 additions & 32 deletions plugins/main/public/controllers/settings/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { UI_LOGGER_LEVELS, PLUGIN_APP_NAME } from '../../../common/constants';
import { UI_ERROR_SEVERITIES } from '../../react-services/error-orchestrator/types';
import { getErrorOrchestrator } from '../../react-services/common-services';
import { getAssetURL } from '../../utils/assets';
import { getHttp } from '../../kibana-services';
import { getHttp, getWzCurrentAppID } from '../../kibana-services';

export class SettingsController {
/**
Expand Down Expand Up @@ -60,7 +60,9 @@ export class SettingsController {
this.tabNames = TabNames;
this.indexPatterns = [];
this.apiEntries = [];
this.$scope.googleGroupsSVG = getHttp().basePath.prepend(getAssetURL('images/icons/google_groups.svg'));
this.$scope.googleGroupsSVG = getHttp().basePath.prepend(
getAssetURL('images/icons/google_groups.svg'),
);
this.tabs = [
{ id: 'api', name: 'Server API' },
{ id: 'modules', name: 'Modules' },
Expand All @@ -70,6 +72,10 @@ export class SettingsController {
{ id: 'miscellaneous', name: 'Miscellaneous' },
{ id: 'about', name: 'About' },
];
this.tabsConfiguration = [
{ id: 'configuration', name: 'Configuration' },
{ id: 'miscellaneous', name: 'Miscellaneous' },
];
}

/**
Expand All @@ -81,17 +87,15 @@ export class SettingsController {
if (location?.tab) {
this.tab = location.tab;
const tabActive = this.tabs.find(tab => tab.id === this.tab);
if(this.tab==='about') store.dispatch(updateSelectedSettingsSection('about'));
if (this.tab === 'about')
store.dispatch(updateSelectedSettingsSection('about'));
const breadcrumb = [
{ text: '' },
{ text: tabActive?.name || 'Server API' }
{ text: tabActive?.name || 'Server API' },
];
store.dispatch(updateGlobalBreadcrumb(breadcrumb));
} else {
const breadcrumb = [
{ text: '' },
{ text: 'Server API' },
];
const breadcrumb = [{ text: '' }, { text: 'Server API' }];
store.dispatch(updateGlobalBreadcrumb(breadcrumb));
}

Expand Down Expand Up @@ -133,29 +137,29 @@ export class SettingsController {
checkManager: entry => this.checkManager(entry),
showAddApi: () => this.showAddApi(),
getHosts: () => this.getHosts(),
testApi: (entry,force) => ApiCheck.checkApi(entry,force),
testApi: (entry, force) => ApiCheck.checkApi(entry, force),
showAddApiWithInitialError: error =>
this.showAddApiWithInitialError(error),
updateClusterInfoInRegistry: (id, clusterInfo) =>
this.updateClusterInfoInRegistry(id, clusterInfo),
showApiIsDown: () => this.showApiIsDown(),
copyToClipBoard: msg => this.copyToClipBoard(msg)
copyToClipBoard: msg => this.copyToClipBoard(msg),
};

this.addApiProps = {
checkForNewApis: () => this.checkForNewApis(),
closeAddApi: () => this.closeAddApi()
closeAddApi: () => this.closeAddApi(),
};

this.apiIsDownProps = {
apiEntries: this.apiEntries,
setDefault: entry => this.setDefault(entry),
testApi: (entry,force) => ApiCheck.checkApi(entry,force),
testApi: (entry, force) => ApiCheck.checkApi(entry, force),
closeApiIsDown: () => this.closeApiIsDown(),
getHosts: () => this.getHosts(),
updateClusterInfoInRegistry: (id, clusterInfo) =>
this.updateClusterInfoInRegistry(id, clusterInfo),
copyToClipBoard: msg => this.copyToClipBoard(msg)
copyToClipBoard: msg => this.copyToClipBoard(msg),
};
this.settingsTabsProps = {
clickAction: tab => {
Expand All @@ -165,14 +169,14 @@ export class SettingsController {
}
},
selectedTab: this.tab || 'api',
tabs: this.tabs,
wazuhConfig: this.wazuhConfig
tabs: this.tabsConfiguration,
wazuhConfig: this.wazuhConfig,
};

this.settingsLogsProps = {
getLogs: async () => {
return await this.getAppLogs();
}
},
};
}

Expand All @@ -181,7 +185,7 @@ export class SettingsController {
* @param {Object} tab
*/
switchTab(tab) {
if(tab==='about') store.dispatch(updateSelectedSettingsSection('about'));
if (tab === 'about') store.dispatch(updateSelectedSettingsSection('about'));
this.tab = tab;
this.$location.search('tab', this.tab);
}
Expand All @@ -196,6 +200,15 @@ export class SettingsController {
}
}

/**
* Compare the string param with currentAppID
* @param {string} appToCompare
* It use into plugins/main/public/templates/settings/settings.html to show tabs into expecified App
*/
compareCurrentAppID(appToCompare) {
return getWzCurrentAppID() === appToCompare;
}

/**
* Returns the index of the API in the entries array
* @param {Object} api
Expand Down Expand Up @@ -262,8 +275,8 @@ export class SettingsController {
AppState.setCurrentAPI(
JSON.stringify({
name: clusterEnabled ? manager : cluster,
id: id
})
id: id,
}),
);

this.$scope.$emit('updateAPI', {});
Expand Down Expand Up @@ -303,9 +316,10 @@ export class SettingsController {
// Get settings function
async getSettings() {
try {
try{
this.indexPatterns = await SavedObject.getListOfWazuhValidIndexPatterns();
}catch(error){
try {
this.indexPatterns =
await SavedObject.getListOfWazuhValidIndexPatterns();
} catch (error) {
this.wzMisc.setBlankScr('Sorry but no valid index patterns were found');
this.$location.search('tab', null);
this.$location.path('/blank-screen');
Expand Down Expand Up @@ -353,7 +367,7 @@ export class SettingsController {
}
// Every time that the API entries are required in the settings the registry will be checked in order to remove orphan host entries
await this.genericReq.request('POST', '/hosts/remove-orphan-entries', {
entries: this.apiEntries
entries: this.apiEntries,
});
return;
}
Expand All @@ -366,7 +380,7 @@ export class SettingsController {
try {
const url = `/hosts/update-hostname/${id}`;
await this.genericReq.request('PUT', url, {
cluster_info: clusterInfo
cluster_info: clusterInfo,
});
} catch (error) {
return Promise.reject(error);
Expand All @@ -388,7 +402,7 @@ export class SettingsController {
port: port,
cluster_info: {},
insecure: 'true',
id: id
id: id,
};

// Test the connection
Expand Down Expand Up @@ -461,8 +475,8 @@ export class SettingsController {
{
date: new Date(),
level: 'error',
message: 'Error when loading logs'
}
message: 'Error when loading logs',
},
];
}
}
Expand All @@ -477,7 +491,7 @@ export class SettingsController {
this.appInfo = {
'app-version': response['app-version'],
installationDate: formatUIDate(response['installationDate']),
revision: response['revision']
revision: response['revision'],
};

this.load = false;
Expand Down Expand Up @@ -534,7 +548,7 @@ export class SettingsController {
throw {
message: 'There were not found any API entry in the wazuh.yml',
type: 'warning',
closedEnabled: false
closedEnabled: false,
};
const notRecheable = await this.checkApisStatus();
if (notRecheable) {
Expand All @@ -544,13 +558,13 @@ export class SettingsController {
message:
'Wazuh API not recheable, please review your configuration',
type: 'danger',
closedEnabled: true
closedEnabled: true,
};
}
throw {
message: `Some of the API entries are not reachable. You can still use the ${PLUGIN_APP_NAME} but please, review your hosts configuration.`,
type: 'warning',
closedEnabled: true
closedEnabled: true,
};
}
} catch (error) {
Expand All @@ -576,7 +590,10 @@ export class SettingsController {
try {
const result = await this.genericReq.request('GET', '/hosts/apis', {});
const hosts = result.data || [];
this.apiEntries = this.apiTableProps.apiEntries = this.apiIsDownProps.apiEntries = hosts;
this.apiEntries =
this.apiTableProps.apiEntries =
this.apiIsDownProps.apiEntries =
hosts;
if (!hosts.length) {
this.apiIsDown = false;
this.addingApi = true;
Expand Down
11 changes: 11 additions & 0 deletions plugins/main/public/templates/settings/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@
></react-component>
</div>

<!-- It must get renderized only in configuration app to show Miscellaneous tab in configuration App -->
<div
ng-if="!ctrl.load && ctrl.settingsTabsProps && !ctrl.apiIsDown && ctrl.apiTableProps.apiEntries.length && ctrl.compareCurrentAppID('configuration')"
class="wz-margin-top-16 md-margin-h"
>
<react-component
name="Tabs"
props="ctrl.settingsTabsProps"
></react-component>
</div>

<!-- end head -->
<!-- api -->
<div ng-if="ctrl.tab === 'api' && !ctrl.load">
Expand Down
Loading