jenkins-bot has submitted this change and it was merged.

Change subject: Change getProjectsForUser to getRoleAssignmentsForUser
......................................................................


Change getProjectsForUser to getRoleAssignmentsForUser

Previously we were discarding information in that call
which would have been useful when getting the quick list
of user roles.  Now we return a more complete picture,
which is used in OpenStackNovaUser::GetRole() to
speed things up.

Change-Id: I6f79de5f3ff6d50d25109207f70d5ebd789cf8d5
---
M nova/OpenStackNovaController.php
M nova/OpenStackNovaUser.php
2 files changed, 29 insertions(+), 21 deletions(-)

Approvals:
  Andrew Bogott: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/nova/OpenStackNovaController.php b/nova/OpenStackNovaController.php
index 59a8ee1..722c5ee 100644
--- a/nova/OpenStackNovaController.php
+++ b/nova/OpenStackNovaController.php
@@ -395,13 +395,19 @@
        }
 
        /**
-        * @return array of projects ids
+        * @return array of arrays:  project ID => role IDs
+        *
+        *  Return array only includes entries for projects
+        *  with roles assigned, so calling array_keys
+        *  on the return value will answer the question
+        *  'what projects is this user in?'
+        *
         */
-       function getProjectsForUser( $userid ) {
+       function getRoleAssignmentsForUser( $userid ) {
                $admintoken = $this->_getAdminToken();
                $headers = array( "X-Auth-Token: $admintoken" );
 
-               $projects = array();
+               $assignments = array();
                $ret = $this->restCall( 'identityv3', 
"/role_assignments?user.id=$userid", 'GET', array(), $headers );
                $role_assignments = self::_get_property( $ret['body'], 
'role_assignments' );
                if ( !$role_assignments ) {
@@ -409,16 +415,18 @@
                }
                foreach ( $role_assignments as $assignment ) {
                        $scope = self::_get_property( $assignment, 'scope' );
+                       $role = self::_get_property( $assignment, 'role' );
+                       $roleid = self::_get_property( $role, 'id' );
                        $project = self::_get_property( $scope, 'project' );
                        $projectid = self::_get_property( $project, 'id' );
 
-                       $projects[] = $projectid;
+                       $assignments[$projectid][] = $roleid;
                }
-               return array_unique( $projects );
+               return $assignments;
        }
 
        /**
-        * @return array of arrays:  role ID => role Names
+        * @return array of arrays:  role ID => user IDs
         */
        function getRoleAssignmentsForProject( $projectid ) {
                $admintoken = $this->_getAdminToken();
diff --git a/nova/OpenStackNovaUser.php b/nova/OpenStackNovaUser.php
index cce657e..134d647 100644
--- a/nova/OpenStackNovaUser.php
+++ b/nova/OpenStackNovaUser.php
@@ -160,39 +160,39 @@
         */
        function getProjects() {
                $controller = OpenStackNovaProject::getController();
-               $projects = $controller->getProjectsForUser( $this->getUid() ) ;
+               $projects = array_keys( $controller->getRoleAssignmentsForUser( 
$this->getUid() ) );
                return $projects;
        }
 
        /**
-        * Returns a list of roles this user is a member of. Includes
+        * Returns a list of role this user is a member of. Includes
         * all projects.
-        * @return array
+        * @return array of rolenames
         */
        function getRoles() {
                global $wgAuth, $wgMemc;
                global $wgOpenStackManagerLDAPProjectBaseDN;
 
-               $key = wfMemcKey( 'openstackmanager', 'roles', $this->userDN );
+               $key = wfMemcKey( 'openstackmanager', 'roles', $this->username 
);
                $roles = $wgMemc->get( $key );
                if ( is_array( $roles ) ) {
                        return $roles;
                }
 
+               $controller = OpenStackNovaProject::getController();
+               $assignments = $controller->getRoleAssignmentsForUser( 
$this->getUid() );
+
+               $everyrole = array();
+               foreach ($assignments as $projectid => $rolelist ) {
+                       $everyrole = array_merge( $everyrole, $rolelist );
+               }
+               $roleids = array_unique( $everyrole );
+
                $roles = array();
-               $projects = $this->getProjects();
-               foreach ( $projects as $projectid ) {
-                       $project = OpenStackNovaProject::getProjectById( 
$projectid );
-                       $projectroles = $project->getRoles();
-                       foreach ( $projectroles as $role ) {
-                               if ( in_array( $this->getUsername(), 
$role->getMembers() ) ) {
-                                       $roles[] = $role->getRoleName();
-                               }
-                       }
+               foreach ( $roleids as $roleid ) {
+                       $roles[] = OpenStackNovaRole::getRoleNameForId( $roleid 
);
                }
 
-               $roles = array_unique( $roles );
-               $key = wfMemcKey( 'openstackmanager', 'roles', 
$this->getUsername() );
                $wgMemc->set( $key, $roles, '3600' );
                return $roles;
        }

-- 
To view, visit https://gerrit.wikimedia.org/r/270501
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I6f79de5f3ff6d50d25109207f70d5ebd789cf8d5
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/OpenStackManager
Gerrit-Branch: wmf/1.27.0-wmf.13
Gerrit-Owner: Andrew Bogott <[email protected]>
Gerrit-Reviewer: Andrew Bogott <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to