-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
COMCL-722: Allow user with with award review permission access option…
… value
- Loading branch information
1 parent
9c8d421
commit 1bf06f3
Showing
2 changed files
with
67 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
use Civi\API\Event\AuthorizeEvent; | ||
use Civi\Api4\Generic\AbstractAction; | ||
use CRM_CiviAwards_Hook_AlterAPIPermissions_Award as AwardPermission; | ||
|
||
/** | ||
* Award filter while fetching cases. | ||
*/ | ||
class CRM_CiviAwards_Event_Listener_AlterPermission { | ||
|
||
/** | ||
* Fetches cases by the given award filters. | ||
* | ||
* @param \Civi\API\Event\PrepareEvent $event | ||
* API Prepare Event Object. | ||
*/ | ||
public static function authorize(AuthorizeEvent $event) { | ||
$apiRequest = $event->getApiRequest(); | ||
if ($apiRequest['version'] != 4) { | ||
return; | ||
} | ||
|
||
if (!self::shouldRun($apiRequest)) { | ||
return; | ||
} | ||
|
||
$hasPermission = CRM_Core_Permission::check(AwardPermission::REVIEW_FIELD_SET_PERM); | ||
if (!$hasPermission) { | ||
return; | ||
} | ||
|
||
$params = CRM_Utils_Request::retrieve('params', 'String'); | ||
if (is_null($params)) { | ||
return; | ||
} | ||
|
||
try { | ||
$params = json_decode($params); | ||
$formName = $params->formName ?? NULL; | ||
$event->setAuthorized($formName == 'qf:CRM_CiviAwards_Form_AwardReview'); | ||
} | ||
catch (\Throwable $th) { | ||
} | ||
} | ||
|
||
/** | ||
* Determines if the processing will run. | ||
* | ||
* @param array $apiRequest | ||
* Api request data. | ||
* | ||
* @return bool | ||
* TRUE if processing should run, FALSE otherwise. | ||
*/ | ||
protected static function shouldRun(AbstractAction $apiRequest) { | ||
return $apiRequest['entity'] == 'OptionValue' && | ||
$apiRequest['action'] == 'get'; | ||
} | ||
|
||
} |
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