4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.3 |
6 +--------------------------------------------------------------------+
7 | Copyright CiviCRM LLC (c) 2004-2013 |
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 // Contact permissions
70 $permissions['contact'] = array(
79 // managed by query object
90 // Contact-related data permissions
91 $permissions['address'] = array(
105 $permissions['email'] = $permissions['address'];
106 $permissions['phone'] = $permissions['address'];
107 $permissions['website'] = $permissions['address'];
108 $permissions['im'] = $permissions['address'];
109 $permissions['loc_block'] = $permissions['address'];
110 $permissions['entity_tag'] = $permissions['address'];
111 $permissions['note'] = $permissions['address'];
113 // Activity permissions
114 $permissions['activity'] = array(
121 'view all activities',
126 $permissions['case'] = array(
133 'delete in CiviCase',
137 'access all cases and activities',
141 // Financial permissions
142 $permissions['contribution'] = array(
145 'access CiviContribute',
149 'access CiviContribute',
150 'delete in CiviContribute',
154 'access CiviContribute',
155 'edit contributions',
158 $permissions['line_item'] = $permissions['contribution'];
160 // Custom field permissions
161 $permissions['custom_field'] = array(
163 'administer CiviCRM',
164 'access all custom data',
167 $permissions['custom_group'] = $permissions['custom_field'];
170 $permissions['event'] = array(
179 'delete in CiviEvent',
194 $permissions['file'] = array(
197 'access uploaded files',
200 $permissions['files_by_entity'] = $permissions['file'];
203 $permissions['group'] = array(
212 $permissions['group_contact'] = $permissions['group'];
213 $permissions['group_nesting'] = $permissions['group'];
214 $permissions['group_organization'] = $permissions['group'];
216 // Membership permissions
217 $permissions['membership'] = array(
225 'delete in CiviMember',
233 $permissions['membership_status'] = $permissions['membership'];
234 $permissions['membership_type'] = $permissions['membership'];
235 $permissions['membership_payment'] = array(
240 'access CiviContribute',
241 'edit contributions',
246 'delete in CiviMember',
247 'access CiviContribute',
248 'delete in CiviContribute',
253 'access CiviContribute',
259 'access CiviContribute',
260 'edit contributions',
264 // Participant permissions
265 $permissions['participant'] = array(
269 'register for events',
274 'edit event participants',
279 'view event participants',
284 'edit event participants',
287 $permissions['participant_payment'] = array(
291 'register for events',
292 'access CiviContribute',
293 'edit contributions',
298 'edit event participants',
299 'access CiviContribute',
300 'delete in CiviContribute',
305 'view event participants',
306 'access CiviContribute',
311 'edit event participants',
312 'access CiviContribute',
313 'edit contributions',
317 // Pledge permissions
318 $permissions['pledge'] = array(
327 'delete in CiviPledge',
339 $permissions['pledge_payment'] = array(
344 'access CiviContribute',
345 'edit contributions',
350 'delete in CiviPledge',
351 'access CiviContribute',
352 'delete in CiviContribute',
357 'access CiviContribute',
363 'access CiviContribute',
364 'edit contributions',
368 // Profile permissions
369 $permissions['uf_group'] = array(
374 $permissions['uf_field'] = $permissions['uf_group'];
376 // Translate 'create' action to 'update' if id is set
377 if ($action == 'create' && (!empty($params['id']) ||
!empty($params[$entity . '_id']))) {
381 // let third parties modify the permissions
382 CRM_Utils_Hook
::alterAPIPermissions($entity, $action, $params, $permissions);
384 // Merge permissions for this entity with the defaults
385 $perm = CRM_Utils_Array
::value($entity, $permissions, array()) +
$permissions['default'];
387 // Return exact match if permission for this action has been declared
388 if (isset($perm[$action])) {
389 return $perm[$action];
392 // Translate specific actions into their generic equivalents
393 $snippet = substr($action, 0, 3);
394 if ($action == 'replace' ||
$snippet == 'del') {
395 // 'Replace' is a combination of get+create+update+delete; however, the permissions
396 // on each of those will be tested separately at runtime. This is just a sniff-test
397 // based on the heuristic that 'delete' tends to be the most closesly guarded
398 // of the necessary permissions.
401 elseif ($action == 'setvalue' ||
$snippet == 'upd') {
404 elseif ($action == 'getfields' ||
$action == 'getspec' ||
$action == 'getoptions') {
407 elseif ($snippet == 'get') {
410 return isset($perm[$action]) ?
$perm[$action] : $perm['default'];
413 # FIXME: not sure how to permission the following API 3 calls:
414 # contribution_transact (make online contributions)
416 # group_contact_pending
417 # group_contact_update_status
418 # mailing_event_bounce
419 # mailing_event_click
420 # mailing_event_confirm
421 # mailing_event_forward
423 # mailing_event_reply
424 # mailing_group_event_domain_unsubscribe
425 # mailing_group_event_resubscribe
426 # mailing_group_event_subscribe
427 # mailing_group_event_unsubscribe
428 # membership_status_calc
429 # survey_respondant_count