From 707cc67a7dcf72bff0a00318a84834ae6c3d33b1 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Mon, 3 Apr 2023 09:51:13 +1200 Subject: [PATCH] Extend Generic\CheckAccess to reduce boilerplate --- .../Civi/Api4/Import/CheckAccessAction.php | 39 ++++--------------- 1 file changed, 7 insertions(+), 32 deletions(-) diff --git a/ext/civiimport/Civi/Api4/Import/CheckAccessAction.php b/ext/civiimport/Civi/Api4/Import/CheckAccessAction.php index d18125af42..1373a47d7c 100644 --- a/ext/civiimport/Civi/Api4/Import/CheckAccessAction.php +++ b/ext/civiimport/Civi/Api4/Import/CheckAccessAction.php @@ -12,39 +12,23 @@ namespace Civi\Api4\Import; -use Civi\Api4\Generic\AbstractAction; use Civi\Api4\Generic\Result; -use Civi\Api4\Generic\Traits\GetSetValueTrait; use Civi\Api4\Utils\CoreUtil; /** - * Check if current user is authorized to perform specified action on a given $ENTITY. + * Check if current user is authorized to perform specified action on the given import. * - * @method $this setAction(string $action) - * @method string getAction() - * @method $this setValues(array $values) - * @method array getValues() + * This is overridden to implement a permission on editing imported rows, mostly + * to make it less confusing as there is no meaning to importing edited rows. */ -class CheckAccessAction extends AbstractAction { - - use GetSetValueTrait; - - /** - * @var string - * @required - */ - protected $action; - - /** - * @var array - * @required - */ - protected $values = []; +class CheckAccessAction extends \Civi\Api4\Generic\CheckAccessAction { /** * @param \Civi\Api4\Generic\Result $result + * + * @throws \CRM_Core_Exception */ - public function _run(Result $result) { + public function _run(Result $result): void { // Prevent circular checks $action = $this->action; $entity = $this->getEntityName(); @@ -67,13 +51,4 @@ class CheckAccessAction extends AbstractAction { $result->exchangeArray([['access' => $granted]]); } - /** - * This action is always allowed - * - * @return bool - */ - public function isAuthorized(): bool { - return TRUE; - } - } -- 2.25.1