3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2014
39 class CRM_Core_Permission_Drupal
extends CRM_Core_Permission_DrupalBase
{
42 * Is this user someone with access for the entire system
46 protected $_viewAdminUser = FALSE;
47 protected $_editAdminUser = FALSE;
50 * Am in in view permission or edit permission?
53 protected $_viewPermission = FALSE;
54 protected $_editPermission = FALSE;
57 * The current set of permissioned groups for the user
61 protected $_viewPermissionedGroups;
62 protected $_editPermissionedGroups;
66 * Given a permission string, check for access requirements
68 * @param string $str the permission to check
70 * @param int $contactID
72 * @return boolean true if yes, else false
75 function check($str, $contactID = NULL) {
76 $str = $this->translatePermission($str, 'Drupal', array(
77 'view user account' => 'access user profiles',
78 'administer users' => 'administer users',
80 if ($str == CRM_Core_Permission
::ALWAYS_DENY_PERMISSION
) {
83 if ($str == CRM_Core_Permission
::ALWAYS_ALLOW_PERMISSION
) {
86 if (function_exists('user_access')) {
87 return user_access($str) ?
TRUE : FALSE;
93 * Given a roles array, check for access requirements
95 * @param array $array the roles to check
97 * @return boolean true if yes, else false
100 function checkGroupRole($array) {
101 if (function_exists('user_load') && isset($array)) {
102 $user = user_load( $GLOBALS['user']->uid
);
103 //if giver roles found in user roles - return true
104 foreach ($array as $key => $value) {
105 if (in_array($value, $user->roles
)) {
116 public function isModulePermissionSupported() {
123 function upgradePermissions($permissions) {
124 if (empty($permissions)) {
125 throw new CRM_Core_Exception("Cannot upgrade permissions: permission list missing");
127 $query = db_delete('role_permission')
128 ->condition('module', 'civicrm')
129 ->condition('permission', array_keys($permissions), 'NOT IN');
134 * Get all the contact emails for users that have a specific permission
136 * @param string $permissionName name of the permission we are interested in
138 * @return string a comma separated list of email addresses
140 public function permissionEmails($permissionName) {
141 static $_cache = array();
143 if (isset($_cache[$permissionName])) {
144 return $_cache[$permissionName];
149 SELECT {users}.uid, {role_permission}.permission
152 ON {users}.uid = {users_roles}.uid
153 JOIN {role_permission}
154 ON {role_permission}.rid = {users_roles}.rid
155 WHERE {role_permission}.permission = '{$permissionName}'
156 AND {users}.status = 1
159 $result = db_query($sql);
160 foreach ( $result as $record ) {
161 $uids[] = $record->uid
;
164 $_cache[$permissionName] = self
::getContactEmails($uids);
165 return $_cache[$permissionName];