CRM-16915 - Filter Profile selector in Configure Event - Registration tab for non...
[civicrm-core.git] / CRM / Core / DAO / permissions.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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 * Decide what permissions to check for an api call
30 * The contact must have all of the returned permissions for the api call to be allowed
31 *
32 * @param $entity : (str) api entity
33 * @param $action : (str) api action
34 * @param $params : (array) api params
35 *
36 * @return array
37 * Array of permissions to check for this entity-action combo
38 */
39 function _civicrm_api3_permissions($entity, $action, &$params) {
40 // FIXME: Lowercase entity_names are nonstandard but difficult to fix here
41 // because this function invokes hook_civicrm_alterAPIPermissions
42 $entity = _civicrm_api_get_entity_name_from_camel($entity);
43
44 /**
45 * @var array of permissions
46 *
47 * For each entity, we declare an array of permissions required for each action
48 * The action is the array key, possible values:
49 * * create: applies to create (with no id in params)
50 * * update: applies to update, setvalue, create (with id in params)
51 * * get: applies to getcount, getsingle, getvalue and other gets
52 * * delete: applies to delete, replace
53 * * meta: applies to getfields, getoptions, getspec
54 * * default: catch-all for anything not declared
55 *
56 * Note: some APIs declare other actions as well
57 */
58 $permissions = array();
59
60 // These are the default permissions - if any entity does not declare permissions for a given action,
61 // (or the entity does not declare permissions at all) - then the action will be used from here
62 $permissions['default'] = array(
63 // applies to getfields, getoptions, etc.
64 'meta' => array('access CiviCRM'),
65 // catch-all, applies to create, get, delete, etc.
66 // If an entity declares it's own 'default' action it will override this one
67 'default' => array('administer CiviCRM'),
68 );
69
70 // Note: Additional permissions in DynamicFKAuthorization
71 $permissions['attachment'] = array(
72 'default' => array(
73 array('access CiviCRM', 'access AJAX API'),
74 ),
75 );
76
77 // Contact permissions
78 $permissions['contact'] = array(
79 'create' => array(
80 'access CiviCRM',
81 'add contacts',
82 ),
83 'delete' => array(
84 'access CiviCRM',
85 'delete contacts',
86 ),
87 // managed by query object
88 'get' => array(),
89 'update' => array(
90 'access CiviCRM',
91 'edit all contacts',
92 ),
93 'getquick' => array(
94 array('access CiviCRM', 'access AJAX API'),
95 ),
96 );
97
98 // Contact-related data permissions.
99 // CRM-14094 - Users can edit and delete contact-related objects using inline edit with 'edit all contacts' permission
100 $permissions['address'] = array(
101 'get' => array(
102 'access CiviCRM',
103 'view all contacts',
104 ),
105 'default' => array(
106 'access CiviCRM',
107 'edit all contacts',
108 ),
109 );
110 $permissions['email'] = $permissions['address'];
111 $permissions['phone'] = $permissions['address'];
112 $permissions['website'] = $permissions['address'];
113 $permissions['im'] = $permissions['address'];
114 $permissions['loc_block'] = $permissions['address'];
115 $permissions['entity_tag'] = $permissions['address'];
116 $permissions['note'] = $permissions['address'];
117
118 // Allow non-admins to get and create tags to support tagset widget
119 // Delete is still reserved for admins
120 $permissions['tag'] = array(
121 'get' => array('access CiviCRM'),
122 'create' => array('access CiviCRM'),
123 'update' => array('access CiviCRM'),
124 );
125
126 //relationship permissions
127 $permissions['relationship'] = array(
128 'get' => array(
129 'access CiviCRM',
130 'view all contacts',
131 ),
132 'delete' => array(
133 'access CiviCRM',
134 'delete contacts',
135 ),
136 'default' => array(
137 'access CiviCRM',
138 'edit all contacts',
139 ),
140 );
141
142 // Activity permissions
143 $permissions['activity'] = array(
144 'delete' => array(
145 'access CiviCRM',
146 'delete activities',
147 ),
148 'default' => array(
149 'access CiviCRM',
150 'view all activities',
151 ),
152 );
153
154 // Case permissions
155 $permissions['case'] = array(
156 'create' => array(
157 'access CiviCRM',
158 'add cases',
159 ),
160 'delete' => array(
161 'access CiviCRM',
162 'delete in CiviCase',
163 ),
164 'default' => array(
165 'access CiviCRM',
166 'access all cases and activities',
167 ),
168 );
169
170 // Financial permissions
171 $permissions['contribution'] = array(
172 'get' => array(
173 'access CiviCRM',
174 'access CiviContribute',
175 ),
176 'delete' => array(
177 'access CiviCRM',
178 'access CiviContribute',
179 'delete in CiviContribute',
180 ),
181 'completetransaction' => array(
182 'edit contributions',
183 ),
184 'default' => array(
185 'access CiviCRM',
186 'access CiviContribute',
187 'edit contributions',
188 ),
189 );
190 $permissions['line_item'] = $permissions['contribution'];
191
192 // Custom field permissions
193 $permissions['custom_field'] = array(
194 'default' => array(
195 'administer CiviCRM',
196 'access all custom data',
197 ),
198 );
199 $permissions['custom_group'] = $permissions['custom_field'];
200
201 // Event permissions
202 $permissions['event'] = array(
203 'create' => array(
204 'access CiviCRM',
205 'access CiviEvent',
206 'edit all events',
207 ),
208 'delete' => array(
209 'access CiviCRM',
210 'access CiviEvent',
211 'delete in CiviEvent',
212 ),
213 'get' => array(
214 'access CiviCRM',
215 'access CiviEvent',
216 'view event info',
217 ),
218 'update' => array(
219 'access CiviCRM',
220 'access CiviEvent',
221 'edit all events',
222 ),
223 );
224
225 // File permissions
226 $permissions['file'] = array(
227 'default' => array(
228 'access CiviCRM',
229 'access uploaded files',
230 ),
231 );
232 $permissions['files_by_entity'] = $permissions['file'];
233
234 // Group permissions
235 $permissions['group'] = array(
236 'get' => array(
237 'access CiviCRM',
238 ),
239 'default' => array(
240 'access CiviCRM',
241 'edit groups',
242 ),
243 );
244
245 $permissions['group_nesting'] = $permissions['group'];
246 $permissions['group_organization'] = $permissions['group'];
247
248 //Group Contact permission
249 $permissions['group_contact'] = array(
250 'get' => array(
251 'access CiviCRM',
252 ),
253 'default' => array(
254 'access CiviCRM',
255 'edit all contacts',
256 ),
257 );
258
259 // CiviMail Permissions
260 $civiMailBasePerms = array(
261 // To get/preview/update, one must have least one of these perms:
262 // Mailing API implementations enforce nuances of create/approve/schedule permissions.
263 'access CiviMail',
264 'create mailings',
265 'schedule mailings',
266 'approve mailings',
267 );
268 $permissions['mailing'] = array(
269 'get' => array(
270 'access CiviCRM',
271 $civiMailBasePerms,
272 ),
273 'delete' => array(
274 'access CiviCRM',
275 $civiMailBasePerms,
276 'delete in CiviMail',
277 ),
278 'submit' => array(
279 'access CiviCRM',
280 array('access CiviMail', 'schedule mailings'),
281 ),
282 'default' => array(
283 'access CiviCRM',
284 $civiMailBasePerms,
285 ),
286 );
287 $permissions['mailing_group'] = $permissions['mailing'];
288 $permissions['mailing_job'] = $permissions['mailing'];
289 $permissions['mailing_recipients'] = $permissions['mailing'];
290
291 $permissions['mailing_a_b'] = array(
292 'get' => array(
293 'access CiviCRM',
294 'access CiviMail',
295 ),
296 'delete' => array(
297 'access CiviCRM',
298 'access CiviMail',
299 'delete in CiviMail',
300 ),
301 'submit' => array(
302 'access CiviCRM',
303 array('access CiviMail', 'schedule mailings'),
304 ),
305 'default' => array(
306 'access CiviCRM',
307 'access CiviMail',
308 ),
309 );
310
311 // Membership permissions
312 $permissions['membership'] = array(
313 'get' => array(
314 'access CiviCRM',
315 'access CiviMember',
316 ),
317 'delete' => array(
318 'access CiviCRM',
319 'access CiviMember',
320 'delete in CiviMember',
321 ),
322 'default' => array(
323 'access CiviCRM',
324 'access CiviMember',
325 'edit memberships',
326 ),
327 );
328 $permissions['membership_status'] = $permissions['membership'];
329 $permissions['membership_type'] = $permissions['membership'];
330 $permissions['membership_payment'] = array(
331 'create' => array(
332 'access CiviCRM',
333 'access CiviMember',
334 'edit memberships',
335 'access CiviContribute',
336 'edit contributions',
337 ),
338 'delete' => array(
339 'access CiviCRM',
340 'access CiviMember',
341 'delete in CiviMember',
342 'access CiviContribute',
343 'delete in CiviContribute',
344 ),
345 'get' => array(
346 'access CiviCRM',
347 'access CiviMember',
348 'access CiviContribute',
349 ),
350 'update' => array(
351 'access CiviCRM',
352 'access CiviMember',
353 'edit memberships',
354 'access CiviContribute',
355 'edit contributions',
356 ),
357 );
358
359 // Participant permissions
360 $permissions['participant'] = array(
361 'create' => array(
362 'access CiviCRM',
363 'access CiviEvent',
364 'register for events',
365 ),
366 'delete' => array(
367 'access CiviCRM',
368 'access CiviEvent',
369 'edit event participants',
370 ),
371 'get' => array(
372 'access CiviCRM',
373 'access CiviEvent',
374 'view event participants',
375 ),
376 'update' => array(
377 'access CiviCRM',
378 'access CiviEvent',
379 'edit event participants',
380 ),
381 );
382 $permissions['participant_payment'] = array(
383 'create' => array(
384 'access CiviCRM',
385 'access CiviEvent',
386 'register for events',
387 'access CiviContribute',
388 'edit contributions',
389 ),
390 'delete' => array(
391 'access CiviCRM',
392 'access CiviEvent',
393 'edit event participants',
394 'access CiviContribute',
395 'delete in CiviContribute',
396 ),
397 'get' => array(
398 'access CiviCRM',
399 'access CiviEvent',
400 'view event participants',
401 'access CiviContribute',
402 ),
403 'update' => array(
404 'access CiviCRM',
405 'access CiviEvent',
406 'edit event participants',
407 'access CiviContribute',
408 'edit contributions',
409 ),
410 );
411
412 // Pledge permissions
413 $permissions['pledge'] = array(
414 'create' => array(
415 'access CiviCRM',
416 'access CiviPledge',
417 'edit pledges',
418 ),
419 'delete' => array(
420 'access CiviCRM',
421 'access CiviPledge',
422 'delete in CiviPledge',
423 ),
424 'get' => array(
425 'access CiviCRM',
426 'access CiviPledge',
427 ),
428 'update' => array(
429 'access CiviCRM',
430 'access CiviPledge',
431 'edit pledges',
432 ),
433 );
434
435 //CRM-16777: Disable schedule reminder for user that have 'edit all events' and 'administer CiviCRM' permission.
436 $permissions['action_schedule'] = array(
437 'update' => array(
438 array(
439 'access CiviCRM',
440 'edit all events',
441 ),
442 ),
443 );
444
445 $permissions['pledge_payment'] = array(
446 'create' => array(
447 'access CiviCRM',
448 'access CiviPledge',
449 'edit pledges',
450 'access CiviContribute',
451 'edit contributions',
452 ),
453 'delete' => array(
454 'access CiviCRM',
455 'access CiviPledge',
456 'delete in CiviPledge',
457 'access CiviContribute',
458 'delete in CiviContribute',
459 ),
460 'get' => array(
461 'access CiviCRM',
462 'access CiviPledge',
463 'access CiviContribute',
464 ),
465 'update' => array(
466 'access CiviCRM',
467 'access CiviPledge',
468 'edit pledges',
469 'access CiviContribute',
470 'edit contributions',
471 ),
472 );
473
474 // Profile permissions
475 $permissions['profile'] = array(
476 'get' => array(), // the profile will take care of this
477 );
478
479 $permissions['uf_group'] = array(
480 'create' => array(
481 'access CiviCRM',
482 array(
483 'administer CiviCRM',
484 'manage event profiles',
485 ),
486 ),
487 'get' => array(
488 'access CiviCRM',
489 ),
490 'update' => array(
491 'access CiviCRM',
492 array(
493 'administer CiviCRM',
494 'manage event profiles',
495 ),
496 ),
497 );
498 $permissions['uf_field'] = $permissions['uf_join'] = $permissions['uf_group'];
499 $permissions['uf_field']['delete'] = array(
500 'access CiviCRM',
501 array(
502 'administer CiviCRM',
503 'manage event profiles',
504 ),
505 );
506 $permissions['option_value'] = $permissions['uf_group'];
507 $permissions['option_group'] = $permissions['option_value'];
508
509 // Translate 'create' action to 'update' if id is set
510 if ($action == 'create' && (!empty($params['id']) || !empty($params[$entity . '_id']))) {
511 $action = 'update';
512 }
513
514 // let third parties modify the permissions
515 CRM_Utils_Hook::alterAPIPermissions($entity, $action, $params, $permissions);
516
517 // Merge permissions for this entity with the defaults
518 $perm = CRM_Utils_Array::value($entity, $permissions, array()) + $permissions['default'];
519
520 // Return exact match if permission for this action has been declared
521 if (isset($perm[$action])) {
522 return $perm[$action];
523 }
524
525 // Translate specific actions into their generic equivalents
526 $snippet = substr($action, 0, 3);
527 if ($action == 'replace' || $snippet == 'del') {
528 // 'Replace' is a combination of get+create+update+delete; however, the permissions
529 // on each of those will be tested separately at runtime. This is just a sniff-test
530 // based on the heuristic that 'delete' tends to be the most closesly guarded
531 // of the necessary permissions.
532 $action = 'delete';
533 }
534 elseif ($action == 'setvalue' || $snippet == 'upd') {
535 $action = 'update';
536 }
537 elseif ($action == 'getfields' || $action == 'getspec' || $action == 'getoptions') {
538 $action = 'meta';
539 }
540 elseif ($snippet == 'get') {
541 $action = 'get';
542 }
543 return isset($perm[$action]) ? $perm[$action] : $perm['default'];
544 }
545
546 # FIXME: not sure how to permission the following API 3 calls:
547 # contribution_transact (make online contributions)
548 # entity_tag_display
549 # group_contact_pending
550 # group_contact_update_status
551 # mailing_event_bounce
552 # mailing_event_click
553 # mailing_event_confirm
554 # mailing_event_forward
555 # mailing_event_open
556 # mailing_event_reply
557 # mailing_group_event_domain_unsubscribe
558 # mailing_group_event_resubscribe
559 # mailing_group_event_subscribe
560 # mailing_group_event_unsubscribe
561 # membership_status_calc
562 # survey_respondant_count