@@ -, +, @@ - convert intaller files as .yml - change column name readonly as is_system - change column name is_system as default_value - add column can_be_added_manually (testplan for this below) - move syspref "PatronRestrictionTypes" to "Accounting > Features" tab - tweak page title - tweak tests to apply these changes --- Koha/RestrictionType.pm | 6 +-- admin/restrictions.pl | 9 +++- ...81_add_PatronRestrictionTypes_syspref.perl | 6 --- ...3681_add_PatronRestrictionTypes_syspref.pl | 14 ++++++ .../bug_23681_add_debarment_types.perl | 33 ------------ .../bug_23681_add_debarment_types.pl | 37 ++++++++++++++ ...1_add_manage_patron_restrictions_perm.perl | 9 ---- ...681_add_manage_patron_restrictions_perm.pl | 14 ++++++ .../en/mandatory/patron_restrictions.sql | 5 -- .../en/mandatory/patron_restrictions.txt | 1 - .../en/mandatory/patron_restrictions.yml | 50 +++++++++++++++++++ installer/data/mysql/kohastructure.sql | 5 +- .../prog/en/includes/borrower_debarments.inc | 4 +- .../modules/admin/preferences/accounting.pref | 6 +++ .../en/modules/admin/preferences/patrons.pref | 6 --- .../prog/en/modules/admin/restrictions.tt | 39 ++++++++++++--- .../prog/en/modules/members/memberentrygen.tt | 4 +- t/db_dependent/RestrictionTypes.t | 32 ++++++------ 18 files changed, 191 insertions(+), 89 deletions(-) delete mode 100644 installer/data/mysql/atomicupdate/bug_23681_add_PatronRestrictionTypes_syspref.perl create mode 100644 installer/data/mysql/atomicupdate/bug_23681_add_PatronRestrictionTypes_syspref.pl delete mode 100644 installer/data/mysql/atomicupdate/bug_23681_add_debarment_types.perl create mode 100644 installer/data/mysql/atomicupdate/bug_23681_add_debarment_types.pl delete mode 100644 installer/data/mysql/atomicupdate/bug_23681_add_manage_patron_restrictions_perm.perl create mode 100644 installer/data/mysql/atomicupdate/bug_23681_add_manage_patron_restrictions_perm.pl delete mode 100644 installer/data/mysql/en/mandatory/patron_restrictions.sql delete mode 100644 installer/data/mysql/en/mandatory/patron_restrictions.txt create mode 100644 installer/data/mysql/en/mandatory/patron_restrictions.yml --- a/Koha/RestrictionType.pm +++ a/Koha/RestrictionType.pm @@ -42,10 +42,10 @@ sub delete { my ( $self ) = @_; # Find out what the default is - my $default = Koha::RestrictionTypes->find({ is_system => 1 })->code; - # Ensure we're not trying to delete a readonly type (this includes + my $default = Koha::RestrictionTypes->find({ default_value => 1 })->code; + # Ensure we're not trying to delete a is_system type (this includes # the default type) - return 0 if $self->readonly == 1; + return 0 if $self->is_system == 1; # We can't use Koha objects here because Koha::Patron::Debarments # is not a Koha object. So we'll do it old skool my $rows = C4::Context->dbh->do( --- a/admin/restrictions.pl +++ a/admin/restrictions.pl @@ -53,6 +53,7 @@ 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) { @@ -66,7 +67,10 @@ if ( $op eq 'add_form') { }; } else { my $restriction = Koha::RestrictionTypes->find($code); - $restriction->display_text($display_text); + unless ($restriction->is_system) { + $restriction->display_text($display_text); + $restriction->can_be_added_manually($can_be_added_manually); + } $restriction->store; } } else { @@ -79,7 +83,8 @@ if ( $op eq 'add_form') { } else { my $restriction = Koha::RestrictionType->new({ code => $code, - display_text => $display_text + display_text => $display_text, + can_be_added_manually => $can_be_added_manually }); $restriction->store; } --- a/installer/data/mysql/atomicupdate/bug_23681_add_PatronRestrictionTypes_syspref.perl +++ a/installer/data/mysql/atomicupdate/bug_23681_add_PatronRestrictionTypes_syspref.perl @@ -1,6 +0,0 @@ -$DBversion = 'XXX'; # will be replaced by the RM -if( CheckVersion( $DBversion ) ) { - $dbh->do( q| INSERT IGNORE INTO systempreferences (variable, value, explanation, options, type) VALUES ('PatronRestrictionTypes', '0', 'If enabled, it is possible to specify the "type" of patron restriction being applied.', '', 'YesNo'); | ); - SetVersion( $DBversion ); - print "Upgrade to $DBversion done (Bug 23681 - Add PatronRestrictionTypes syspref)\n"; -} --- a/installer/data/mysql/atomicupdate/bug_23681_add_PatronRestrictionTypes_syspref.pl +++ a/installer/data/mysql/atomicupdate/bug_23681_add_PatronRestrictionTypes_syspref.pl @@ -0,0 +1,14 @@ +use Modern::Perl; + +return { + bug_number => "23681", + description => "Add PatronRestrictionTypes syspref", + up => sub { + my ($args) = @_; + my ($dbh, $out) = @$args{qw(dbh out)}; + # Do you stuffs here + $dbh->do(q{INSERT IGNORE INTO systempreferences (variable, value, explanation, options, type) VALUES ('PatronRestrictionTypes', '0', 'If enabled, it is possible to specify the "type" of patron restriction being applied.', '', 'YesNo');}); + # Print useful stuff here + say $out "Update is going well so far"; + }, +}; --- a/installer/data/mysql/atomicupdate/bug_23681_add_debarment_types.perl +++ a/installer/data/mysql/atomicupdate/bug_23681_add_debarment_types.perl @@ -1,33 +0,0 @@ -$DBversion = 'XXX'; - -if ( CheckVersion( $DBversion ) ) { - - if ( !TableExists( 'debarment_types' ) ) { - $dbh->do( q| - CREATE TABLE debarment_types ( - code varchar(50) NOT NULL PRIMARY KEY, - display_text text NOT NULL, - readonly tinyint(1) NOT NULL DEFAULT 0, - system tinyint(1) NOT NULL DEFAULT 0 - ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; - | ); - $dbh->do( q| - INSERT INTO debarment_types (code, display_text, readonly, system) VALUES - ('MANUAL', 'Manual', 1, 1), - ('OVERDUES', 'Overdues', 1, 0), - ('SUSPENSION', 'Suspension', 1, 0), - ('DISCHARGE', 'Discharge', 1, 0); - |); - $dbh->do( q| - ALTER TABLE borrower_debarments - MODIFY COLUMN type varchar(50) NOT NULL - | ); - $dbh->do( q| - ALTER TABLE borrower_debarments - ADD CONSTRAINT borrower_debarments_ibfk_2 FOREIGN KEY (type) REFERENCES debarment_types(code) ON DELETE NO ACTION ON UPDATE CASCADE; - | ); - } - - SetVersion( $DBversion ); - print "Upgrade to $DBversion done (Bug 23681 - Add debarment_types)\n"; -} --- a/installer/data/mysql/atomicupdate/bug_23681_add_debarment_types.pl +++ a/installer/data/mysql/atomicupdate/bug_23681_add_debarment_types.pl @@ -0,0 +1,37 @@ +use Modern::Perl; + +return { + bug_number => "23681", + description => "Add debarment_types", + up => sub { + my ($args) = @_; + my ($dbh, $out) = @$args{qw(dbh out)}; + # Do you stuffs here + $dbh->do(q{ + CREATE TABLE IF NOT EXISTS 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 + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; + }); + $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); + }); + $dbh->do(q{ + ALTER TABLE borrower_debarments + MODIFY COLUMN type varchar(50) NOT NULL + }); + $dbh->do(q{ + ALTER TABLE borrower_debarments + ADD CONSTRAINT borrower_debarments_ibfk_2 FOREIGN KEY (type) REFERENCES debarment_types(code) ON DELETE NO ACTION ON UPDATE CASCADE; + }); + # Print useful stuff here + say $out "Update is going well so far"; + }, +}; --- a/installer/data/mysql/atomicupdate/bug_23681_add_manage_patron_restrictions_perm.perl +++ a/installer/data/mysql/atomicupdate/bug_23681_add_manage_patron_restrictions_perm.perl @@ -1,9 +0,0 @@ -$DBversion = 'XXX'; -if( CheckVersion( $DBversion ) ) { - $dbh->do(q{ - INSERT IGNORE INTO permissions (module_bit, code, description) VALUES - ( 3, 'manage_patron_restrictions', 'Manage patron restrictions') - }); - SetVersion( $DBversion ); - print "Upgrade to $DBversion done (Bug 23681 - Add manage_patron_restrictions_permission)\n"; -} --- a/installer/data/mysql/atomicupdate/bug_23681_add_manage_patron_restrictions_perm.pl +++ a/installer/data/mysql/atomicupdate/bug_23681_add_manage_patron_restrictions_perm.pl @@ -0,0 +1,14 @@ +use Modern::Perl; + +return { + bug_number => "23681", + description => "Add manage_patron_restrictions_permission", + up => sub { + my ($args) = @_; + my ($dbh, $out) = @$args{qw(dbh out)}; + # Do you stuffs here + $dbh->do(q{ INSERT IGNORE INTO permissions (module_bit, code, description) VALUES ( 3, 'manage_patron_restrictions', 'Manage patron restrictions')}); + # Print useful stuff here + say $out "Update is going well so far"; + }, +}; --- a/installer/data/mysql/en/mandatory/patron_restrictions.sql +++ a/installer/data/mysql/en/mandatory/patron_restrictions.sql @@ -1,5 +0,0 @@ -INSERT INTO debarment_types (code, display_text, readonly, system) VALUES - ('MANUAL', 'Manual', 1, 1), - ('OVERDUES', 'Overdues', 1, 0), - ('SUSPENSION', 'Suspension', 1, 0), - ('DISCHARGE', 'Discharge', 1, 0); --- a/installer/data/mysql/en/mandatory/patron_restrictions.txt +++ a/installer/data/mysql/en/mandatory/patron_restrictions.txt @@ -1, +0,0 @@ -Default Koha system patron restriction types --- a/installer/data/mysql/en/mandatory/patron_restrictions.yml +++ a/installer/data/mysql/en/mandatory/patron_restrictions.yml @@ -0,0 +1,50 @@ +--- +# +# Copyright 2020 Koha Development Team +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . + +description: + - "Default Koha system patron restriction types" + +tables: + - debarment_types: + translatable: [ display_text ] + multiline: [] + rows: + - code: "MANUAL" + display_text: "Manual" + is_system: 1 + default: 1 + can_be_added_manually: 0 + + - code: "OVERDUES" + display_text: "Overdues" + is_system: 1 + default: 0 + can_be_added_manually: 0 + + - code: "SUSPENSION" + display_text: "Suspension" + is_system: 1 + default: 0 + can_be_added_manually: 0 + + - code: "DISCHARGE" + display_text: "Discharge" + is_system: 1 + default: 0 + can_be_added_manually: 0 --- a/installer/data/mysql/kohastructure.sql +++ a/installer/data/mysql/kohastructure.sql @@ -2031,8 +2031,9 @@ DROP TABLE IF EXISTS `debarment_types`; CREATE TABLE debarment_types ( code varchar(50) NOT NULL PRIMARY KEY, display_text text NOT NULL, - readonly tinyint(1) NOT NULL DEFAULT 0, - is_system tinyint(1) NOT NULL DEFAULT 0 + 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 ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- --- a/koha-tmpl/intranet-tmpl/prog/en/includes/borrower_debarments.inc +++ a/koha-tmpl/intranet-tmpl/prog/en/includes/borrower_debarments.inc @@ -64,7 +64,9 @@ --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/accounting.pref +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/accounting.pref @@ -56,3 +56,9 @@ Accounting: branchyyyymmincr: 'Automatically generate credit numbers in the form yyyymm0001' incremental: 'Automatically generate credit numbers in the form 1, 2, 3' - Automatic generation also has to be enabled for each credit type (Configure credit types) + - + - pref: PatronRestrictionTypes + choices: + 1: Allow + 0: Don't allow + - "the type of patron restriction to be specified when applying manually." --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref @@ -330,12 +330,6 @@ Patrons: 1: Allow 0: "Don't allow" - staff to set the ability for a patron's fines to be viewed by linked patrons in the OPAC. - - - - pref: PatronRestrictionTypes - choices: - 1: Allow - 0: Don't allow - - "the type of patron restriction to be specified when applying manually." Privacy: - --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/restrictions.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/restrictions.tt @@ -21,19 +21,19 @@
  • Administration
  • -
  • - Patron restrictions -
  • [% IF op == 'list' %]
  • - All restrictions + Patron restrictions
  • [% END %] [% IF op == 'add_form' %] +
  • + Patron restrictions +
  • [% IF restriction %]
  • @@ -50,6 +50,9 @@ [% END %] [% IF op == 'delete_confirm' %] +
  • + Patron restrictions +
  • Delete restriction? @@ -99,6 +102,16 @@ 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 %]
  • @@ -110,6 +123,16 @@ 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 %] @@ -156,6 +179,7 @@ Code Label + Manual Default Actions @@ -170,11 +194,14 @@ [% restriction.display_text | html %] - [% IF restriction.is_system %]Yes[% END %] + [% IF restriction.can_be_added_manually %]Yes[% END %] + + + [% IF restriction.default_value %]Yes[% END %]
    Edit - [% IF !restriction.readonly %] + [% IF !restriction.is_system %] Delete [% END %] --- a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/members/memberentrygen.tt @@ -1397,7 +1397,9 @@ legend:hover { --- a/t/db_dependent/RestrictionTypes.t +++ a/t/db_dependent/RestrictionTypes.t @@ -17,15 +17,16 @@ use_ok('Koha::RestrictionType'); use_ok('Koha::RestrictionTypes'); $dbh->do(q|DELETE FROM borrower_debarments|); -Koha::RestrictionTypes->search->delete; +$dbh->do(q|DELETE FROM debarment_types|); $builder->build({ source => 'DebarmentType', value => { code => 'ONE', display_text => 'One', - readonly => 1, - is_system => 0 + is_system => 1, + default_value => 0, + can_be_added_manually => 0 } }); $builder->build({ @@ -33,8 +34,9 @@ $builder->build({ value => { code => 'TWO', display_text => 'Two', - readonly => 1, - is_system => 1 + is_system => 1, + default_value => 1, + can_be_added_manually => 0 } }); $builder->build({ @@ -42,8 +44,9 @@ $builder->build({ value => { code => 'THREE', display_text => 'Three', - readonly => 1, - is_system => 0 + is_system => 1, + default_value => 0, + can_be_added_manually => 0 } }); $builder->build({ @@ -51,8 +54,9 @@ $builder->build({ value => { code => 'FOUR', display_text => 'Four', - readonly => 0, - is_system => 0 + is_system => 0, + default_value => 0, + can_be_added_manually => 0 } }); $builder->build({ @@ -60,8 +64,9 @@ $builder->build({ value => { code => 'FIVE', display_text => 'Five', - readonly => 0, - is_system => 0 + is_system => 0, + default_value => 0, + can_be_added_manually => 0 } }); @@ -71,10 +76,9 @@ ok( $created->display_text eq 'One', 'Restrictions created'); # Can we delete RestrictionTypes, when appropriate my $deleted = Koha::RestrictionTypes->find({ code => 'FOUR' })->delete; -ok( $deleted == 1, 'Restriction deleted'); +ok( $deleted, 'Restriction deleted'); my $not_deleted = Koha::RestrictionTypes->find({ code => 'TWO' })->delete; -ok( $not_deleted == 0, 'Read only restriction not deleted'); - +ok( !$not_deleted, 'Read only restriction not deleted'); # Add a patron with a debarment my $library = $builder->build({ source => 'Branch' }); --