4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.6 |
6 +--------------------------------------------------------------------+
7 | Copyright CiviCRM LLC (c) 2004-2014 |
8 +--------------------------------------------------------------------+
9 | This file is a part of CiviCRM. |
11 | CiviCRM is free software; you can copy, modify, and distribute it |
12 | under the terms of the GNU Affero General Public License |
13 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
15 | CiviCRM is distributed in the hope that it will be useful, but |
16 | WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
18 | See the GNU Affero General Public License for more details. |
20 | You should have received a copy of the GNU Affero General Public |
21 | License and the CiviCRM Licensing Exception along |
22 | with this program; if not, contact CiviCRM LLC |
23 | at info[AT]civicrm[DOT]org. If you have questions about the |
24 | GNU Affero General Public License or the licensing of CiviCRM, |
25 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
26 +--------------------------------------------------------------------+
30 * Decide what permissions to check for an api call
31 * The contact must have all of the returned permissions for the api call to be allowed
33 * @param $entity : (str) api entity
34 * @param $action : (str) api action
35 * @param $params : (array) api params
38 * of permissions to check for this entity-action combo
40 function _civicrm_api3_permissions($entity, $action, &$params) {
41 $entity = _civicrm_api_get_entity_name_from_camel($entity);
42 $action = strtolower($action);
45 * @var array of permissions
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
56 * Note: some APIs declare other actions as well
58 $permissions = array();
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'),
70 $permissions['attachment'] = array(
71 'default' => array('access CiviCRM', 'access AJAX API'),
74 // Contact permissions
75 $permissions['contact'] = array(
84 // managed by query object
91 array('access CiviCRM', 'access AJAX API'),
95 // Contact-related data permissions.
96 // CRM-14094 - Users can edit and delete contact-related objects using inline edit with 'edit all contacts' permission
97 $permissions['address'] = array(
107 $permissions['email'] = $permissions['address'];
108 $permissions['phone'] = $permissions['address'];
109 $permissions['website'] = $permissions['address'];
110 $permissions['im'] = $permissions['address'];
111 $permissions['loc_block'] = $permissions['address'];
112 $permissions['entity_tag'] = $permissions['address'];
113 $permissions['note'] = $permissions['address'];
115 //relationship permissions
116 $permissions['relationship'] = array(
131 // Activity permissions
132 $permissions['activity'] = array(
139 'view all activities',
144 $permissions['case'] = array(
151 'delete in CiviCase',
155 'access all cases and activities',
159 // Financial permissions
160 $permissions['contribution'] = array(
163 'access CiviContribute',
167 'access CiviContribute',
168 'delete in CiviContribute',
170 'completetransaction' => array(
171 'edit contributions',
175 'access CiviContribute',
176 'edit contributions',
179 $permissions['line_item'] = $permissions['contribution'];
181 // Custom field permissions
182 $permissions['custom_field'] = array(
184 'administer CiviCRM',
185 'access all custom data',
188 $permissions['custom_group'] = $permissions['custom_field'];
191 $permissions['event'] = array(
200 'delete in CiviEvent',
215 $permissions['file'] = array(
218 'access uploaded files',
221 $permissions['files_by_entity'] = $permissions['file'];
224 $permissions['group'] = array(
233 $permissions['group_contact'] = $permissions['group'];
234 $permissions['group_nesting'] = $permissions['group'];
235 $permissions['group_organization'] = $permissions['group'];
237 // CiviMail Permissions
238 $permissions['mailing'] = array(
246 'delete in CiviMail',
254 // Membership permissions
255 $permissions['membership'] = array(
263 'delete in CiviMember',
271 $permissions['membership_status'] = $permissions['membership'];
272 $permissions['membership_type'] = $permissions['membership'];
273 $permissions['membership_payment'] = array(
278 'access CiviContribute',
279 'edit contributions',
284 'delete in CiviMember',
285 'access CiviContribute',
286 'delete in CiviContribute',
291 'access CiviContribute',
297 'access CiviContribute',
298 'edit contributions',
302 // Participant permissions
303 $permissions['participant'] = array(
307 'register for events',
312 'edit event participants',
317 'view event participants',
322 'edit event participants',
325 $permissions['participant_payment'] = array(
329 'register for events',
330 'access CiviContribute',
331 'edit contributions',
336 'edit event participants',
337 'access CiviContribute',
338 'delete in CiviContribute',
343 'view event participants',
344 'access CiviContribute',
349 'edit event participants',
350 'access CiviContribute',
351 'edit contributions',
355 // Pledge permissions
356 $permissions['pledge'] = array(
365 'delete in CiviPledge',
377 $permissions['pledge_payment'] = array(
382 'access CiviContribute',
383 'edit contributions',
388 'delete in CiviPledge',
389 'access CiviContribute',
390 'delete in CiviContribute',
395 'access CiviContribute',
401 'access CiviContribute',
402 'edit contributions',
406 // Profile permissions
407 $permissions['profile'] = array(
408 'get' => array(), // the profile will take care of this
411 $permissions['uf_group'] = array(
416 $permissions['uf_field'] = $permissions['uf_group'];
417 $permissions['option_value'] = $permissions['uf_group'];
418 $permissions['option_group'] = $permissions['option_value'];
420 // Translate 'create' action to 'update' if id is set
421 if ($action == 'create' && (!empty($params['id']) ||
!empty($params[$entity . '_id']))) {
425 // let third parties modify the permissions
426 CRM_Utils_Hook
::alterAPIPermissions($entity, $action, $params, $permissions);
428 // Merge permissions for this entity with the defaults
429 $perm = CRM_Utils_Array
::value($entity, $permissions, array()) +
$permissions['default'];
431 // Return exact match if permission for this action has been declared
432 if (isset($perm[$action])) {
433 return $perm[$action];
436 // Translate specific actions into their generic equivalents
437 $snippet = substr($action, 0, 3);
438 if ($action == 'replace' ||
$snippet == 'del') {
439 // 'Replace' is a combination of get+create+update+delete; however, the permissions
440 // on each of those will be tested separately at runtime. This is just a sniff-test
441 // based on the heuristic that 'delete' tends to be the most closesly guarded
442 // of the necessary permissions.
445 elseif ($action == 'setvalue' ||
$snippet == 'upd') {
448 elseif ($action == 'getfields' ||
$action == 'getspec' ||
$action == 'getoptions') {
451 elseif ($snippet == 'get') {
454 return isset($perm[$action]) ?
$perm[$action] : $perm['default'];
457 # FIXME: not sure how to permission the following API 3 calls:
458 # contribution_transact (make online contributions)
460 # group_contact_pending
461 # group_contact_update_status
462 # mailing_event_bounce
463 # mailing_event_click
464 # mailing_event_confirm
465 # mailing_event_forward
467 # mailing_event_reply
468 # mailing_group_event_domain_unsubscribe
469 # mailing_group_event_resubscribe
470 # mailing_group_event_subscribe
471 # mailing_group_event_unsubscribe
472 # membership_status_calc
473 # survey_respondant_count