4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC. All rights reserved. |
7 | This work is published under the GNU AGPLv3 license with some |
8 | permitted exceptions and without any warranty. For full license |
9 | and copyright information, see https://civicrm.org/licensing |
10 +--------------------------------------------------------------------+
16 * @copyright CiviCRM LLC https://civicrm.org/licensing
20 namespace Civi\Api4\Generic
;
22 use Civi\Api4\Utils\CoreUtil
;
25 * Check if current user is authorized to perform specified action on a given $ENTITY.
27 * @method $this setAction(string $action)
28 * @method string getAction()
29 * @method $this setValues(array $values)
30 * @method array getValues()
32 class CheckAccessAction
extends AbstractAction
{
44 protected $values = [];
47 * @param \Civi\Api4\Generic\Result $result
49 public function _run(Result
$result) {
50 // Prevent circular checks
51 if ($this->action
=== 'checkAccess') {
55 $granted = CoreUtil
::checkAccessDelegated($this->getEntityName(), $this->action
, $this->values
, \CRM_Core_Session
::getLoggedInContactID() ?
: 0);
57 $result->exchangeArray([['access' => $granted]]);
61 * This action is always allowed
65 public function isAuthorized(): bool {
70 * Add an item to the values array
71 * @param string $fieldName
75 public function addValue(string $fieldName, $value) {
76 $this->values
[$fieldName] = $value;