Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

COMCL-722: Allow user with award review permission access option value #283

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions CRM/CiviAwards/Event/Listener/AlterPermission.php
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\AuthorizeEvent $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 Civi\Api4\Generic\AbstractAction $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';
}

}
6 changes: 6 additions & 0 deletions civiawards.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ function civiawards_civicrm_config(&$config) {
['CRM_CiviAwards_Event_Listener_AwardCaseFilter', 'onPrepare'],
10
);

Civi::dispatcher()->addListener(
'civi.api.authorize',
['CRM_CiviAwards_Event_Listener_AlterPermission', 'authorize'],
10
);
}

/**
Expand Down
Loading