From 0bf26201343a1070cacd95ab23d5e7217001cbba Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Wed, 4 May 2022 12:36:17 +0100 Subject: [PATCH] Bug 23681: (QA follow-up) Proper handling of default option This patch removes the 'can_be_added_manually' flag. Only non-system restriction types can be added manually, so we exclude is_system instead of having two flags. (And we set the 'Manual' that's added at install time to default but not system). We then add proper handling for setting the default manual restriction type in the management page and set the dropdown list to use that value by default. --- Koha/RestrictionType.pm | 22 +++++++++++++ admin/restrictions.pl | 11 +++---- .../data/mysql/atomicupdate/bug_23681.pl | 13 ++++---- installer/data/mysql/kohastructure.sql | 3 +- .../prog/en/includes/borrower_debarments.inc | 8 +++-- .../prog/en/modules/admin/restrictions.tt | 31 +++---------------- 6 files changed, 45 insertions(+), 43 deletions(-) diff --git a/Koha/RestrictionType.pm b/Koha/RestrictionType.pm index 4d43f20609..ff821aefd3 100644 --- a/Koha/RestrictionType.pm +++ b/Koha/RestrictionType.pm @@ -63,6 +63,28 @@ sub delete { return 0; } +=head3 make_default + +Set the current restriction type as the default for manual restrictions + +=cut + +sub make_default { + my ( $self ) = @_; + + $self->_result->result_source->schema->txn_do( + sub { + my $types = + Koha::RestrictionTypes->search( { code => { '!=' => $self->code } } ); + $types->update( { is_default => 0 } ); + $self->set( { is_default => 1 } ); + $self->SUPER::store; + } + ); + + return $self; +} + =head2 Internal methods =head3 type diff --git a/admin/restrictions.pl b/admin/restrictions.pl index b41fd3f6cd..6344e6ab92 100755 --- a/admin/restrictions.pl +++ b/admin/restrictions.pl @@ -53,7 +53,6 @@ if ( $op eq 'add_form') { } elsif ( $op eq 'add_validate' ) { my $display_text = $input->param('display_text'); - my $can_be_added_manually = $input->param('can_be_added_manually') || 0; my $is_a_modif = $input->param("is_a_modif"); if ($is_a_modif) { @@ -68,9 +67,6 @@ if ( $op eq 'add_form') { } else { my $restriction = Koha::RestrictionTypes->find($code); $restriction->display_text($display_text); - unless ($restriction->is_system) { - $restriction->can_be_added_manually($can_be_added_manually); - } $restriction->store; } } else { @@ -83,13 +79,16 @@ if ( $op eq 'add_form') { } else { my $restriction = Koha::RestrictionType->new({ code => $code, - display_text => $display_text, - can_be_added_manually => $can_be_added_manually + display_text => $display_text }); $restriction->store; } } $op = 'list'; +} elsif ( $op eq 'make_default' ) { + my $restriction = Koha::RestrictionTypes->find($code); + $restriction->make_default; + $op = 'list'; } elsif ( $op eq 'delete_confirm' ) { $template->param( restriction => scalar Koha::RestrictionTypes->find($code) diff --git a/installer/data/mysql/atomicupdate/bug_23681.pl b/installer/data/mysql/atomicupdate/bug_23681.pl index 375f5a1459..422de181bc 100644 --- a/installer/data/mysql/atomicupdate/bug_23681.pl +++ b/installer/data/mysql/atomicupdate/bug_23681.pl @@ -12,18 +12,17 @@ return { code varchar(50) NOT NULL PRIMARY KEY, display_text text NOT NULL, is_system tinyint(1) NOT NULL DEFAULT 0, - default_value tinyint(1) NOT NULL DEFAULT 0, - can_be_added_manually tinyint(1) NOT NULL DEFAULT 0 + is_default tinyint(1) NOT NULL DEFAULT 0 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; }); say $out "Added debarment_types table"; $dbh->do(q{ - INSERT IGNORE INTO debarment_types (code, display_text, is_system, default_value, can_be_added_manually) VALUES - ('MANUAL', 'Manual', 1, 1, 0), - ('OVERDUES', 'Overdues', 1, 0, 0), - ('SUSPENSION', 'Suspension', 1, 0, 0), - ('DISCHARGE', 'Discharge', 1, 0, 0); + INSERT IGNORE INTO debarment_types (code, display_text, is_system, is_default) VALUES + ('MANUAL', 'Manual', 0, 1), + ('OVERDUES', 'Overdues', 1, 0), + ('SUSPENSION', 'Suspension', 1, 0), + ('DISCHARGE', 'Discharge', 1, 0); }); say $out "Added system debarment_types"; diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index 359109ae75..f2fbabaa0a 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -2026,8 +2026,7 @@ CREATE TABLE debarment_types ( code varchar(50) NOT NULL PRIMARY KEY, display_text text NOT NULL, is_system tinyint(1) NOT NULL DEFAULT 0, - default_value tinyint(1) NOT NULL DEFAULT 0, - can_be_added_manually tinyint(1) NOT NULL DEFAULT 0 + is_default tinyint(1) NOT NULL DEFAULT 0 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/borrower_debarments.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/borrower_debarments.inc index e5ff9639dc..c70073db7a 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/borrower_debarments.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/borrower_debarments.inc @@ -58,8 +58,12 @@ diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/restrictions.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/restrictions.tt index 4b9767e46e..a8dd141271 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/restrictions.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/restrictions.tt @@ -103,16 +103,6 @@ Required -
  • - - [% IF restriction && restriction.is_system %] - [% IF restriction.can_be_added_manually %]Yes[% ELSE %]No[% END %] - [% ELSIF restriction.can_be_added_manually %] - - [% ELSE %] - - [% END %] -
  • [% ELSE %]
  • @@ -124,16 +114,6 @@ Required
  • -
  • - - [% IF restriction && restriction.is_system %] - [% IF restriction.can_be_added_manually %]Yes[% ELSE %]No[% END %] - [% ELSIF restriction.can_be_added_manually %] - - [% ELSE %] - - [% END %] -
  • [% END %] @@ -180,7 +160,6 @@ Code Label - Manual Default Actions @@ -195,16 +174,16 @@ [% PROCESS restriction_type_description %] - [% IF restriction.can_be_added_manually %]Yes[% END %] - - - [% IF restriction.default_value %]Yes[% END %] + [% IF restriction.is_default %]Yes[% END %] Edit - [% IF !restriction.is_system %] + [% IF !restriction.is_system && !restriction.is_default %] Delete [% END %] + [% IF !restriction.is_system && !restriction.is_default %] + Make default + [% END %] [% END %] -- 2.20.1