Bugzilla – Attachment 97658 Details for
Bug 21674
Data integrity not enforced for library groups
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 21674: Prevent to insert twice the same library in a group
Bug-21674-Prevent-to-insert-twice-the-same-library.patch (text/plain), 4.34 KB, created by
Jonathan Druart
on 2020-01-21 12:25:37 UTC
(
hide
)
Description:
Bug 21674: Prevent to insert twice the same library in a group
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2020-01-21 12:25:37 UTC
Size:
4.34 KB
patch
obsolete
>From 8d3d807ea61b638654c4b56c09beadcc7205a736 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Wed, 11 Dec 2019 12:51:23 +0100 >Subject: [PATCH] Bug 21674: Prevent to insert twice the same library in a > group >MIME-Version: 1.0 >Content-Type: text/plain; charset=UTF-8 >Content-Transfer-Encoding: 8bit > >You can create hierarchical groups of libraries you are not allowed to add >several times the same library to a given group/subgroup. The libraries >that are part of the group is not displayed on the interface, to prevent >the user to select it. > >However this restriction is only done template-side, the controller and >module does not handle it. > >To prevent that this patchset enforces the constraint at DB level, and >display a message to the end user. > >Test plan: >- Go to Home ⺠Administration ⺠Library groups >- Add a group >- Add a library >- reload the page several times >=> Without this patch the same library appears several times in the group >=> With this patch applied you will see a friendly error message >--- > admin/library_groups.pl | 37 +++++++++++++--------- > .../prog/en/modules/admin/library_groups.tt | 11 +++++++ > 2 files changed, 33 insertions(+), 15 deletions(-) > >diff --git a/admin/library_groups.pl b/admin/library_groups.pl >index f8b2574cda..dcf71c87a3 100755 >--- a/admin/library_groups.pl >+++ b/admin/library_groups.pl >@@ -41,6 +41,7 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( > ); > > my $action = $cgi->param('action') || q{}; >+my @messages; > > if ( $action eq 'add' ) { > my $parent_id = $cgi->param('parent_id') || undef; >@@ -56,20 +57,26 @@ if ( $action eq 'add' ) { > $template->param( error_duplicate_title => $title ); > } > else { >- my $group = Koha::Library::Group->new( >- { >- parent_id => $parent_id, >- title => $title, >- description => $description, >- ft_hide_patron_info => $ft_hide_patron_info, >- ft_search_groups_opac => $ft_search_groups_opac, >- ft_search_groups_staff => $ft_search_groups_staff, >- ft_local_hold_group => $ft_local_hold_group, >- branchcode => $branchcode, >- } >- )->store(); >- >- $template->param( added => $group ); >+ my $group = eval { >+ Koha::Library::Group->new( >+ { >+ parent_id => $parent_id, >+ title => $title, >+ description => $description, >+ ft_hide_patron_info => $ft_hide_patron_info, >+ ft_search_groups_opac => $ft_search_groups_opac, >+ ft_search_groups_staff => $ft_search_groups_staff, >+ ft_local_hold_group => $ft_local_hold_group, >+ branchcode => $branchcode, >+ } >+ )->store(); >+ }; >+ if ($@) { >+ push @messages, { type => 'alert', code => 'error_on_insert' }; >+ } >+ else { >+ $template->param( added => $group ); >+ } > } > } > elsif ( $action eq 'edit' ) { >@@ -118,6 +125,6 @@ elsif ( $action eq 'delete' ) { > > my $root_groups = Koha::Library::Groups->get_root_groups(); > >-$template->param( root_groups => $root_groups, ); >+$template->param( root_groups => $root_groups, messages => \@messages, ); > > output_html_with_http_headers $cgi, $cookie, $template->output; >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/library_groups.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/library_groups.tt >index c4d1a83813..8bfc06d61a 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/library_groups.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/library_groups.tt >@@ -18,6 +18,17 @@ > › <a href="/cgi-bin/koha/admin/library_groups.pl">Library groups</a> > </div> > >+[% FOR m IN messages %] >+ <div class="dialog [% m.type | html %]"> >+ [% SWITCH m.code %] >+ [% CASE 'error_on_insert' %] >+ An error occurred when adding this library. The library id might already exist in this group. >+ [% CASE %] >+ [% m.code | html %] >+ [% END %] >+ </div> >+[% END %] >+ > [% IF added %] > <div class="dialog message group-added"> > [% IF added.branchcode %] >-- >2.11.0
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 21674
:
96199
|
96200
|
97658
|
97667
|
97811
|
97837
|
97838
|
97839
|
98170
|
98171
|
98172
|
98224