3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
21 class CRM_Core_Permission_Drupal
extends CRM_Core_Permission_DrupalBase
{
24 * Is this user someone with access for the entire system.
28 protected $_viewAdminUser = FALSE;
29 protected $_editAdminUser = FALSE;
32 * Am in in view permission or edit permission?
35 protected $_viewPermission = FALSE;
36 protected $_editPermission = FALSE;
39 * The current set of permissioned groups for the user.
43 protected $_viewPermissionedGroups;
44 protected $_editPermissionedGroups;
47 * Given a permission string, check for access requirements
50 * The permission to check.
55 * true if yes, else false
57 public function check($str, $userId = NULL) {
58 $str = $this->translatePermission($str, 'Drupal', [
59 'view user account' => 'access user profiles',
60 'administer users' => 'administer users',
62 if ($str == CRM_Core_Permission
::ALWAYS_DENY_PERMISSION
) {
65 if ($str == CRM_Core_Permission
::ALWAYS_ALLOW_PERMISSION
) {
68 if (function_exists('user_access')) {
71 $account = user_load($userId);
73 return user_access($str, $account);
79 * Given a roles array, check for access requirements
85 * true if yes, else false
87 public function checkGroupRole($array) {
88 if (function_exists('user_load') && isset($array)) {
89 $user = user_load($GLOBALS['user']->uid
);
90 //if giver roles found in user roles - return true
91 foreach ($array as $key => $value) {
92 if (in_array($value, $user->roles
)) {
103 public function isModulePermissionSupported() {
110 public function upgradePermissions($permissions) {
111 if (empty($permissions)) {
112 throw new CRM_Core_Exception("Cannot upgrade permissions: permission list missing");
114 $query = db_delete('role_permission')
115 ->condition('module', 'civicrm')
116 ->condition('permission', array_keys($permissions), 'NOT IN');
121 * Get all the contact emails for users that have a specific permission.
123 * @param string $permissionName
124 * Name of the permission we are interested in.
127 * a comma separated list of email addresses
129 public function permissionEmails($permissionName) {
132 if (isset($_cache[$permissionName])) {
133 return $_cache[$permissionName];
138 SELECT {users}.uid, {role_permission}.permission
141 ON {users}.uid = {users_roles}.uid
142 JOIN {role_permission}
143 ON {role_permission}.rid = {users_roles}.rid
144 WHERE {role_permission}.permission = '{$permissionName}'
145 AND {users}.status = 1
148 $result = db_query($sql);
149 foreach ($result as $record) {
150 $uids[] = $record->uid
;
153 $_cache[$permissionName] = self
::getContactEmails($uids);
154 return $_cache[$permissionName];