Bugzilla – Attachment 178070 Details for
Bug 36081
ArticleRequestsSupportedFormats not enforced server-side
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 36081: Use multivalue_preference
Bug-36081-Use-multivaluepreference.patch (text/plain), 6.95 KB, created by
Marcel de Rooy
on 2025-02-14 07:32:14 UTC
(
hide
)
Description:
Bug 36081: Use multivalue_preference
Filename:
MIME Type:
Creator:
Marcel de Rooy
Created:
2025-02-14 07:32:14 UTC
Size:
6.95 KB
patch
obsolete
>From 9edefd7223131f894a8d669a70756f43fe932b7a Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Thu, 30 Jan 2025 16:48:40 +0100 >Subject: [PATCH] Bug 36081: Use multivalue_preference >Content-Type: text/plain; charset=utf-8 > >C4::Context->multivalue_preference is not used so far and split on | >However the values of "multiple" sysprefs are separated by... comma! > >Let support both here. > >This patch also removes silly JS code in the template. > >Signed-off-by: Magnus Enger <magnus@libriotech.no> > >Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >--- > C4/Context.pm | 6 +++-- > Koha/ArticleRequest.pm | 7 +++--- > Koha/Template/Plugin/Koha.pm | 5 ++++ > .../admin/preferences/circulation.pref | 5 +++- > .../en/modules/opac-request-article.tt | 24 ++++++++----------- > t/Context.t | 5 +++- > 6 files changed, 30 insertions(+), 22 deletions(-) > >diff --git a/C4/Context.pm b/C4/Context.pm >index bb3080ffde..63dcb6773a 100644 >--- a/C4/Context.pm >+++ b/C4/Context.pm >@@ -318,9 +318,11 @@ sub multivalue_preference { > my ( $self, $preference ) = @_; > > my $syspref = $self->preference($preference) // q{}; >- my $values = [ split qr{\|}, $syspref ]; > >- return $values; >+ return [ split qr{\|}, $syspref ] >+ if $syspref =~ qr{\|}; >+ >+ return [ split qr{,}, $syspref ] > } > > =head2 enable_syspref_cache >diff --git a/Koha/ArticleRequest.pm b/Koha/ArticleRequest.pm >index d7c6e6fc30..33421fbb3a 100644 >--- a/Koha/ArticleRequest.pm >+++ b/Koha/ArticleRequest.pm >@@ -268,10 +268,9 @@ sub store { > if ( !$self->in_storage ) { > $self->created_on( dt_from_string() ); > } >- my $format = $self->format; >- if ( C4::Context->preference('ArticleRequestsSupportedFormats') !~ /\b$format\b/ ) { >- Koha::Exceptions::ArticleRequest::WrongFormat->throw; >- } >+ >+ Koha::Exceptions::ArticleRequest::WrongFormat->throw >+ unless grep { $_ eq $self->format } @{ C4::Context->multivalue_preference('ArticleRequestsSupportedFormats') }; > > return $self->SUPER::store; > } >diff --git a/Koha/Template/Plugin/Koha.pm b/Koha/Template/Plugin/Koha.pm >index 7b836afd54..d33e2b08b0 100644 >--- a/Koha/Template/Plugin/Koha.pm >+++ b/Koha/Template/Plugin/Koha.pm >@@ -70,6 +70,11 @@ sub Preference { > return C4::Context->preference($pref); > } > >+sub MultivaluePreference { >+ my ( $self, $pref ) = @_; >+ return C4::Context->multivalue_preference( $pref ); >+} >+ > =head3 CSVDelimiter > > The delimiter option 'tabs' is stored in the DB as 'tabulation' to avoid issues >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref >index 7192181ea4..e380c2fa0e 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref >@@ -1403,7 +1403,10 @@ Circulation: > - > - "The following article request formats are supported:" > - pref: ArticleRequestsSupportedFormats >- - ". Valid choices are currently: PHOTOCOPY and SCAN. Separate the supported formats by a vertical bar. The first listed format is selected by default when you request via the OPAC." >+ multiple_sortable: >+ PHOTOCOPY: Photocopy >+ SCAN: Scan >+ - "The first listed format is selected by default when you request via the OPAC." > > > Item bundles: >diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-request-article.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-request-article.tt >index d14bf15657..16a27cb58b 100644 >--- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-request-article.tt >+++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-request-article.tt >@@ -154,13 +154,21 @@ > <input type="text" name="patron_notes" id="patron_notes" size="50" /> > </li> > >+ [% SET ArticleRequestsSupportedFormats = Koha.MultivaluePreference('ArticleRequestsSupportedFormats') %] >+ [% IF ArticleRequestsSupportedFormats.size %] > <li> > <label for="format">Format:</label> > <select name="format" id="format"> >- <option value="PHOTOCOPY">Photocopy</option> >- <option value="SCAN">Digital scan</option> >+ [% FOR format IN ArticleRequestsSupportedFormats %] >+ [% IF format == 'PHOTOCOPY' %] >+ <option value="PHOTOCOPY">Photocopy</option> >+ [% ELSIF format == 'SCAN' %] >+ <option value="SCAN">Digital scan</option> >+ [% END %] >+ [% END %] > </select> > </li> >+ [% END %] > > [% IF AllPublicBranches.size > 1 %] > <li> >@@ -317,18 +325,6 @@ > } > }); > >- // Initialize format(s) >- var supported_formats = "[% Koha.Preference('ArticleRequestsSupportedFormats') | html %]"; >- if( !supported_formats.match(/PHOTOCOPY/) ) >- $('#format option[value="PHOTOCOPY"]').remove(); >- if( !supported_formats.match(/SCAN/) ) >- $('#format option[value="SCAN"]').remove(); >- >- if( $('#format option').length > 1 ) { >- // Select first listed format >- var first_format = supported_formats.split('|')[0].replace(/^\s*|\s*$/g, ''); >- $('#format option[value="'+first_format+'"]').attr('selected', true); >- } > }); > </script> > [% END %] >diff --git a/t/Context.t b/t/Context.t >index af37e46830..c49bc9957c 100755 >--- a/t/Context.t >+++ b/t/Context.t >@@ -60,7 +60,7 @@ subtest 'yaml_preference() tests' => sub { > > subtest 'multivalue_preference() tests' => sub { > >- plan tests => 3; >+ plan tests => 4; > > t::lib::Mocks::mock_preference( 'MultiValuedSyspref', '' ); > is_deeply( C4::Context->multivalue_preference('MultiValuedSyspref'), [] ); >@@ -70,6 +70,9 @@ subtest 'multivalue_preference() tests' => sub { > > t::lib::Mocks::mock_preference( 'MultiValuedSyspref', 'some|more|values' ); > is_deeply( C4::Context->multivalue_preference('MultiValuedSyspref'), [ 'some', 'more', 'values' ] ); >+ >+ t::lib::Mocks::mock_preference( 'MultiValuedSyspref', 'some,more,values' ); >+ is_deeply( C4::Context->multivalue_preference('MultiValuedSyspref'), [ 'some', 'more', 'values' ] ); > }; > > subtest 'needs_install() tests' => sub { >-- >2.39.5
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 36081
:
162107
|
162113
|
177355
|
177356
|
177388
|
177389
|
177675
|
178020
|
178021
|
178022
|
178023
|
178024
|
178069
| 178070 |
178071
|
178072
|
178073
|
178074
|
178610
|
178611
|
178612
|
178613
|
178614
|
178615
|
181287