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 +--------------------------------------------------------------------+
13 namespace Civi\Api4\Generic
;
15 use Civi\Api4\Utils\CoreUtil
;
18 * Check if current user is authorized to perform specified action on a given $ENTITY.
20 * @method $this setAction(string $action)
21 * @method string getAction()
22 * @method $this setValues(array $values)
23 * @method array getValues()
25 class CheckAccessAction
extends AbstractAction
{
37 protected $values = [];
40 * @param \Civi\Api4\Generic\Result $result
42 public function _run(Result
$result) {
43 // Prevent circular checks
44 if ($this->action
=== 'checkAccess') {
48 $granted = CoreUtil
::checkAccessDelegated($this->getEntityName(), $this->action
, $this->values
, \CRM_Core_Session
::getLoggedInContactID() ?
: 0);
50 $result->exchangeArray([['access' => $granted]]);
54 * This action is always allowed
58 public function isAuthorized(): bool {
63 * Add an item to the values array
64 * @param string $fieldName
68 public function addValue(string $fieldName, $value) {
69 $this->values
[$fieldName] = $value;