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
23 class CRM_Core_Permission_Drupal
extends CRM_Core_Permission_DrupalBase
{
26 * Is this user someone with access for the entire system.
30 protected $_viewAdminUser = FALSE;
31 protected $_editAdminUser = FALSE;
34 * Am in in view permission or edit permission?
37 protected $_viewPermission = FALSE;
38 protected $_editPermission = FALSE;
41 * The current set of permissioned groups for the user.
45 protected $_viewPermissionedGroups;
46 protected $_editPermissionedGroups;
49 * Given a permission string, check for access requirements
52 * The permission to check.
57 * true if yes, else false
59 public function check($str, $userId = NULL) {
60 $str = $this->translatePermission($str, 'Drupal', [
61 'view user account' => 'access user profiles',
62 'administer users' => 'administer users',
64 if ($str == CRM_Core_Permission
::ALWAYS_DENY_PERMISSION
) {
67 if ($str == CRM_Core_Permission
::ALWAYS_ALLOW_PERMISSION
) {
70 if (function_exists('user_access')) {
73 $account = user_load($userId);
75 return user_access($str, $account);
81 * Given a roles array, check for access requirements
87 * true if yes, else false
89 public function checkGroupRole($array) {
90 if (function_exists('user_load') && isset($array)) {
91 $user = user_load($GLOBALS['user']->uid
);
92 //if giver roles found in user roles - return true
93 foreach ($array as $key => $value) {
94 if (in_array($value, $user->roles
)) {
105 public function isModulePermissionSupported() {
112 public function upgradePermissions($permissions) {
113 if (empty($permissions)) {
114 throw new CRM_Core_Exception("Cannot upgrade permissions: permission list missing");
116 $query = db_delete('role_permission')
117 ->condition('module', 'civicrm')
118 ->condition('permission', array_keys($permissions), 'NOT IN');
123 * Get all the contact emails for users that have a specific permission.
125 * @param string $permissionName
126 * Name of the permission we are interested in.
129 * a comma separated list of email addresses
131 public function permissionEmails($permissionName) {
134 if (isset($_cache[$permissionName])) {
135 return $_cache[$permissionName];
140 SELECT {users}.uid, {role_permission}.permission
143 ON {users}.uid = {users_roles}.uid
144 JOIN {role_permission}
145 ON {role_permission}.rid = {users_roles}.rid
146 WHERE {role_permission}.permission = '{$permissionName}'
147 AND {users}.status = 1
150 $result = db_query($sql);
151 foreach ($result as $record) {
152 $uids[] = $record->uid
;
155 $_cache[$permissionName] = self
::getContactEmails($uids);
156 return $_cache[$permissionName];