Skip to content
This repository has been archived by the owner on Dec 13, 2022. It is now read-only.

fix(api): Resource::list return empty list if the regex is not valid #8437

Merged
merged 19 commits into from
Mar 25, 2020

Conversation

vhr
Copy link
Contributor

@vhr vhr commented Mar 20, 2020

Description

when the user sends invalid regexp to with operator $rg server will throw an exception from the DB,
the idea is to return empty list

related PR https://github.com/centreon/centreon/pull/8432

Fixes MON-5034

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
  • Updating documentation (missing information, typo...)

Target serie

  • 2.8.x
  • 18.10.x
  • 19.04.x
  • 19.10.x
  • 20.04.x (master)

How this pull request can be tested ?

send GET request to http://localhost/centreon/api/beta/monitoring/resources?page=1&limit=100&search={%22$or%22:[{%22name%22:{%22$rg%22:%22a%22}}]}

Checklist

Community contributors & Centreon team

  • I 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 made corresponding changes to the documentation.
  • I have rebased my development branch on the base branch (master, maintenance).

Centreon team only

  • I have made sure that the unit tests related to the story are successful.
  • I have made sure that unit tests cover 80% of the code written for the story.
  • I have made sure that acceptance tests related to the story are successful (local and CI)

victorvassilev
victorvassilev previously approved these changes Mar 20, 2020
->findResources($filter);
} catch (\PDOException $e) {
if ($e->getCode() !== "42000") {
throw $e;
Copy link
Contributor

Choose a reason for hiding this comment

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

The controller must not be aware of structure exceptions.
PDO is a class to read data so it's not a business class.

Copy link
Contributor

@callapa callapa Mar 20, 2020

Choose a reason for hiding this comment

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

Your repository can raised a specific exception that will can be catch by the service

Copy link
Contributor Author

@vhr vhr Mar 20, 2020

Choose a reason for hiding this comment

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

could you give an example from the existing code base, because the idea isn't to change the behavior that we have already just to avoid the particular problem described in the PR

Copy link
Contributor

Choose a reason for hiding this comment

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

ok

vhr added 6 commits March 20, 2020 12:53
…erviceInterface

ERROR: Call to an undefined method Centreon\Domain\Monitoring\Interfaces\ResourceServiceInterface::filterByContact()

Resolve MON-5034
victorvassilev
victorvassilev previously approved these changes Mar 20, 2020
@vhr vhr requested a review from callapa March 20, 2020 13:24
@@ -48,7 +48,7 @@
final class ResourceRepositoryRDB extends AbstractRepositoryDRB implements ResourceRepositoryInterface
{
/**
* @var AccessGroup[] List of access group used to filter the requests
* @var AccessGroup[]|null List of access group used to filter the requests
Copy link
Contributor

Choose a reason for hiding this comment

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

List can be emty, not null

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I changed it

Copy link
Contributor Author

@vhr vhr left a comment

Choose a reason for hiding this comment

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

@callapa please be more careful when you introduce a new code and be sure it's tested and at least it's working properly

victorvassilev
victorvassilev previously approved these changes Mar 24, 2020
Co-Authored-By: Laurent Calvet <lcalvet@centreon.com>
@vhr vhr merged commit bfa1794 into master Mar 25, 2020
@vhr vhr deleted the MON-5034-err-500-in-ctrl branch March 25, 2020 16:08
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants