Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
06b69b18 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
6a488035 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 | |
06b69b18 | 31 | * @copyright CiviCRM LLC (c) 2004-2014 |
6a488035 TO |
32 | * $Id$ |
33 | * | |
34 | */ | |
35 | ||
36 | /** | |
37 | * | |
38 | */ | |
39 | class CRM_Core_Permission_Base { | |
40 | ||
dcbec360 EM |
41 | // permission mapping to stub check() calls |
42 | public $permissions = NULL; | |
43 | ||
085823c1 TO |
44 | /** |
45 | * Translate permission | |
46 | * | |
77b97be7 | 47 | * @param $perm |
085823c1 | 48 | * @param string $nativePrefix |
6a0b768e TO |
49 | * @param array $map |
50 | * Array($portableName => $nativeName). | |
77b97be7 EM |
51 | * |
52 | * @internal param string $name e.g. "administer CiviCRM", "cms:access user record", "Drupal:administer content", "Joomla:action:com_asset" | |
085823c1 TO |
53 | * @return NULL|string a permission name |
54 | */ | |
55 | public function translatePermission($perm, $nativePrefix, $map) { | |
56 | list ($civiPrefix, $name) = CRM_Utils_String::parsePrefix(':', $perm, NULL); | |
57 | switch ($civiPrefix) { | |
58 | case $nativePrefix: | |
2aa397bc TO |
59 | return $name; |
60 | ||
61 | // pass through | |
085823c1 TO |
62 | case 'cms': |
63 | return CRM_Utils_Array::value($name, $map, CRM_Core_Permission::ALWAYS_DENY_PERMISSION); | |
2aa397bc | 64 | |
085823c1 TO |
65 | case NULL: |
66 | return $name; | |
2aa397bc | 67 | |
085823c1 TO |
68 | default: |
69 | return CRM_Core_Permission::ALWAYS_DENY_PERMISSION; | |
70 | } | |
71 | } | |
72 | ||
42762e35 | 73 | /** |
100fef9d | 74 | * Get the current permission of this user |
42762e35 | 75 | * |
a6c01b45 CW |
76 | * @return string |
77 | * the permission of the user (edit or view or null) | |
42762e35 DL |
78 | */ |
79 | public function getPermission() { | |
80 | return CRM_Core_Permission::EDIT; | |
81 | } | |
82 | ||
6a488035 TO |
83 | /** |
84 | * Get the permissioned where clause for the user | |
85 | * | |
6a0b768e TO |
86 | * @param int $type |
87 | * The type of permission needed. | |
88 | * @param array $tables | |
89 | * (reference ) add the tables that are needed for the select clause. | |
90 | * @param array $whereTables | |
91 | * (reference ) add the tables that are needed for the where clause. | |
6a488035 | 92 | * |
a6c01b45 CW |
93 | * @return string |
94 | * the group where clause for this user | |
6a488035 TO |
95 | */ |
96 | public function whereClause($type, &$tables, &$whereTables) { | |
97 | return '( 1 )'; | |
98 | } | |
353ffa53 | 99 | |
6a488035 TO |
100 | /** |
101 | * Get the permissioned where clause for the user when trying to see groups | |
102 | * | |
6a0b768e TO |
103 | * @param int $type |
104 | * The type of permission needed. | |
105 | * @param array $tables | |
106 | * (reference ) add the tables that are needed for the select clause. | |
107 | * @param array $whereTables | |
108 | * (reference ) add the tables that are needed for the where clause. | |
6a488035 | 109 | * |
a6c01b45 CW |
110 | * @return string |
111 | * the group where clause for this user | |
6a488035 TO |
112 | */ |
113 | public function getPermissionedStaticGroupClause($type, &$tables, &$whereTables) { | |
114 | $this->group(); | |
115 | return $this->groupClause($type, $tables, $whereTables); | |
116 | } | |
77b97be7 | 117 | |
6a488035 TO |
118 | /** |
119 | * Get all groups from database, filtered by permissions | |
120 | * for this user | |
121 | * | |
6a0b768e TO |
122 | * @param string $groupType |
123 | * Type of group(Access/Mailing). | |
77b97be7 | 124 | * @param bool|\boolen $excludeHidden exclude hidden groups. |
6a488035 | 125 | * |
6a488035 | 126 | * |
a6c01b45 CW |
127 | * @return array |
128 | * array reference of all groups. | |
6a488035 TO |
129 | */ |
130 | public function group($groupType = NULL, $excludeHidden = TRUE) { | |
42762e35 | 131 | return CRM_Core_PseudoConstant::allGroup($groupType, $excludeHidden); |
6a488035 TO |
132 | } |
133 | ||
134 | /** | |
42762e35 | 135 | * Get group clause for this user |
6a488035 | 136 | * |
6a0b768e TO |
137 | * @param int $type |
138 | * The type of permission needed. | |
139 | * @param array $tables | |
140 | * (reference ) add the tables that are needed for the select clause. | |
141 | * @param array $whereTables | |
142 | * (reference ) add the tables that are needed for the where clause. | |
6a488035 | 143 | * |
a6c01b45 CW |
144 | * @return string |
145 | * the group where clause for this user | |
6a488035 TO |
146 | */ |
147 | public function groupClause($type, &$tables, &$whereTables) { | |
42762e35 | 148 | return ' (1) '; |
6a488035 TO |
149 | } |
150 | ||
151 | /** | |
100fef9d | 152 | * Given a permission string, check for access requirements |
6a488035 | 153 | * |
6a0b768e TO |
154 | * @param string $str |
155 | * The permission to check. | |
6a488035 | 156 | * |
a6c01b45 CW |
157 | * @return boolean |
158 | * true if yes, else false | |
6a488035 TO |
159 | */ |
160 | ||
00be9182 | 161 | public function check($str) { |
42762e35 | 162 | //no default behaviour |
6a488035 TO |
163 | } |
164 | ||
165 | /** | |
166 | * Given a roles array, check for access requirements | |
167 | * | |
6a0b768e TO |
168 | * @param array $array |
169 | * The roles to check. | |
6a488035 | 170 | * |
a6c01b45 CW |
171 | * @return boolean |
172 | * true if yes, else false | |
6a488035 | 173 | */ |
42762e35 | 174 | |
00be9182 | 175 | public function checkGroupRole($array) { |
6a488035 TO |
176 | return FALSE; |
177 | } | |
178 | ||
179 | /** | |
180 | * Get all the contact emails for users that have a specific permission | |
181 | * | |
6a0b768e TO |
182 | * @param string $permissionName |
183 | * Name of the permission we are interested in. | |
6a488035 | 184 | * |
a6c01b45 CW |
185 | * @return string |
186 | * a comma separated list of email addresses | |
6a488035 TO |
187 | */ |
188 | public function permissionEmails($permissionName) { | |
189 | CRM_Core_Error::fatal("this function only works in Drupal 6 at the moment"); | |
190 | } | |
191 | ||
192 | /** | |
193 | * Get all the contact emails for users that have a specific role | |
194 | * | |
6a0b768e TO |
195 | * @param string $roleName |
196 | * Name of the role we are interested in. | |
6a488035 | 197 | * |
a6c01b45 CW |
198 | * @return string |
199 | * a comma separated list of email addresses | |
6a488035 TO |
200 | */ |
201 | public function roleEmails($roleName) { | |
202 | CRM_Core_Error::fatal("this function only works in Drupal 6 at the moment"); | |
203 | } | |
204 | ||
7fccad46 TO |
205 | /** |
206 | * Determine whether the permission store allows us to store | |
207 | * a list of permissions generated dynamically (eg by | |
208 | * hook_civicrm_permissions.) | |
209 | * | |
210 | * @return bool | |
211 | */ | |
212 | public function isModulePermissionSupported() { | |
213 | return FALSE; | |
214 | } | |
215 | ||
6a488035 | 216 | /** |
0d8fc497 TO |
217 | * Ensure that the CMS supports all the permissions defined by CiviCRM |
218 | * and its extensions. If there are stale permissions, they should be | |
219 | * deleted. This is useful during module upgrade when the newer module | |
220 | * version has removed permission that were defined in the older version. | |
c4bc14ed | 221 | * |
6a0b768e TO |
222 | * @param array $permissions |
223 | * Same format as CRM_Core_Permission::getCorePermissions(). | |
77b97be7 EM |
224 | * |
225 | * @throws CRM_Core_Exception | |
c4bc14ed | 226 | * @see CRM_Core_Permission::getCorePermissions |
6a488035 | 227 | */ |
00be9182 | 228 | public function upgradePermissions($permissions) { |
7fccad46 | 229 | throw new CRM_Core_Exception("Unimplemented method: CRM_Core_Permission_*::upgradePermissions"); |
6a488035 TO |
230 | } |
231 | ||
232 | /** | |
233 | * Get the permissions defined in the hook_civicrm_permission implementation | |
234 | * of the given module. | |
235 | * | |
789565bf TO |
236 | * Note: At time of writing, this is only used with native extension-modules, so |
237 | * there's one, predictable calling convention (regardless of CMS). | |
238 | * | |
77b97be7 EM |
239 | * @param $module |
240 | * | |
a6c01b45 CW |
241 | * @return Array |
242 | * of permissions, in the same format as CRM_Core_Permission::getCorePermissions(). | |
b57fc2e3 | 243 | * @see CRM_Core_Permission::getCorePermissions |
6a488035 | 244 | */ |
00be9182 | 245 | public static function getModulePermissions($module) { |
789565bf TO |
246 | $return_permissions = array(); |
247 | $fn_name = "{$module}_civicrm_permission"; | |
248 | if (function_exists($fn_name)) { | |
249 | $module_permissions = array(); | |
250 | $fn_name($module_permissions); | |
251 | $return_permissions = $module_permissions; | |
252 | } | |
253 | return $return_permissions; | |
6a488035 TO |
254 | } |
255 | ||
256 | /** | |
257 | * Get the permissions defined in the hook_civicrm_permission implementation | |
258 | * in all enabled CiviCRM module extensions. | |
259 | * | |
a6c01b45 CW |
260 | * @return Array |
261 | * of permissions, in the same format as CRM_Core_Permission::getCorePermissions(). | |
6a488035 | 262 | */ |
00be9182 | 263 | public function getAllModulePermissions() { |
6a488035 TO |
264 | $permissions = array(); |
265 | CRM_Utils_Hook::permission($permissions); | |
266 | return $permissions; | |
267 | } | |
268 | } |