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 header and footer report customization #4505

Merged
merged 112 commits into from
Oct 31, 2022

Conversation

asteriscos
Copy link
Member

@asteriscos asteriscos commented Sep 13, 2022

Description

This PR is part of White-Labeling Epic #4392.
It adds custom text to the PDF report header and footer.

Changes

  • Add new plugin settings:
    • customization.reports.header: customize the footer of the PDF reports. Restricted to 4 lines.
    • customization.reports.footer: customize the header of the PDF reports Restricted to 2 lines.
key description values
customization.reports.header Set the custom header of the PDF reports String. Maximum lines: 2. If the value is an empty string, the default value will be displayed.
customization.reports.footer Set the custom footer of the PDF reports String. Maximum lines: 2. If the value is an empty string, the default value will be displayed.
  • When the settings contain multiple lines, these are stored as \n in the configuration file.
  • Add new form input of type textarea
  • Tests:
    • Validate the setting in the API endpoint to update it
    • InputForm component of type textarea matches the snapshot

Closes #4426
Base: feat/settings-validation

Screenshots

image

image

Tests

Manual tests

Scenario: The customization.reports.* settings should appear in the default configuration file
Given there is not a plugin configuration file
When the user starts the plugin platform
Then the configuration file should be generated and includes the customization.reports.* settings

Scenario: The customization.reports.* settings should appear in the Settings/Configuration section
When the user navigates to Settings/Configuration
Then the customization.reports.* settings should be there

Scenario: Set the customization.reports.header with a valid value through Settings/Configuration.
When the user navigates to Settings/Configuration and sets the customization.reports.header with a valid value. Maximum 4 lines.
Then the user can save the configuration successfully.
And the configuration file is updated with the configuration.

Scenario: Set the customization.reports.footer with a valid value through Settings/Configuration.
When the user navigates to Settings/Configuration and sets the customization.reports.header with a valid value. Maximum 2 lines.
Then the user can save the configuration successfully.
And the configuration file is updated with the configuration.

Scenario: Set the customization.reports.header with a valid value through Settings/Configuration that includes multiple lines.
When the user navigates to Settings/Configuration and sets the customization.reports.header with a valid value. Maximum 4 lines.
Then the user can save the configuration successfully.
And the configuration file is updated with the configuration.
And the configuration file is valid and parseable.

Scenario: Set the customization.reports.footer with a valid value through Settings/Configuration that includes multiple lines.
When the user navigates to Settings/Configuration and sets the customization.reports.header with a valid value. Maximum 2 lines.
Then the user can save the configuration successfully.
And the configuration file is updated with the configuration.
And the configuration file is valid and parseable.

Scenario: Set the customization.reports.header with a invalid value through Settings/Configuration.
When the user sets the customization.reports.header with an invalid value. Maximum 4 lines.
Then a validation error is displayed.

Scenario: Set the customization.reports.footer with a invalid value through Settings/Configuration.
When the user sets the customization.reports.header with an invalid value. Maximum 2 lines.
Then a validation error is displayed.

Scenario: Set the customization.reports.header with a valid value through an API request.
When the user does an API request to update the customization.reports.header setting with a valid value. Maximum 4 lines.
Then the endpoint replies with a successful response.
And the configuration file is updated with the configuration.

Scenario: Set the customization.reports.footer with a valid value through an API request.
When the user does an API request to update the customization.reports.footer setting with a valid value. Maximum 2 lines.
Then the endpoint replies with a successful response.
And the configuration file is updated with the configuration.

Scenario: Set the customization.reports.header with an invalid value through an API request.
When the user does an API request to update the customization.reports.header setting with an invalid value. Maximum 4 lines.
Then the endpoint replies with a bad request response.

Scenario: Set the customization.reports.footer with an invalid value through an API request.
When the user does an API request to update the customization.reports.header setting with an invalid value. Maximum 2 lines.
Then the endpoint replies with a bad request response.

Scenario: Generate a PDF with a custom report header.
Given the customization.reports.header setting has a custom value.
When generates a PDF module report.
Then the custom text should appear in the header.

Scenario: Generate a PDF with a custom report footer.
Given the customization.reports.footer setting has a custom value.
When generates a PDF module report.
Then the custom text should appear in the footer.

Scenario: Generate a PDF with an empty custom report header.
Given the customization.reports.header setting has an empty custom value ""
When generates a PDF module report.
Then the default text should appear in the header.

Scenario: Generate a PDF with a custom report footer.
Given the customization.reports.footer setting has an empty custom value ""
When generates a PDF module report.
Then the default text should appear in the footer.


To manually test the configuration endpoint here are 2 scripts to update different configuration values.

pdf-report-conf.zip

To use it, first unzip the files in the same folder and allow both executing the file as a program. Afterwards you can run the manual-test-header-footer.sh script.

You can also use wz-api-conf.sh script with custom configuration parameters, like:

\- s setting_name
\- v setting_value

eg.
./wz-api-conf.sh -s disabled_roles -v [\"disabled\"]

Output

./manual-test-header-footer.sh 
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   398  100   398    0     0    829      0 --:--:-- --:--:-- --:--:--   827
{"customization.reports.footer":"Custom footer"}
{"data":{"requiresRunningHealthCheck":false,"requiresReloadingBrowserTab":false,"requiresRestartingPluginPlatform":false,"updatedConfiguration":{"customization.reports.footer":"Custom footer"}}}  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   398  100   398    0     0    896      0 --:--:-- --:--:-- --:--:--   894
{"customization.reports.header":"Custom header"}
{"data":{"requiresRunningHealthCheck":false,"requiresReloadingBrowserTab":false,"requiresRestartingPluginPlatform":false,"updatedConfiguration":{"customization.reports.header":"Custom header"}}}  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   398  100   398    0     0    906      0 --:--:-- --:--:-- --:--:--   906
{"customization.reports.footer":1111}
{"statusCode":400,"error":"Bad Request","message":"[request body.customization.reports.footer]: expected value of type [string] but got [number]"}  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   398  100   398    0     0    902      0 --:--:-- --:--:-- --:--:--   902
{"customization.reports.header":true}
{"statusCode":400,"error":"Bad Request","message":"[request body.customization.reports.header]: expected value of type [string] but got [boolean]"}

Automatic tests

  • public/components/common/form/index.test.tsx
  • server/routes/wazuh-utils/wazuh-utils.test.ts
  • common/plugin-settings.test.ts
  • server/routes/wazuh-reporting.test.ts

Run all PR tests

yarn test:jest public/components/common/form/index.test.tsx server/routes/wazuh-utils/wazuh-utils.test.ts common/plugin-settings.test.ts server/routes/wazuh-reporting.test.ts

Desvelao and others added 13 commits September 13, 2022 08:08
Create the plugin setting schema
Define the current plugin settings
Remove refactored code
Use dynamically the definition of the plugin settings
Add new hooks to manage when a input value or form has changed
Add new inputs components
Refactor Header, BottomBar, Configuration components
Remove deprecated files
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
Create services to validate
Add the validation to the plugin settings
@asteriscos asteriscos self-assigned this Sep 13, 2022
@Desvelao Desvelao added the type/enhancement Enhancement issue label Sep 13, 2022
@Desvelao Desvelao linked an issue Sep 13, 2022 that may be closed by this pull request
4 tasks
@asteriscos
Copy link
Member Author

Examples of different logos ratios

Before
Screenshot from 2022-09-14 17-21-41

After
More width than height:
Screenshot from 2022-09-14 18-49-40

Equal width and height:
Screenshot from 2022-09-14 18-48-14


Wazuh Logo for reference
image

@Desvelao
Copy link
Member

I added some manual tests to the initial comment.

@Desvelao Desvelao requested a review from a team as a code owner October 27, 2022 07:12
Mayons95
Mayons95 previously approved these changes Oct 28, 2022
Copy link
Contributor

@Mayons95 Mayons95 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TR: ✔️
Test Details

Screenshot from 2022-10-28 10-23-32

Screenshot from 2022-10-28 10-23-26

Screenshot from 2022-10-28 10-16-06

Screenshot from 2022-10-28 10-15-04

image

Copy link
Member

@AlexRuiz7 AlexRuiz7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Code review: ✔️
  • Test: 🔴

The customization of the logo, header and footer for the PDFs work quite well:

image

However, I found a few errors:

  • The header allows 4 lines of text, however only 3 are actually rendered.
  • The inputs limit the number of text lines, but not their length. It's quite easy to break this feature by adding a single, extra long line.

image
image

Texts used:

Powered by Wazuh
- This is a custom footer for PDF reports -
Powered by Wazuh
________________________
- This is a custom header for PDF reports -
- Provided by the @wazuh/frontend-team -

@Desvelao
Copy link
Member

  • Code review: heavy_check_mark
  • Test: red_circle

The customization of the logo, header and footer for the PDFs work quite well:

image

However, I found a few errors:

  • The header allows 4 lines of text, however only 3 are actually rendered.
  • The inputs limit the number of text lines, but not their length. It's quite easy to break this feature by adding a single, extra long line.

image image

Texts used:

Powered by Wazuh
- This is a custom footer for PDF reports -
Powered by Wazuh
________________________
- This is a custom header for PDF reports -
- Provided by the @wazuh/frontend-team -

Yes, the settings only limit the number of lines and not the length of the lines, we could limit if we consider it.

When I developed it, I considered the length of the lines is under the responsibility of the user, so the plugin has no limit that could affect some use cases. Anyways, we could set some value and check the input is valid.

@asteriscos
Copy link
Member Author

Added max length per line validation.

Peek 2022-10-28 18-56

@github-actions
Copy link
Contributor

Code coverage (Jest) % values
Statements 8.29% ( 3037 / 36640 )
Branches 3.83% ( 1080 / 28200 )
Functions 7.26% ( 659 / 9080 )
Lines 8.34% ( 2926 / 35070 )

Copy link
Member

@Desvelao Desvelao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@Desvelao Desvelao requested a review from AlexRuiz7 October 31, 2022 09:31
@Desvelao Desvelao dismissed AlexRuiz7’s stale review October 31, 2022 09:43

The request changes were solved.

@Desvelao Desvelao merged commit ce29034 into 4.4-7.10 Oct 31, 2022
@Desvelao Desvelao deleted the feat/header-footer-report-customization-4426 branch October 31, 2022 09:44
@github-actions
Copy link
Contributor

The backport to 4.4-7.16 failed:

The process '/usr/bin/git' failed with exit code 1

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-4.4-7.16 4.4-7.16
# Navigate to the new working tree
cd .worktrees/backport-4.4-7.16
# Create a new branch
git switch --create backport-4505-to-4.4-7.16
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 ce29034e17045a808b43390f314b44fbf2c7c8e2
# Push it to GitHub
git push --set-upstream origin backport-4505-to-4.4-7.16
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-4.4-7.16

Then, create a pull request where the base branch is 4.4-7.16 and the compare/head branch is backport-4505-to-4.4-7.16.

github-actions bot pushed a commit that referenced this pull request Oct 31, 2022
* 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

* 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

* 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

* 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

* 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

* test: fix tests

* Set textArea size

* Add max character length validation

* test(settings): fix tests

* changelog: add PR entry

* test(settings): format tests

Co-authored-by: Antonio David Gutiérrez <antonio.gutierrez@wazuh.com>
Co-authored-by: Álex <alejandro.ruiz.becerra@wazuh.com>
(cherry picked from commit ce29034)
asteriscos added a commit that referenced this pull request Oct 31, 2022
* 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

* 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

* 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

* 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

* 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

* test: fix tests

* Set textArea size

* Add max character length validation

* test(settings): fix tests

* changelog: add PR entry

* test(settings): format tests

Co-authored-by: Antonio David Gutiérrez <antonio.gutierrez@wazuh.com>
Co-authored-by: Álex <alejandro.ruiz.becerra@wazuh.com>
(cherry picked from commit ce29034)
asteriscos added a commit that referenced this pull request Oct 31, 2022
…4783)

* Add header and footer report customization (#4505)

* 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

* 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

* 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

* 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

* 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

* test: fix tests

* Set textArea size

* Add max character length validation

* test(settings): fix tests

* changelog: add PR entry

* test(settings): format tests

Co-authored-by: Antonio David Gutiérrez <antonio.gutierrez@wazuh.com>
Co-authored-by: Álex <alejandro.ruiz.becerra@wazuh.com>
(cherry picked from commit ce29034)

* Fix reporting unit test

* Updated PDF report md5 fingerprint in unit test
asteriscos added a commit that referenced this pull request Oct 31, 2022
)

Add header and footer report customization (#4505)

* 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

* 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

* 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

* 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

* 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

* test: fix tests

* Set textArea size

* Add max character length validation

* test(settings): fix tests

* changelog: add PR entry

* test(settings): format tests

Co-authored-by: Antonio David Gutiérrez <antonio.gutierrez@wazuh.com>
Co-authored-by: Álex <alejandro.ruiz.becerra@wazuh.com>
(cherry picked from commit ce29034)

Co-authored-by: Federico Rodriguez <federico.rodriguez@wazuh.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/enhancement Enhancement issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Custom branding: PDF reports
5 participants