Created
May 3, 2018 22:57
-
-
Save asmecher/bab85892525ea2d919f38fc52286af8f to your computer and use it in GitHub Desktop.
Include site admin roles in RoleDAO::userHasRole
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/classes/security/RoleDAO.inc.php b/classes/security/RoleDAO.inc.php | |
index 6c5122e..6a3f91e 100644 | |
--- a/classes/security/RoleDAO.inc.php | |
+++ b/classes/security/RoleDAO.inc.php | |
@@ -114,10 +114,16 @@ class RoleDAO extends DAO { | |
* @return bool True iff at least one such role exists | |
*/ | |
function userHasRole($contextId, $userId, $roleId) { | |
+ $includeAdminRoles = $roleId === ROLE_ID_SITE_ADMIN || (is_array($roleId) && in_array(ROLE_ID_SITE_ADMIN, $roles)); | |
+ | |
$roleId = is_array($roleId) ? join(',', array_map('intval', $roleId)) : (int) $roleId; | |
$result = $this->retrieve( | |
- 'SELECT count(*) FROM user_groups ug JOIN user_user_groups uug ON ug.user_group_id = uug.user_group_id | |
- WHERE ug.context_id = ? AND uug.user_id = ? AND ug.role_id IN (' . $roleId . ')', | |
+ 'SELECT count(*) | |
+ FROM user_groups ug | |
+ JOIN user_user_groups uug ON ug.user_group_id = uug.user_group_id | |
+ WHERE (ug.context_id = ?' . ($includeAdminRoles?' OR ug.context_id = ' . CONTEXT_ID_NONE:'') . ') | |
+ AND uug.user_id = ? | |
+ AND ug.role_id IN (' . $roleId . ')', | |
array((int) $contextId, (int) $userId) | |
); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment