3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2018 |
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);
42 $permissions = CRM_Core_Permission
::getEntityActionPermissions();
44 // Translate 'create' action to 'update' if id is set
45 if ($action == 'create' && (!empty($params['id']) ||
!empty($params[$entity . '_id']))) {
49 // let third parties modify the permissions
50 CRM_Utils_Hook
::alterAPIPermissions($entity, $action, $params, $permissions);
52 // Merge permissions for this entity with the defaults
53 $perm = CRM_Utils_Array
::value($entity, $permissions, array()) +
$permissions['default'];
55 // Return exact match if permission for this action has been declared
56 if (isset($perm[$action])) {
57 return $perm[$action];
60 // Translate specific actions into their generic equivalents
61 $action = CRM_Core_Permission
::getGenericAction($action);
63 return isset($perm[$action]) ?
$perm[$action] : $perm['default'];
66 # FIXME: not sure how to permission the following API 3 calls:
67 # contribution_transact (make online contributions)
69 # group_contact_pending
70 # group_contact_update_status
71 # mailing_event_bounce
73 # mailing_event_confirm
74 # mailing_event_forward
77 # mailing_group_event_domain_unsubscribe
78 # mailing_group_event_resubscribe
79 # mailing_group_event_subscribe
80 # mailing_group_event_unsubscribe
81 # membership_status_calc
82 # survey_respondant_count