From 78007763b93b371d93d4ef1151e041b23ae55ff8 Mon Sep 17 00:00:00 2001 From: Jens Schuppe Date: Wed, 12 Dec 2018 13:14:55 +0100 Subject: [PATCH] Add and require permission for accessing API --- twingle.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/twingle.php b/twingle.php index 2187bdc..c2a064e 100644 --- a/twingle.php +++ b/twingle.php @@ -123,6 +123,27 @@ function twingle_civicrm_alterSettingsFolders(&$metaDataFolders = NULL) { _twingle_civix_civicrm_alterSettingsFolders($metaDataFolders); } +/** + * Implements hook_civicrm_permission(). + * + * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_permission + */ +function twingle_civicrm_permission(&$permissions) { + $permissions['access Twingle API'] = 'Twingle API: Access Twingle API'; +} + +/** + * Implements hook_civicrm_alterAPIPermissions(). + * + * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_alterAPIPermissions + */ +function twingle_civicrm_alterAPIPermissions($entity, $action, &$params, &$permissions) { + // Restrict API calls to the permission. + $permissions['twingle_donation']['submit'] = array('access Twingle API'); + $permissions['twingle_donation']['cancel'] = array('access Twingle API'); + $permissions['twingle_donation']['endrecurring'] = array('access Twingle API'); +} + // --- Functions below this ship commented out. Uncomment as required. --- /**