Merge pull request #22928 from artfulrobot/artfulrobot-title-double-html-encoding
[civicrm-core.git] / Civi / Api4 / Event / AuthorizeRecordEvent.php
1 <?php
2
3 /*
4 +--------------------------------------------------------------------+
5 | Copyright CiviCRM LLC. All rights reserved. |
6 | |
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 +--------------------------------------------------------------------+
11 */
12 namespace Civi\Api4\Event;
13
14 use Civi\API\Event\AuthorizedTrait;
15 use Civi\API\Event\RequestTrait;
16 use Civi\Core\Event\GenericHookEvent;
17
18 /**
19 * Determine if the a user has access to a given record.
20 *
21 * Event name: 'civi.api4.authorizeRecord'
22 */
23 class AuthorizeRecordEvent extends GenericHookEvent {
24
25 use RequestTrait;
26 use AuthorizedTrait;
27 use ActiveUserTrait;
28
29 /**
30 * All (known/loaded) values of individual record being accessed.
31 * The record should provide an 'id' but may otherwise be incomplete; guard accordingly.
32 *
33 * @var array
34 */
35 private $record;
36
37 /**
38 * CheckAccessEvent constructor.
39 *
40 * @param \Civi\Api4\Generic\AbstractAction $apiRequest
41 * @param array $record
42 * All (known/loaded) values of individual record being accessed.
43 * The record should provide an 'id' but may otherwise be incomplete; guard accordingly.
44 * @param int $userID
45 * Contact ID of the active/target user (whose access we must check).
46 * 0 for anonymous.
47 */
48 public function __construct($apiRequest, array $record, int $userID) {
49 $this->setApiRequest($apiRequest);
50 $this->record = $record;
51 $this->setUser($userID);
52 }
53
54 /**
55 * @inheritDoc
56 */
57 public function getHookValues() {
58 return [$this->getApiRequest(), $this->record, &$this->authorized];
59 }
60
61 /**
62 * @return array
63 */
64 public function getRecord(): array {
65 return $this->record;
66 }
67
68 }