Bugzilla – Attachment 137027 Details for
Bug 17170
Add the ability to create 'saved searches' for use as filters when searching the catalog
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 17170: DB Updates
Bug-17170-DB-Updates.patch (text/plain), 11.61 KB, created by
Nick Clemens (kidclamp)
on 2022-07-01 16:30:39 UTC
(
hide
)
Description:
Bug 17170: DB Updates
Filename:
MIME Type:
Creator:
Nick Clemens (kidclamp)
Created:
2022-07-01 16:30:39 UTC
Size:
11.61 KB
patch
obsolete
>From 98d1075e776794b6cf9470aacf74a67c8c061246 Mon Sep 17 00:00:00 2001 >From: Nick Clemens <nick@bywatersolutions.com> >Date: Tue, 14 Sep 2021 12:58:00 +0000 >Subject: [PATCH] Bug 17170: DB Updates > >This patch adds the new table, permission, and a syspref to enable the feature >--- > Koha/SearchFilter.pm | 92 +++++++++++++++++++ > Koha/SearchFilters.pm | 52 +++++++++++ > .../data/mysql/atomicupdate/bug_17170.pl | 36 ++++++++ > installer/data/mysql/kohastructure.sql | 18 ++++ > installer/data/mysql/mandatory/sysprefs.sql | 1 + > .../data/mysql/mandatory/userpermissions.sql | 1 + > .../prog/en/includes/permissions.inc | 5 + > .../modules/admin/preferences/searching.pref | 7 ++ > 8 files changed, 212 insertions(+) > create mode 100644 Koha/SearchFilter.pm > create mode 100644 Koha/SearchFilters.pm > create mode 100755 installer/data/mysql/atomicupdate/bug_17170.pl > >diff --git a/Koha/SearchFilter.pm b/Koha/SearchFilter.pm >new file mode 100644 >index 0000000000..f400a8f703 >--- /dev/null >+++ b/Koha/SearchFilter.pm >@@ -0,0 +1,92 @@ >+package Koha::SearchFilter; >+ >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it under the >+# terms of the GNU General Public License as published by the Free Software >+# Foundation; either version 3 of the License, or (at your option) any later >+# version. >+# >+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY >+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR >+# A PARTICULAR PURPOSE. See the GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License >+# along with Koha; if not, see <http://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+ >+ >+use Koha::Database; >+ >+use base qw(Koha::Object); >+ >+=head1 NAME >+ >+Koha::SearchFilter - Koha Search filter object class >+ >+=head1 API >+ >+=head2 Class methods >+ >+=head3 to_api_mapping >+ >+=cut >+ >+sub to_api_mapping { >+ return { >+ id => 'search_filter_id', >+ query => 'filter_query', >+ limits => 'filter_limits', >+ }; >+} >+ >+=head3 expand_filter >+ >+ my $expanded_filter = $filter->expand_filter; >+ >+ Returns the filter as an arrayref of limit queries suitable to >+ be passed to QueryBuilder >+ >+=cut >+ >+sub expand_filter { >+ my $self = shift; >+ >+ my $query_part = $self->query; >+ my $limits_part = $self->limits; >+ >+ my $limits = decode_json($limits_part)->{limits}; >+ >+ my $query = decode_json($query_part); >+ my $operators = $query->{operators}; >+ my $operands = $query->{operands}; >+ my $indexes = $query->{indexes}; >+ >+ my $query_limit; >+ for( my $i = 0; $i < scalar @$operands; $i++ ){ >+ next unless @$operands[$i]; >+ my $index = @$indexes[$i] ? @$indexes[$i] . "=" : ""; >+ my $query = "(" . @$operands[$i] . ")"; >+ my $operator = ""; >+ $operator = @$operators[$i-1] ? " " . @$operators[$i-1] . " " : scalar @$operands > $i ? " AND " : "" if $i > 0; >+ my $limit = $operator . $index . $query; >+ $query_limit .= $limit; >+ } >+ >+ push @$limits, "(".$query_limit.")" if $query_limit; >+ >+ return $limits; >+} >+ >+=head2 Internal methods >+ >+=head3 _type >+ >+=cut >+ >+sub _type { >+ return 'SearchFilter'; >+} >+ >+1; >diff --git a/Koha/SearchFilters.pm b/Koha/SearchFilters.pm >new file mode 100644 >index 0000000000..3104cd3d14 >--- /dev/null >+++ b/Koha/SearchFilters.pm >@@ -0,0 +1,52 @@ >+package Koha::SearchFilters; >+ >+# This file is part of Koha. >+# >+# Koha is free software; you can redistribute it and/or modify it under the >+# terms of the GNU General Public License as published by the Free Software >+# Foundation; either version 3 of the License, or (at your option) any later >+# version. >+# >+# Koha is distributed in the hope that it will be useful, but WITHOUT ANY >+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR >+# A PARTICULAR PURPOSE. See the GNU General Public License for more details. >+# >+# You should have received a copy of the GNU General Public License >+# along with Koha; if not, see <http://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+ >+ >+use Koha::Database; >+ >+use Koha::SearchFilter; >+ >+use base qw(Koha::Objects); >+ >+=head1 NAME >+ >+Koha::SearchFilters - Koha Search filters object set class >+ >+=head1 API >+ >+=head2 Class Methods >+ >+=cut >+ >+=head3 type >+ >+=cut >+ >+sub _type { >+ return 'SearchFilter'; >+} >+ >+=head3 object_class >+ >+=cut >+ >+sub object_class { >+ return 'Koha::SearchFilter'; >+} >+ >+1; >diff --git a/installer/data/mysql/atomicupdate/bug_17170.pl b/installer/data/mysql/atomicupdate/bug_17170.pl >new file mode 100755 >index 0000000000..4fee3bb5a0 >--- /dev/null >+++ b/installer/data/mysql/atomicupdate/bug_17170.pl >@@ -0,0 +1,36 @@ >+use Modern::Perl; >+ >+return { >+ bug_number => "17170", >+ description => "Add permission for creating saved search filters", >+ up => sub { >+ my ($args) = @_; >+ my ($dbh, $out) = @$args{qw(dbh out)}; >+ $dbh->do(q{ >+ INSERT IGNORE INTO permissions (module_bit, code, description) VALUES >+ (3, 'manage_search_filters', 'Manage custom search filters'); >+ }); >+ say $out "Added manage_search_filters permission"; >+ unless( TableExists( 'search_filters' ) ){ >+ $dbh->do(q{ >+ CREATE TABLE `search_filters` ( >+ id int(11) NOT NULL auto_increment, -- unique identifier for each search filter >+ name varchar(100) NOT NULL, -- display name for this filter >+ query mediumtext DEFAULT NULL, -- query part of the filter, can be blank >+ limits mediumtext DEFAULT NULL, -- limits part of the filter, can be blank >+ opac tinyint(1) NOT NULL DEFAULT 0, -- whether this filter is shown on OPAC >+ staff_client tinyint(1) NOT NULL DEFAULT 0, -- whether this filter is shown in staff client >+ PRIMARY KEY (id) >+ ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_unicode_ci; >+ }); >+ say $out "Added search_filters table"; >+ } else { >+ say $out "search_filters table already created"; >+ } >+ $dbh->do(q{ >+ INSERT IGNORE INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type` ) VALUES >+ ('SavedSearchFilters', '0', NULL, 'Allow staff with permission to create/edit custom search filters', 'YesNo') >+ }); >+ say $out "Added SavedSearchFilters system preference"; >+ }, >+} >diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql >index c1b20477dd..e04486e947 100644 >--- a/installer/data/mysql/kohastructure.sql >+++ b/installer/data/mysql/kohastructure.sql >@@ -4549,6 +4549,24 @@ CREATE TABLE `search_field` ( > ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; > /*!40101 SET character_set_client = @saved_cs_client */; > >+-- >+-- Table structure for table `search_filters` >+-- >+ >+DROP TABLE IF EXISTS `search_filters`; >+/*!40101 SET @saved_cs_client = @@character_set_client */; >+/*!40101 SET character_set_client = utf8 */; >+CREATE TABLE `search_filters` ( >+ `id` int(11) NOT NULL AUTO_INCREMENT, >+ `name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL, >+ `query` mediumtext COLLATE utf8mb4_unicode_ci, >+ `limits` mediumtext COLLATE utf8mb4_unicode_ci, >+ `opac` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'whether this filter is shown on OPAC', >+ `staff_client` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'whether this filter is shown in staff client', >+ PRIMARY KEY (`id`) >+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; >+/*!40101 SET character_set_client = @saved_cs_client */; >+ > -- > -- Table structure for table `search_history` > -- >diff --git a/installer/data/mysql/mandatory/sysprefs.sql b/installer/data/mysql/mandatory/sysprefs.sql >index c1162d9f6c..b1c929b1bf 100644 >--- a/installer/data/mysql/mandatory/sysprefs.sql >+++ b/installer/data/mysql/mandatory/sysprefs.sql >@@ -601,6 +601,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` > ('RoutingListAddReserves','0','','If ON the patrons on routing lists are automatically added to holds on the issue.','YesNo'), > ('RoutingListNote','To change this note edit <a href=\"/cgi-bin/koha/admin/preferences.pl?op=search&searchfield=RoutingListNote#jumped\">RoutingListNote</a> system preference.','70|10','Define a note to be shown on all routing lists','Textarea'), > ('RoutingSerials','1',NULL,'If ON, serials routing is enabled','YesNo'), >+('SavedSearchFilters', '0', NULL, 'Allow staff with permission to create/edit custom search filters', 'YesNo'), > ('SCOAllowCheckin','0','','If enabled, patrons may return items through the Web-based Self Checkout','YesNo'), > ('SCOMainUserBlock','','70|10','Add a block of HTML that will display on the self checkout screen','Textarea'), > ('SCOUserCSS','',NULL,'Add CSS to be included in the SCO module in an embedded <style> tag.','free'), >diff --git a/installer/data/mysql/mandatory/userpermissions.sql b/installer/data/mysql/mandatory/userpermissions.sql >index 6241c1a1ff..ccc57580d9 100644 >--- a/installer/data/mysql/mandatory/userpermissions.sql >+++ b/installer/data/mysql/mandatory/userpermissions.sql >@@ -37,6 +37,7 @@ INSERT INTO permissions (module_bit, code, description) VALUES > ( 3, 'manage_keyboard_shortcuts', 'Manage keyboard shortcuts for the advanced cataloging editor'), > ( 3, 'manage_smtp_servers', 'Manage SMTP servers configuration'), > ( 3, 'manage_background_jobs', 'Manage background jobs'), >+ ( 3, 'manage_search_filters', 'Manage custom search filters'), > ( 4, 'delete_borrowers', 'Delete patrons'), > ( 4, 'edit_borrowers', 'Add, modify and view patron information'), > ( 4, 'view_borrower_infos_from_any_libraries', 'View patron infos from any libraries'), >diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/permissions.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/permissions.inc >index 445221fa52..4628d44e99 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/includes/permissions.inc >+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/permissions.inc >@@ -208,6 +208,11 @@ > Manage item search fields > </span> > <span class="permissioncode">([% name | html %])</span> >+ [%- CASE 'manage_search_filters' -%] >+ <span class="sub_permission manage_search_filters_subpermission"> >+ Manage saved search filters >+ </span> >+ <span class="permissioncode">([% name | html %])</span> > [%- CASE 'manage_search_engine_config' -%] > <span class="sub_permission manage_search_engine_config_subpermission"> > Manage search engine configuration >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/searching.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/searching.pref >index 69619fd6f8..f2e3304ffe 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/searching.pref >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/searching.pref >@@ -87,6 +87,13 @@ Searching: > 0: Disable > - "the cross_fields option for Elasticsearch searches, supported in Elasticsearch 6.X and above." > - "See documentation at https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-multi-match-query.html#type-cross-fields" >+ - >+ - pref: SavedSearchFilters >+ default: 0 >+ choices: >+ 1: Enable >+ 0: Disable >+ - "the option for staff with permission to create/edit custom saved search filters." > Search form: > - > - pref : LoadSearchHistoryToTheFirstLoggedUser >-- >2.30.2
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 17170
:
133263
|
133264
|
133265
|
133266
|
133267
|
133268
|
133269
|
133270
|
133361
|
133376
|
137027
|
137028
|
137029
|
137030
|
137031
|
137032
|
137033
|
137034
|
137035
|
137036
|
137186
|
137187
|
137188
|
137189
|
137190
|
137191
|
137192
|
137193
|
137194
|
137195
|
137808
|
137809
|
137810
|
137811
|
137812
|
137813
|
137814
|
137815
|
137816
|
137817
|
138505
|
138506
|
138507
|
138508
|
138509
|
138510
|
138511
|
138512
|
138513
|
138514
|
139948
|
139949
|
139950
|
139951
|
139952
|
139953
|
139954
|
139955
|
139956
|
139957
|
141228
|
141229
|
141230
|
141231
|
141232
|
141233
|
141234
|
141235
|
141236
|
141237
|
141316
|
141317
|
141318
|
141319
|
141320
|
141321
|
141322
|
141323
|
141324
|
141325
|
141326
|
141327
|
141328
|
141348
|
141349
|
141350
|
141351
|
141352
|
141353
|
141354
|
141355
|
141356
|
141357
|
141358
|
141359
|
141360
|
141422
|
141423
|
141424
|
141425
|
141426
|
141427
|
141428
|
141429
|
141430
|
141431
|
141432
|
141433
|
141434
|
141435
|
141436
|
141437
|
141438
|
141461
|
141462
|
142365
|
142367
|
142368
|
142369
|
142370
|
142371
|
142372
|
142373
|
142374
|
142375
|
142376
|
142377
|
142378
|
142379
|
142380
|
142381
|
142382
|
142383
|
142384
|
142385
|
142494
|
142498