Decouple CiviGrant from core permission function
authorColeman Watts <coleman@civicrm.org>
Tue, 9 Aug 2022 02:03:47 +0000 (22:03 -0400)
committerColeman Watts <coleman@civicrm.org>
Tue, 9 Aug 2022 02:03:47 +0000 (22:03 -0400)
CRM/Core/Permission.php
ext/civigrant/CRM/Grant/BAO/Grant.php
ext/civigrant/CRM/Grant/Form/Grant.php
ext/civigrant/CRM/Grant/Form/GrantView.php
ext/civigrant/CRM/Grant/Form/Task/Delete.php
ext/civigrant/CRM/Grant/Form/Task/Update.php

index a9d085594ef8d728f74c3135a5dd6666469f2da3..8c7982dc0a4f8d67265f7a1b066bab485768b29c 100644 (file)
@@ -476,7 +476,6 @@ class CRM_Core_Permission {
         'CiviMember' => 'edit memberships',
         'CiviPledge' => 'edit pledges',
         'CiviContribute' => 'edit contributions',
-        'CiviGrant' => 'edit grants',
         'CiviMail' => 'access CiviMail',
         'CiviAuction' => 'add auction items',
       ];
index 51d09236b58883055a0a4db03dc603bbe55e0962..fbf9f1420ceb004a85105767c4ab4d18d5ca901e 100644 (file)
@@ -114,12 +114,12 @@ class CRM_Grant_BAO_Grant extends CRM_Grant_DAO_Grant {
       $title = CRM_Contact_BAO_Contact::displayName($grant->contact_id) . ' - ' . ts('Grant') . ': ' . $grantTypes[$grant->grant_type_id];
 
       $recentOther = [];
-      if (CRM_Core_Permission::checkActionPermission('CiviGrant', CRM_Core_Action::UPDATE)) {
+      if (CRM_Core_Permission::check('edit grants')) {
         $recentOther['editUrl'] = CRM_Utils_System::url('civicrm/contact/view/grant',
           "action=update&reset=1&id={$grant->id}&cid={$grant->contact_id}&context=home"
         );
       }
-      if (CRM_Core_Permission::checkActionPermission('CiviGrant', CRM_Core_Action::DELETE)) {
+      if (CRM_Core_Permission::check('delete in CiviGrant')) {
         $recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/contact/view/grant',
           "action=delete&reset=1&id={$grant->id}&cid={$grant->contact_id}&context=home"
         );
index 6d9a7aab2691a2fb6f0857f59f7b2c8e1e2dbd9d..870ddf432682afde9c48b495a28d278dbeb6d6fb 100644 (file)
@@ -54,8 +54,9 @@ class CRM_Grant_Form_Grant extends CRM_Core_Form {
     $this->assign('action', $this->_action);
     $this->assign('context', $this->_context);
 
-    //check permission for action.
-    if (!CRM_Core_Permission::checkActionPermission('CiviGrant', $this->_action)) {
+    // check permission for action.
+    $perm = $this->_action & CRM_Core_Action::DELETE ? 'delete in CiviGrant' : 'edit grants';
+    if (!CRM_Core_Permission::check($perm)) {
       CRM_Core_Error::statusBounce(ts('You do not have permission to access this page.'));
     }
 
index b6e4cfa4f55fb43dc99b20403ea261fe96c0801e..261060bfeb34ace44e57111454139bb30cfee280 100644 (file)
@@ -76,12 +76,12 @@ class CRM_Grant_Form_GrantView extends CRM_Core_Form {
     $title = CRM_Contact_BAO_Contact::displayName($values['contact_id']) . ' - ' . ts('Grant') . ': ' . CRM_Utils_Money::format($values['amount_total']) . ' (' . $grantType[$values['grant_type_id']] . ')';
 
     $recentOther = [];
-    if (CRM_Core_Permission::checkActionPermission('CiviGrant', CRM_Core_Action::UPDATE)) {
+    if (CRM_Core_Permission::check('edit grants')) {
       $recentOther['editUrl'] = CRM_Utils_System::url('civicrm/contact/view/grant',
         "action=update&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home"
       );
     }
-    if (CRM_Core_Permission::checkActionPermission('CiviGrant', CRM_Core_Action::DELETE)) {
+    if (CRM_Core_Permission::check('delete in CiviGrant')) {
       $recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/contact/view/grant',
         "action=delete&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home"
       );
index 5a05c0d98cc576500a9ab23ea0829ed4688583e3..c6f3036cac2811f594e13579cc399252adc699ba 100644 (file)
@@ -39,7 +39,7 @@ class CRM_Grant_Form_Task_Delete extends CRM_Grant_Form_Task {
     parent::preProcess();
 
     //check permission for delete.
-    if (!CRM_Core_Permission::checkActionPermission('CiviGrant', CRM_Core_Action::DELETE)) {
+    if (!CRM_Core_Permission::check('delete in CiviGrant')) {
       CRM_Core_Error::statusBounce(ts('You do not have permission to access this page.'));
     }
   }
index d8388cb5f29e797c3ffa044fc1ac254bc2b87beb..074ef3fee8e385ec39ec3f3d8c18378bb70069cf 100644 (file)
@@ -31,7 +31,7 @@ class CRM_Grant_Form_Task_Update extends CRM_Grant_Form_Task {
     parent::preProcess();
 
     //check permission for update.
-    if (!CRM_Core_Permission::checkActionPermission('CiviGrant', CRM_Core_Action::UPDATE)) {
+    if (!CRM_Core_Permission::check('edit grants')) {
       CRM_Core_Error::statusBounce(ts('You do not have permission to access this page.'));
     }
   }