Bugzilla – Attachment 150155 Details for
Bug 32748
Library limitations will cause data loss when editing items
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 32748: Prevent data erasing when editing item
Bug-32748-Prevent-data-erasing-when-editing-item.patch (text/plain), 5.85 KB, created by
Thibaud Guillot (thibaud_g)
on 2023-04-24 12:48:58 UTC
(
hide
)
Description:
Bug 32748: Prevent data erasing when editing item
Filename:
MIME Type:
Creator:
Thibaud Guillot (thibaud_g)
Created:
2023-04-24 12:48:58 UTC
Size:
5.85 KB
patch
obsolete
>From 9225eb320d03a7ebb247f14aaaf99a3787a9743c Mon Sep 17 00:00:00 2001 >From: Thibaud Guillot <thibaud.guillot@biblibre.com> >Date: Thu, 6 Apr 2023 17:16:22 +0200 >Subject: [PATCH] Bug 32748: Prevent data erasing when editing item > >When we set an authorised value linked to one library, >users who do not belong to this library do not get the >value and can therefore overwrite it. > >This patch add current value to the dropdown list even if it comes from an authorized value of another library. > >Test plan : > >1) Edit an item with one of these fields has an authorized value from >another library. >2) See that you don't get this value on 'edit' >3) Apply this patch >4) Refresh and do step 1 >5) Now you have the value in dropdown list and a tooltip info >--- > C4/Koha.pm | 11 ++++++++--- > Koha/UI/Form/Builder/Item.pm | 10 ++++++++-- > .../intranet-tmpl/prog/en/includes/html_helpers.inc | 10 +++++++++- > 3 files changed, 25 insertions(+), 6 deletions(-) > >diff --git a/C4/Koha.pm b/C4/Koha.pm >index 7132910adf..67d765771d 100644 >--- a/C4/Koha.pm >+++ b/C4/Koha.pm >@@ -486,20 +486,24 @@ C<$opac> If set to a true value, displays OPAC descriptions rather than normal o > sub GetAuthorisedValues { > my $category = shift // ''; # optional parameter > my $opac = shift ? 1 : 0; # normalise to be safe >+ my $options = shift // ''; >+ my $no_limit = $options->{'no_limit'} if $options; #optional paramater to ignore branch limitation > > # Is this cached already? > my $branch_limit = > C4::Context->userenv ? C4::Context->userenv->{"branch"} : ""; > my $cache_key = >- "AuthorisedValues-$category-$opac-$branch_limit"; >+ "AuthorisedValues-$category-$opac-$branch_limit-$no_limit"; > my $cache = Koha::Caches->get_instance(); > my $result = $cache->get_from_cache($cache_key); > return $result if $result; > > my @results; > my $dbh = C4::Context->dbh; >+ my $select_clause = 'SELECT av.*'; >+ $select_clause .= ", GROUP_CONCAT( authorised_values_branches.branchcode SEPARATOR '-' ) as restricted_to" if $no_limit; > my $query = qq{ >- SELECT DISTINCT av.* >+ $select_clause > FROM authorised_values av > }; > $query .= qq{ >@@ -511,13 +515,14 @@ sub GetAuthorisedValues { > push @where_strings, "category = ?"; > push @where_args, $category; > } >- if($branch_limit) { >+ if($branch_limit && !defined $no_limit) { > push @where_strings, "( branchcode = ? OR branchcode IS NULL )"; > push @where_args, $branch_limit; > } > if(@where_strings > 0) { > $query .= " WHERE " . join(" AND ", @where_strings); > } >+ $query .= ' GROUP BY av.id '; > $query .= ' ORDER BY category, ' . ( > $opac ? 'COALESCE(lib_opac, lib)' > : 'lib, lib_opac' >diff --git a/Koha/UI/Form/Builder/Item.pm b/Koha/UI/Form/Builder/Item.pm >index 3a478ee05e..c0783ce893 100644 >--- a/Koha/UI/Form/Builder/Item.pm >+++ b/Koha/UI/Form/Builder/Item.pm >@@ -251,11 +251,17 @@ sub generate_subfield_form { > } > else { > push @authorised_values, qq{}; >- my $av = GetAuthorisedValues( $subfield->{authorised_value} ); >+ my $av = GetAuthorisedValues( $subfield->{authorised_value}, undef, { 'no_limit' => 1 } ); >+ my @restricted_av; > for my $r (@$av) { >- push @authorised_values, $r->{authorised_value}; >+ if ( defined $r->{restricted_to} ) { >+ push @restricted_av, {code => $r->{authorised_value}, lib => $r->{lib}, restricted_to => $r->{restricted_to}}; >+ } else { >+ push @authorised_values, $r->{authorised_value}; >+ } > $authorised_lib{ $r->{authorised_value} } = $r->{lib}; > } >+ $subfield_data{restricted_av} = \@restricted_av if scalar(@restricted_av) > 0; > } > > if ( $subfield->{hidden} > 4 or $subfield->{hidden} <= -4 ) { >diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers.inc >index f0d695bc9c..477bbbbbd6 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers.inc >+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/html_helpers.inc >@@ -124,6 +124,15 @@ > [% END %] > [% END %] > [% END %] >+ [% FOREACH r_av IN subfield.restricted_av %] >+ [% SET r_av_lib = r_av.lib %] >+ [% SET r_av_code = r_av.code %] >+ [% SET r_av_from = r_av.restricted_to %] >+ [% IF r_av_code == mv.default %] >+ [% SET matched = 1 %] >+ [% END %] >+ <option value="[%- r_av_lib | html -%]" selected="selected" style="float:right" title="This value ([%- r_av_lib | html -%]) is limited to other branches ([%- r_av_from | html -%])">[%- r_av_lib | html -%]<i class="fa fa-exclamation-triangle" aria-hidden="true"></i></option> >+ [% END %] > [% UNLESS matched || ( ( kohafield == 'items.damaged' || kohafield == 'items.itemlost' || kohafield == 'items.withdrawn' || kohafield == 'items.notforloan' ) && mv.default == '0' ) %] > [%# If the current value is not in the authorised list and is not a field where 0 means unset #%] > <option value="[%- mv.default | html -%]" selected="selected">[%- mv.default | html -%] (Not an authorised value)</option> >@@ -210,7 +219,6 @@ > [% END %] > > <span class="hint" id="hint[% subfield.tag | html %][% subfield.subfield | html %][% subfield.random | html %]"></span> >- > </div> > </li> > [% END %] >-- >2.25.1
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 32748
:
148409
|
148491
|
150155
|
151989
|
154039
|
154040
|
154041
|
154042