Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code cleanup in CRM_Core_Permission::check #15141

Merged
merged 1 commit into from
Aug 26, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 25 additions & 30 deletions CRM/Core/Permission.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,48 +81,43 @@ public static function getPermission() {

/**
* Given a permission string or array, check for access requirements
* @param string|array $permissions
* The permission to check as an array or string -see examples.
*
* @param int $contactId
* Contact id to check permissions for. Defaults to current logged-in user.
*
* Ex 1
* Ex 1: Must have 'access CiviCRM'
* (string) 'access CiviCRM'
*
* Must have 'access CiviCRM'
* (string) 'access CiviCRM'
* Ex 2: Must have 'access CiviCRM' and 'access Ajax API'
* ['access CiviCRM', 'access Ajax API']
*
* Ex 3: Must have 'access CiviCRM' or 'access Ajax API'
* [
* ['access CiviCRM', 'access Ajax API'],
* ],
*
* Ex 2 Must have 'access CiviCRM' and 'access Ajax API'
* array('access CiviCRM', 'access Ajax API')
* Ex 4: Must have 'access CiviCRM' or 'access Ajax API' AND 'access CiviEvent'
* [
* ['access CiviCRM', 'access Ajax API'],
* 'access CiviEvent',
* ],
*
* Ex 3 Must have 'access CiviCRM' or 'access Ajax API'
* array(
* array('access CiviCRM', 'access Ajax API'),
* ),
* Note that in permissions.php this is keyed by the action eg.
* (access Civi || access AJAX) && (access CiviEvent || access CiviContribute)
* 'myaction' => [
* ['access CiviCRM', 'access Ajax API'],
* ['access CiviEvent', 'access CiviContribute']
* ],
*
* Ex 4 Must have 'access CiviCRM' or 'access Ajax API' AND 'access CiviEvent'
* array(
* array('access CiviCRM', 'access Ajax API'),
* 'access CiviEvent',
* ),
* @param string|array $permissions
* The permission to check as an array or string -see examples.
*
* Note that in permissions.php this is keyed by the action eg.
* (access Civi || access AJAX) && (access CiviEvent || access CiviContribute)
* 'myaction' => array(
* array('access CiviCRM', 'access Ajax API'),
* array('access CiviEvent', 'access CiviContribute')
* ),
* @param int $contactId
* Contact id to check permissions for. Defaults to current logged-in user.
*
* @return bool
* true if yes, else false
* true if contact has permission(s), else false
*/
public static function check($permissions, $contactId = NULL) {
$permissions = (array) $permissions;
$userId = NULL;
if ($contactId) {
$userId = CRM_Core_BAO_UFMatch::getUFId($contactId);
}
$userId = CRM_Core_BAO_UFMatch::getUFId($contactId);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CRM_Core_BAO_UFMatch::getUFId already returns null if $contactId is empty, so this conditional was redundant.


/** @var CRM_Core_Permission_Temp $tempPerm */
$tempPerm = CRM_Core_Config::singleton()->userPermissionTemp;
Expand Down