Skip to content

Commit

Permalink
Add switch to toggle the use of custom branding (#4507)
Browse files Browse the repository at this point in the history
* feat(settings): centralize the plugin settings

Create the plugin setting schema
Define the current plugin settings
Remove refactored code

* feat(settings): add setting services and replaced the references to constants

* feat(settings): refactor the content of the default configuration file

Use dynamically the definition of the plugin settings

* feat(inputs): create new inputs components

Add new hooks to manage when a input value or form has changed
Add new inputs components

* feat(configuration): refactor the form of Settings/Configuration

Refactor Header, BottomBar, Configuration components
Remove deprecated files

* feat(settings): support updating multiple setting at the same time

Changed the endpoint that updating the plugin setting to support
  multiple settings at the same time
Refactor the getConfiguration service. Split the logic to:
  - Read the file and transform to JSON
  - Obfuscate the password key of the host configuration

* feat: add validation to the plugin settings

Create services to validate
Add the validation to the plugin settings

* feat(validation): add validation to the `PUT /utils/configuration`
endpoint

* feat(validation): add validation to the configuration form in
`Settings/Configuration`

* feat(validatio): remove no used import

* clean: remove not used code

* Add report header-footer configuration

* fix: fixed category name in `Settings/Configuration`

* fix(settings): Fix accessing to `validate` of undefined error

* fix(settings): fixed error due to missing service

* Add custom branding enabled switch

* Fix custom logo ratio in PDF sheet

* fix(settings): refactor the form and inputs of `Settings/Configuration` to control the global state of the form

* fix: add value transformation for the form inputs and output of fields changed

* fix: Fixed some settings validation

* fix(settings): fixed validation of literals

* fix(settings): removed unused import

* fix(settings): renamed properties related to transform the value of the input

* feat(settings): add description to the plugin setting definition properties

* fix(settings): fix getConfiguration service when the configuration file has no `hosts` entry

* fix(settings): Fixed error when do changes of the `useForm` hook an rename methods of this

* tests(settings): add test related to the plugin settings and its configuration from the UI

* feat(settings): rename plugin setting options of type select to match its type

* feat(settings): add plugin settings services and enhance the description of the plugin settings in default configuration file and UI

* tests(input-form): update tests of InputForm component

* test(configuration-file): add tests of the default configuration file

* feat(settings): remove `extensions.mitre` plugin setting

* test(settings): add test to validate the plugin setting when updating it through PUT /utils/configuration

fix some plugin settings validation

* feat(settings): add documentation to some setting services and test some of them

* fix: fixed documentation of setting service

* doc(settings): move the documentation of the plugin setting properties

* fix(settings): rename some plugin setting properties because of request changes

- Rename plugin setting properties:
  - `default` to `defaultValue`
  - `defaultHidden` to `defaultValueIfNotSet`
  - `configurableFile` to `isConfigurableFromFile`
  - configurableUI` to `isConfigurableFromUI`
  - `requireHealthCheck` to `requiresRunningHealthCheck`
  - `requireReload` to `requiresReloadingBrowserTab`
  - `requireRestart` to `requiresRestartingPluginPlatform`
- Fix tests

* tests: fix tests of InputForm component

* fix: response properties when saving the configuration

* fix(settings): fix validation plugin settings value in the UI

* fix(settings): fix `customization.reports.header` and `customization.reports.footer` setting properties

* fix(settings): fix validation of numbers

* fix(settings): fix validation of numbers

* test(settings): Add tests related to validation for the `useForm` hook and the `InputForm` component

* fix(settings): fix displaying toast to run the healthcheck when saving the configuration

* test(settings): add tests for the `customization.reports.footer` and `customization.reports.header` settings

* test(settings): Add tests for the `customization.enabled` setting

* Added category sorting + description + docs link

* Added settings sorting within their category

* Fixed constant types definition

* Checks if localCompare exists validation

* fix(settings): fixed plugin setting description doesn't display the minimum number value when it is falsy (0)

* fix(settings): fix setting type of `wazuh.monitoring.replicas` and limit the valid number for the number input

* feat(settins): add plugin settings category description

* fix(settings): fix a problem comparing the initial and current value for the plugin settings of the `number` type

* fix(settings): fix wrong conflict resolution

* fix(settings): fix typo in setting description

* Add set custom header footer unit test

* feat(settings): enhance the validation of plugin settings related to indices or index patterns taking in account the supported characters

* feat(settings): add validation of setting values in the inputs

* Added unit test to verify the PDF report integrity

* fix(tests): format tables of the tests

* fix: remove unnecessary import

* test(endpoints): add test to GET /reports endpoint

* test(settings): add test for `customization.enabled` setting in the form input

* Improved report unit test with more cases

* Fix small typo

* fix(settings): fix a typo in a toast related to modify the plugin settings from UI

* Changed Custom Branding documentation link

* Merge centralize plugin settings PR

* Fix white-labeling documentation link

* Fix white-labeling documentation link

* Code format

* Delete unused imports

* fix(settings): fix a problem with the useForm hook

* fix(settings): refactor the settings validation function to a class and rename the file

* feat(settings): add check for integer numbers and adapt the affected settings

* changelog: Add PR entry

* fix(settings): fix the customization settings do not apply when the `customization.enabled` setting is not defined in the configuration file

* fix(settings): the `customization.logo.sidebar` is updated without reloading the browser tab.

This solves an indirect problem when the `customization.enabled` setting
is changed from the UI, that should have in account the
rest of the `customization.*` settings to display some action.

This change enhances the UX because the change is instant and doesn't
require to reload the browser tab.

* Fix customization.enable on GET api/logos endpoint

* fix: revert unused change

* fix: revert the updating of the `customization.logo.sidebar` when the setting was changed or removed

* fix: removed unused code and removed space

* fix: undone unwanted changes

* fix: resolve setting when it is an empty string

* fix: request changes and rename function

* fix: fix settings tests

Co-authored-by: Antonio David Gutiérrez <[email protected]>
Co-authored-by: Álex <[email protected]>
(cherry picked from commit c1c39b3)
  • Loading branch information
asteriscos authored and Desvelao committed Nov 2, 2022
1 parent 2ffa5a4 commit a97462b
Show file tree
Hide file tree
Showing 15 changed files with 134 additions and 42 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ All notable changes to the Wazuh app project will be documented in this file.
- Enhanced the plugin setting description displayed in the UI and the configuration file. [#4501](https://github.com/wazuh/wazuh-kibana-app/pull/4501)
- Added validation to the plugin settings in the form of `Settings/Configuration` and the endpoint to update the plugin configuration [#4503](https://github.com/wazuh/wazuh-kibana-app/pull/4503)
- Added new plugin settings to customize the header and footer on the PDF reports [#4505](https://github.com/wazuh/wazuh-kibana-app/pull/4505)
- Add a new plugin setting to enable or disable the customization [#4507](https://github.com/wazuh/wazuh-kibana-app/pull/4507)

### Changed

Expand Down
29 changes: 27 additions & 2 deletions common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -932,6 +932,31 @@ export const PLUGIN_SETTINGS: { [key: string]: TPluginSetting } = {
return schema.boolean();
},
},
"customization.enabled": {
title: "Status",
description: "Enable or disable the customization.",
category: SettingCategory.CUSTOMIZATION,
type: EpluginSettingType.switch,
defaultValue: true,
isConfigurableFromFile: true,
isConfigurableFromUI: true,
requiresReloadingBrowserTab: true,
options: {
switch: {
values: {
disabled: {label: 'false', value: false},
enabled: {label: 'true', value: true},
}
}
},
uiFormTransformChangedInputValue: function(value: boolean | string): boolean{
return Boolean(value);
},
validate: SettingsValidator.isBoolean,
validateBackend: function(schema){
return schema.boolean();
},
},
"customization.logo.app": {
title: "App main logo",
description: `This logo is used in the app main menu, at the top left corner.`,
Expand Down Expand Up @@ -1087,7 +1112,7 @@ export const PLUGIN_SETTINGS: { [key: string]: TPluginSetting } = {
category: SettingCategory.CUSTOMIZATION,
type: EpluginSettingType.textarea,
defaultValue: "",
defaultValueIfNotSet: REPORTS_PAGE_FOOTER_TEXT,
defaultValueIfNotSet: REPORTS_PAGE_FOOTER_TEXT,
isConfigurableFromFile: true,
isConfigurableFromUI: true,
options: { rowsSize: 2, maxLength: 30 },
Expand Down Expand Up @@ -1118,7 +1143,7 @@ export const PLUGIN_SETTINGS: { [key: string]: TPluginSetting } = {
})(value)
},
validateBackend: function(schema){
return schema.string({validate: this.validate?.bind(this)});
return schema.string({validate: this.validate.bind(this)});
},
},
"disabled_roles": {
Expand Down
1 change: 1 addition & 0 deletions common/plugin-settings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ describe('[settings] Input validation', () => {
${'cron.statistics.interval'} | ${true} | ${"Interval is not valid."}
${'cron.statistics.status'} | ${true} | ${undefined}
${'cron.statistics.status'} | ${0} | ${'It should be a boolean. Allowed values: true or false.'}
${'customization.enabled'} | ${true} | ${undefined}
${'customization.logo.app'} | ${{size: 124000, name: 'image.jpg'}} | ${undefined}
${'customization.logo.app'} | ${{size: 124000, name: 'image.jpeg'}} | ${undefined}
${'customization.logo.app'} | ${{size: 124000, name: 'image.png'}} | ${undefined}
Expand Down
28 changes: 27 additions & 1 deletion common/services/settings.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
formatLabelValuePair,
formatSettingValueToFile
formatSettingValueToFile,
getCustomizationSetting
} from "./settings";

describe('[settings] Methods', () => {
Expand Down Expand Up @@ -31,4 +32,29 @@ describe('[settings] Methods', () => {
expect(formatSettingValueToFile(input)).toBe(expected);
});
});

describe('getCustomizationSetting: Get the value for the "customization." settings depending on the "customization.enabled" setting', () => {
it.each`
customizationEnabled | settingKey | configValue | expected
${true} | ${'customization.logo.app'} | ${'custom-image-app.png'} | ${'custom-image-app.png'}
${true} | ${'customization.logo.app'} | ${''} | ${''}
${false} | ${'customization.logo.app'} | ${'custom-image-app.png'} | ${''}
${false} | ${'customization.logo.app'} | ${''} | ${''}
${true} | ${'customization.reports.footer'} | ${'Custom footer'} | ${'Custom footer'}
${true} | ${'customization.reports.footer'} | ${''} | ${'Copyright © 2022 Wazuh, Inc.'}
${false} | ${'customization.reports.footer'} | ${'Custom footer'} | ${'Copyright © 2022 Wazuh, Inc.'}
${false} | ${'customization.reports.footer'} | ${''} | ${'Copyright © 2022 Wazuh, Inc.'}
${false} | ${'customization.reports.footer'} | ${''} | ${'Copyright © 2022 Wazuh, Inc.'}
${true} | ${'customization.reports.header'} | ${'Custom header'} | ${'Custom header'}
${true} | ${'customization.reports.header'} | ${''} | ${'[email protected]\nhttps://wazuh.com'}
${false} | ${'customization.reports.header'} | ${'Custom header'} | ${'[email protected]\nhttps://wazuh.com'}
${false} | ${'customization.reports.header'} | ${''} | ${'[email protected]\nhttps://wazuh.com'}
`(`customizationEnabled: $customizationEnabled | settingKey: $settingKey | configValue: $configValue | expected: $expected`, ({ configValue, customizationEnabled, expected, settingKey }) => {
const configuration = {
'customization.enabled': customizationEnabled,
[settingKey]: configValue
};
expect(getCustomizationSetting(configuration, settingKey)).toBe(expected);
});
});
});
31 changes: 31 additions & 0 deletions common/services/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,34 @@ export function formatLabelValuePair(label, value){
? `${value} (${label})`
: `${value}`
};

/**
* Get the configuration value if the customization is enabled.
* @param configuration JSON object from `wazuh.yml`
* @param settingKey key of the setting
* @returns
*/
export function getCustomizationSetting(configuration: {[key: string]: any }, settingKey: string): any {
const isCustomizationEnabled = typeof configuration['customization.enabled'] === 'undefined'
? getSettingDefaultValue('customization.enabled')
: configuration['customization.enabled'];
const defaultValue = getSettingDefaultValue(settingKey);

if ( isCustomizationEnabled && settingKey.startsWith('customization') && settingKey !== 'customization.enabled'){
return (typeof configuration[settingKey] !== 'undefined' ? resolveEmptySetting(settingKey, configuration[settingKey]) : defaultValue);
}else{
return defaultValue;
};
};

/**
* Returns the default value if not set when the setting is an empty string
* @param settingKey plugin setting
* @param value value of the plugin setting
* @returns
*/
function resolveEmptySetting(settingKey: string, value : unknown){
return typeof value === 'string' && value.length === 0 && PLUGIN_SETTINGS[settingKey].defaultValueIfNotSet
? getSettingDefaultValue(settingKey)
: value;
};
2 changes: 1 addition & 1 deletion public/components/common/form/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ export const InputForm = ({
const Input = {
switch: InputFormSwitch,
editor: InputFormEditor,
filepicker: InputFormFilePicker,
number: InputFormNumber,
select: InputFormSelect,
text: InputFormText,
textarea: InputFormTextArea,
filepicker: InputFormFilePicker
};
4 changes: 2 additions & 2 deletions public/components/common/hocs/withUserLogged.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import { getHttp } from '../../../kibana-services';
import { getAssetURL, getThemeAssetURL } from "../../../utils/assets";

export const withUserLogged = (WrappedComponent) => (props) => {
const withUserLogged = useSelector((state)=> state.appStateReducers.withUserLogged);
const customAppLogo = useSelector((state)=> state?.appConfig?.data?.['customization.logo.app']);
const withUserLogged = useSelector((state) => state.appStateReducers.withUserLogged);
const customAppLogo = useSelector((state) => state?.appConfig?.data?.['customization.enabled'] && state?.appConfig?.data?.['customization.logo.app']);

return withUserLogged ? <WrappedComponent {...props}/> : (
<div className="withUserLogged">
Expand Down
39 changes: 23 additions & 16 deletions public/components/health-check/container/health-check.container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,18 +107,21 @@ const checks = {
timeFilter: {
title: `Check ${PLUGIN_PLATFORM_SETTING_NAME_TIME_FILTER} setting`,
label: `${PLUGIN_PLATFORM_SETTING_NAME_TIME_FILTER} setting`,
validator: checkPluginPlatformSettings(PLUGIN_PLATFORM_SETTING_NAME_TIME_FILTER, JSON.stringify(WAZUH_PLUGIN_PLATFORM_SETTING_TIME_FILTER), (checkLogger: CheckLogger, options: {defaultAppValue: any}) => {
getDataPlugin().query.timefilter.timefilter.setTime(WAZUH_PLUGIN_PLATFORM_SETTING_TIME_FILTER)
&& checkLogger.action(`Timefilter set to ${JSON.stringify(options.defaultAppValue)}`);
}),
validator: checkPluginPlatformSettings(
PLUGIN_PLATFORM_SETTING_NAME_TIME_FILTER,
JSON.stringify(WAZUH_PLUGIN_PLATFORM_SETTING_TIME_FILTER),
(checkLogger: CheckLogger, options: { defaultAppValue: any }) => {
getDataPlugin().query.timefilter.timefilter.setTime(WAZUH_PLUGIN_PLATFORM_SETTING_TIME_FILTER)
&& checkLogger.action(`Timefilter set to ${JSON.stringify(options.defaultAppValue)}`);
}),
awaitFor: [],
canRetry: true,
}
};

function HealthCheckComponent() {
const [checkErrors, setCheckErrors] = useState<{[key:string]: []}>({});
const [checksReady, setChecksReady] = useState<{[key: string]: boolean}>({});
const [checkErrors, setCheckErrors] = useState<{ [key: string]: [] }>({});
const [checksReady, setChecksReady] = useState<{ [key: string]: boolean }>({});
const [isDebugMode, setIsDebugMode] = useState<boolean>(false);
const appConfig = useAppConfig();
const checksInitiated = useRef(false);
Expand All @@ -142,35 +145,39 @@ function HealthCheckComponent() {
// Redirect to app when all checks are ready
Object.keys(checks)
.every(check => checksReady[check])
&& !isDebugMode && (() => setTimeout(redirectionPassHealthcheck, HEALTH_CHECK_REDIRECTION_TIME)
&& !isDebugMode && (() => setTimeout(redirectionPassHealthcheck, HEALTH_CHECK_REDIRECTION_TIME)
)()
}, [checksReady]);

useEffect(() => {
// Check if Health should not redirect automatically (Debug mode)
setIsDebugMode(window.location.href.includes('debug'));
},[]);
}, []);

const handleErrors = (checkID, errors, parsed) => {
const newErrors = parsed
? errors.map((error) =>
ErrorHandler.handle(error, 'Health Check', { warning: false, silent: true })
)
ErrorHandler.handle(error, 'Health Check', { warning: false, silent: true })
)
: errors;
setCheckErrors((prev) => ({...prev, [checkID]: newErrors}));
setCheckErrors((prev) => ({ ...prev, [checkID]: newErrors }));
};

const cleanErrors = (checkID: string) => {
delete checkErrors[checkID];
setCheckErrors({...checkErrors});
setCheckErrors({ ...checkErrors });
}

const handleCheckReady = (checkID, isReady) => {
setChecksReady(prev => ({...prev, [checkID]: isReady}));
setChecksReady(prev => ({ ...prev, [checkID]: isReady }));
}


const logoUrl = getHttp().basePath.prepend(appConfig.data['customization.logo.healthcheck'] ? getAssetURL(appConfig.data['customization.logo.healthcheck']) : getThemeAssetURL('logo.svg'));
const logoUrl = getHttp().basePath.prepend(
appConfig.data['customization.enabled'] && appConfig.data['customization.logo.healthcheck'] ?
getAssetURL(appConfig.data['customization.logo.healthcheck']) :
getThemeAssetURL('logo.svg')
);
const thereAreErrors = Object.keys(checkErrors).length > 0;

const renderChecks = () => {
Expand All @@ -188,7 +195,7 @@ function HealthCheckComponent() {
handleErrors={handleErrors}
cleanErrors={cleanErrors}
isLoading={appConfig.isLoading}
handleCheckReady= {handleCheckReady}
handleCheckReady={handleCheckReady}
checksReady={checksReady}
canRetry={checks[check].canRetry}
/>
Expand Down Expand Up @@ -277,7 +284,7 @@ function HealthCheckComponent() {
);
}

export const HealthCheck = compose (withErrorBoundary,withReduxProvider) (HealthCheckComponent);
export const HealthCheck = compose(withErrorBoundary, withReduxProvider)(HealthCheckComponent);

export const HealthCheckTest = HealthCheckComponent;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ const InputFormFilePickerPreInput = ({image, field}: {image: string, field: any}
try{
const response = await WzRequest.genericReq('DELETE', `/utils/configuration/files/${field.key}`);
dispatch(updateAppConfig(response.data.data.updatedConfiguration));

// Show the toasts if necessary
const { requiresRunningHealthCheck, requiresReloadingBrowserTab, requiresRestartingPluginPlatform } = response.data.data;
requiresRunningHealthCheck && toastRequiresRunningHealthcheck();
Expand Down
6 changes: 3 additions & 3 deletions public/components/settings/configuration/configuration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import { Category } from './components/categories/components';
import { WzRequest } from '../../../react-services';
import { UIErrorLog, UIErrorSeverity, UILogLevel, UI_ERROR_SEVERITIES } from '../../../react-services/error-orchestrator/types';
import { getErrorOrchestrator } from '../../../react-services/common-services';
import { getToasts } from '../../../kibana-services';
import { updateAppConfig } from '../../../redux/actions/appConfigActions';
import path from 'path';
import { toastRequiresReloadingBrowserTab, toastRequiresRestartingPluginPlatform, toastRequiresRunningHealthcheck, toastSuccessUpdateConfiguration } from './components/categories/components/show-toasts';
Expand Down Expand Up @@ -172,14 +171,15 @@ const WzConfigurationSettingsProvider = (props) => {
responses.some(({data: { data: {requiresRestartingPluginPlatform}}}) => requiresRestartingPluginPlatform) && toastRequiresRestartingPluginPlatform();

// Update the app configuration frontend-cached setting in memory with the new values
dispatch(updateAppConfig({
const updatedConfiguration = {
...responses.reduce((accum, {data: {data}}) => {
return {
...accum,
...(data.updatedConfiguration ? {...data.updatedConfiguration} : {}),
}
},{})
}));
};
dispatch(updateAppConfig(updatedConfiguration));

// Remove the selected files on the file picker inputs
if(Object.keys(settingsToUpdate.fileUpload).length){
Expand Down
4 changes: 1 addition & 3 deletions public/components/wz-menu/wz-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ import {
EuiPopover,
EuiIcon,
EuiButtonEmpty,
EuiText,
EuiCallOut,
EuiPageHeader,
EuiToolTip,
EuiLoadingSpinner,
EuiFormRow,
Expand Down Expand Up @@ -904,7 +902,7 @@ export const WzMenu = withWindowSize(class WzMenu extends Component {
);


const logotypeURL = getHttp().basePath.prepend(this.wazuhConfig.getConfig()['customization.logo.app'] ? getAssetURL(this.wazuhConfig.getConfig()['customization.logo.app']) : getThemeAssetURL('logo.svg'));
const logotypeURL = getHttp().basePath.prepend(this.wazuhConfig.getConfig()['customization.enabled'] && this.wazuhConfig.getConfig()['customization.logo.app'] ? getAssetURL(this.wazuhConfig.getConfig()['customization.logo.app']) : getThemeAssetURL('logo.svg'));
const mainButton = (
<button data-test-subj='menuWazuhButton' className="eui" onClick={() => this.switchMenuOpened()}>
<EuiFlexGroup
Expand Down
4 changes: 2 additions & 2 deletions public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class WazuhPlugin implements Plugin<WazuhSetup, WazuhStart, WazuhSetupPlu
private hideTelemetryBanner?: () => void;
public async setup(core: CoreSetup, plugins: WazuhSetupPlugins): WazuhSetup {
const UI_THEME = core.uiSettings.get('theme:darkMode') ? 'dark' : 'light';

// Get custom logos configuration to start up the app with the correct logos
let logosInitialState={};
try{
Expand Down Expand Up @@ -166,4 +166,4 @@ export class WazuhPlugin implements Plugin<WazuhSetup, WazuhStart, WazuhSetupPlu
setErrorOrchestrator(ErrorOrchestratorService);
return {};
}
}
}
15 changes: 8 additions & 7 deletions server/controllers/wazuh-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { KeyEquivalence } from '../../common/csv-key-equivalence';
import { ApiErrorEquivalence } from '../lib/api-errors-equivalence';
import apiRequestList from '../../common/api-info/endpoints';
import { HTTP_STATUS_CODES } from '../../common/constants';
import { getCustomizationSetting } from '../../common/services/settings';
import { addJobToQueue } from '../start/queue';
import fs from 'fs';
import { ManageHosts } from '../lib/manage-hosts';
Expand Down Expand Up @@ -1108,14 +1109,14 @@ export class WazuhApiCtrl {
const APP_LOGO = 'customization.logo.app';
const HEALTHCHECK_LOGO = 'customization.logo.healthcheck';

const logos= {
[SIDEBAR_LOGO]: getCustomizationSetting(configuration, SIDEBAR_LOGO),
[APP_LOGO]: getCustomizationSetting(configuration, APP_LOGO),
[HEALTHCHECK_LOGO]: getCustomizationSetting(configuration, HEALTHCHECK_LOGO),
}

return response.ok({
body: {
logos: {
[SIDEBAR_LOGO]: configuration[SIDEBAR_LOGO],
[APP_LOGO]: configuration[APP_LOGO],
[HEALTHCHECK_LOGO]: configuration[HEALTHCHECK_LOGO],
}
}
body: { logos }
});
} catch (error) {
log('wazuh-api:getAppLogos', error.message || error);
Expand Down
8 changes: 4 additions & 4 deletions server/lib/reporting/printer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { log } from '../logger';
import * as TimSort from 'timsort';
import { getConfiguration } from '../get-configuration';
import { REPORTS_PRIMARY_COLOR} from '../../../common/constants';
import { getSettingDefaultValue } from '../../../common/services/settings';
import { getCustomizationSetting } from '../../../common/services/settings';

const COLORS = {
PRIMARY: REPORTS_PRIMARY_COLOR
Expand Down Expand Up @@ -619,9 +619,9 @@ export class ReportPrinter{
try {
const configuration = getConfiguration();

const pathToLogo = configuration['customization.logo.reports'] || getSettingDefaultValue('customization.logo.reports');
const pageHeader = configuration['customization.reports.header'] || getSettingDefaultValue('customization.reports.header');
const pageFooter = configuration['customization.reports.footer'] || getSettingDefaultValue('customization.reports.footer');
const pathToLogo = getCustomizationSetting(configuration, 'customization.logo.reports');
const pageHeader = getCustomizationSetting(configuration, 'customization.reports.header');
const pageFooter = getCustomizationSetting(configuration, 'customization.reports.footer');

const document = this._printer.createPdfKitDocument({ ...pageConfiguration({ pathToLogo, pageHeader, pageFooter }), content: this._content });

Expand Down
2 changes: 2 additions & 0 deletions server/routes/wazuh-utils/wazuh-utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,8 @@ hosts:
${'cron.statistics.interval'} | ${true} | ${400} | ${"[request body.cron.statistics.interval]: expected value of type [string] but got [boolean]"}
${'cron.statistics.status'} | ${true} | ${200} | ${null}
${'cron.statistics.status'} | ${0} | ${400} | ${'[request body.cron.statistics.status]: expected value of type [boolean] but got [number]'}
${'customization.enabled'} | ${true} | ${200} | ${null}
${'customization.enabled'} | ${0} | ${400} | ${'[request body.customization.enabled]: expected value of type [boolean] but got [number]'}
${'customization.reports.footer'} | ${'Test'} | ${200} | ${null}
${'customization.reports.footer'} | ${'Test\nTest'} | ${200} | ${null}
${'customization.reports.footer'} | ${'Test\nTest\nTest\nTest\nTest'} | ${400} | ${"[request body.customization.reports.footer]: The string should have less or equal to 2 line/s."}
Expand Down

0 comments on commit a97462b

Please sign in to comment.