mirror of
https://github.com/Combodo/iTop.git
synced 2026-07-03 05:16:43 +02:00
Merge remote-tracking branch 'origin/support/3.2.3' into support/3.2
This commit is contained in:
@@ -1928,9 +1928,8 @@ class DBObjectSearch extends DBSearch
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @return DBObjectSearch
|
||||
*/
|
||||
protected function ApplyDataFilters(): DBObjectSearch
|
||||
protected function ApplyDataFilters(): DBSearch
|
||||
{
|
||||
if ($this->IsAllDataAllowed() || $this->IsDataFiltered()) {
|
||||
return $this;
|
||||
|
||||
@@ -676,9 +676,8 @@ class DBUnionSearch extends DBSearch
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @return DBUnionSearch
|
||||
*/
|
||||
protected function ApplyDataFilters(): DBUnionSearch
|
||||
protected function ApplyDataFilters(): DBSearch
|
||||
{
|
||||
if ($this->IsAllDataAllowed() || $this->IsDataFiltered()) {
|
||||
return $this;
|
||||
|
||||
@@ -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');
|
||||
|
||||
// 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);
|
||||
|
||||
$this->assertEquals(DBUnionSearch::class, get_class($oFilteredSearch), "DBObjectSearch::ApplyDataFilters() should be able to return a \DBUnionSearch");
|
||||
}
|
||||
}
|
||||
@@ -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"),
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user