3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
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 +--------------------------------------------------------------------+
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
32 * @param $entity : (str) api entity
33 * @param $action : (str) api action
34 * @param $params : (array) api params
37 * Array of permissions to check for this entity-action combo
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);
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 // Note: Additional permissions in DynamicFKAuthorization
71 $permissions['attachment'] = array(
73 array('access CiviCRM', 'access AJAX API'),
77 // Contact permissions
78 $permissions['contact'] = array(
87 // managed by query object
94 array('access CiviCRM', 'access AJAX API'),
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(
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'];
118 //relationship permissions
119 $permissions['relationship'] = array(
134 // Activity permissions
135 $permissions['activity'] = array(
142 'view all activities',
147 $permissions['case'] = array(
154 'delete in CiviCase',
158 'access all cases and activities',
162 // Financial permissions
163 $permissions['contribution'] = array(
166 'access CiviContribute',
170 'access CiviContribute',
171 'delete in CiviContribute',
173 'completetransaction' => array(
174 'edit contributions',
178 'access CiviContribute',
179 'edit contributions',
182 $permissions['line_item'] = $permissions['contribution'];
184 // Custom field permissions
185 $permissions['custom_field'] = array(
187 'administer CiviCRM',
188 'access all custom data',
191 $permissions['custom_group'] = $permissions['custom_field'];
194 $permissions['event'] = array(
203 'delete in CiviEvent',
218 $permissions['file'] = array(
221 'access uploaded files',
224 $permissions['files_by_entity'] = $permissions['file'];
227 $permissions['group'] = array(
236 $permissions['group_contact'] = $permissions['group'];
237 $permissions['group_nesting'] = $permissions['group'];
238 $permissions['group_organization'] = $permissions['group'];
240 // CiviMail Permissions
241 $civiMailBasePerms = array(
242 // To get/preview/update, one must have least one of these perms:
243 // Mailing API implementations enforce nuances of create/approve/schedule permissions.
249 $permissions['mailing'] = array(
257 'delete in CiviMail',
261 array('access CiviMail', 'schedule mailings'),
268 $permissions['mailing_group'] = $permissions['mailing'];
269 $permissions['mailing_job'] = $permissions['mailing'];
270 $permissions['mailing_recipients'] = $permissions['mailing'];
272 $permissions['mailing_a_b'] = array(
280 'delete in CiviMail',
284 array('access CiviMail', 'schedule mailings'),
292 // Membership permissions
293 $permissions['membership'] = array(
301 'delete in CiviMember',
309 $permissions['membership_status'] = $permissions['membership'];
310 $permissions['membership_type'] = $permissions['membership'];
311 $permissions['membership_payment'] = array(
316 'access CiviContribute',
317 'edit contributions',
322 'delete in CiviMember',
323 'access CiviContribute',
324 'delete in CiviContribute',
329 'access CiviContribute',
335 'access CiviContribute',
336 'edit contributions',
340 // Participant permissions
341 $permissions['participant'] = array(
345 'register for events',
350 'edit event participants',
355 'view event participants',
360 'edit event participants',
363 $permissions['participant_payment'] = array(
367 'register for events',
368 'access CiviContribute',
369 'edit contributions',
374 'edit event participants',
375 'access CiviContribute',
376 'delete in CiviContribute',
381 'view event participants',
382 'access CiviContribute',
387 'edit event participants',
388 'access CiviContribute',
389 'edit contributions',
393 // Pledge permissions
394 $permissions['pledge'] = array(
403 'delete in CiviPledge',
415 $permissions['pledge_payment'] = array(
420 'access CiviContribute',
421 'edit contributions',
426 'delete in CiviPledge',
427 'access CiviContribute',
428 'delete in CiviContribute',
433 'access CiviContribute',
439 'access CiviContribute',
440 'edit contributions',
444 // Profile permissions
445 $permissions['profile'] = array(
446 'get' => array(), // the profile will take care of this
449 $permissions['uf_group'] = array(
454 $permissions['uf_field'] = $permissions['uf_group'];
455 $permissions['option_value'] = $permissions['uf_group'];
456 $permissions['option_group'] = $permissions['option_value'];
458 // Translate 'create' action to 'update' if id is set
459 if ($action == 'create' && (!empty($params['id']) ||
!empty($params[$entity . '_id']))) {
463 // let third parties modify the permissions
464 CRM_Utils_Hook
::alterAPIPermissions($entity, $action, $params, $permissions);
466 // Merge permissions for this entity with the defaults
467 $perm = CRM_Utils_Array
::value($entity, $permissions, array()) +
$permissions['default'];
469 // Return exact match if permission for this action has been declared
470 if (isset($perm[$action])) {
471 return $perm[$action];
474 // Translate specific actions into their generic equivalents
475 $snippet = substr($action, 0, 3);
476 if ($action == 'replace' ||
$snippet == 'del') {
477 // 'Replace' is a combination of get+create+update+delete; however, the permissions
478 // on each of those will be tested separately at runtime. This is just a sniff-test
479 // based on the heuristic that 'delete' tends to be the most closesly guarded
480 // of the necessary permissions.
483 elseif ($action == 'setvalue' ||
$snippet == 'upd') {
486 elseif ($action == 'getfields' ||
$action == 'getspec' ||
$action == 'getoptions') {
489 elseif ($snippet == 'get') {
492 return isset($perm[$action]) ?
$perm[$action] : $perm['default'];
495 # FIXME: not sure how to permission the following API 3 calls:
496 # contribution_transact (make online contributions)
498 # group_contact_pending
499 # group_contact_update_status
500 # mailing_event_bounce
501 # mailing_event_click
502 # mailing_event_confirm
503 # mailing_event_forward
505 # mailing_event_reply
506 # mailing_group_event_domain_unsubscribe
507 # mailing_group_event_resubscribe
508 # mailing_group_event_subscribe
509 # mailing_group_event_unsubscribe
510 # membership_status_calc
511 # survey_respondant_count