27
27
*/
28
28
class AuthService
29
29
{
30
+ public static $ cacheRoles = false ;
30
31
public static $ roles ;
31
32
public static $ useSession = true ;
32
33
private static $ currentUser ;
@@ -623,7 +624,8 @@ public static function updateDefaultRights(&$userObject)
623
624
{
624
625
if (!$ userObject ->hasParent ()) {
625
626
$ changes = false ;
626
- foreach (ConfService::getRepositoriesList () as $ repositoryId => $ repoObject ) {
627
+ $ repoList = ConfService::getRepositoriesList ();
628
+ foreach ($ repoList as $ repositoryId => $ repoObject ) {
627
629
if (!self ::allowedForCurrentGroup ($ repoObject , $ userObject )) continue ;
628
630
if ($ repoObject ->isTemplate ) continue ;
629
631
if ($ repoObject ->getDefaultRight () != "" ) {
@@ -634,7 +636,8 @@ public static function updateDefaultRights(&$userObject)
634
636
if ($ changes ) {
635
637
$ userObject ->recomputeMergedRole ();
636
638
}
637
- foreach (self ::getRolesList (array (), true ) as $ roleId => $ roleObject ) {
639
+ $ rolesList = self ::getRolesList (array (), true );
640
+ foreach ($ rolesList as $ roleId => $ roleObject ) {
638
641
if (!self ::allowedForCurrentGroup ($ roleObject , $ userObject )) continue ;
639
642
if ($ userObject ->getProfile () == "shared " && $ roleObject ->autoAppliesTo ("shared " )) {
640
643
$ userObject ->addRole ($ roleObject );
@@ -651,7 +654,8 @@ public static function updateDefaultRights(&$userObject)
651
654
*/
652
655
public static function updateAutoApplyRole (&$ userObject )
653
656
{
654
- foreach (self ::getRolesList (array (), true ) as $ roleId => $ roleObject ) {
657
+ $ roles = self ::getRolesList (array (), true );
658
+ foreach ($ roles as $ roleObject ) {
655
659
if (!self ::allowedForCurrentGroup ($ roleObject , $ userObject )) continue ;
656
660
if ($ roleObject ->autoAppliesTo ($ userObject ->getProfile ()) || $ roleObject ->autoAppliesTo ("all " )) {
657
661
$ userObject ->addRole ($ roleObject );
@@ -990,6 +994,8 @@ public static function listUsers($baseGroup = "/", $regexp = null, $offset = -1,
990
994
call_user_func ($ countCallback , $ index , count ($ users ), "Update users " );
991
995
}
992
996
997
+ self ::$ cacheRoles = true ;
998
+ self ::$ roles = null ;
993
999
foreach (array_keys ($ users ) as $ userId ) {
994
1000
if (($ userId == "guest " && !ConfService::getCoreConf ("ALLOW_GUEST_BROWSING " , "auth " )) || $ userId == "ajxp.admin.users " || $ userId == "" ) continue ;
995
1001
if ($ regexp != null && !$ authDriver ->supportsUsersPagination () && !preg_match ("/ $ regexp/i " , $ userId )) continue ;
@@ -1008,6 +1014,8 @@ public static function listUsers($baseGroup = "/", $regexp = null, $offset = -1,
1008
1014
}
1009
1015
}
1010
1016
}
1017
+ self ::$ cacheRoles = false ;
1018
+
1011
1019
if ($ paginated && $ cleanLosts ) {
1012
1020
// Remove 'lost' items (children without parents).
1013
1021
foreach ($ allUsers as $ id => $ object ) {
@@ -1224,20 +1232,25 @@ public static function limitedRoleFromParent($parentUser)
1224
1232
*/
1225
1233
public static function getRolesList ($ roleIds = array (), $ excludeReserved = false )
1226
1234
{
1227
- //if(isSet(self::$roles)) return self::$roles;
1235
+ if (self ::$ cacheRoles && !count ($ roleIds ) && $ excludeReserved == true && self ::$ roles != null ) {
1236
+ return self ::$ roles ;
1237
+ }
1228
1238
$ confDriver = ConfService::getConfStorageImpl ();
1229
- self :: $ roles = $ confDriver ->listRoles ($ roleIds , $ excludeReserved );
1239
+ $ roles = $ confDriver ->listRoles ($ roleIds , $ excludeReserved );
1230
1240
$ repoList = null ;
1231
- foreach (self :: $ roles as $ roleId => $ roleObject ) {
1241
+ foreach ($ roles as $ roleId => $ roleObject ) {
1232
1242
if (is_a ($ roleObject , "AjxpRole " )) {
1233
1243
if ($ repoList == null ) $ repoList = ConfService::getRepositoriesList ("all " );
1234
1244
$ newRole = new AJXP_Role ($ roleId );
1235
1245
$ newRole ->migrateDeprectated ($ repoList , $ roleObject );
1236
- self :: $ roles [$ roleId ] = $ newRole ;
1246
+ $ roles [$ roleId ] = $ newRole ;
1237
1247
self ::updateRole ($ newRole );
1238
1248
}
1239
1249
}
1240
- return self ::$ roles ;
1250
+ if (self ::$ cacheRoles && !count ($ roleIds ) && $ excludeReserved == true ) {
1251
+ self ::$ roles = $ roles ;
1252
+ }
1253
+ return $ roles ;
1241
1254
}
1242
1255
1243
1256
/**
0 commit comments