From bebdb7f4c5c0f26bd11e014625e7df176b163933 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Tue, 15 Jun 2021 02:07:33 -0400 Subject: [PATCH] SearchKit - Add acl_bypass column to civicrm_search_display table The new column determines whether permissions will be checked when running a display --- .../CRM/Search/DAO/SearchDisplay.php | 25 ++++++++++- ext/search_kit/CRM/Search/Upgrader.php | 32 +++++++++++++- ext/search_kit/sql/auto_install.sql | 44 ++++++------------- ext/search_kit/sql/auto_uninstall.sql | 6 +-- .../xml/schema/CRM/Search/SearchDisplay.xml | 12 +++++ 5 files changed, 82 insertions(+), 37 deletions(-) diff --git a/ext/search_kit/CRM/Search/DAO/SearchDisplay.php b/ext/search_kit/CRM/Search/DAO/SearchDisplay.php index e4dd814bfb..c7dfeb7b18 100644 --- a/ext/search_kit/CRM/Search/DAO/SearchDisplay.php +++ b/ext/search_kit/CRM/Search/DAO/SearchDisplay.php @@ -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']); } diff --git a/ext/search_kit/CRM/Search/Upgrader.php b/ext/search_kit/CRM/Search/Upgrader.php index 31c06e64ca..cab3255156 100644 --- a/ext/search_kit/CRM/Search/Upgrader.php +++ b/ext/search_kit/CRM/Search/Upgrader.php @@ -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; + } + } diff --git a/ext/search_kit/sql/auto_install.sql b/ext/search_kit/sql/auto_install.sql index 3a4deb2b66..e6c2463ec5 100644 --- a/ext/search_kit/sql/auto_install.sql +++ b/ext/search_kit/sql/auto_install.sql @@ -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; diff --git a/ext/search_kit/sql/auto_uninstall.sql b/ext/search_kit/sql/auto_uninstall.sql index ff5a74dc51..e1c88f5cb2 100644 --- a/ext/search_kit/sql/auto_uninstall.sql +++ b/ext/search_kit/sql/auto_uninstall.sql @@ -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; diff --git a/ext/search_kit/xml/schema/CRM/Search/SearchDisplay.xml b/ext/search_kit/xml/schema/CRM/Search/SearchDisplay.xml index 750977d933..d2dde8906d 100644 --- a/ext/search_kit/xml/schema/CRM/Search/SearchDisplay.xml +++ b/ext/search_kit/xml/schema/CRM/Search/SearchDisplay.xml @@ -97,4 +97,16 @@ 1.0 + + acl_bypass + Bypass ACL Permissions + boolean + 0 + Skip permission checks and ACLs when running this display. + 5.40 + + Checkbox + + + -- 2.25.1