Return the highest role for a project when a user is member of multiple groups
This commit is contained in:
@@ -86,6 +86,26 @@ class AccessMap
|
||||
return $roles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the highest role from a list
|
||||
*
|
||||
* @access public
|
||||
* @param array $roles
|
||||
* @return string
|
||||
*/
|
||||
public function getHighestRole(array $roles)
|
||||
{
|
||||
$rank = array();
|
||||
|
||||
foreach ($roles as $role) {
|
||||
$rank[$role] = count($this->getRoleHierarchy($role));
|
||||
}
|
||||
|
||||
asort($rank);
|
||||
|
||||
return key($rank);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add new access rules
|
||||
*
|
||||
|
||||
@@ -48,11 +48,13 @@ class ProjectGroupRole extends Base
|
||||
*/
|
||||
public function getUserRole($project_id, $user_id)
|
||||
{
|
||||
return $this->db->table(self::TABLE)
|
||||
$roles = $this->db->table(self::TABLE)
|
||||
->join(GroupMember::TABLE, 'group_id', 'group_id', self::TABLE)
|
||||
->eq(GroupMember::TABLE.'.user_id', $user_id)
|
||||
->eq(self::TABLE.'.project_id', $project_id)
|
||||
->findOneColumn('role');
|
||||
->findAllByColumn('role');
|
||||
|
||||
return $this->projectAccessMap->getHighestRole($roles);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user