CRM-12747 : component access permission defining way for end developer
authorPratik Joshi <pratik.joshi@webaccess.co.in>
Mon, 3 Jun 2013 14:54:19 +0000 (20:24 +0530)
committerPratik Joshi <pratik.joshi@webaccess.co.in>
Mon, 3 Jun 2013 14:54:19 +0000 (20:24 +0530)
CRM/Contact/Form/Search/Custom.php
CRM/Contact/Form/Search/Custom/ContribSYBNT.php
CRM/Contact/Form/Search/Custom/ContributionAggregate.php
CRM/Contact/Form/Search/Custom/EventAggregate.php
CRM/Contact/Form/Search/Custom/PriceSet.php
CRM/Contact/Form/Search/Custom/TagContributions.php

index 97c8f773b8189d8619c095d57edd090b0c7365ce..dec43979e60d5866c11b70bcbc14bf2139b03e64 100644 (file)
@@ -81,6 +81,12 @@ class CRM_Contact_Form_Search_Custom extends CRM_Contact_Form_Search {
 
     // instantiate the new class
     $this->_customClass = new $this->_customSearchClass( $this->_formValues );
+
+    // CRM-12747
+    if (isset($this->_customClass->_permissionedComponent) &&
+      !self::isPermissioned($this->_customClass->_permissionedComponent)) {
+      CRM_Utils_System::permissionDenied();
+    }
   }
 
   function setDefaultValues() {
@@ -132,5 +138,23 @@ class CRM_Contact_Form_Search_Custom extends CRM_Contact_Form_Search {
   public function getTitle() {
     return ts('Custom Search');
   }
-}
 
+  function isPermissioned($components) {
+    if (empty($components)) {
+      return TRUE;
+    }
+    if (is_array($components)) {
+      foreach ($components as $component) {
+        if (!CRM_Core_Permission::access($component)) {
+          return FALSE;
+        }
+      }
+    }
+    else {
+      if (!CRM_Core_Permission::access($components)) {
+        return FALSE;
+      }
+    }
+    return TRUE;
+  }
+}
\ No newline at end of file
index 515698b20ef9104da634999cde9f4a1681a46d6b..7390e5be2ec5758c68e31af5ac25cf6df189e84e 100644 (file)
  */
 class CRM_Contact_Form_Search_Custom_ContribSYBNT implements CRM_Contact_Form_Search_Interface {
 
-  protected $_formValues; function __construct(&$formValues) {
+  protected $_formValues;
+  public $_permissionedComponent;
+
+  function __construct(&$formValues) {
     $this->_formValues = $formValues;
+    $this->_permissionedComponent = 'CiviContribute';
 
     $this->_columns = array(
       ts('Contact Id') => 'contact_id',
index 7552ca61524d4c2ec8041bf04a947282ed264d7e..7937845d2fef0318227b642542ca9aceadd52e01 100644 (file)
  */
 class CRM_Contact_Form_Search_Custom_ContributionAggregate implements CRM_Contact_Form_Search_Interface {
 
-  protected $_formValues; function __construct(&$formValues) {
-    $this->_formValues = $formValues;
+  protected $_formValues;
+  public $_permissionedComponent;
 
+  function __construct(&$formValues) {
+    $this->_formValues = $formValues;
     /**
      * Define the columns for search result rows
      */
+
     $this->_columns = array(
       ts('Contact Id') => 'contact_id',
       ts('Name') => 'sort_name',
       ts('Donation Count') => 'donation_count',
       ts('Donation Amount') => 'donation_amount',
     );
+
+    // define component access permission needed
+    $this->_permissionedComponent = 'CiviContribute';
   }
 
   function buildForm(&$form) {
index e7435082b0c0653e4ef7abeefe8fa2d687f76450..b7b86ca725e7c545dd00d04dca58c2a97e943c7f 100644 (file)
  */
 class CRM_Contact_Form_Search_Custom_EventAggregate extends CRM_Contact_Form_Search_Custom_Base implements CRM_Contact_Form_Search_Interface {
 
-  protected $_formValues; function __construct(&$formValues) {
+  protected $_formValues;
+  public $_permissionedComponent;
+
+  function __construct(&$formValues) {
     $this->_formValues = $formValues;
+    $this->_permissionedComponent = array('CiviContribute', 'CiviEvent');
 
     /**
      * Define the columns for search result rows
index dc3fe401484b8f587dfe92b98e81330f6f53ddad..cf3141ba4e14d6884a385513913afa1975673484 100644 (file)
@@ -36,7 +36,10 @@ class CRM_Contact_Form_Search_Custom_PriceSet extends CRM_Contact_Form_Search_Cu
 
   protected $_eventID = NULL;
 
-  protected $_tableName = NULL; function __construct(&$formValues) {
+  protected $_tableName = NULL;
+  public $_permissionedComponent;
+
+  function __construct(&$formValues) {
     parent::__construct($formValues);
 
     $this->_eventID = CRM_Utils_Array::value('event_id',
@@ -47,9 +50,11 @@ class CRM_Contact_Form_Search_Custom_PriceSet extends CRM_Contact_Form_Search_Cu
 
     if ($this->_eventID) {
       $this->buildTempTable();
-
       $this->fillTable();
     }
+
+    // define component access permission needed
+    $this->_permissionedComponent = 'CiviEvent';
   }
 
   function __destruct() {
index 5b24abfc9a404bbe4f1d40012ba344ea5781e9d8..da25978466362319b42195589b40fa001526eca9 100644 (file)
  */
 class CRM_Contact_Form_Search_Custom_TagContributions implements CRM_Contact_Form_Search_Interface {
 
-  protected $_formValues; function __construct(&$formValues) {
+  protected $_formValues;
+  public $_permissionedComponent;
+
+  function __construct(&$formValues) {
     $this->_formValues = $formValues;
+    $this->_permissionedComponent = 'CiviContribute';
 
     /**
      * Define the columns for search result rows