4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.4 |
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',
152 'completetransaction' => array(
153 'edit contributions',
157 'access CiviContribute',
158 'edit contributions',
161 $permissions['line_item'] = $permissions['contribution'];
163 // Custom field permissions
164 $permissions['custom_field'] = array(
166 'administer CiviCRM',
167 'access all custom data',
170 $permissions['custom_group'] = $permissions['custom_field'];
173 $permissions['event'] = array(
182 'delete in CiviEvent',
197 $permissions['file'] = array(
200 'access uploaded files',
203 $permissions['files_by_entity'] = $permissions['file'];
206 $permissions['group'] = array(
215 $permissions['group_contact'] = $permissions['group'];
216 $permissions['group_nesting'] = $permissions['group'];
217 $permissions['group_organization'] = $permissions['group'];
219 // Membership permissions
220 $permissions['membership'] = array(
228 'delete in CiviMember',
236 $permissions['membership_status'] = $permissions['membership'];
237 $permissions['membership_type'] = $permissions['membership'];
238 $permissions['membership_payment'] = array(
243 'access CiviContribute',
244 'edit contributions',
249 'delete in CiviMember',
250 'access CiviContribute',
251 'delete in CiviContribute',
256 'access CiviContribute',
262 'access CiviContribute',
263 'edit contributions',
267 // Participant permissions
268 $permissions['participant'] = array(
272 'register for events',
277 'edit event participants',
282 'view event participants',
287 'edit event participants',
290 $permissions['participant_payment'] = array(
294 'register for events',
295 'access CiviContribute',
296 'edit contributions',
301 'edit event participants',
302 'access CiviContribute',
303 'delete in CiviContribute',
308 'view event participants',
309 'access CiviContribute',
314 'edit event participants',
315 'access CiviContribute',
316 'edit contributions',
320 // Pledge permissions
321 $permissions['pledge'] = array(
330 'delete in CiviPledge',
342 $permissions['pledge_payment'] = array(
347 'access CiviContribute',
348 'edit contributions',
353 'delete in CiviPledge',
354 'access CiviContribute',
355 'delete in CiviContribute',
360 'access CiviContribute',
366 'access CiviContribute',
367 'edit contributions',
371 // Profile permissions
372 $permissions['profile'] = array(
373 'get' => array(), // the profile will take care of this
376 $permissions['uf_group'] = array(
381 $permissions['uf_field'] = $permissions['uf_group'];
383 // Translate 'create' action to 'update' if id is set
384 if ($action == 'create' && (!empty($params['id']) ||
!empty($params[$entity . '_id']))) {
388 // let third parties modify the permissions
389 CRM_Utils_Hook
::alterAPIPermissions($entity, $action, $params, $permissions);
391 // Merge permissions for this entity with the defaults
392 $perm = CRM_Utils_Array
::value($entity, $permissions, array()) +
$permissions['default'];
394 // Return exact match if permission for this action has been declared
395 if (isset($perm[$action])) {
396 return $perm[$action];
399 // Translate specific actions into their generic equivalents
400 $snippet = substr($action, 0, 3);
401 if ($action == 'replace' ||
$snippet == 'del') {
402 // 'Replace' is a combination of get+create+update+delete; however, the permissions
403 // on each of those will be tested separately at runtime. This is just a sniff-test
404 // based on the heuristic that 'delete' tends to be the most closesly guarded
405 // of the necessary permissions.
408 elseif ($action == 'setvalue' ||
$snippet == 'upd') {
411 elseif ($action == 'getfields' ||
$action == 'getspec' ||
$action == 'getoptions') {
414 elseif ($snippet == 'get') {
417 return isset($perm[$action]) ?
$perm[$action] : $perm['default'];
420 # FIXME: not sure how to permission the following API 3 calls:
421 # contribution_transact (make online contributions)
423 # group_contact_pending
424 # group_contact_update_status
425 # mailing_event_bounce
426 # mailing_event_click
427 # mailing_event_confirm
428 # mailing_event_forward
430 # mailing_event_reply
431 # mailing_group_event_domain_unsubscribe
432 # mailing_group_event_resubscribe
433 # mailing_group_event_subscribe
434 # mailing_group_event_unsubscribe
435 # membership_status_calc
436 # survey_respondant_count