3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
19 * This is the basic permission class wrapper
21 class CRM_Core_Permission
{
24 * Static strings used to compose permissions.
29 const EDIT_GROUPS
= 'edit contacts in ', VIEW_GROUPS
= 'view contacts in ';
32 * The various type of permissions.
36 const EDIT
= 1, VIEW
= 2, DELETE
= 3, CREATE
= 4, SEARCH
= 5, ALL
= 6, ADMIN
= 7;
39 * A placeholder permission which always fails.
41 const ALWAYS_DENY_PERMISSION
= "*always deny*";
44 * A placeholder permission which always fails.
46 const ALWAYS_ALLOW_PERMISSION
= "*always allow*";
49 * Various authentication sources.
53 const AUTH_SRC_UNKNOWN
= 0, AUTH_SRC_CHECKSUM
= 1, AUTH_SRC_SITEKEY
= 2, AUTH_SRC_LOGIN
= 4;
56 * Get the current permission of this user.
59 * the permission of the user (edit or view or null)
61 public static function getPermission() {
62 $config = CRM_Core_Config
::singleton();
63 return $config->userPermissionClass
->getPermission();
67 * Given a permission string or array, check for access requirements
69 * Ex 1: Must have 'access CiviCRM'
70 * (string) 'access CiviCRM'
72 * Ex 2: Must have 'access CiviCRM' and 'access Ajax API'
73 * ['access CiviCRM', 'access Ajax API']
75 * Ex 3: Must have 'access CiviCRM' or 'access Ajax API'
77 * ['access CiviCRM', 'access Ajax API'],
80 * Ex 4: Must have 'access CiviCRM' or 'access Ajax API' AND 'access CiviEvent'
82 * ['access CiviCRM', 'access Ajax API'],
86 * Note that in permissions.php this is keyed by the action eg.
87 * (access Civi || access AJAX) && (access CiviEvent || access CiviContribute)
89 * ['access CiviCRM', 'access Ajax API'],
90 * ['access CiviEvent', 'access CiviContribute']
93 * @param string|array $permissions
94 * The permission to check as an array or string -see examples.
96 * @param int $contactId
97 * Contact id to check permissions for. Defaults to current logged-in user.
100 * true if contact has permission(s), else false
102 public static function check($permissions, $contactId = NULL) {
103 $permissions = (array) $permissions;
104 $userId = CRM_Core_BAO_UFMatch
::getUFId($contactId);
106 /** @var CRM_Core_Permission_Temp $tempPerm */
107 $tempPerm = CRM_Core_Config
::singleton()->userPermissionTemp
;
109 foreach ($permissions as $permission) {
110 if (is_array($permission)) {
111 foreach ($permission as $orPerm) {
112 if (self
::check($orPerm, $contactId)) {
113 //one of our 'or' permissions has succeeded - stop checking this permission
117 //none of our our conditions was met
121 // This is an individual permission
122 $granted = CRM_Core_Config
::singleton()->userPermissionClass
->check($permission, $userId);
123 // Call the permission_check hook to permit dynamic escalation (CRM-19256)
124 CRM_Utils_Hook
::permission_check($permission, $granted, $contactId);
127 && !($tempPerm && $tempPerm->check($permission))
129 //one of our 'and' conditions has not been met
138 * Determine if any one of the permissions strings applies to current user.
140 * @param array $perms
143 public static function checkAnyPerm($perms) {
144 foreach ($perms as $perm) {
145 if (CRM_Core_Permission
::check($perm)) {
153 * Given a group/role array, check for access requirements
155 * @param array $array
156 * The group/role to check.
159 * true if yes, else false
161 public static function checkGroupRole($array) {
162 $config = CRM_Core_Config
::singleton();
163 return $config->userPermissionClass
->checkGroupRole($array);
167 * Get the permissioned where clause for the user.
170 * The type of permission needed.
171 * @param array $tables
172 * (reference ) add the tables that are needed for the select clause.
173 * @param array $whereTables
174 * (reference ) add the tables that are needed for the where clause.
177 * the group where clause for this user
179 public static function getPermissionedStaticGroupClause($type, &$tables, &$whereTables) {
180 $config = CRM_Core_Config
::singleton();
181 return $config->userPermissionClass
->getPermissionedStaticGroupClause($type, $tables, $whereTables);
185 * Get all groups from database, filtered by permissions
188 * @param string $groupType
189 * Type of group(Access/Mailing).
190 * @param bool $excludeHidden
191 * exclude hidden groups.
195 * array reference of all groups.
197 public static function group($groupType, $excludeHidden = TRUE) {
198 $config = CRM_Core_Config
::singleton();
199 return $config->userPermissionClass
->group($groupType, $excludeHidden);
205 public static function customGroupAdmin() {
208 // check if user has all powerful permission
209 // or administer civicrm permission (CRM-1905)
210 if (self
::check('access all custom data')) {
215 self
::check('administer Multiple Organizations') &&
216 self
::isMultisiteEnabled()
221 if (self
::check('administer CiviCRM')) {
234 public static function customGroup($type = CRM_Core_Permission
::VIEW
, $reset = FALSE) {
235 $customGroups = CRM_Core_PseudoConstant
::get('CRM_Core_DAO_CustomField', 'custom_group_id',
236 ['fresh' => $reset]);
239 // check if user has all powerful permission
240 // or administer civicrm permission (CRM-1905)
241 if (self
::customGroupAdmin()) {
242 $defaultGroups = array_keys($customGroups);
245 return CRM_ACL_API
::group($type, NULL, 'civicrm_custom_group', $customGroups, $defaultGroups);
250 * @param null $prefix
255 public static function customGroupClause($type = CRM_Core_Permission
::VIEW
, $prefix = NULL, $reset = FALSE) {
256 if (self
::customGroupAdmin()) {
260 $groups = self
::customGroup($type, $reset);
261 if (empty($groups)) {
265 return "{$prefix}id IN ( " . implode(',', $groups) . ' ) ';
275 public static function ufGroupValid($gid, $type = CRM_Core_Permission
::VIEW
) {
280 $groups = self
::ufGroup($type);
281 return !empty($groups) && in_array($gid, $groups) ?
TRUE : FALSE;
289 public static function ufGroup($type = CRM_Core_Permission
::VIEW
) {
290 $ufGroups = CRM_Core_PseudoConstant
::get('CRM_Core_DAO_UFField', 'uf_group_id');
292 $allGroups = array_keys($ufGroups);
294 // check if user has all powerful permission
295 if (self
::check('profile listings and forms')) {
300 case CRM_Core_Permission
::VIEW
:
301 if (self
::check('profile view')) {
306 case CRM_Core_Permission
::CREATE
:
307 if (self
::check('profile create')) {
312 case CRM_Core_Permission
::EDIT
:
313 if (self
::check('profile edit')) {
318 case CRM_Core_Permission
::SEARCH
:
319 if (self
::check('profile listings')) {
325 return CRM_ACL_API
::group($type, NULL, 'civicrm_uf_group', $ufGroups);
330 * @param null $prefix
331 * @param bool $returnUFGroupIds
333 * @return array|string
335 public static function ufGroupClause($type = CRM_Core_Permission
::VIEW
, $prefix = NULL, $returnUFGroupIds = FALSE) {
336 $groups = self
::ufGroup($type);
337 if ($returnUFGroupIds) {
340 elseif (empty($groups)) {
344 return "{$prefix}id IN ( " . implode(',', $groups) . ' ) ';
350 * @param int $eventID
351 * @param string $context
355 public static function event($type = CRM_Core_Permission
::VIEW
, $eventID = NULL, $context = '') {
356 if (!empty($context)) {
357 if (CRM_Core_Permission
::check($context)) {
361 $events = CRM_Event_PseudoConstant
::event(NULL, TRUE);
364 // check if user has all powerful permission
365 if (self
::check('register for events')) {
366 $includeEvents = array_keys($events);
369 if ($type == CRM_Core_Permission
::VIEW
&&
370 self
::check('view event info')
372 $includeEvents = array_keys($events);
375 $permissionedEvents = CRM_ACL_API
::group($type, NULL, 'civicrm_event', $events, $includeEvents);
377 return $permissionedEvents;
379 if (!empty($permissionedEvents)) {
380 return array_search($eventID, $permissionedEvents) === FALSE ?
NULL : $eventID;
387 * @param null $prefix
391 public static function eventClause($type = CRM_Core_Permission
::VIEW
, $prefix = NULL) {
392 $events = self
::event($type);
393 if (empty($events)) {
397 return "{$prefix}id IN ( " . implode(',', $events) . ' ) ';
402 * Checks that component is enabled and optionally that user has basic perm.
404 * @param string $module
405 * Specifies the name of the CiviCRM component.
406 * @param bool $checkPermission
407 * Check not only that module is enabled, but that user has necessary
409 * @param bool $requireAllCasesPermOnCiviCase
410 * Significant only if $module == CiviCase
411 * Require "access all cases and activities", not just
412 * "access my cases and activities".
415 * Access to specified $module is granted.
417 public static function access($module, $checkPermission = TRUE, $requireAllCasesPermOnCiviCase = FALSE) {
418 $config = CRM_Core_Config
::singleton();
420 if (!in_array($module, $config->enableComponents
)) {
424 if ($checkPermission) {
427 $access_all_cases = CRM_Core_Permission
::check("access all cases and activities");
428 $access_my_cases = CRM_Core_Permission
::check("access my cases and activities");
429 return $access_all_cases ||
(!$requireAllCasesPermOnCiviCase && $access_my_cases);
432 return CRM_Core_Permission
::check("administer $module");
435 return CRM_Core_Permission
::check("access $module");
443 * Check permissions for delete and edit actions.
445 * @param string $module
448 * Action to be check across component.
453 public static function checkActionPermission($module, $action) {
454 //check delete related permissions.
455 if ($action & CRM_Core_Action
::DELETE
) {
456 $permissionName = "delete in $module";
460 'CiviEvent' => 'edit event participants',
461 'CiviMember' => 'edit memberships',
462 'CiviPledge' => 'edit pledges',
463 'CiviContribute' => 'edit contributions',
464 'CiviGrant' => 'edit grants',
465 'CiviMail' => 'access CiviMail',
466 'CiviAuction' => 'add auction items',
468 $permissionName = CRM_Utils_Array
::value($module, $editPermissions);
471 if ($module == 'CiviCase' && !$permissionName) {
472 return CRM_Case_BAO_Case
::accessCiviCase();
475 //check for permission.
476 return CRM_Core_Permission
::check($permissionName);
486 public static function checkMenu(&$args, $op = 'and') {
487 if (!is_array($args)) {
490 foreach ($args as $str) {
491 $res = CRM_Core_Permission
::check($str);
492 if ($op == 'or' && $res) {
495 elseif ($op == 'and' && !$res) {
499 return ($op == 'or') ?
FALSE : TRUE;
508 public static function checkMenuItem(&$item) {
509 if (!array_key_exists('access_callback', $item)) {
510 CRM_Core_Error
::backtrace();
511 CRM_Core_Error
::fatal();
514 // if component_id is present, ensure it is enabled
515 if (isset($item['component_id']) && $item['component_id']) {
516 if (!isset(Civi
::$statics[__CLASS__
]['componentNameId'])) {
517 Civi
::$statics[__CLASS__
]['componentNameId'] = array_flip(CRM_Core_Component
::getComponentIDs());
519 $componentName = Civi
::$statics[__CLASS__
]['componentNameId'][$item['component_id']];
521 $config = CRM_Core_Config
::singleton();
522 if (is_array($config->enableComponents
) && in_array($componentName, $config->enableComponents
)) {
523 // continue with process
530 // the following is imitating drupal 6 code in includes/menu.inc
531 if (empty($item['access_callback']) ||
532 is_numeric($item['access_callback'])
534 return (boolean
) $item['access_callback'];
537 // check whether the following Ajax requests submitted the right key
538 // FIXME: this should be integrated into ACLs proper
539 if (CRM_Utils_Array
::value('page_type', $item) == 3) {
540 if (!CRM_Core_Key
::validate($_REQUEST['key'], $item['path'])) {
545 // check if callback is for checkMenu, if so optimize it
546 if (is_array($item['access_callback']) &&
547 $item['access_callback'][0] == 'CRM_Core_Permission' &&
548 $item['access_callback'][1] == 'checkMenu'
550 $op = CRM_Utils_Array
::value(1, $item['access_arguments'], 'and');
551 return self
::checkMenu($item['access_arguments'][0], $op);
554 return call_user_func_array($item['access_callback'], $item['access_arguments']);
560 * Include disabled components
561 * @param bool $descriptions
562 * Whether to return descriptions
566 public static function basicPermissions($all = FALSE, $descriptions = FALSE) {
567 $cacheKey = implode('-', [$all, $descriptions]);
568 if (empty(Civi
::$statics[__CLASS__
][__FUNCTION__
][$cacheKey])) {
569 Civi
::$statics[__CLASS__
][__FUNCTION__
][$cacheKey] = self
::assembleBasicPermissions($all, $descriptions);
571 return Civi
::$statics[__CLASS__
][__FUNCTION__
][$cacheKey];
576 * @param bool $descriptions
577 * whether to return descriptions
581 public static function assembleBasicPermissions($all = FALSE, $descriptions = FALSE) {
582 $config = CRM_Core_Config
::singleton();
583 $prefix = ts('CiviCRM') . ': ';
584 $permissions = self
::getCorePermissions($descriptions);
586 if (self
::isMultisiteEnabled()) {
587 $permissions['administer Multiple Organizations'] = [$prefix . ts('administer Multiple Organizations')];
590 if (!$descriptions) {
591 foreach ($permissions as $name => $attr) {
592 $permissions[$name] = array_shift($attr);
596 $components = CRM_Core_Component
::getEnabledComponents();
599 $components = CRM_Core_Component
::getComponents();
602 foreach ($components as $comp) {
603 $perm = $comp->getPermissions($all, $descriptions);
605 $info = $comp->getInfo();
606 foreach ($perm as $p => $attr) {
608 if (!is_array($attr)) {
612 $attr[0] = $info['translatedName'] . ': ' . $attr[0];
615 $permissions[$p] = $attr;
618 $permissions[$p] = $attr[0];
624 // Add any permissions defined in hook_civicrm_permission implementations.
625 $module_permissions = $config->userPermissionClass
->getAllModulePermissions($descriptions);
626 $permissions = array_merge($permissions, $module_permissions);
627 CRM_Financial_BAO_FinancialType
::permissionedFinancialTypes($permissions, $descriptions);
634 public static function getAnonymousPermissionsWarnings() {
635 static $permissions = [];
636 if (empty($permissions)) {
638 'administer CiviCRM',
640 $components = CRM_Core_Component
::getComponents();
641 foreach ($components as $comp) {
642 if (!method_exists($comp, 'getAnonymousPermissionWarnings')) {
645 $permissions = array_merge($permissions, $comp->getAnonymousPermissionWarnings());
652 * @param $anonymous_perms
656 public static function validateForPermissionWarnings($anonymous_perms) {
657 return array_intersect($anonymous_perms, self
::getAnonymousPermissionsWarnings());
661 * Get core permissions.
665 public static function getCorePermissions() {
666 $prefix = ts('CiviCRM') . ': ';
669 $prefix . ts('add contacts'),
670 ts('Create a new contact record in CiviCRM'),
672 'view all contacts' => [
673 $prefix . ts('view all contacts'),
674 ts('View ANY CONTACT in the CiviCRM database, export contact info and perform activities such as Send Email, Phone Call, etc.'),
676 'edit all contacts' => [
677 $prefix . ts('edit all contacts'),
678 ts('View, Edit and Delete ANY CONTACT in the CiviCRM database; Create and edit relationships, tags and other info about the contacts'),
680 'view my contact' => [
681 $prefix . ts('view my contact'),
683 'edit my contact' => [
684 $prefix . ts('edit my contact'),
686 'delete contacts' => [
687 $prefix . ts('delete contacts'),
689 'access deleted contacts' => [
690 $prefix . ts('access deleted contacts'),
691 ts('Access contacts in the trash'),
693 'import contacts' => [
694 $prefix . ts('import contacts'),
695 ts('Import contacts and activities'),
697 'import SQL datasource' => [
698 $prefix . ts('import SQL datasource'),
699 ts('When importing, consume data directly from a SQL datasource'),
702 $prefix . ts('edit groups'),
703 ts('Create new groups, edit group settings (e.g. group name, visibility...), delete groups'),
705 'administer CiviCRM' => [
706 $prefix . ts('administer CiviCRM'),
707 ts('Perform all tasks in the Administer CiviCRM control panel and Import Contacts'),
709 'skip IDS check' => [
710 $prefix . ts('skip IDS check'),
711 ts('Warning: Give to trusted roles only; this permission has security implications. IDS system is bypassed for users with this permission. Prevents false errors for admin users.'),
713 'access uploaded files' => [
714 $prefix . ts('access uploaded files'),
715 ts('View / download files including images and photos'),
717 'profile listings and forms' => [
718 $prefix . ts('profile listings and forms'),
719 ts('Warning: Give to trusted roles only; this permission has privacy implications. Add/edit data in online forms and access public searchable directories.'),
721 'profile listings' => [
722 $prefix . ts('profile listings'),
723 ts('Warning: Give to trusted roles only; this permission has privacy implications. Access public searchable directories.'),
725 'profile create' => [
726 $prefix . ts('profile create'),
727 ts('Add data in a profile form.'),
730 $prefix . ts('profile edit'),
731 ts('Edit data in a profile form.'),
734 $prefix . ts('profile view'),
735 ts('View data in a profile.'),
737 'access all custom data' => [
738 $prefix . ts('access all custom data'),
739 ts('View all custom fields regardless of ACL rules'),
741 'view all activities' => [
742 $prefix . ts('view all activities'),
743 ts('View all activities (for visible contacts)'),
745 'delete activities' => [
746 $prefix . ts('Delete activities'),
748 'edit inbound email basic information' => [
749 $prefix . ts('edit inbound email basic information'),
750 ts('Edit all inbound email activities (for visible contacts) basic information. Content editing not allowed.'),
752 'edit inbound email basic information and content' => [
753 $prefix . ts('edit inbound email basic information and content'),
754 ts('Edit all inbound email activities (for visible contacts) basic information and content.'),
756 'access CiviCRM' => [
757 $prefix . ts('access CiviCRM backend and API'),
758 ts('Master control for access to the main CiviCRM backend and API. Give to trusted roles only.'),
760 'access Contact Dashboard' => [
761 $prefix . ts('access Contact Dashboard'),
762 ts('View Contact Dashboard (for themselves and visible contacts)'),
764 'translate CiviCRM' => [
765 $prefix . ts('translate CiviCRM'),
766 ts('Allow User to enable multilingual'),
769 $prefix . ts('manage tags'),
770 ts('Create and rename tags'),
772 'administer reserved groups' => [
773 $prefix . ts('administer reserved groups'),
774 ts('Edit and disable Reserved Groups (Needs Edit Groups)'),
776 'administer Tagsets' => [
777 $prefix . ts('administer Tagsets'),
779 'administer reserved tags' => [
780 $prefix . ts('administer reserved tags'),
782 'administer dedupe rules' => [
783 $prefix . ts('administer dedupe rules'),
784 ts('Create and edit rules, change the supervised and unsupervised rules'),
786 'merge duplicate contacts' => [
787 $prefix . ts('merge duplicate contacts'),
788 ts('Delete Contacts must also be granted in order for this to work.'),
790 'force merge duplicate contacts' => [
791 $prefix . ts('force merge duplicate contacts'),
792 ts('Delete Contacts must also be granted in order for this to work.'),
794 'view debug output' => [
795 $prefix . ts('view debug output'),
796 ts('View results of debug and backtrace'),
799 'view all notes' => [
800 $prefix . ts('view all notes'),
801 ts("View notes (for visible contacts) even if they're marked admin only"),
803 'add contact notes' => [
804 $prefix . ts('add contact notes'),
805 ts("Create notes for contacts"),
807 'access AJAX API' => [
808 $prefix . ts('access AJAX API'),
809 ts('Allow API access even if Access CiviCRM is not granted'),
811 'access contact reference fields' => [
812 $prefix . ts('access contact reference fields'),
813 ts('Allow entering data into contact reference fields'),
815 'create manual batch' => [
816 $prefix . ts('create manual batch'),
817 ts('Create an accounting batch (with Access to CiviContribute and View Own/All Manual Batches)'),
819 'edit own manual batches' => [
820 $prefix . ts('edit own manual batches'),
821 ts('Edit accounting batches created by user'),
823 'edit all manual batches' => [
824 $prefix . ts('edit all manual batches'),
825 ts('Edit all accounting batches'),
827 'close own manual batches' => [
828 $prefix . ts('close own manual batches'),
829 ts('Close accounting batches created by user (with Access to CiviContribute)'),
831 'close all manual batches' => [
832 $prefix . ts('close all manual batches'),
833 ts('Close all accounting batches (with Access to CiviContribute)'),
835 'reopen own manual batches' => [
836 $prefix . ts('reopen own manual batches'),
837 ts('Reopen accounting batches created by user (with Access to CiviContribute)'),
839 'reopen all manual batches' => [
840 $prefix . ts('reopen all manual batches'),
841 ts('Reopen all accounting batches (with Access to CiviContribute)'),
843 'view own manual batches' => [
844 $prefix . ts('view own manual batches'),
845 ts('View accounting batches created by user (with Access to CiviContribute)'),
847 'view all manual batches' => [
848 $prefix . ts('view all manual batches'),
849 ts('View all accounting batches (with Access to CiviContribute)'),
851 'delete own manual batches' => [
852 $prefix . ts('delete own manual batches'),
853 ts('Delete accounting batches created by user'),
855 'delete all manual batches' => [
856 $prefix . ts('delete all manual batches'),
857 ts('Delete all accounting batches'),
859 'export own manual batches' => [
860 $prefix . ts('export own manual batches'),
861 ts('Export accounting batches created by user'),
863 'export all manual batches' => [
864 $prefix . ts('export all manual batches'),
865 ts('Export all accounting batches'),
867 'administer payment processors' => [
868 $prefix . ts('administer payment processors'),
869 ts('Add, Update, or Disable Payment Processors'),
871 'edit message templates' => [
872 $prefix . ts('edit message templates'),
874 'edit system workflow message templates' => [
875 $prefix . ts('edit system workflow message templates'),
877 'edit user-driven message templates' => [
878 $prefix . ts('edit user-driven message templates'),
880 'view my invoices' => [
881 $prefix . ts('view my invoices'),
882 ts('Allow users to view/ download their own invoices'),
885 $prefix . ts('edit api keys'),
888 'edit own api keys' => [
889 $prefix . ts('edit own api keys'),
890 ts('Edit user\'s own API keys'),
893 $prefix . ts('send SMS'),
902 * For each entity provides an array of permissions required for each action
904 * The action is the array key, possible values:
905 * * create: applies to create (with no id in params)
906 * * update: applies to update, setvalue, create (with id in params)
907 * * get: applies to getcount, getsingle, getvalue and other gets
908 * * delete: applies to delete, replace
909 * * meta: applies to getfields, getoptions, getspec
910 * * default: catch-all for anything not declared
912 * Note: some APIs declare other actions as well
914 * Permissions should use arrays for AND and arrays of arrays for OR
915 * @see CRM_Core_Permission::check
917 * @return array of permissions
919 public static function getEntityActionPermissions() {
921 // These are the default permissions - if any entity does not declare permissions for a given action,
922 // (or the entity does not declare permissions at all) - then the action will be used from here
923 $permissions['default'] = [
924 // applies to getfields, getoptions, etc.
925 'meta' => ['access CiviCRM'],
926 // catch-all, applies to create, get, delete, etc.
927 // If an entity declares it's own 'default' action it will override this one
928 'default' => ['administer CiviCRM'],
931 // Note: Additional permissions in DynamicFKAuthorization
932 $permissions['attachment'] = [
934 ['access CiviCRM', 'access AJAX API'],
938 // Contact permissions
939 $permissions['contact'] = [
948 // managed by query object
950 // managed by _civicrm_api3_check_edit_permissions
953 ['access CiviCRM', 'access AJAX API'],
955 'duplicatecheck' => [
958 'merge' => ['merge duplicate contacts'],
961 $permissions['dedupe'] = [
962 'getduplicates' => ['access CiviCRM'],
963 'getstatistics' => ['access CiviCRM'],
966 // CRM-16963 - Permissions for country.
967 $permissions['country'] = [
972 'administer CiviCRM',
976 // Contact-related data permissions.
977 $permissions['address'] = [
978 // get is managed by BAO::addSelectWhereClause
979 // create/delete are managed by _civicrm_api3_check_edit_permissions
982 $permissions['email'] = $permissions['address'];
983 $permissions['phone'] = $permissions['address'];
984 $permissions['website'] = $permissions['address'];
985 $permissions['im'] = $permissions['address'];
986 $permissions['open_i_d'] = $permissions['address'];
988 // Also managed by ACLs - CRM-19448
989 $permissions['entity_tag'] = ['default' => []];
990 $permissions['note'] = $permissions['entity_tag'];
992 // Allow non-admins to get and create tags to support tagset widget
993 // Delete is still reserved for admins
994 $permissions['tag'] = [
995 'get' => ['access CiviCRM'],
996 'create' => ['access CiviCRM'],
997 'update' => ['access CiviCRM'],
1000 //relationship permissions
1001 $permissions['relationship'] = [
1002 // get is managed by BAO::addSelectWhereClause
1006 'edit all contacts',
1010 'edit all contacts',
1014 // CRM-17741 - Permissions for RelationshipType.
1015 $permissions['relationship_type'] = [
1020 'administer CiviCRM',
1024 // Activity permissions
1025 $permissions['activity'] = [
1028 'delete activities',
1032 // Note that view all activities is also required within the api
1033 // if the id is not passed in. Where the id is passed in the activity
1034 // specific check functions are used and tested.
1038 'view all activities',
1041 $permissions['activity_contact'] = $permissions['activity'];
1044 $permissions['case'] = [
1051 'delete in CiviCase',
1054 'administer CiviCase',
1057 'administer CiviCase',
1060 // At minimum the user needs one of the following. Finer-grained access is controlled by CRM_Case_BAO_Case::addSelectWhereClause
1061 ['access my cases and activities', 'access all cases and activities'],
1064 $permissions['case_contact'] = $permissions['case'];
1066 $permissions['case_type'] = [
1067 'default' => ['administer CiviCase'],
1069 // nested array = OR
1070 ['access my cases and activities', 'access all cases and activities'],
1074 // Campaign permissions
1075 $permissions['campaign'] = [
1076 'get' => ['access CiviCRM'],
1078 // nested array = OR
1079 ['administer CiviCampaign', 'manage campaign'],
1082 $permissions['survey'] = $permissions['campaign'];
1084 // Financial permissions
1085 $permissions['contribution'] = [
1088 'access CiviContribute',
1092 'access CiviContribute',
1093 'delete in CiviContribute',
1095 'completetransaction' => [
1096 'edit contributions',
1100 'access CiviContribute',
1101 'edit contributions',
1104 $permissions['line_item'] = $permissions['contribution'];
1106 // Payment permissions
1107 $permissions['payment'] = [
1110 'access CiviContribute',
1114 'access CiviContribute',
1115 'delete in CiviContribute',
1119 'access CiviContribute',
1120 'edit contributions',
1124 'access CiviContribute',
1125 'edit contributions',
1129 'access CiviContribute',
1130 'edit contributions',
1133 $permissions['contribution_recur'] = $permissions['payment'];
1135 // Custom field permissions
1136 $permissions['custom_field'] = [
1138 'administer CiviCRM',
1139 'access all custom data',
1142 $permissions['custom_group'] = $permissions['custom_field'];
1144 // Event permissions
1145 $permissions['event'] = [
1154 'delete in CiviEvent',
1167 // Exception refers to dedupe_exception.
1168 $permissions['exception'] = [
1169 'default' => ['merge duplicate contacts'],
1172 $permissions['job'] = [
1173 'process_batch_merge' => ['merge duplicate contacts'],
1175 $permissions['rule_group']['get'] = [['merge duplicate contacts', 'administer CiviCRM']];
1176 // Loc block is only used for events
1177 $permissions['loc_block'] = $permissions['event'];
1179 $permissions['state_province'] = [
1185 // Price sets are shared by several components, user needs access to at least one of them
1186 $permissions['price_set'] = [
1188 ['access CiviEvent', 'access CiviContribute', 'access CiviMember'],
1191 ['access CiviCRM', 'view event info', 'make online contributions'],
1196 $permissions['file'] = [
1199 'access uploaded files',
1202 $permissions['files_by_entity'] = $permissions['file'];
1204 // Group permissions
1205 $permissions['group'] = [
1215 $permissions['group_nesting'] = $permissions['group'];
1216 $permissions['group_organization'] = $permissions['group'];
1218 //Group Contact permission
1219 $permissions['group_contact'] = [
1225 'edit all contacts',
1229 // CiviMail Permissions
1230 $civiMailBasePerms = [
1231 // To get/preview/update, one must have least one of these perms:
1232 // Mailing API implementations enforce nuances of create/approve/schedule permissions.
1235 'schedule mailings',
1238 $permissions['mailing'] = [
1246 'delete in CiviMail',
1250 ['access CiviMail', 'schedule mailings'],
1257 $permissions['mailing_group'] = $permissions['mailing'];
1258 $permissions['mailing_job'] = $permissions['mailing'];
1259 $permissions['mailing_recipients'] = $permissions['mailing'];
1261 $permissions['mailing_a_b'] = [
1269 'delete in CiviMail',
1273 ['access CiviMail', 'schedule mailings'],
1281 // Membership permissions
1282 $permissions['membership'] = [
1285 'access CiviMember',
1289 'access CiviMember',
1290 'delete in CiviMember',
1294 'access CiviMember',
1298 $permissions['membership_status'] = $permissions['membership'];
1299 $permissions['membership_type'] = $permissions['membership'];
1300 $permissions['membership_payment'] = [
1303 'access CiviMember',
1305 'access CiviContribute',
1306 'edit contributions',
1310 'access CiviMember',
1311 'delete in CiviMember',
1312 'access CiviContribute',
1313 'delete in CiviContribute',
1317 'access CiviMember',
1318 'access CiviContribute',
1322 'access CiviMember',
1324 'access CiviContribute',
1325 'edit contributions',
1329 // Participant permissions
1330 $permissions['participant'] = [
1334 'register for events',
1339 'edit event participants',
1344 'view event participants',
1349 'edit event participants',
1352 $permissions['participant_payment'] = [
1356 'register for events',
1357 'access CiviContribute',
1358 'edit contributions',
1363 'edit event participants',
1364 'access CiviContribute',
1365 'delete in CiviContribute',
1370 'view event participants',
1371 'access CiviContribute',
1376 'edit event participants',
1377 'access CiviContribute',
1378 'edit contributions',
1382 // Pledge permissions
1383 $permissions['pledge'] = [
1386 'access CiviPledge',
1391 'access CiviPledge',
1392 'delete in CiviPledge',
1396 'access CiviPledge',
1400 'access CiviPledge',
1405 //CRM-16777: Disable schedule reminder for user that have 'edit all events' and 'administer CiviCRM' permission.
1406 $permissions['action_schedule'] = [
1415 $permissions['pledge_payment'] = [
1418 'access CiviPledge',
1420 'access CiviContribute',
1421 'edit contributions',
1425 'access CiviPledge',
1426 'delete in CiviPledge',
1427 'access CiviContribute',
1428 'delete in CiviContribute',
1432 'access CiviPledge',
1433 'access CiviContribute',
1437 'access CiviPledge',
1439 'access CiviContribute',
1440 'edit contributions',
1444 // Profile permissions
1445 $permissions['profile'] = [
1446 // the profile will take care of this
1450 $permissions['uf_group'] = [
1454 'administer CiviCRM',
1455 'manage event profiles',
1464 'administer CiviCRM',
1465 'manage event profiles',
1469 $permissions['uf_field'] = $permissions['uf_join'] = $permissions['uf_group'];
1470 $permissions['uf_field']['delete'] = [
1473 'administer CiviCRM',
1474 'manage event profiles',
1477 $permissions['option_value'] = $permissions['uf_group'];
1478 $permissions['option_group'] = $permissions['option_value'];
1480 $permissions['custom_value'] = [
1481 'gettree' => ['access CiviCRM'],
1484 $permissions['message_template'] = [
1485 'get' => ['access CiviCRM'],
1486 'create' => [['edit message templates', 'edit user-driven message templates', 'edit system workflow message templates']],
1487 'update' => [['edit message templates', 'edit user-driven message templates', 'edit system workflow message templates']],
1490 $permissions['report_template']['update'] = 'save Report Criteria';
1491 $permissions['report_template']['create'] = 'save Report Criteria';
1492 return $permissions;
1496 * Translate an unknown action to a canonical form.
1498 * @param string $action
1501 * the standardised action name
1503 public static function getGenericAction($action) {
1504 $snippet = substr($action, 0, 3);
1505 if ($action == 'replace' ||
$snippet == 'del') {
1506 // 'Replace' is a combination of get+create+update+delete; however, the permissions
1507 // on each of those will be tested separately at runtime. This is just a sniff-test
1508 // based on the heuristic that 'delete' tends to be the most closely guarded
1509 // of the necessary permissions.
1512 elseif ($action == 'setvalue' ||
$snippet == 'upd') {
1515 elseif ($action == 'getfields' ||
$action == 'getfield' ||
$action == 'getspec' ||
$action == 'getoptions') {
1518 elseif ($snippet == 'get') {
1525 * Validate user permission across.
1526 * edit or view or with supportable acls.
1530 public static function giveMeAllACLs() {
1531 if (CRM_Core_Permission
::check('view all contacts') ||
1532 CRM_Core_Permission
::check('edit all contacts')
1537 $session = CRM_Core_Session
::singleton();
1538 $contactID = $session->get('userID');
1541 $aclPermission = self
::getPermission();
1542 if (in_array($aclPermission, [
1543 CRM_Core_Permission
::EDIT
,
1544 CRM_Core_Permission
::VIEW
,
1550 // run acl where hook and see if the user is supplying an ACL clause
1551 // that is not false
1552 $tables = $whereTables = [];
1555 CRM_Utils_Hook
::aclWhereClause(CRM_Core_Permission
::VIEW
,
1556 $tables, $whereTables,
1559 return empty($whereTables) ?
FALSE : TRUE;
1563 * Get component name from given permission.
1565 * @param string $permission
1567 * @return null|string
1568 * the name of component.
1570 public static function getComponentName($permission) {
1571 $componentName = NULL;
1572 $permission = trim($permission);
1573 if (empty($permission)) {
1574 return $componentName;
1577 static $allCompPermissions = [];
1578 if (empty($allCompPermissions)) {
1579 $components = CRM_Core_Component
::getComponents();
1580 foreach ($components as $name => $comp) {
1581 //get all permissions of each components unconditionally
1582 $allCompPermissions[$name] = $comp->getPermissions(TRUE);
1586 if (is_array($allCompPermissions)) {
1587 foreach ($allCompPermissions as $name => $permissions) {
1588 if (array_key_exists($permission, $permissions)) {
1589 $componentName = $name;
1595 return $componentName;
1599 * Get all the contact emails for users that have a specific permission.
1601 * @param string $permissionName
1602 * Name of the permission we are interested in.
1605 * a comma separated list of email addresses
1607 public static function permissionEmails($permissionName) {
1608 $config = CRM_Core_Config
::singleton();
1609 return $config->userPermissionClass
->permissionEmails($permissionName);
1613 * Get all the contact emails for users that have a specific role.
1615 * @param string $roleName
1616 * Name of the role we are interested in.
1619 * a comma separated list of email addresses
1621 public static function roleEmails($roleName) {
1622 $config = CRM_Core_Config
::singleton();
1623 return $config->userRoleClass
->roleEmails($roleName);
1629 public static function isMultisiteEnabled() {
1630 return Civi
::settings()->get('is_enabled') ?
TRUE : FALSE;
1634 * Verify if the user has permission to get the invoice.
1637 * TRUE if the user has download all invoices permission or download my
1638 * invoices permission and the invoice author is the current user.
1640 public static function checkDownloadInvoice() {
1641 $cid = CRM_Core_Session
::getLoggedInContactID();
1642 if (CRM_Core_Permission
::check('access CiviContribute') ||
1643 (CRM_Core_Permission
::check('view my invoices') && $_GET['cid'] == $cid)