diff --git a/sources/Users/ITopUserCountingRepository.php b/sources/Users/ITopUserCountingRepository.php index 0ad0d9ddc2..e2356b9047 100644 --- a/sources/Users/ITopUserCountingRepository.php +++ b/sources/Users/ITopUserCountingRepository.php @@ -37,7 +37,7 @@ class ITopUserCountingRepository * @throws MySQLException * @throws Exception */ - public function GetConsoleUsers(array $aExcludedUsers = [], array $aExcludedProfiles = ['Portal user'], bool $bAllData = true, array $aExcludedFinalClasses = ['UserToken', 'UserRemoteSaaS']): array + public function GetConsoleUsers(array $aExcludedUsers = [], array $aExcludedProfiles = ['Portal user', 'Business partner user'], bool $bAllData = true, array $aExcludedFinalClasses = ['UserToken', 'UserRemoteSaaS']): array { $sExcludedUsers = $this->ArrayToOQLStringParameter($aExcludedUsers); $sExcludedProfiles = $this->ArrayToOQLStringParameter($aExcludedProfiles); @@ -89,6 +89,29 @@ class ITopUserCountingRepository return $this->GetUsersFromFilter($oFilter); } + /** + * @throws Exception + */ + public function GetBusinessPartnerUsers(bool $bAllData = true, array $aExcludedFinalClasses = ['UserToken', 'UserRemoteSaaS']): array + { + $sExcludedFinalClasses = $this->ArrayToOQLStringParameter($aExcludedFinalClasses); + + $sOQLPortalUser = " + SELECT User AS u + JOIN URP_UserProfile AS uup ON uup.userid = u.id + JOIN URP_Profiles AS up ON uup.profileid = up.id + WHERE up.id = '40' AND u.status != 'disabled' AND u.finalclass NOT IN ($sExcludedFinalClasses)"; + + try { + $oFilter = $bAllData ? DBObjectSearch::FromOQL_AllData($sOQLPortalUser) : DBObjectSearch::FromOQL($sOQLPortalUser); + } catch (Exception $e) { + IssueLog::Error(Dict::Format('Core:GetCountingUsers:Error', Dict::S('Core:CountingUsers:BusinessPartnerUser')).' - error details : '.$e->getMessage()); + throw new Exception(Dict::Format('Core:GetCountingUsers:Error', Dict::S('Core:CountingUsers:BusinessPartnerUser')).'.'); + } + + return $this->GetUsersFromFilter($oFilter); + } + /** * @throws DictExceptionMissingString * @throws CoreException diff --git a/tests/php-unit-tests/src/BaseTestCase/ItopDataTestCase.php b/tests/php-unit-tests/src/BaseTestCase/ItopDataTestCase.php index 88d4ab0a18..82e0e129f9 100644 --- a/tests/php-unit-tests/src/BaseTestCase/ItopDataTestCase.php +++ b/tests/php-unit-tests/src/BaseTestCase/ItopDataTestCase.php @@ -100,6 +100,7 @@ abstract class ItopDataTestCase extends ItopTestCase 'Service Manager' => 10, 'Document author' => 11, 'Portal power user' => 12, + 'Business partner user' => 40, 'REST Services User' => 1024, 'Configuration ReadOnly' => 5500, 'Ticket ReadOnly' => 5501, diff --git a/tests/php-unit-tests/unitary-tests/sources/Users/ITopUserCountingRepositoryTest.php b/tests/php-unit-tests/unitary-tests/sources/Users/ITopUserCountingRepositoryTest.php index a603327009..71cda244d4 100644 --- a/tests/php-unit-tests/unitary-tests/sources/Users/ITopUserCountingRepositoryTest.php +++ b/tests/php-unit-tests/unitary-tests/sources/Users/ITopUserCountingRepositoryTest.php @@ -16,6 +16,7 @@ class ITopUserCountingRepositoryTest extends ItopDataTestCase $this->CreatePortalUsers(); $this->CreateTokenUsers(); $this->CreateConsoleUsers(); + $this->CreateBusinessPartnerUser(); } @@ -68,6 +69,12 @@ class ITopUserCountingRepositoryTest extends ItopDataTestCase $this->GivenUserInDB('qpf_z17H3232*"ré$"é', ['Administrator'], false); } + private function CreateBusinessPartnerUser() + { + $this->GivenUserInDB('qpf_z17H3232*"ré$"é', ['Business partner user'], false); + $this->GivenUserInDB('qpf_z17H3232*"ré$"é', ['Business partner user'], false); + } + /** * @throws \CoreUnexpectedValue * @throws \DictExceptionMissingString @@ -85,6 +92,7 @@ class ITopUserCountingRepositoryTest extends ItopDataTestCase 'disabled' => $oITopUserRepository->GetDisabledUsers(), 'readonly' => $oITopUserRepository->GetReadOnlyUsers(), 'application' => $oITopUserRepository->GetApplicationUsers(), + 'businesspartner' => $oITopUserRepository->GetBusinessPartnerUsers(), ]; $aCountedUserFormated = []; @@ -119,12 +127,40 @@ class ITopUserCountingRepositoryTest extends ItopDataTestCase $aDisabledUsers = $oITopUserRepository->GetDisabledUsers(); $aReadOnlyUsers = $oITopUserRepository->GetReadOnlyUsers(); $aApplicationUsers = $oITopUserRepository->GetApplicationUsers(); + $aBusinessPartnerUsers = $oITopUserRepository->GetBusinessPartnerUsers(); - $aAllUsersFromMergedCounts = array_merge($aConsoleUsers, $aPortalUsers, $aDisabledUsers, $aReadOnlyUsers, $aApplicationUsers); + $aAllUsersFromMergedCounts = array_merge($aConsoleUsers, $aPortalUsers, $aDisabledUsers, $aReadOnlyUsers, $aApplicationUsers, $aBusinessPartnerUsers); $aAllUsersFromOQL = $oITopUserRepository->GetAllUsers(); - $this->assertEmpty(array_merge(array_diff($aAllUsersFromMergedCounts, $aAllUsersFromOQL), array_diff($aAllUsersFromOQL, $aAllUsersFromMergedCounts))); + $this->assertEmpty( // asserts that all users are in both arrays + array_merge( + array_diff( + $aAllUsersFromMergedCounts, + $aAllUsersFromOQL + ), + array_diff( + $aAllUsersFromOQL, + $aAllUsersFromMergedCounts + ) + ) + ); + + // check for cardinality + $aMergedCountingUsersIds = []; + foreach ($aAllUsersFromMergedCounts as $oUser) { + $aMergedCountingUsersIds[] = (int) $oUser->GetKey(); + } + + $aOqlUsersIds = []; + foreach ($aAllUsersFromOQL as $oUser) { + $aOqlUsersIds[] = (int) $oUser->GetKey(); + } + + sort($aMergedCountingUsersIds, SORT_NUMERIC); + sort($aOqlUsersIds, SORT_NUMERIC); + + $this->assertSame($aOqlUsersIds, $aMergedCountingUsersIds); } public function testAllCountedUsersAreUsersObjects() @@ -136,6 +172,7 @@ class ITopUserCountingRepositoryTest extends ItopDataTestCase $aDisabledUsers = $oITopUserRepository->GetDisabledUsers(); $aReadOnlyUsers = $oITopUserRepository->GetReadOnlyUsers(); $aApplicationUsers = $oITopUserRepository->GetApplicationUsers(); + $aBusinessPartnerUsers = $oITopUserRepository->GetBusinessPartnerUsers(); $aCountedUsers = array_merge($aConsoleUsers, $aPortalUsers, $aDisabledUsers, $aReadOnlyUsers, $aApplicationUsers);