22f44500342915da69a8b176d2424abade865e65
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 $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'];
416 $permissions['option_value'] = $permissions['uf_group'];
417 $permissions['option_group'] = $permissions['option_value'];
419 // Translate 'create' action to 'update' if id is set
420 if ($action == 'create' && (!empty($params['id']) ||
!empty($params[$entity . '_id']))) {
424 // let third parties modify the permissions
425 CRM_Utils_Hook
::alterAPIPermissions($entity, $action, $params, $permissions);
427 // Merge permissions for this entity with the defaults
428 $perm = CRM_Utils_Array
::value($entity, $permissions, array()) +
$permissions['default'];
430 // Return exact match if permission for this action has been declared
431 if (isset($perm[$action])) {
432 return $perm[$action];
435 // Translate specific actions into their generic equivalents
436 $snippet = substr($action, 0, 3);
437 if ($action == 'replace' ||
$snippet == 'del') {
438 // 'Replace' is a combination of get+create+update+delete; however, the permissions
439 // on each of those will be tested separately at runtime. This is just a sniff-test
440 // based on the heuristic that 'delete' tends to be the most closesly guarded
441 // of the necessary permissions.
444 elseif ($action == 'setvalue' ||
$snippet == 'upd') {
447 elseif ($action == 'getfields' ||
$action == 'getspec' ||
$action == 'getoptions') {
450 elseif ($snippet == 'get') {
453 return isset($perm[$action]) ?
$perm[$action] : $perm['default'];
456 # FIXME: not sure how to permission the following API 3 calls:
457 # contribution_transact (make online contributions)
459 # group_contact_pending
460 # group_contact_update_status
461 # mailing_event_bounce
462 # mailing_event_click
463 # mailing_event_confirm
464 # mailing_event_forward
466 # mailing_event_reply
467 # mailing_group_event_domain_unsubscribe
468 # mailing_group_event_resubscribe
469 # mailing_group_event_subscribe
470 # mailing_group_event_unsubscribe
471 # membership_status_calc
472 # survey_respondant_count