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 $permissions['mailing'] = array(
249 'delete in CiviMail',
256 $permissions['mailing_a_b'] = $permissions['mailing'];
257 $permissions['mailing_group'] = $permissions['mailing'];
258 $permissions['mailing_job'] = $permissions['mailing'];
259 $permissions['mailing_recipients'] = $permissions['mailing'];
261 // Membership permissions
262 $permissions['membership'] = array(
270 'delete in CiviMember',
278 $permissions['membership_status'] = $permissions['membership'];
279 $permissions['membership_type'] = $permissions['membership'];
280 $permissions['membership_payment'] = array(
285 'access CiviContribute',
286 'edit contributions',
291 'delete in CiviMember',
292 'access CiviContribute',
293 'delete in CiviContribute',
298 'access CiviContribute',
304 'access CiviContribute',
305 'edit contributions',
309 // Participant permissions
310 $permissions['participant'] = array(
314 'register for events',
319 'edit event participants',
324 'view event participants',
329 'edit event participants',
332 $permissions['participant_payment'] = array(
336 'register for events',
337 'access CiviContribute',
338 'edit contributions',
343 'edit event participants',
344 'access CiviContribute',
345 'delete in CiviContribute',
350 'view event participants',
351 'access CiviContribute',
356 'edit event participants',
357 'access CiviContribute',
358 'edit contributions',
362 // Pledge permissions
363 $permissions['pledge'] = array(
372 'delete in CiviPledge',
384 $permissions['pledge_payment'] = array(
389 'access CiviContribute',
390 'edit contributions',
395 'delete in CiviPledge',
396 'access CiviContribute',
397 'delete in CiviContribute',
402 'access CiviContribute',
408 'access CiviContribute',
409 'edit contributions',
413 // Profile permissions
414 $permissions['profile'] = array(
415 'get' => array(), // the profile will take care of this
418 $permissions['uf_group'] = array(
423 $permissions['uf_field'] = $permissions['uf_group'];
424 $permissions['option_value'] = $permissions['uf_group'];
425 $permissions['option_group'] = $permissions['option_value'];
427 // Translate 'create' action to 'update' if id is set
428 if ($action == 'create' && (!empty($params['id']) ||
!empty($params[$entity . '_id']))) {
432 // let third parties modify the permissions
433 CRM_Utils_Hook
::alterAPIPermissions($entity, $action, $params, $permissions);
435 // Merge permissions for this entity with the defaults
436 $perm = CRM_Utils_Array
::value($entity, $permissions, array()) +
$permissions['default'];
438 // Return exact match if permission for this action has been declared
439 if (isset($perm[$action])) {
440 return $perm[$action];
443 // Translate specific actions into their generic equivalents
444 $snippet = substr($action, 0, 3);
445 if ($action == 'replace' ||
$snippet == 'del') {
446 // 'Replace' is a combination of get+create+update+delete; however, the permissions
447 // on each of those will be tested separately at runtime. This is just a sniff-test
448 // based on the heuristic that 'delete' tends to be the most closesly guarded
449 // of the necessary permissions.
452 elseif ($action == 'setvalue' ||
$snippet == 'upd') {
455 elseif ($action == 'getfields' ||
$action == 'getspec' ||
$action == 'getoptions') {
458 elseif ($snippet == 'get') {
461 return isset($perm[$action]) ?
$perm[$action] : $perm['default'];
464 # FIXME: not sure how to permission the following API 3 calls:
465 # contribution_transact (make online contributions)
467 # group_contact_pending
468 # group_contact_update_status
469 # mailing_event_bounce
470 # mailing_event_click
471 # mailing_event_confirm
472 # mailing_event_forward
474 # mailing_event_reply
475 # mailing_group_event_domain_unsubscribe
476 # mailing_group_event_resubscribe
477 # mailing_group_event_subscribe
478 # mailing_group_event_unsubscribe
479 # membership_status_calc
480 # survey_respondant_count