Commit | Line | Data |
---|---|---|
84fce21c TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
fee14197 | 4 | | CiviCRM version 5 | |
84fce21c | 5 | +--------------------------------------------------------------------+ |
6b83d5bd | 6 | | Copyright CiviCRM LLC (c) 2004-2019 | |
84fce21c TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
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. | | |
13 | | | | |
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. | | |
18 | | | | |
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 | +--------------------------------------------------------------------+ | |
26 | */ | |
27 | ||
28 | /** | |
29 | * | |
30 | * @package CRM | |
6b83d5bd | 31 | * @copyright CiviCRM LLC (c) 2004-2019 |
84fce21c TO |
32 | * $Id$ |
33 | * | |
34 | */ | |
35 | ||
36 | /** | |
37 | * | |
38 | */ | |
39 | class CRM_Core_Permission_Backdrop extends CRM_Core_Permission_DrupalBase { | |
40 | ||
41 | /** | |
42 | * Is this user someone with access for the entire system. | |
43 | * | |
44 | * @var boolean | |
45 | */ | |
46 | protected $_viewAdminUser = FALSE; | |
47 | protected $_editAdminUser = FALSE; | |
48 | ||
49 | /** | |
50 | * Am in in view permission or edit permission? | |
51 | * @var boolean | |
52 | */ | |
53 | protected $_viewPermission = FALSE; | |
54 | protected $_editPermission = FALSE; | |
55 | ||
56 | /** | |
57 | * The current set of permissioned groups for the user. | |
58 | * | |
59 | * @var array | |
60 | */ | |
61 | protected $_viewPermissionedGroups; | |
62 | protected $_editPermissionedGroups; | |
63 | ||
84fce21c TO |
64 | /** |
65 | * Given a permission string, check for access requirements | |
66 | * | |
67 | * @param string $str | |
68 | * The permission to check. | |
69 | * | |
18be3201 | 70 | * @param int $userId |
84fce21c TO |
71 | * |
72 | * @return bool | |
73 | * true if yes, else false | |
74 | */ | |
18be3201 | 75 | public function check($str, $userId = NULL) { |
be2fb01f | 76 | $str = $this->translatePermission($str, 'Drupal', [ |
84fce21c TO |
77 | 'view user account' => 'access user profiles', |
78 | 'administer users' => 'administer users', | |
be2fb01f | 79 | ]); |
84fce21c TO |
80 | if ($str == CRM_Core_Permission::ALWAYS_DENY_PERMISSION) { |
81 | return FALSE; | |
82 | } | |
83 | if ($str == CRM_Core_Permission::ALWAYS_ALLOW_PERMISSION) { | |
84 | return TRUE; | |
85 | } | |
86 | if (function_exists('user_access')) { | |
18be3201 CW |
87 | $account = NULL; |
88 | if ($userId) { | |
89 | $account = user_load($userId); | |
90 | } | |
91 | return user_access($str, $account); | |
84fce21c TO |
92 | } |
93 | return TRUE; | |
94 | } | |
95 | ||
96 | /** | |
97 | * Given a roles array, check for access requirements | |
98 | * | |
99 | * @param array $array | |
100 | * The roles to check. | |
101 | * | |
102 | * @return bool | |
103 | * true if yes, else false | |
104 | */ | |
105 | public function checkGroupRole($array) { | |
106 | if (function_exists('user_load') && isset($array)) { | |
107 | $user = user_load($GLOBALS['user']->uid); | |
108 | //if giver roles found in user roles - return true | |
109 | foreach ($array as $key => $value) { | |
110 | if (in_array($value, $user->roles)) { | |
111 | return TRUE; | |
112 | } | |
113 | } | |
114 | } | |
115 | return FALSE; | |
116 | } | |
117 | ||
118 | /** | |
119 | * @inheritDoc | |
120 | */ | |
121 | public function isModulePermissionSupported() { | |
122 | return TRUE; | |
123 | } | |
124 | ||
125 | /** | |
126 | * @inheritDoc | |
127 | */ | |
128 | public function upgradePermissions($permissions) { | |
129 | if (empty($permissions)) { | |
130 | throw new CRM_Core_Exception("Cannot upgrade permissions: permission list missing"); | |
131 | } | |
5c6ebf4c TO |
132 | // FIXME!!!! |
133 | /* | |
84fce21c | 134 | $query = db_delete('role_permission') |
5c6ebf4c TO |
135 | ->condition('module', 'civicrm') |
136 | ->condition('permission', array_keys($permissions), 'NOT IN'); | |
84fce21c | 137 | $query->execute(); |
5c6ebf4c | 138 | */ |
84fce21c TO |
139 | } |
140 | ||
141 | /** | |
142 | * Get all the contact emails for users that have a specific permission. | |
143 | * | |
144 | * @param string $permissionName | |
145 | * Name of the permission we are interested in. | |
146 | * | |
147 | * @return string | |
148 | * a comma separated list of email addresses | |
149 | */ | |
150 | public function permissionEmails($permissionName) { | |
be2fb01f | 151 | static $_cache = []; |
84fce21c TO |
152 | |
153 | if (isset($_cache[$permissionName])) { | |
154 | return $_cache[$permissionName]; | |
155 | } | |
156 | ||
5c6ebf4c TO |
157 | // FIXME!!!! |
158 | /** | |
518fa0ee SL |
159 | * $uids = array(); |
160 | * $sql = " | |
161 | * SELECT {users}.uid, {role_permission}.permission | |
162 | * FROM {users} | |
163 | * JOIN {users_roles} | |
164 | * ON {users}.uid = {users_roles}.uid | |
165 | * JOIN {role_permission} | |
166 | * ON {role_permission}.rid = {users_roles}.rid | |
167 | * WHERE {role_permission}.permission = '{$permissionName}' | |
168 | * AND {users}.status = 1 | |
169 | * "; | |
170 | * | |
171 | * $result = db_query($sql); | |
172 | * foreach ($result as $record) { | |
173 | * $uids[] = $record->uid; | |
174 | * } | |
175 | * | |
176 | * $_cache[$permissionName] = self::getContactEmails($uids); | |
177 | * return $_cache[$permissionName]; | |
5c6ebf4c | 178 | */ |
be2fb01f | 179 | return []; |
84fce21c TO |
180 | } |
181 | ||
182 | } |