SearchKit - Add acl_bypass column to civicrm_search_display table
authorColeman Watts <coleman@civicrm.org>
Tue, 15 Jun 2021 06:07:33 +0000 (02:07 -0400)
committerColeman Watts <coleman@civicrm.org>
Tue, 15 Jun 2021 06:07:33 +0000 (02:07 -0400)
The new column determines whether permissions will be checked when running a display

ext/search_kit/CRM/Search/DAO/SearchDisplay.php
ext/search_kit/CRM/Search/Upgrader.php
ext/search_kit/sql/auto_install.sql
ext/search_kit/sql/auto_uninstall.sql
ext/search_kit/xml/schema/CRM/Search/SearchDisplay.xml

index e4dd814bfb94d53cbefc92e094a20623b4d93967..c7dfeb7b1841287d35a2f8fe1e3e5ef1eead4089 100644 (file)
@@ -6,7 +6,7 @@
  *
  * Generated from org.civicrm.search_kit/xml/schema/CRM/Search/SearchDisplay.xml
  * DO NOT EDIT.  Generated by CRM_Core_CodeGen
- * (GenCodeChecksum:6042d1e2bee9eaed4c3a7c59c34ad224)
+ * (GenCodeChecksum:6d44d0c212e3f352182cac098e4d44ac)
  */
 use CRM_Search_ExtensionUtil as E;
 
@@ -73,6 +73,13 @@ class CRM_Search_DAO_SearchDisplay extends CRM_Core_DAO {
    */
   public $settings;
 
+  /**
+   * Skip permission checks and ACLs when running this display.
+   *
+   * @var bool
+   */
+  public $acl_bypass;
+
   /**
    * Class constructor.
    */
@@ -214,6 +221,22 @@ class CRM_Search_DAO_SearchDisplay extends CRM_Core_DAO {
           'serialize' => self::SERIALIZE_JSON,
           'add' => '1.0',
         ],
+        'acl_bypass' => [
+          'name' => 'acl_bypass',
+          'type' => CRM_Utils_Type::T_BOOLEAN,
+          'title' => E::ts('Bypass ACL Permissions'),
+          'description' => E::ts('Skip permission checks and ACLs when running this display.'),
+          'where' => 'civicrm_search_display.acl_bypass',
+          'default' => '0',
+          'table_name' => 'civicrm_search_display',
+          'entity' => 'SearchDisplay',
+          'bao' => 'CRM_Search_DAO_SearchDisplay',
+          'localizable' => 0,
+          'html' => [
+            'type' => 'Checkbox',
+          ],
+          'add' => '5.40',
+        ],
       ];
       CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']);
     }
index 31c06e64ca70a425cc359d75de17b31ddb2de720..cab3255156332c2747483f7b4d253495866202ac 100644 (file)
@@ -139,9 +139,39 @@ class CRM_Search_Upgrader extends CRM_Search_Upgrader_Base {
    * @return bool
    */
   public function upgrade_1004() {
-    $this->ctx->log->info('Applying update 1000 - fix menu permission.');
+    $this->ctx->log->info('Applying update 1004 - fix menu permission.');
     CRM_Core_DAO::executeQuery("UPDATE civicrm_navigation SET permission = 'administer CiviCRM data' WHERE url = 'civicrm/admin/search'");
     return TRUE;
   }
 
+  /**
+   * Upgrade 1005 - add acl_bypass column.
+   * @return bool
+   */
+  public function upgrade_1005() {
+    $this->ctx->log->info('Applying update 1005 - add acl_bypass column.');
+    $this->addTask('Add Cancel Button Setting to the Profile', 'addColumn',
+      'civicrm_search_display', 'acl_bypass', "tinyint DEFAULT 0 COMMENT 'Skip permission checks and ACLs when running this display.'");
+    return TRUE;
+  }
+
+  /**
+   * Add a column to a table if it doesn't already exist
+   *
+   * FIXME: Move to a shared class, delegate to CRM_Upgrade_Incremental_Base::addColumn
+   *
+   * @param string $table
+   * @param string $column
+   * @param string $properties
+   *
+   * @return bool
+   */
+  public static function addColumn($table, $column, $properties) {
+    if (!CRM_Core_BAO_SchemaHandler::checkIfFieldExists($table, $column, FALSE)) {
+      $query = "ALTER TABLE `$table` ADD COLUMN `$column` $properties";
+      CRM_Core_DAO::executeQuery($query, [], TRUE, NULL, FALSE, FALSE);
+    }
+    return TRUE;
+  }
+
 }
index 3a4deb2b66308508096ef1a3b7efa13d29044981..e6c2463ec5c4c49d0d7768681f82d785786fcf2a 100644 (file)
@@ -9,21 +9,9 @@
 -- Generated from schema.tpl
 -- DO NOT EDIT.  Generated by CRM_Core_CodeGen
 --
-
--- +--------------------------------------------------------------------+
--- | Copyright CiviCRM LLC. All rights reserved.                        |
--- |                                                                    |
--- | This work is published under the GNU AGPLv3 license with some      |
--- | permitted exceptions and without any warranty. For full license    |
--- | and copyright information, see https://civicrm.org/licensing       |
--- +--------------------------------------------------------------------+
---
--- Generated from drop.tpl
--- DO NOT EDIT.  Generated by CRM_Core_CodeGen
---
 -- /*******************************************************
 -- *
--- * Clean up the existing tables
+-- * Clean up the existing tables - this section generated from drop.tpl
 -- *
 -- *******************************************************/
 
@@ -46,21 +34,15 @@ SET FOREIGN_KEY_CHECKS=1;
 -- *
 -- *******************************************************/
 CREATE TABLE `civicrm_search_display` (
-
-
-     `id` int unsigned NOT NULL AUTO_INCREMENT  COMMENT 'Unique SearchDisplay ID',
-     `name` varchar(255) NOT NULL   COMMENT 'Unique name for identifying search display',
-     `label` varchar(255) NOT NULL   COMMENT 'Label for identifying search display to administrators',
-     `saved_search_id` int unsigned NOT NULL   COMMENT 'FK to saved search table.',
-     `type` varchar(128) NOT NULL   COMMENT 'Type of display',
-     `settings` text   DEFAULT NULL COMMENT 'Configuration data for the search display'
-,
-        PRIMARY KEY (`id`)
-
-    ,     UNIQUE INDEX `UI_saved_search__id_name`(
-        saved_search_id
-      , name
-  )
-
-,          CONSTRAINT FK_civicrm_search_display_saved_search_id FOREIGN KEY (`saved_search_id`) REFERENCES `civicrm_saved_search`(`id`) ON DELETE CASCADE
-) ROW_FORMAT=DYNAMIC    ;
+  `id` int unsigned NOT NULL AUTO_INCREMENT COMMENT 'Unique SearchDisplay ID',
+  `name` varchar(255) NOT NULL COMMENT 'Unique name for identifying search display',
+  `label` varchar(255) NOT NULL COMMENT 'Label for identifying search display to administrators',
+  `saved_search_id` int unsigned NOT NULL COMMENT 'FK to saved search table.',
+  `type` varchar(128) NOT NULL COMMENT 'Type of display',
+  `settings` text DEFAULT NULL COMMENT 'Configuration data for the search display',
+  `acl_bypass` tinyint DEFAULT 0 COMMENT 'Skip permission checks and ACLs when running this display.',
+  PRIMARY KEY (`id`),
+  UNIQUE INDEX `UI_saved_search__id_name`(saved_search_id, name),
+  CONSTRAINT FK_civicrm_search_display_saved_search_id FOREIGN KEY (`saved_search_id`) REFERENCES `civicrm_saved_search`(`id`) ON DELETE CASCADE
+)
+ENGINE=InnoDB;
index ff5a74dc51e711d951ffaea55aeab8f4c2ef4a8b..e1c88f5cb233ee656148e8b37d0721594fdb944c 100644 (file)
@@ -8,11 +8,9 @@
 --
 -- Generated from drop.tpl
 -- DO NOT EDIT.  Generated by CRM_Core_CodeGen
---
--- /*******************************************************
--- *
--- * Clean up the existing tables
+---- /*******************************************************
 -- *
+-- * Clean up the existing tables-- *
 -- *******************************************************/
 
 SET FOREIGN_KEY_CHECKS=0;
index 750977d933e3d46a3981e232b10cba83b2e39b24..d2dde8906dd78ded66bfd53919bacad705695a7c 100644 (file)
     <add>1.0</add>
   </field>
 
+  <field>
+    <name>acl_bypass</name>
+    <title>Bypass ACL Permissions</title>
+    <type>boolean</type>
+    <default>0</default>
+    <comment>Skip permission checks and ACLs when running this display.</comment>
+    <add>5.40</add>
+    <html>
+      <type>Checkbox</type>
+    </html>
+  </field>
+
 </table>