-
-
Notifications
You must be signed in to change notification settings - Fork 825
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert hook_civicrm_checkAccess to civi.api4.authorizeRecord
- Loading branch information
Showing
7 changed files
with
132 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<?php | ||
|
||
/* | ||
+--------------------------------------------------------------------+ | ||
| Copyright CiviCRM LLC. All rights reserved. | | ||
| | | ||
| This work is published under the GNU AGPLv3 license with some | | ||
| permitted exceptions and without any warranty. For full license | | ||
| and copyright information, see https://civicrm.org/licensing | | ||
+--------------------------------------------------------------------+ | ||
*/ | ||
|
||
/** | ||
* | ||
* @package CRM | ||
* @copyright CiviCRM LLC https://civicrm.org/licensing | ||
*/ | ||
|
||
namespace Civi\Api4\Event; | ||
|
||
use Civi\API\Event\AuthorizedTrait; | ||
use Civi\API\Event\RequestTrait; | ||
use Civi\Core\Event\GenericHookEvent; | ||
|
||
/** | ||
* Determine if the a user has access to a given record. | ||
* | ||
* Event name: 'civi.api4.authorizeRecord' | ||
*/ | ||
class AuthorizeRecordEvent extends GenericHookEvent { | ||
|
||
use RequestTrait; | ||
use AuthorizedTrait; | ||
|
||
/** | ||
* All (known/loaded) values of individual record being accessed. | ||
* The record should provide an 'id' but may otherwise be incomplete; guard accordingly. | ||
* | ||
* @var array | ||
*/ | ||
private $record; | ||
|
||
/** | ||
* Contact ID of the active/target user (whose access we must check). | ||
* NULL for anonymous. | ||
* | ||
* @var int|null | ||
*/ | ||
private $userID; | ||
|
||
/** | ||
* CheckAccessEvent constructor. | ||
* | ||
* @param \Civi\Api4\Generic\AbstractAction $apiRequest | ||
* @param array $record | ||
* All (known/loaded) values of individual record being accessed. | ||
* The record should provide an 'id' but may otherwise be incomplete; guard accordingly. | ||
* @param int|null $userID | ||
* Contact ID of the active/target user (whose access we must check). | ||
* NULL for anonymous. | ||
*/ | ||
public function __construct($apiRequest, array $record, ?int $userID) { | ||
$this->setApiRequest($apiRequest); | ||
$this->record = $record; | ||
$this->userID = $userID; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function getHookValues() { | ||
return [$this->getApiRequest(), $this->record, &$this->authorized]; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getRecord(): array { | ||
return $this->record; | ||
} | ||
|
||
/** | ||
* @return int|null | ||
* Contact ID of the active/target user (whose access we must check). | ||
* NULL for anonymous. | ||
*/ | ||
public function getUserID(): ?int { | ||
return $this->userID; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters