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
37 * @return array of permissions to check for this entity-action combo
39 function _civicrm_api3_permissions($entity, $action, &$params) {
40 $entity = _civicrm_api_get_entity_name_from_camel($entity);
41 $action = strtolower($action);
44 * @var array of permissions
46 * For each entity, we declare an array of permissions required for each action
47 * The action is the array key, possible values:
48 * * create: applies to create (with no id in params)
49 * * update: applies to update, setvalue, create (with id in params)
50 * * get: applies to getcount, getsingle, getvalue and other gets
51 * * delete: applies to delete, replace
52 * * meta: applies to getfields, getoptions, getspec
53 * * default: catch-all for anything not declared
55 * Note: some APIs declare other actions as well
57 $permissions = array();
59 // These are the default permissions - if any entity does not declare permissions for a given action,
60 // (or the entity does not declare permissions at all) - then the action will be used from here
61 $permissions['default'] = array(
62 // applies to getfields, getoptions, etc.
63 'meta' => array('access CiviCRM'),
64 // catch-all, applies to create, get, delete, etc.
65 // If an entity declares it's own 'default' action it will override this one
66 'default' => array('administer CiviCRM'),
69 $permissions['attachment'] = array(
70 'default' => array('access CiviCRM', 'access AJAX API'),
73 // Contact permissions
74 $permissions['contact'] = array(
83 // managed by query object
90 array('access CiviCRM', 'access AJAX API'),
94 // Contact-related data permissions.
95 // CRM-14094 - Users can edit and delete contact-related objects using inline edit with 'edit all contacts' permission
96 $permissions['address'] = array(
106 $permissions['email'] = $permissions['address'];
107 $permissions['phone'] = $permissions['address'];
108 $permissions['website'] = $permissions['address'];
109 $permissions['im'] = $permissions['address'];
110 $permissions['loc_block'] = $permissions['address'];
111 $permissions['entity_tag'] = $permissions['address'];
112 $permissions['note'] = $permissions['address'];
114 //relationship permissions
115 $permissions['relationship'] = array(
130 // Activity permissions
131 $permissions['activity'] = array(
138 'view all activities',
143 $permissions['case'] = array(
150 'delete in CiviCase',
154 'access all cases and activities',
158 // Financial permissions
159 $permissions['contribution'] = array(
162 'access CiviContribute',
166 'access CiviContribute',
167 'delete in CiviContribute',
169 'completetransaction' => array(
170 'edit contributions',
174 'access CiviContribute',
175 'edit contributions',
178 $permissions['line_item'] = $permissions['contribution'];
180 // Custom field permissions
181 $permissions['custom_field'] = array(
183 'administer CiviCRM',
184 'access all custom data',
187 $permissions['custom_group'] = $permissions['custom_field'];
190 $permissions['event'] = array(
199 'delete in CiviEvent',
214 $permissions['file'] = array(
217 'access uploaded files',
220 $permissions['files_by_entity'] = $permissions['file'];
223 $permissions['group'] = array(
232 $permissions['group_contact'] = $permissions['group'];
233 $permissions['group_nesting'] = $permissions['group'];
234 $permissions['group_organization'] = $permissions['group'];
236 // CiviMail Permissions
237 $permissions['mailing'] = array(
245 'delete in CiviMail',
253 // Membership permissions
254 $permissions['membership'] = array(
262 'delete in CiviMember',
270 $permissions['membership_status'] = $permissions['membership'];
271 $permissions['membership_type'] = $permissions['membership'];
272 $permissions['membership_payment'] = array(
277 'access CiviContribute',
278 'edit contributions',
283 'delete in CiviMember',
284 'access CiviContribute',
285 'delete in CiviContribute',
290 'access CiviContribute',
296 'access CiviContribute',
297 'edit contributions',
301 // Participant permissions
302 $permissions['participant'] = array(
306 'register for events',
311 'edit event participants',
316 'view event participants',
321 'edit event participants',
324 $permissions['participant_payment'] = array(
328 'register for events',
329 'access CiviContribute',
330 'edit contributions',
335 'edit event participants',
336 'access CiviContribute',
337 'delete in CiviContribute',
342 'view event participants',
343 'access CiviContribute',
348 'edit event participants',
349 'access CiviContribute',
350 'edit contributions',
354 // Pledge permissions
355 $permissions['pledge'] = array(
364 'delete in CiviPledge',
376 $permissions['pledge_payment'] = array(
381 'access CiviContribute',
382 'edit contributions',
387 'delete in CiviPledge',
388 'access CiviContribute',
389 'delete in CiviContribute',
394 'access CiviContribute',
400 'access CiviContribute',
401 'edit contributions',
405 // Profile permissions
406 $permissions['profile'] = array(
407 'get' => array(), // the profile will take care of this
410 $permissions['uf_group'] = array(
415 $permissions['uf_field'] = $permissions['uf_group'];
417 // Translate 'create' action to 'update' if id is set
418 if ($action == 'create' && (!empty($params['id']) ||
!empty($params[$entity . '_id']))) {
422 // let third parties modify the permissions
423 CRM_Utils_Hook
::alterAPIPermissions($entity, $action, $params, $permissions);
425 // Merge permissions for this entity with the defaults
426 $perm = CRM_Utils_Array
::value($entity, $permissions, array()) +
$permissions['default'];
428 // Return exact match if permission for this action has been declared
429 if (isset($perm[$action])) {
430 return $perm[$action];
433 // Translate specific actions into their generic equivalents
434 $snippet = substr($action, 0, 3);
435 if ($action == 'replace' ||
$snippet == 'del') {
436 // 'Replace' is a combination of get+create+update+delete; however, the permissions
437 // on each of those will be tested separately at runtime. This is just a sniff-test
438 // based on the heuristic that 'delete' tends to be the most closesly guarded
439 // of the necessary permissions.
442 elseif ($action == 'setvalue' ||
$snippet == 'upd') {
445 elseif ($action == 'getfields' ||
$action == 'getspec' ||
$action == 'getoptions') {
448 elseif ($snippet == 'get') {
451 return isset($perm[$action]) ?
$perm[$action] : $perm['default'];
454 # FIXME: not sure how to permission the following API 3 calls:
455 # contribution_transact (make online contributions)
457 # group_contact_pending
458 # group_contact_update_status
459 # mailing_event_bounce
460 # mailing_event_click
461 # mailing_event_confirm
462 # mailing_event_forward
464 # mailing_event_reply
465 # mailing_group_event_domain_unsubscribe
466 # mailing_group_event_resubscribe
467 # mailing_group_event_subscribe
468 # mailing_group_event_unsubscribe
469 # membership_status_calc
470 # survey_respondant_count