3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2016 |
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
31 * @param $entity : (str) api entity
32 * @param $action : (str) api action
33 * @param $params : (array) api params
36 * Array of permissions to check for this entity-action combo
38 function _civicrm_api3_permissions($entity, $action, &$params) {
39 // FIXME: Lowercase entity_names are nonstandard but difficult to fix here
40 // because this function invokes hook_civicrm_alterAPIPermissions
41 $entity = _civicrm_api_get_entity_name_from_camel($entity);
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 should use arrays for AND and arrays of arrays for OR
58 * @see CRM_Core_Permission::check for more documentation
60 $permissions = array();
62 // These are the default permissions - if any entity does not declare permissions for a given action,
63 // (or the entity does not declare permissions at all) - then the action will be used from here
64 $permissions['default'] = array(
65 // applies to getfields, getoptions, etc.
66 'meta' => array('access CiviCRM'),
67 // catch-all, applies to create, get, delete, etc.
68 // If an entity declares it's own 'default' action it will override this one
69 'default' => array('administer CiviCRM'),
72 // Note: Additional permissions in DynamicFKAuthorization
73 $permissions['attachment'] = array(
75 array('access CiviCRM', 'access AJAX API'),
79 // Contact permissions
80 $permissions['contact'] = array(
89 // managed by query object
91 // managed by _civicrm_api3_check_edit_permissions
94 array('access CiviCRM', 'access AJAX API'),
98 // CRM-16963 - Permissions for country.
99 $permissions['country'] = array(
104 'administer CiviCRM',
108 // Contact-related data permissions.
109 $permissions['address'] = array(
110 // get is managed by BAO::addSelectWhereClause
111 // create/delete are managed by _civicrm_api3_check_edit_permissions
112 'default' => array(),
114 $permissions['email'] = $permissions['address'];
115 $permissions['phone'] = $permissions['address'];
116 $permissions['website'] = $permissions['address'];
117 $permissions['im'] = $permissions['address'];
119 // Also managed by ACLs - CRM-19448
120 $permissions['entity_tag'] = array('default' => array());
121 $permissions['note'] = $permissions['entity_tag'];
123 // Allow non-admins to get and create tags to support tagset widget
124 // Delete is still reserved for admins
125 $permissions['tag'] = array(
126 'get' => array('access CiviCRM'),
127 'create' => array('access CiviCRM'),
128 'update' => array('access CiviCRM'),
131 //relationship permissions
132 $permissions['relationship'] = array(
133 // get is managed by BAO::addSelectWhereClause
145 // CRM-17741 - Permissions for RelationshipType.
146 $permissions['relationship_type'] = array(
151 'administer CiviCRM',
155 // Activity permissions
156 $permissions['activity'] = array(
163 // Note that view all activities is also required within the api
164 // if the id is not passed in. Where the id is passed in the activity
165 // specific check functions are used and tested.
169 'view all activities',
174 $permissions['case'] = array(
181 'delete in CiviCase',
184 // At minimum the user needs one of the following. Finer-grained access is controlled by CRM_Case_BAO_Case::addSelectWhereClause
185 array('access my cases and activities', 'access all cases and activities'),
188 $permissions['case_contact'] = $permissions['case'];
190 $permissions['case_type'] = array(
191 'default' => array('administer CiviCase'),
194 array('access my cases and activities', 'access all cases and activities'),
198 // Campaign permissions
199 $permissions['campaign'] = array(
200 'get' => array('access CiviCRM'),
203 array('administer CiviCampaign', 'manage campaign')
206 $permissions['survey'] = $permissions['campaign'];
208 // Financial permissions
209 $permissions['contribution'] = array(
212 'access CiviContribute',
216 'access CiviContribute',
217 'delete in CiviContribute',
219 'completetransaction' => array(
220 'edit contributions',
224 'access CiviContribute',
225 'edit contributions',
228 $permissions['line_item'] = $permissions['contribution'];
230 // Payment permissions
231 $permissions['payment'] = array(
234 'access CiviContribute',
238 'access CiviContribute',
239 'delete in CiviContribute',
243 'access CiviContribute',
244 'edit contributions',
248 'access CiviContribute',
249 'edit contributions',
253 'access CiviContribute',
254 'edit contributions',
258 // Custom field permissions
259 $permissions['custom_field'] = array(
261 'administer CiviCRM',
262 'access all custom data',
265 $permissions['custom_group'] = $permissions['custom_field'];
268 $permissions['event'] = array(
277 'delete in CiviEvent',
290 // Loc block is only used for events
291 $permissions['loc_block'] = $permissions['event'];
293 // Price sets are shared by several components, user needs access to at least one of them
294 $permissions['price_set'] = array(
296 array('access CiviEvent', 'access CiviContribute', 'access CiviMember'),
299 array('access CiviCRM', 'view event info', 'make online contributions'),
304 $permissions['file'] = array(
307 'access uploaded files',
310 $permissions['files_by_entity'] = $permissions['file'];
313 $permissions['group'] = array(
323 $permissions['group_nesting'] = $permissions['group'];
324 $permissions['group_organization'] = $permissions['group'];
326 //Group Contact permission
327 $permissions['group_contact'] = array(
337 // CiviMail Permissions
338 $civiMailBasePerms = array(
339 // To get/preview/update, one must have least one of these perms:
340 // Mailing API implementations enforce nuances of create/approve/schedule permissions.
346 $permissions['mailing'] = array(
354 'delete in CiviMail',
358 array('access CiviMail', 'schedule mailings'),
365 $permissions['mailing_group'] = $permissions['mailing'];
366 $permissions['mailing_job'] = $permissions['mailing'];
367 $permissions['mailing_recipients'] = $permissions['mailing'];
369 $permissions['mailing_a_b'] = array(
377 'delete in CiviMail',
381 array('access CiviMail', 'schedule mailings'),
389 // Membership permissions
390 $permissions['membership'] = array(
398 'delete in CiviMember',
406 $permissions['membership_status'] = $permissions['membership'];
407 $permissions['membership_type'] = $permissions['membership'];
408 $permissions['membership_payment'] = array(
413 'access CiviContribute',
414 'edit contributions',
419 'delete in CiviMember',
420 'access CiviContribute',
421 'delete in CiviContribute',
426 'access CiviContribute',
432 'access CiviContribute',
433 'edit contributions',
437 // Participant permissions
438 $permissions['participant'] = array(
442 'register for events',
447 'edit event participants',
452 'view event participants',
457 'edit event participants',
460 $permissions['participant_payment'] = array(
464 'register for events',
465 'access CiviContribute',
466 'edit contributions',
471 'edit event participants',
472 'access CiviContribute',
473 'delete in CiviContribute',
478 'view event participants',
479 'access CiviContribute',
484 'edit event participants',
485 'access CiviContribute',
486 'edit contributions',
490 // Pledge permissions
491 $permissions['pledge'] = array(
500 'delete in CiviPledge',
513 //CRM-16777: Disable schedule reminder for user that have 'edit all events' and 'administer CiviCRM' permission.
514 $permissions['action_schedule'] = array(
523 $permissions['pledge_payment'] = array(
528 'access CiviContribute',
529 'edit contributions',
534 'delete in CiviPledge',
535 'access CiviContribute',
536 'delete in CiviContribute',
541 'access CiviContribute',
547 'access CiviContribute',
548 'edit contributions',
552 // Profile permissions
553 $permissions['profile'] = array(
554 'get' => array(), // the profile will take care of this
557 $permissions['uf_group'] = array(
561 'administer CiviCRM',
562 'manage event profiles',
571 'administer CiviCRM',
572 'manage event profiles',
576 $permissions['uf_field'] = $permissions['uf_join'] = $permissions['uf_group'];
577 $permissions['uf_field']['delete'] = array(
580 'administer CiviCRM',
581 'manage event profiles',
584 $permissions['option_value'] = $permissions['uf_group'];
585 $permissions['option_group'] = $permissions['option_value'];
587 $permissions['message_template'] = array(
588 'get' => array('access CiviCRM'),
589 'create' => array('edit message templates'),
590 'update' => array('edit message templates'),
593 // Translate 'create' action to 'update' if id is set
594 if ($action == 'create' && (!empty($params['id']) ||
!empty($params[$entity . '_id']))) {
598 // let third parties modify the permissions
599 CRM_Utils_Hook
::alterAPIPermissions($entity, $action, $params, $permissions);
601 // Merge permissions for this entity with the defaults
602 $perm = CRM_Utils_Array
::value($entity, $permissions, array()) +
$permissions['default'];
604 // Return exact match if permission for this action has been declared
605 if (isset($perm[$action])) {
606 return $perm[$action];
609 // Translate specific actions into their generic equivalents
610 $snippet = substr($action, 0, 3);
611 if ($action == 'replace' ||
$snippet == 'del') {
612 // 'Replace' is a combination of get+create+update+delete; however, the permissions
613 // on each of those will be tested separately at runtime. This is just a sniff-test
614 // based on the heuristic that 'delete' tends to be the most closely guarded
615 // of the necessary permissions.
618 elseif ($action == 'setvalue' ||
$snippet == 'upd') {
621 elseif ($action == 'getfields' ||
$action == 'getfield' ||
$action == 'getspec' ||
$action == 'getoptions') {
624 elseif ($snippet == 'get') {
627 return isset($perm[$action]) ?
$perm[$action] : $perm['default'];
630 # FIXME: not sure how to permission the following API 3 calls:
631 # contribution_transact (make online contributions)
633 # group_contact_pending
634 # group_contact_update_status
635 # mailing_event_bounce
636 # mailing_event_click
637 # mailing_event_confirm
638 # mailing_event_forward
640 # mailing_event_reply
641 # mailing_group_event_domain_unsubscribe
642 # mailing_group_event_resubscribe
643 # mailing_group_event_subscribe
644 # mailing_group_event_unsubscribe
645 # membership_status_calc
646 # survey_respondant_count