-
Notifications
You must be signed in to change notification settings - Fork 289
N°9687 - Fix incorrect return type for the DBObjectSearch::ApplyDataFilter() function #939
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
Open
Molkobain
wants to merge
4
commits into
support/3.2.3
Choose a base branch
from
issue/9687-fix-incorrect-return-type-for-the-dbobjectsearch-applydatafilter-function
base: support/3.2.3
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+93
−4
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
e1d274b
N°9687 - Fix incorrect return type for the DBObjectSearch::ApplyDataF…
Molkobain 0f7653a
N°9687 - Add unit test
Molkobain 2466406
N°9687 - Improve unit test after code review
Molkobain 14d1862
N°9687 - Improve unit test after code review
Molkobain File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -676,9 +676,8 @@ public function GetExpectedArguments(): array | |
|
|
||
| /** | ||
| * @inheritDoc | ||
| * @return DBUnionSearch | ||
| */ | ||
| protected function ApplyDataFilters(): DBUnionSearch | ||
| protected function ApplyDataFilters(): DBSearch | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it is a pity that we compute further times IsDataAllowed and IsDataFiltered when dealing with Union.... first time in DBUnion. and 2nd time in the loop when calling each sub item. |
||
| { | ||
| if ($this->IsAllDataAllowed() || $this->IsDataFiltered()) { | ||
| return $this; | ||
|
|
||
67 changes: 67 additions & 0 deletions
67
tests/php-unit-tests/unitary-tests/core/DBSearch/DBSearchApplyDataFiltersTest.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| <?php | ||
|
|
||
| /* | ||
| * @copyright Copyright (C) 2010-2026 Combodo SAS | ||
| * @license http://opensource.org/licenses/AGPL-3.0 | ||
| */ | ||
|
|
||
| namespace Combodo\iTop\Test\UnitTest\Core; | ||
|
|
||
| use Combodo\iTop\Test\UnitTest\ItopDataTestCase; | ||
| use DBObjectSearch; | ||
| use DBUnionSearch; | ||
| use UserRights; | ||
|
|
||
| class DBSearchApplyDataFiltersTest extends ItopDataTestCase | ||
| { | ||
| public const CREATE_TEST_ORG = true; | ||
|
|
||
| protected string $sOriginalUserRightsSelectModuleClass = ''; | ||
|
|
||
| /** | ||
| * @throws \Exception | ||
| */ | ||
| protected function setUp(): void | ||
| { | ||
| parent::setUp(); | ||
|
|
||
| // Backup original UserRights select module as it will changed in some tests | ||
| $this->sOriginalUserRightsSelectModuleClass = get_class(UserRights::GetModuleInstance()); | ||
|
|
||
| $this->RequireOnceUnitTestFile('Fixtures/N9687_CustomGetSelectFilterClass.php'); | ||
| } | ||
|
|
||
| /** | ||
| * @inheritDoc | ||
| */ | ||
| public function tearDown(): void | ||
| { | ||
| // Restore original UserRights select module to not interfere with next tests | ||
| UserRights::SelectModule($this->sOriginalUserRightsSelectModuleClass); | ||
|
|
||
| parent::tearDown(); | ||
| } | ||
|
|
||
| public function testApplyDataFiltersOnDBObjectSearchShouldAcceptGetSelectFilterClassReturningDBUnionSearch() | ||
| { | ||
| // Use custom select filter that returns a DBUnionSearch | ||
| $sPreviousSelectModuleClass = get_class(UserRights::GetModuleInstance()); | ||
| UserRights::SelectModule('\\Combodo\\iTop\\Test\\UnitTest\\Core\\Fixtures\\N9687_CustomGetSelectFilterClass'); | ||
|
greptile-apps[bot] marked this conversation as resolved.
|
||
|
|
||
| // Create a user and login, otherwise the select filter won't apply | ||
| self::CreateUser('test_dbsearch_applydatafilters', 3); | ||
| UserRights::Login('test_dbsearch_applydatafilters'); | ||
|
|
||
| // Create a person | ||
| $oCreatedPerson = $this->CreatePerson(microtime()); | ||
|
|
||
| // Try to retrieve it using the select filter | ||
| $oSearch = DBObjectSearch::FromOQL("SELECT Person WHERE id = {$oCreatedPerson->GetKey()}"); | ||
| $oFilteredSearch = $this->InvokeNonPublicMethod(DBObjectSearch::class, 'ApplyDataFilters', $oSearch); | ||
|
|
||
| // Restore original select module to not interfere with next tests | ||
| UserRights::SelectModule($sPreviousSelectModuleClass); | ||
|
greptile-apps[bot] marked this conversation as resolved.
|
||
|
|
||
| $this->assertEquals(DBUnionSearch::class, get_class($oFilteredSearch), "DBObjectSearch::ApplyDataFilters() should be able to return a \DBUnionSearch"); | ||
| } | ||
| } | ||
24 changes: 24 additions & 0 deletions
24
.../php-unit-tests/unitary-tests/core/DBSearch/Fixtures/N9687_CustomGetSelectFilterClass.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| <?php | ||
|
|
||
| /* | ||
| * @copyright Copyright (C) 2010-2026 Combodo SAS | ||
| * @license http://opensource.org/licenses/AGPL-3.0 | ||
| */ | ||
|
|
||
| namespace Combodo\iTop\Test\UnitTest\Core\Fixtures; | ||
|
|
||
| use DBObjectSearch; | ||
| use DBUnionSearch; | ||
| use UserRightsProfile; | ||
|
|
||
| class N9687_CustomGetSelectFilterClass extends UserRightsProfile | ||
| { | ||
| public function GetSelectFilter($oUser, $sClass, $aSettings = []) | ||
| { | ||
| // We just need the method to return an union search | ||
| return new DBUnionSearch([ | ||
| DBObjectSearch::FromOQL("SELECT $sClass WHERE 1!=2"), | ||
| DBObjectSearch::FromOQL("SELECT $sClass WHERE 1=1"), | ||
| ]); | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IsDataFiltered() is doing the opposite of what the name seems to tell... hard to understand at first sight.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I strongly advice to complete PHPDOC of all used methods... some are missing or incomplete (mixed).
ie GetSearches, FromEmptySet, GetSelectedClasses, GetJoinedClasses.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
apart from that if we do the minimum to change the code, it could be nice to have full test cover of 3 distincts kinds of ApplyDataFilters (DBUnionSearch, DBsearch, DBObjSearch().
for example security.disable_joined_classes_filter in the conf can change the behaviour. just as UserRightsGetSelectFilter extensibility.... we can discuss it if you want
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
last but not least it could be nice to refactor in one common method. where we would pass an array of string (coming from either GetSearches, GetSelectedClasses or GetJoinedClasses).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need to compute GetSelectedClass if 'security.disable_joined_classes_filter' is disabled.