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_Backdrop
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?
38 protected $_viewPermission = FALSE;
39 protected $_editPermission = FALSE;
42 * The current set of permissioned groups for the user.
46 protected $_viewPermissionedGroups;
47 protected $_editPermissionedGroups;
50 * Given a permission string, check for access requirements
53 * The permission to check.
58 * true if yes, else false
60 public function check($str, $userId = NULL) {
61 $str = $this->translatePermission($str, 'Drupal', [
62 'view user account' => 'access user profiles',
63 'administer users' => 'administer users',
65 if ($str == CRM_Core_Permission
::ALWAYS_DENY_PERMISSION
) {
68 if ($str == CRM_Core_Permission
::ALWAYS_ALLOW_PERMISSION
) {
71 if (function_exists('user_access')) {
74 $account = user_load($userId);
76 return user_access($str, $account);
82 * Given a roles array, check for access requirements
88 * true if yes, else false
90 public function checkGroupRole($array) {
91 if (function_exists('user_load') && isset($array)) {
92 $user = user_load($GLOBALS['user']->uid
);
93 //if giver roles found in user roles - return true
94 foreach ($array as $key => $value) {
95 if (in_array($value, $user->roles
)) {
106 public function isModulePermissionSupported() {
113 public function upgradePermissions($permissions) {
114 if (empty($permissions)) {
115 throw new CRM_Core_Exception("Cannot upgrade permissions: permission list missing");
119 $query = db_delete('role_permission')
120 ->condition('module', 'civicrm')
121 ->condition('permission', array_keys($permissions), 'NOT IN');
127 * Get all the contact emails for users that have a specific permission.
129 * @param string $permissionName
130 * Name of the permission we are interested in.
133 * a comma separated list of email addresses
135 public function permissionEmails($permissionName) {
138 if (isset($_cache[$permissionName])) {
139 return $_cache[$permissionName];
146 * SELECT {users}.uid, {role_permission}.permission
149 * ON {users}.uid = {users_roles}.uid
150 * JOIN {role_permission}
151 * ON {role_permission}.rid = {users_roles}.rid
152 * WHERE {role_permission}.permission = '{$permissionName}'
153 * AND {users}.status = 1
156 * $result = db_query($sql);
157 * foreach ($result as $record) {
158 * $uids[] = $record->uid;
161 * $_cache[$permissionName] = self::getContactEmails($uids);
162 * return $_cache[$permissionName];