4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.5 |
6 +--------------------------------------------------------------------+
7 | Copyright CiviCRM LLC (c) 2004-2014 |
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
86 array('access CiviCRM', 'access AJAX API'),
90 // Contact-related data permissions.
91 // CRM-14094 - Users can edit and delete contact-related objects using inline edit with 'edit all contacts' permission
92 $permissions['address'] = array(
102 $permissions['email'] = $permissions['address'];
103 $permissions['phone'] = $permissions['address'];
104 $permissions['website'] = $permissions['address'];
105 $permissions['im'] = $permissions['address'];
106 $permissions['loc_block'] = $permissions['address'];
107 $permissions['entity_tag'] = $permissions['address'];
108 $permissions['note'] = $permissions['address'];
110 //relationship permissions
111 $permissions['relationship'] = array(
126 // Activity permissions
127 $permissions['activity'] = array(
134 'view all activities',
139 $permissions['case'] = array(
146 'delete in CiviCase',
150 'access all cases and activities',
154 // Financial permissions
155 $permissions['contribution'] = array(
158 'access CiviContribute',
162 'access CiviContribute',
163 'delete in CiviContribute',
165 'completetransaction' => array(
166 'edit contributions',
170 'access CiviContribute',
171 'edit contributions',
174 $permissions['line_item'] = $permissions['contribution'];
176 // Custom field permissions
177 $permissions['custom_field'] = array(
179 'administer CiviCRM',
180 'access all custom data',
183 $permissions['custom_group'] = $permissions['custom_field'];
186 $permissions['event'] = array(
195 'delete in CiviEvent',
210 $permissions['file'] = array(
213 'access uploaded files',
216 $permissions['files_by_entity'] = $permissions['file'];
219 $permissions['group'] = array(
228 $permissions['group_contact'] = $permissions['group'];
229 $permissions['group_nesting'] = $permissions['group'];
230 $permissions['group_organization'] = $permissions['group'];
232 // Membership permissions
233 $permissions['membership'] = array(
241 'delete in CiviMember',
249 $permissions['membership_status'] = $permissions['membership'];
250 $permissions['membership_type'] = $permissions['membership'];
251 $permissions['membership_payment'] = array(
256 'access CiviContribute',
257 'edit contributions',
262 'delete in CiviMember',
263 'access CiviContribute',
264 'delete in CiviContribute',
269 'access CiviContribute',
275 'access CiviContribute',
276 'edit contributions',
280 // Participant permissions
281 $permissions['participant'] = array(
285 'register for events',
290 'edit event participants',
295 'view event participants',
300 'edit event participants',
303 $permissions['participant_payment'] = array(
307 'register for events',
308 'access CiviContribute',
309 'edit contributions',
314 'edit event participants',
315 'access CiviContribute',
316 'delete in CiviContribute',
321 'view event participants',
322 'access CiviContribute',
327 'edit event participants',
328 'access CiviContribute',
329 'edit contributions',
333 // Pledge permissions
334 $permissions['pledge'] = array(
343 'delete in CiviPledge',
355 $permissions['pledge_payment'] = array(
360 'access CiviContribute',
361 'edit contributions',
366 'delete in CiviPledge',
367 'access CiviContribute',
368 'delete in CiviContribute',
373 'access CiviContribute',
379 'access CiviContribute',
380 'edit contributions',
384 // Profile permissions
385 $permissions['profile'] = array(
386 'get' => array(), // the profile will take care of this
389 $permissions['uf_group'] = array(
394 $permissions['uf_field'] = $permissions['uf_group'];
396 // Translate 'create' action to 'update' if id is set
397 if ($action == 'create' && (!empty($params['id']) ||
!empty($params[$entity . '_id']))) {
401 // let third parties modify the permissions
402 CRM_Utils_Hook
::alterAPIPermissions($entity, $action, $params, $permissions);
404 // Merge permissions for this entity with the defaults
405 $perm = CRM_Utils_Array
::value($entity, $permissions, array()) +
$permissions['default'];
407 // Return exact match if permission for this action has been declared
408 if (isset($perm[$action])) {
409 return $perm[$action];
412 // Translate specific actions into their generic equivalents
413 $snippet = substr($action, 0, 3);
414 if ($action == 'replace' ||
$snippet == 'del') {
415 // 'Replace' is a combination of get+create+update+delete; however, the permissions
416 // on each of those will be tested separately at runtime. This is just a sniff-test
417 // based on the heuristic that 'delete' tends to be the most closesly guarded
418 // of the necessary permissions.
421 elseif ($action == 'setvalue' ||
$snippet == 'upd') {
424 elseif ($action == 'getfields' ||
$action == 'getspec' ||
$action == 'getoptions') {
427 elseif ($snippet == 'get') {
430 return isset($perm[$action]) ?
$perm[$action] : $perm['default'];
433 # FIXME: not sure how to permission the following API 3 calls:
434 # contribution_transact (make online contributions)
436 # group_contact_pending
437 # group_contact_update_status
438 # mailing_event_bounce
439 # mailing_event_click
440 # mailing_event_confirm
441 # mailing_event_forward
443 # mailing_event_reply
444 # mailing_group_event_domain_unsubscribe
445 # mailing_group_event_resubscribe
446 # mailing_group_event_subscribe
447 # mailing_group_event_unsubscribe
448 # membership_status_calc
449 # survey_respondant_count