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_Backdrop
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?
36 protected $_viewPermission = FALSE;
37 protected $_editPermission = FALSE;
40 * The current set of permissioned groups for the user.
44 protected $_viewPermissionedGroups;
45 protected $_editPermissionedGroups;
48 * Given a permission string, check for access requirements
51 * The permission to check.
56 * true if yes, else false
58 public function check($str, $userId = NULL) {
59 $str = $this->translatePermission($str, 'Drupal', [
60 'view user account' => 'access user profiles',
61 'administer users' => 'administer users',
63 if ($str == CRM_Core_Permission
::ALWAYS_DENY_PERMISSION
) {
66 if ($str == CRM_Core_Permission
::ALWAYS_ALLOW_PERMISSION
) {
69 if (function_exists('user_access')) {
72 $account = user_load($userId);
74 return user_access($str, $account);
80 * Given a roles array, check for access requirements
86 * true if yes, else false
88 public function checkGroupRole($array) {
89 if (function_exists('user_load') && isset($array)) {
90 $user = user_load($GLOBALS['user']->uid
);
91 //if giver roles found in user roles - return true
92 foreach ($array as $key => $value) {
93 if (in_array($value, $user->roles
)) {
104 public function isModulePermissionSupported() {
111 public function upgradePermissions($permissions) {
112 if (empty($permissions)) {
113 throw new CRM_Core_Exception("Cannot upgrade permissions: permission list missing");
117 $query = db_delete('role_permission')
118 ->condition('module', 'civicrm')
119 ->condition('permission', array_keys($permissions), 'NOT IN');
125 * Get all the contact emails for users that have a specific permission.
127 * @param string $permissionName
128 * Name of the permission we are interested in.
131 * a comma separated list of email addresses
133 public function permissionEmails($permissionName) {
136 if (isset($_cache[$permissionName])) {
137 return $_cache[$permissionName];
144 * SELECT {users}.uid, {role_permission}.permission
147 * ON {users}.uid = {users_roles}.uid
148 * JOIN {role_permission}
149 * ON {role_permission}.rid = {users_roles}.rid
150 * WHERE {role_permission}.permission = '{$permissionName}'
151 * AND {users}.status = 1
154 * $result = db_query($sql);
155 * foreach ($result as $record) {
156 * $uids[] = $record->uid;
159 * $_cache[$permissionName] = self::getContactEmails($uids);
160 * return $_cache[$permissionName];