added code to restrict restrictions

This commit is contained in:
CiviWare Solutions 2018-06-29 01:50:47 +05:30
parent c087cc7a27
commit a864caa95f

View File

@ -154,7 +154,7 @@ function batchexportperm_civicrm_permission(&$permissions) {
*/ */
function batchexportperm_civicrm_links($op, $objectName, $objectId, &$links, &$mask, &$values) { function batchexportperm_civicrm_links($op, $objectName, $objectId, &$links, &$mask, &$values) {
if ($op == 'contribution.selector.row' && $objectName == 'Contribution') { if ($op == 'contribution.selector.row' && $objectName == 'Contribution') {
if (!CRM_Core_Permission::check('edit exported contributions')) { if (!_batchexportperm_civicrm_allow_contribution_to_edit($objectId)) {
foreach ($links as $key => $link) { foreach ($links as $key => $link) {
if ($link['name'] == 'Edit') { if ($link['name'] == 'Edit') {
unset($links[$key]); unset($links[$key]);
@ -163,3 +163,78 @@ function batchexportperm_civicrm_links($op, $objectName, $objectId, &$links, &$m
} }
} }
} }
/**
* Implements hook_civicrm_pre().
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_pre
*/
function batchexportperm_civicrm_pre($op, $objectName, $id, &$params) {
if ($op == 'edit' && $objectName == 'Contribution') {
_batchexportperm_civicrm_check_permission($id);
}
}
/**
* Implements hook_civicrm_apiWrappers().
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_apiWrappers
*/
function batchexportperm_civicrm_apiWrappers(&$wrappers, $apiRequest) {
if ($apiRequest['entity'] == 'Contribution' && $apiRequest['action'] == 'create') {
$contibutionId = CRM_Utils_Array::value('id', $apiRequest['params']);
_batchexportperm_civicrm_check_permission($contibutionId, 'exception');
}
}
/**
* Implements hook_civicrm_preProcess().
*
* @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_preProcess
*/
function batchexportperm_civicrm_preProcess($formName, &$form) {
if ($formName == 'CRM_Contribute_Form_Contribution' && $form->_action & CRM_Core_Action::UPDATE) {
$contributionId = $form->_id;
_batchexportperm_civicrm_check_permission($contributionId);
}
}
/**
* Check if user has permission to update contribution.
*
* @param int $contributionId
* @param string $errorType
*/
function _batchexportperm_civicrm_check_permission($contributionId, $errorType = NULL) {
if (empty($contributionId) || _batchexportperm_civicrm_allow_contribution_to_edit($contributionId)) {
return FALSE;
}
$message = ts('You do not have the necessary permission to edit this contribution.');
if ($errorType == 'exception') {
throw new API_Exception($message);
}
else {
CRM_Core_Error::statusBounce($message);
}
}
/**
* Check if user has permission to update contribution.
*
* @param int $contributionId
*/
function _batchexportperm_civicrm_allow_contribution_to_edit($contributionId) {
$customFieldId = civicrm_api3('CustomField', 'getvalue', [
'return' => "id",
'custom_group_id' => "Batch_Details",
'name' => "Export_Date",
]);
$exportDate = civicrm_api3('Contribution', 'getvalue', [
'return' => "custom_{$customFieldId}",
'id' => $contributionId,
]);
if (empty($exportDate) || CRM_Core_Permission::check('edit exported contributions')) {
return TRUE;
}
return FALSE;
}