3939use Glpi \Exception \Http \AccessDeniedHttpException ;
4040use Glpi \Exception \SessionExpiredException ;
4141use PHPUnit \Framework \Attributes \DataProvider ;
42+ use Profile ;
43+ use Profile_User ;
44+ use ProfileRight ;
4245use ReflectionClass ;
46+ use User ;
4347
4448class SessionTest extends DbTestCase
4549{
@@ -280,7 +284,7 @@ public function testMustChangePassword(string $last_update, int $expiration_dela
280284 global $ CFG_GLPI ;
281285
282286 $ this ->login ();
283- $ user = new \ User ();
287+ $ user = new User ();
284288 $ username = 'test_must_change_pass_ ' . mt_rand ();
285289 $ user_id = (int ) $ user ->add ([
286290 'name ' => $ username ,
@@ -723,7 +727,7 @@ public function testCanImpersonate()
723727
724728 $ users = [];
725729 for ($ i = 0 ; $ i < 6 ; $ i ++) {
726- $ user = new \ User ();
730+ $ user = new User ();
727731 $ users_id = $ user ->add ([
728732 'name ' => 'testCanImpersonate ' . $ i ,
729733 'password ' => 'test ' ,
@@ -737,27 +741,27 @@ public function testCanImpersonate()
737741 $ profiles_to_copy = ['Technician ' , 'Admin ' ];
738742 // Copy the data of each profile to a new one with the same name but suffixed with '-Impersonate
739743 foreach ($ profiles_to_copy as $ profile_name ) {
740- $ profile = new \ Profile ();
744+ $ profile = new Profile ();
741745 $ profiles_id = getItemByTypeName ('Profile ' , $ profile_name , true );
742746 $ this ->assertGreaterThan (0 , $ profiles_id );
743747 $ profile ->getFromDB ($ profiles_id );
744- $ old_user_rights = \ ProfileRight::getProfileRights ($ profiles_id , ['user ' ])['user ' ];
748+ $ old_user_rights = ProfileRight::getProfileRights ($ profiles_id , ['user ' ])['user ' ];
745749 $ new_profiles_id = $ profile ->clone (['name ' => $ profile_name . '-Impersonate ' ]);
746- $ DB ->update ('glpi_profilerights ' , ['rights ' => $ old_user_rights | \ User::IMPERSONATE ], [
750+ $ DB ->update ('glpi_profilerights ' , ['rights ' => $ old_user_rights | User::IMPERSONATE ], [
747751 'profiles_id ' => $ new_profiles_id ,
748752 'name ' => 'user ' ,
749753 ]);
750754 }
751755
752756 $ assign_profile = function (int $ users_id , int $ profiles_id ) use ($ root_entity ) {
753- $ profile_user = new \ Profile_User ();
757+ $ profile_user = new Profile_User ();
754758 $ result = $ profile_user ->add ([
755759 'profiles_id ' => $ profiles_id ,
756760 'users_id ' => $ users_id ,
757761 'entities_id ' => $ root_entity ,
758762 ]);
759763 $ this ->assertGreaterThan (0 , $ result );
760- $ user = new \ User ();
764+ $ user = new User ();
761765 $ this ->assertTrue ($ user ->update ([
762766 'id ' => $ users_id ,
763767 'profiles_id ' => $ profiles_id ,
@@ -913,7 +917,7 @@ public static function getRightNameForErrorProvider()
913917 ['_nonexistant ' , UNLOCK , 'UNLOCK ' ],
914918 ['ticket ' , READ , 'See my ticket ' ],
915919 ['ticket ' , \Ticket::READALL , 'See all tickets ' ],
916- ['user ' , \ User::IMPORTEXTAUTHUSERS , 'Add external ' ],
920+ ['user ' , User::IMPORTEXTAUTHUSERS , 'Add external ' ],
917921 ];
918922 }
919923
@@ -1479,4 +1483,45 @@ public function testRightCheckBypass()
14791483 $ this ->assertFalse (\Session::isRightChecksDisabled ());
14801484 $ this ->assertFalse (\Session::haveRight ('_nonexistant_module ' , READ ));
14811485 }
1486+
1487+ public function testDropdownMenuIsNotAddedIfUserCantSeeAny (): void
1488+ {
1489+ global $ DB ;
1490+
1491+ // Arrange: create a central user with no rights
1492+ $ profile = $ this ->createItem (Profile::class, [
1493+ 'name ' => 'Central profile ' ,
1494+ 'interface ' => 'central ' ,
1495+ ]);
1496+ $ user = $ this ->createItem (User::class, [
1497+ 'name ' => 'central_user ' ,
1498+ ]);
1499+ $ this ->createItem (Profile_User::class, [
1500+ 'users_id ' => $ user ->getID (),
1501+ 'profiles_id ' => $ profile ->getID (),
1502+ 'entities_id ' => $ this ->getTestRootEntity (only_id: true ),
1503+ ]);
1504+ $ DB ->update (
1505+ table: ProfileRight::getTable (),
1506+ params: [
1507+ 'rights ' => 0 ,
1508+ ],
1509+ where: [
1510+ 'profiles_id ' => $ profile ->getID (),
1511+ ],
1512+ );
1513+
1514+
1515+ // Act: loggin as the user and get the menu
1516+ $ this ->login ('central_user ' );
1517+ \Html::generateMenuSession (true );
1518+
1519+ // Assert: the config menu content should not be generated
1520+ $ this ->assertArrayNotHasKey ('content ' , $ _SESSION ['glpimenu ' ]['config ' ]);
1521+
1522+ // Control group: make sure the given key is set for another user
1523+ $ this ->login ('glpi ' );
1524+ \Html::generateMenuSession (true );
1525+ $ this ->assertArrayHasKey ('content ' , $ _SESSION ['glpimenu ' ]['config ' ]);
1526+ }
14821527}
0 commit comments