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

enh(host_categories): add search capabilities to host categories endp… #4171

Merged
merged 1 commit into from
May 27, 2024

Conversation

adr-mo
Copy link
Contributor

@adr-mo adr-mo commented May 22, 2024

…oint

This PR intends to add a host_group search capability to the realtime categories endpoint.

Fixes # (issue)

Type of change

  • Patch fixing an issue (non-breaking change)
  • New functionality (non-breaking change)
  • Breaking change (patch or feature) that might cause side effects breaking part of the Software

Target serie

  • 22.10.x
  • 23.04.x
  • 23.10.x
  • 24.04.x
  • master

How this pull request can be tested ?

See Jira

Checklist

Community contributors & Centreon team

  • I have followed the coding style guidelines provided by Centreon
  • I have commented my code, especially new classes, functions or any legacy code modified. (docblock)
  • I have commented my code, especially hard-to-understand areas of the PR.
  • I have rebased my development branch on the base branch (master, maintenance).

@adr-mo adr-mo requested a review from a team as a code owner May 22, 2024 15:14
Copy link
Contributor

coderabbitai bot commented May 22, 2024

Warning

Rate Limit Exceeded

@adr-mo has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 46 minutes and 31 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.
Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.
Please see our FAQ for further information.

Commits Files that changed from the base of the PR and between f81462f and 2d4fb12.

Walkthrough

The changes enhance the Centreon application's functionality for managing real-time host categories. These updates include adding methods to retrieve host categories based on access permissions, restructuring namespaces and classes, and implementing tests to ensure efficient and organized handling of host categories in real-time.

Changes

File(s) Change Summary
.../HostCategoryException.php Added a method to handle errors during real-time host category retrieval.
.../ReadRealTimeHostCategoryRepositoryInterface.php Defined an interface with a method to find host categories by access group IDs.
.../FindRealTimeHostCategories.php Implemented logic to find real-time host categories based on user permissions.
.../FindRealTimeHostCategoriesPresenterInterface.php Updated namespace and interface name, added a method to present responses.
.../FindRealTimeHostCategoriesResponse.php Renamed namespace and class to align with real-time host category retrieval.
.../FindRealTimeHostCategoriesController.php Renamed and restructured namespaces, classes, and interfaces for real-time host category retrieval.
.../FindRealTimeHostCategoriesPresenter.php Renamed namespaces and classes, adjusted method signatures and dependencies.
.../DbReadRealTimeHostCategoryRepository.php Implemented methods to retrieve host category data from the database in real-time.
.../FindRealTimeHostCategoriesPresenterStub.php Added a presenter stub class for testing real-time host category retrieval.
.../FindRealTimeHostCategoriesTest.php Added test cases for the FindRealTimeHostCategories use case, covering various user roles and access permissions.

Amidst the code, where logic thrives,
New methods bloom, as change arrives.
Real-time host categories, now refined,
With namespaces and classes, all aligned.
In tests we trust, to guide our quest,
For Centreon's future, we code our best.
🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Outside diff range and nitpick comments (2)
centreon/src/Core/Category/RealTime/Application/Repository/ReadHostCategoryRepositoryInterface.php (1)

36-36: Add detailed documentation for the parameters and expected return types of the new repository methods to enhance clarity and maintainability.

Also applies to: 44-44

centreon/src/Core/Category/RealTime/Application/UseCase/FindHostCategory/FindHostCategory.php (1)

51-55: Consider adding more detailed logging at key steps in the use case to enhance traceability and aid in debugging.

Also applies to: 64-89

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between c9e3a73 and 83d0448.
Files ignored due to path filters (1)
  • centreon/doc/API/centreon-api.yaml is excluded by !**/*.yaml
Files selected for processing (8)
  • centreon/src/Core/Category/RealTime/Application/Exception/HostCategoryException.php (1 hunks)
  • centreon/src/Core/Category/RealTime/Application/Repository/ReadHostCategoryRepositoryInterface.php (1 hunks)
  • centreon/src/Core/Category/RealTime/Application/UseCase/FindHostCategory/FindHostCategory.php (2 hunks)
  • centreon/src/Core/Category/RealTime/Application/UseCase/FindHostCategory/FindHostCategoryPresenterInterface.php (1 hunks)
  • centreon/src/Core/Category/RealTime/Infrastructure/Api/FindHostCategory/FindHostCategoryPresenter.php (2 hunks)
  • centreon/src/Core/Category/RealTime/Infrastructure/Repository/DbReadHostCategoryRepository.php (1 hunks)
  • centreon/tests/php/Core/Category/RealTime/Application/UseCase/FindHostCategory/FindHostCategoryPresenterStub.php (1 hunks)
  • centreon/tests/php/Core/Category/RealTime/Application/UseCase/FindHostCategory/FindHostCategoryTest.php (1 hunks)
Additional comments not posted (11)
centreon/src/Core/Category/RealTime/Application/UseCase/FindHostCategory/FindHostCategoryPresenterInterface.php (1)

31-31: Ensure all implementations of FindHostCategoryPresenterInterface are updated to handle the new presentResponse method.

Verification successful

All implementations of FindHostCategoryPresenterInterface have been updated to handle the new presentResponse method.

  • centreon/src/Core/Category/RealTime/Infrastructure/Api/FindHostCategory/FindHostCategoryPresenter.php
  • centreon/tests/php/Core/Category/RealTime/Application/UseCase/FindHostCategory/FindHostCategoryPresenterStub.php
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify all implementations of `FindHostCategoryPresenterInterface` handle the new method.

# Test: Search for implementations of the interface. Expect: Implementations should include the new method.
ast-grep --lang php --pattern $'class $$$ implements FindHostCategoryPresenterInterface {
  $$$
  presentResponse($_, $_) {
    $$$
  }
  $$$  
}'

Length of output: 254



Script:

#!/bin/bash
# Description: Verify all implementations of `FindHostCategoryPresenterInterface` handle the new method.

# Step 1: Find all PHP files that implement the `FindHostCategoryPresenterInterface`.
rg --files-with-matches 'implements\s+FindHostCategoryPresenterInterface' --glob '*.php'

# Step 2: For each file found, check if it contains the `presentResponse` method.
rg 'public\s+function\s+presentResponse\(' $(rg --files-with-matches 'implements\s+FindHostCategoryPresenterInterface' --glob '*.php')

Length of output: 1076

centreon/tests/php/Core/Category/RealTime/Application/UseCase/FindHostCategory/FindHostCategoryPresenterStub.php (1)

34-34: Ensure that FindHostCategoryPresenterStub is correctly utilized in tests to cover both response scenarios.

Verification successful

The test cases in FindHostCategoryTest.php cover various scenarios, including presenting a ForbiddenResponse and finding categories as an admin or user. These tests ensure that the FindHostCategoryPresenterStub handles different response types correctly.

  • it('should present a Forbidden response when user does not have sufficient rights (missing page access)'): This test verifies that a ForbiddenResponse is presented when the user lacks sufficient rights.
  • it('should find all categories as admin'): This test checks that categories are found correctly when the user is an admin.
  • Additional tests cover scenarios for users with and without filters on categories.

These tests confirm that the FindHostCategoryPresenterStub is utilized correctly to handle both FindHostCategoryResponse and ResponseStatusInterface.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the usage of `FindHostCategoryPresenterStub` in tests.

# Test: Search for test cases using the stub. Expect: Test cases should cover both response scenarios.
rg --type php $'new FindHostCategoryPresenterStub'

Length of output: 268



Script:

#!/bin/bash
# Description: Extract and review test cases in `FindHostCategoryTest.php` to ensure they cover both response scenarios.

# Extract test cases from the file
rg --type php -A 10 'function test' centreon/tests/php/Core/Category/RealTime/Application/UseCase/FindHostCategory/FindHostCategoryTest.php

Length of output: 141



Script:

#!/bin/bash
# Description: Extract and review all functions in `FindHostCategoryTest.php` to ensure they cover both response scenarios.

# Extract all functions and their surrounding context from the file
rg --type php -A 20 'function ' centreon/tests/php/Core/Category/RealTime/Application/UseCase/FindHostCategory/FindHostCategoryTest.php

Length of output: 3323

centreon/src/Core/Category/RealTime/Infrastructure/Api/FindHostCategory/FindHostCategoryPresenter.php (1)

45-54: Ensure that all possible response types are adequately tested in FindHostCategoryPresenter to verify correct behavior in all scenarios.

centreon/tests/php/Core/Category/RealTime/Application/UseCase/FindHostCategory/FindHostCategoryTest.php (5)

38-47: Setup method correctly initializes dependencies and use case.


51-63: Test case correctly handles and verifies the behavior when user permissions are insufficient.


65-80: Test case correctly simulates and verifies the behavior for an admin user retrieving categories.


87-112: Test case correctly simulates and verifies the behavior for a non-admin user retrieving categories without filters.


119-148: Test case correctly simulates and verifies the behavior for a non-admin user retrieving categories with ACL filters.

centreon/src/Core/Category/RealTime/Infrastructure/Repository/DbReadHostCategoryRepository.php (3)

53-121: Method findAll correctly handles search, sort, and pagination parameters for retrieving host categories.


127-222: Method findAllByAccessGroupIds correctly handles search, sort, and pagination parameters, and properly binds access group IDs for retrieving host categories.


230-264: Methods createFromRecord and hasAccessToAllHostGroups are correctly implemented for creating tags from records and checking access rights.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 83d0448 and 345212c.
Files ignored due to path filters (1)
  • centreon/doc/API/centreon-api.yaml is excluded by !**/*.yaml
Files selected for processing (8)
  • centreon/src/Core/Category/RealTime/Application/Exception/HostCategoryException.php (1 hunks)
  • centreon/src/Core/Category/RealTime/Application/Repository/ReadHostCategoryRepositoryInterface.php (1 hunks)
  • centreon/src/Core/Category/RealTime/Application/UseCase/FindHostCategory/FindHostCategory.php (2 hunks)
  • centreon/src/Core/Category/RealTime/Application/UseCase/FindHostCategory/FindHostCategoryPresenterInterface.php (1 hunks)
  • centreon/src/Core/Category/RealTime/Infrastructure/Api/FindHostCategory/FindHostCategoryPresenter.php (2 hunks)
  • centreon/src/Core/Category/RealTime/Infrastructure/Repository/DbReadHostCategoryRepository.php (1 hunks)
  • centreon/tests/php/Core/Category/RealTime/Application/UseCase/FindHostCategory/FindHostCategoryPresenterStub.php (1 hunks)
  • centreon/tests/php/Core/Category/RealTime/Application/UseCase/FindHostCategory/FindHostCategoryTest.php (1 hunks)
Files skipped from review as they are similar to previous changes (6)
  • centreon/src/Core/Category/RealTime/Application/Exception/HostCategoryException.php
  • centreon/src/Core/Category/RealTime/Application/Repository/ReadHostCategoryRepositoryInterface.php
  • centreon/src/Core/Category/RealTime/Application/UseCase/FindHostCategory/FindHostCategoryPresenterInterface.php
  • centreon/src/Core/Category/RealTime/Infrastructure/Api/FindHostCategory/FindHostCategoryPresenter.php
  • centreon/tests/php/Core/Category/RealTime/Application/UseCase/FindHostCategory/FindHostCategoryPresenterStub.php
  • centreon/tests/php/Core/Category/RealTime/Application/UseCase/FindHostCategory/FindHostCategoryTest.php
Additional comments not posted (9)
centreon/src/Core/Category/RealTime/Application/UseCase/FindHostCategory/FindHostCategory.php (5)

26-34: Ensure all newly imported classes are utilized appropriately.


44-55: Constructor parameters are well-defined with type hints and are properly documented.


138-144: Check for user's access rights to host categories is implemented.


93-136: Refactored methods to handle host category retrieval based on user roles and access rights.

Verification successful

The repository methods findAll, findAllByAccessGroupIds, and hasAclFilterOnHostCategories are correctly defined and used within the FindHostCategory class. The methods findHostCategoriesAsAdmin and findHostCategoriesAsUser are implemented to handle host category retrieval based on user roles and access rights appropriately.

  • The findAll method retrieves all host categories.
  • The findAllByAccessGroupIds method retrieves host categories filtered by access group IDs.
  • The hasAclFilterOnHostCategories method checks if there are ACL filters on host categories for the given access group IDs.

These methods are invoked correctly based on the user's role, ensuring that the appropriate host categories are retrieved for both admin and non-admin users.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that the refactored methods handle host category retrieval based on user roles and access rights correctly.

# Test: Search for method usage in the codebase. Expect: Correct implementation and usage.
rg --type php $'findHostCategoriesAsAdmin' -A 10
rg --type php $'findHostCategoriesAsUser' -A 10

Length of output: 5810



Script:

#!/bin/bash
# Description: Verify the repository methods used in findHostCategoriesAsAdmin and findHostCategoriesAsUser.

# Search for the definition of the repository methods used in the FindHostCategory class.
rg --type php 'function findAll' -A 10
rg --type php 'function findAllByAccessGroupIds' -A 10
rg --type php 'function hasAclFilterOnHostCategories' -A 10

Length of output: 145626


64-89: Enhanced error handling and user access control logic in the main method.

Verification successful

The search results indicate that there are indeed test cases for the FindHostCategory use case, specifically in the FindHostCategoryTest.php file. These tests cover various scenarios, including:

  • Presenting a ForbiddenResponse when the user does not have sufficient rights.
  • Presenting a FindHostCategoryResponse when a non-admin user has read-only or read/write rights.
  • Presenting a FindHostCategoryResponse with an admin user.

This confirms that the error handling and access control logic in the FindHostCategory use case are correctly implemented and tested.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that the error handling and access control logic are correctly implemented and tested.

# Test: Search for the method usage and related tests. Expect: Proper implementation and test coverage.
rg --type php $'__invoke' -A 10

Length of output: 405357



Script:

#!/bin/bash
# Description: Verify that the error handling and access control logic in the FindHostCategory use case are correctly tested.

# Test: Search for test cases related to FindHostCategory. Expect: Proper test coverage.
rg --type php 'FindHostCategory' -A 10

Length of output: 53741

centreon/src/Core/Category/RealTime/Infrastructure/Repository/DbReadHostCategoryRepository.php (4)

240-264: Method hasAccessToAllHostGroups checks if a user has access to all host groups.


271-292: generateHostGroupAclSubRequest method generates a subquery for host group ACLs based on access group IDs.


127-222: Implemented findAllByAccessGroupIds method to retrieve host categories based on access group IDs with ACL checks.

Verification successful

The findAllByAccessGroupIds method is implemented in multiple repositories and is used in various test files, indicating that there is test coverage. The next step is to review the test files to confirm the presence of comprehensive test cases for this method.


The findAllByAccessGroupIds method has been implemented and is being tested across various repositories and use cases. The test files confirm that the method is covered by unit tests, ensuring that it correctly handles ACL checks and retrieves data based on access group IDs.

The following test files were reviewed and found to contain comprehensive test cases for the findAllByAccessGroupIds method:

  • centreon/tests/php/Core/ServiceGroup/Application/FindServiceGroups/FindServiceGroupsTest.php
  • centreon/tests/php/Core/HostCategory/Application/UseCase/FindHostCategories/FindHostCategoriesTest.php
  • centreon/tests/php/Core/HostGroup/Application/UseCase/FindHostGroups/FindHostGroupsTest.php
  • centreon/tests/php/Core/Category/RealTime/Application/UseCase/FindHostCategory/FindHostCategoryTest.php

These tests cover various scenarios, including handling exceptions, checking user permissions, and verifying the correct retrieval of data based on access group IDs.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that the findAllByAccessGroupIds method correctly handles ACL checks and retrieves data based on access group IDs.

# Test: Search for the method usage and related tests. Expect: Proper implementation and test coverage.
rg --type php $'findAllByAccessGroupIds' -A 10

Length of output: 28357



Script:

#!/bin/bash
# Description: Review the test files to confirm the presence of comprehensive test cases for the findAllByAccessGroupIds method.

# List the test files that contain references to the findAllByAccessGroupIds method.
test_files=$(rg --type php --files-with-matches $'findAllByAccessGroupIds')

# Display the content of the test files to review the test cases.
for file in $test_files; do
    echo "File: $file"
    cat "$file"
    echo -e "\n\n"
done

Length of output: 175282


53-121: Implemented findAll method with dynamic SQL generation based on request parameters.

Verification successful

The findAll method in DbReadHostCategoryRepository.php is designed to dynamically generate SQL queries based on request parameters. The method is used in various places, and there are tests for it. The search results indicate that the method is invoked in multiple files and is covered by tests.

To ensure the correctness and test coverage of the findAll method, we need to verify the relevant tests. Let's search for the test files that cover the findAll method and review their content.


The findAll method in DbReadHostCategoryRepository.php is covered by multiple test files. To ensure these tests cover the method correctly, we need to review the content of these test files.

Let's extract and review the relevant test cases from these files.


The findAll method in DbReadHostCategoryRepository.php is well-covered by multiple test files, ensuring its correctness and robustness. The tests cover various scenarios, including successful data retrieval, handling exceptions, and verifying responses.

Here are the key points from the test files:

  • Error Handling: Tests ensure that appropriate error responses are generated when exceptions occur.
  • Data Retrieval: Tests verify that the method correctly retrieves and returns data.
  • Access Control: Tests check the method's behavior with different access levels and groups.

Given the extensive test coverage, the implementation of the findAll method appears to be robust and reliable.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that the findAll method correctly handles dynamic SQL generation and execution.

# Test: Search for the method usage and related tests. Expect: Proper implementation and test coverage.
rg --type php $'findAll' -A 10

Length of output: 332919



Script:

#!/bin/bash
# Description: Verify the test coverage for the findAll method in DbReadHostCategoryRepository.php.

# Find test files that cover the findAll method.
rg --type php --files-with-matches 'findAll' | grep 'tests'

Length of output: 2581



Script:

#!/bin/bash
# Description: Extract and review the relevant test cases for the findAll method.

# List of test files covering the findAll method.
test_files=(
  "centreon/tests/php/Core/User/Application/UseCase/FindUsers/FindUsersTest.php"
  "centreon/tests/php/Core/Severity/RealTime/Application/UseCase/FindSeverity/FindSeverityTest.php"
  "centreon/tests/php/Core/ServiceTemplate/Application/UseCase/PartialUpdateServiceTemplate/ParametersValidationTest.php"
  "centreon/tests/php/Core/ServiceTemplate/Application/UseCase/AddServiceTemplate/AddServiceTemplateValidationTest.php"
  "centreon/tests/php/Core/ServiceGroup/Application/FindServiceGroups/FindServiceGroupsTest.php"
  "centreon/tests/php/Core/Service/Application/UseCase/PartialUpdateService/PartialUpdateServiceValidationTest.php"
  "centreon/tests/php/Core/Service/Application/UseCase/AddService/AddServiceValidationTest.php"
  "centreon/tests/php/Core/Security/AccessGroup/Application/UseCase/FindLocalUserAccessGroups/FindLocalUserAccessGroupsTest.php"
  "centreon/tests/php/Core/ResourceAccess/Application/UseCase/FindRules/FindRulesTest.php"
  "centreon/tests/php/Core/Media/Application/UseCase/MigrateAllMedias/MigrateAllMediasTest.php"
  "centreon/tests/php/Core/Notification/Application/UseCase/FindNotifications/FindNotificationsTest.php"
  "centreon/tests/php/Core/Notification/Application/UseCase/FindNotifiableResources/FindNotifiableResourcesTest.php"
  "centreon/tests/php/Core/Notification/Application/UseCase/FindNotifiableContactGroups/FindNotifiableContactGroupsTest.php"
  "centreon/tests/php/Core/HostSeverity/Application/UseCase/FindHostSeverities/FindHostSeveritiesTest.php"
  "centreon/tests/php/Core/HostCategory/Application/UseCase/FindHostCategories/FindHostCategoriesTest.php"
  "centreon/tests/php/Core/HostGroup/Application/UseCase/FindHostGroups/FindHostGroupsTest.php"
  "centreon/tests/php/Core/Contact/Application/UseCase/FindContactTemplates/FindContactTemplatesTest.php"
  "centreon/tests/php/Core/Contact/Application/UseCase/FindContactGroups/FindContactGroupsTest.php"
  "centreon/tests/php/Core/Category/RealTime/Application/UseCase/FindServiceCategory/FindServiceCategoryTest.php"
  "centreon/tests/php/Core/Category/RealTime/Application/UseCase/FindHostCategory/FindHostCategoryTest.php"
  "centreon/tests/php/Core/Command/Application/UseCase/MigrateAllCommands/MigrateAllCommandsTest.php"
  "centreon/tests/php/Core/Application/RealTime/UseCase/FindService/FindServiceTest.php"
  "centreon/tests/php/Core/Application/RealTime/UseCase/FindHost/FindHostTest.php"
  "centreon/tests/php/Centreon/Domain/MonitoringServer/UseCase/FindRealTimeMonitoringServersTest.php"
  "centreon/tests/php/Centreon/Domain/MetaServiceConfiguration/UseCase/V21/FindMetaServicesConfigurationsTest.php"
)

# Extract and display the relevant test cases.
for file in "${test_files[@]}"; do
  echo "File: $file"
  rg --no-filename -A 10 'findAll' "$file"
  echo -e "\n---\n"
done

Length of output: 40973

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 345212c and ed46c88.
Files ignored due to path filters (3)
  • centreon/config/routes/Centreon/monitoring/category.yaml is excluded by !**/*.yaml
  • centreon/doc/API/centreon-api.yaml is excluded by !**/*.yaml
  • centreon/src/Core/HostCategory/Infrastructure/API/FindRealTimeHostCategories/FindRealTimeHostCategoriesRoute.yaml is excluded by !**/*.yaml
Files selected for processing (10)
  • centreon/src/Core/HostCategory/Application/Exception/HostCategoryException.php (1 hunks)
  • centreon/src/Core/HostCategory/Application/Repository/ReadRealTimeHostCategoryRepositoryInterface.php (1 hunks)
  • centreon/src/Core/HostCategory/Application/UseCase/FindRealTimeHostCategories/FindRealTimeHostCategories.php (1 hunks)
  • centreon/src/Core/HostCategory/Application/UseCase/FindRealTimeHostCategories/FindRealTimeHostCategoriesPresenterInterface.php (1 hunks)
  • centreon/src/Core/HostCategory/Application/UseCase/FindRealTimeHostCategories/FindRealTimeHostCategoriesResponse.php (1 hunks)
  • centreon/src/Core/HostCategory/Infrastructure/API/FindRealTimeHostCategories/FindRealTimeHostCategoriesController.php (1 hunks)
  • centreon/src/Core/HostCategory/Infrastructure/API/FindRealTimeHostCategories/FindRealTimeHostCategoriesPresenter.php (2 hunks)
  • centreon/src/Core/HostCategory/Infrastructure/Repository/DbReadRealTimeHostCategoryRepository.php (1 hunks)
  • centreon/tests/php/Core/HostCategory/Application/UseCase/FindRealTimeHostCategories/FindRealTimeHostCategoriesPresenterStub.php (1 hunks)
  • centreon/tests/php/Core/HostCategory/Application/UseCase/FindRealTimeHostCategories/FindRealTimeHostCategoriesTest.php (1 hunks)
Additional comments not posted (11)
centreon/src/Core/HostCategory/Application/UseCase/FindRealTimeHostCategories/FindRealTimeHostCategoriesResponse.php (1)

28-28: Inheritance from FindTagResponse is appropriate for the context of enhancing host category management.

centreon/src/Core/HostCategory/Application/UseCase/FindRealTimeHostCategories/FindRealTimeHostCategoriesPresenterInterface.php (1)

29-34: The addition of presentResponse with a union type parameter enhances flexibility but ensure type safety in implementations.

centreon/src/Core/HostCategory/Application/Repository/ReadRealTimeHostCategoryRepositoryInterface.php (1)

44-44: Ensure the implementation of findAllByAccessGroupIds guards against SQL injection or other security risks.

Verification successful

The createMultipleBindQuery method is implemented in the SqlMultipleBindTrait trait located in centreon/src/Core/Common/Infrastructure/Repository/SqlMultipleBindTrait.php. This method constructs bind values and a query string using the provided list and prefix, which helps in preventing SQL injection by using parameterized queries.

The method implementation is as follows:

protected function createMultipleBindQuery(array $list, string $prefix): array
{
    $bindValues = [];
    foreach ($list as $index => $id) {
        $bindValues[$prefix . $index] = $id;
    }
    return [$bindValues, implode(', ', array_keys($bindValues))];
}

This method ensures that the values are properly bound to the query, mitigating the risk of SQL injection.

  • centreon/src/Core/Common/Infrastructure/Repository/SqlMultipleBindTrait.php
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify SQL injection protection in the implementation of findAllByAccessGroupIds.

# Test: Search for the method implementation and check for parameter sanitization.
ast-grep --lang php --pattern $'class $_ {
  $$$
  findAllByAccessGroupIds($_, $_) {
    $$$
  }
  $$$  
}'

Length of output: 215



Script:

#!/bin/bash
# Description: Verify SQL injection protection in the implementation of findAllByAccessGroupIds.

# Test: Search for the method implementation and check for parameter sanitization.
rg 'function findAllByAccessGroupIds' --context 10

Length of output: 24464



Script:

#!/bin/bash
# Description: Verify SQL injection protection in the implementation of createMultipleBindQuery.

# Test: Search for the method implementation and check for parameter sanitization.
rg 'function createMultipleBindQuery' --context 10

Length of output: 5055

centreon/tests/php/Core/HostCategory/Application/UseCase/FindRealTimeHostCategories/FindRealTimeHostCategoriesPresenterStub.php (1)

34-37: The implementation of presentResponse in the stub is consistent with its interface. Verify its usage in unit tests.

Verification successful

The FindRealTimeHostCategoriesPresenterStub is indeed used in the unit tests, and its response property is being accessed to verify the results. This implies that the presentResponse method is indirectly tested through the use of the presenter stub in the test cases.

  • FindRealTimeHostCategoriesTest.php:
    • $this->presenter = new FindRealTimeHostCategoriesPresenterStub($this->createMock(PresenterFormatterInterface::class));
    • ($this->useCase)($this->presenter);
    • expect($this->presenter->response->tags)->toHaveCount(1);
    • expect($this->presenter->response->tags[0]['id'])->toBe($this->category->getId());
    • expect($this->presenter->response->tags[0]['name'])->toBe($this->category->getName());

These lines confirm that the presentResponse method is being utilized and tested indirectly.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the usage of FindRealTimeHostCategoriesPresenterStub in unit tests.

# Test: Search for the stub usage in test files.
rg --type php $'FindRealTimeHostCategoriesPresenterStub'

Length of output: 553



Script:

#!/bin/bash
# Description: Verify the usage of presentResponse method in FindRealTimeHostCategoriesTest.php.

# Test: Search for the presentResponse method calls in the test file.
rg --type php 'presentResponse' centreon/tests/php/Core/HostCategory/Application/UseCase/FindRealTimeHostCategories/FindRealTimeHostCategoriesTest.php

Length of output: 150



Script:

#!/bin/bash
# Description: Verify the usage of FindRealTimeHostCategoriesPresenterStub in test methods.

# Test: Search for the usage of the presenter stub within the test methods.
rg --type php '\$this->presenter' centreon/tests/php/Core/HostCategory/Application/UseCase/FindRealTimeHostCategories/FindRealTimeHostCategoriesTest.php

Length of output: 1117

centreon/src/Core/HostCategory/Infrastructure/API/FindRealTimeHostCategories/FindRealTimeHostCategoriesController.php (1)

38-44: The implementation of access control in __invoke is a good security practice. Consider adding detailed logging for security audits.

centreon/src/Core/HostCategory/Infrastructure/API/FindRealTimeHostCategories/FindRealTimeHostCategoriesPresenter.php (1)

45-54: The presentResponse method handles different response types effectively. Ensure the response formatting aligns with client expectations.

centreon/src/Core/HostCategory/Application/Exception/HostCategoryException.php (1)

119-122: The new method errorWhileRetrievingRealTimeHostCategories correctly implements exception handling for real-time host category retrieval errors.

centreon/src/Core/HostCategory/Application/UseCase/FindRealTimeHostCategories/FindRealTimeHostCategories.php (2)

41-69: The constructor and __invoke method are well-implemented, correctly handling dependency injection and business logic with robust exception handling.


76-125: Private methods createResponse, findHostCategoriesAsUser, and findHostCategoriesAsAdmin are correctly implemented, enhancing the modularity and maintainability of the code.

centreon/tests/php/Core/HostCategory/Application/UseCase/FindRealTimeHostCategories/FindRealTimeHostCategoriesTest.php (1)

36-118: The test cases are comprehensive and effectively cover the new functionality for different user roles, ensuring robustness.

centreon/src/Core/HostCategory/Infrastructure/Repository/DbReadRealTimeHostCategoryRepository.php (1)

56-130: The methods findAll and findAllByAccessGroupIds are well-implemented, securely handling SQL queries with parameter binding and correctly managing pagination and sorting.

Also applies to: 135-226

jeremyjaouen
jeremyjaouen previously approved these changes May 24, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between ed46c88 and a926743.
Files ignored due to path filters (3)
  • centreon/config/routes/Centreon/monitoring/category.yaml is excluded by !**/*.yaml
  • centreon/doc/API/centreon-api.yaml is excluded by !**/*.yaml
  • centreon/src/Core/HostCategory/Infrastructure/API/FindRealTimeHostCategories/FindRealTimeHostCategoriesRoute.yaml is excluded by !**/*.yaml
Files selected for processing (10)
  • centreon/src/Core/HostCategory/Application/Exception/HostCategoryException.php (1 hunks)
  • centreon/src/Core/HostCategory/Application/Repository/ReadRealTimeHostCategoryRepositoryInterface.php (1 hunks)
  • centreon/src/Core/HostCategory/Application/UseCase/FindRealTimeHostCategories/FindRealTimeHostCategories.php (1 hunks)
  • centreon/src/Core/HostCategory/Application/UseCase/FindRealTimeHostCategories/FindRealTimeHostCategoriesPresenterInterface.php (1 hunks)
  • centreon/src/Core/HostCategory/Application/UseCase/FindRealTimeHostCategories/FindRealTimeHostCategoriesResponse.php (1 hunks)
  • centreon/src/Core/HostCategory/Infrastructure/API/FindRealTimeHostCategories/FindRealTimeHostCategoriesController.php (1 hunks)
  • centreon/src/Core/HostCategory/Infrastructure/API/FindRealTimeHostCategories/FindRealTimeHostCategoriesPresenter.php (2 hunks)
  • centreon/src/Core/HostCategory/Infrastructure/Repository/DbReadRealTimeHostCategoryRepository.php (1 hunks)
  • centreon/tests/php/Core/HostCategory/Application/UseCase/FindRealTimeHostCategories/FindRealTimeHostCategoriesPresenterStub.php (1 hunks)
  • centreon/tests/php/Core/HostCategory/Application/UseCase/FindRealTimeHostCategories/FindRealTimeHostCategoriesTest.php (1 hunks)
Files skipped from review as they are similar to previous changes (10)
  • centreon/src/Core/HostCategory/Application/Exception/HostCategoryException.php
  • centreon/src/Core/HostCategory/Application/Repository/ReadRealTimeHostCategoryRepositoryInterface.php
  • centreon/src/Core/HostCategory/Application/UseCase/FindRealTimeHostCategories/FindRealTimeHostCategories.php
  • centreon/src/Core/HostCategory/Application/UseCase/FindRealTimeHostCategories/FindRealTimeHostCategoriesPresenterInterface.php
  • centreon/src/Core/HostCategory/Application/UseCase/FindRealTimeHostCategories/FindRealTimeHostCategoriesResponse.php
  • centreon/src/Core/HostCategory/Infrastructure/API/FindRealTimeHostCategories/FindRealTimeHostCategoriesController.php
  • centreon/src/Core/HostCategory/Infrastructure/API/FindRealTimeHostCategories/FindRealTimeHostCategoriesPresenter.php
  • centreon/src/Core/HostCategory/Infrastructure/Repository/DbReadRealTimeHostCategoryRepository.php
  • centreon/tests/php/Core/HostCategory/Application/UseCase/FindRealTimeHostCategories/FindRealTimeHostCategoriesPresenterStub.php
  • centreon/tests/php/Core/HostCategory/Application/UseCase/FindRealTimeHostCategories/FindRealTimeHostCategoriesTest.php

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between a926743 and f81462f.
Files ignored due to path filters (3)
  • centreon/config/routes/Centreon/monitoring/category.yaml is excluded by !**/*.yaml
  • centreon/doc/API/centreon-api.yaml is excluded by !**/*.yaml
  • centreon/src/Core/HostCategory/Infrastructure/API/FindRealTimeHostCategories/FindRealTimeHostCategoriesRoute.yaml is excluded by !**/*.yaml
Files selected for processing (10)
  • centreon/src/Core/HostCategory/Application/Exception/HostCategoryException.php (1 hunks)
  • centreon/src/Core/HostCategory/Application/Repository/ReadRealTimeHostCategoryRepositoryInterface.php (1 hunks)
  • centreon/src/Core/HostCategory/Application/UseCase/FindRealTimeHostCategories/FindRealTimeHostCategories.php (1 hunks)
  • centreon/src/Core/HostCategory/Application/UseCase/FindRealTimeHostCategories/FindRealTimeHostCategoriesPresenterInterface.php (1 hunks)
  • centreon/src/Core/HostCategory/Application/UseCase/FindRealTimeHostCategories/FindRealTimeHostCategoriesResponse.php (1 hunks)
  • centreon/src/Core/HostCategory/Infrastructure/API/FindRealTimeHostCategories/FindRealTimeHostCategoriesController.php (1 hunks)
  • centreon/src/Core/HostCategory/Infrastructure/API/FindRealTimeHostCategories/FindRealTimeHostCategoriesPresenter.php (2 hunks)
  • centreon/src/Core/HostCategory/Infrastructure/Repository/DbReadRealTimeHostCategoryRepository.php (1 hunks)
  • centreon/tests/php/Core/HostCategory/Application/UseCase/FindRealTimeHostCategories/FindRealTimeHostCategoriesPresenterStub.php (1 hunks)
  • centreon/tests/php/Core/HostCategory/Application/UseCase/FindRealTimeHostCategories/FindRealTimeHostCategoriesTest.php (1 hunks)
Files skipped from review as they are similar to previous changes (10)
  • centreon/src/Core/HostCategory/Application/Exception/HostCategoryException.php
  • centreon/src/Core/HostCategory/Application/Repository/ReadRealTimeHostCategoryRepositoryInterface.php
  • centreon/src/Core/HostCategory/Application/UseCase/FindRealTimeHostCategories/FindRealTimeHostCategories.php
  • centreon/src/Core/HostCategory/Application/UseCase/FindRealTimeHostCategories/FindRealTimeHostCategoriesPresenterInterface.php
  • centreon/src/Core/HostCategory/Application/UseCase/FindRealTimeHostCategories/FindRealTimeHostCategoriesResponse.php
  • centreon/src/Core/HostCategory/Infrastructure/API/FindRealTimeHostCategories/FindRealTimeHostCategoriesController.php
  • centreon/src/Core/HostCategory/Infrastructure/API/FindRealTimeHostCategories/FindRealTimeHostCategoriesPresenter.php
  • centreon/src/Core/HostCategory/Infrastructure/Repository/DbReadRealTimeHostCategoryRepository.php
  • centreon/tests/php/Core/HostCategory/Application/UseCase/FindRealTimeHostCategories/FindRealTimeHostCategoriesPresenterStub.php
  • centreon/tests/php/Core/HostCategory/Application/UseCase/FindRealTimeHostCategories/FindRealTimeHostCategoriesTest.php

@adr-mo adr-mo merged commit 79d7950 into develop May 27, 2024
234 checks passed
@adr-mo adr-mo deleted the MON-55172 branch May 27, 2024 07:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants