Bug 21674: Prevent to insert twice the same library in a group
When you 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 Signed-off-by: Nick Clemens <nick@bywatersolutions.com> Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
This commit is contained in:
parent
09ac74baca
commit
812a863d86
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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 %]
|
||||
|
|
|
|||
Loading…
Reference in New Issue