Koha/installer/data/mysql/db_revs/221200003.pl
Nick Clemens 2bdfe69df8
Bug 34589: Only update users if permission is added
To test:
1 - Assign a user 'edit_items' permission
2 - Manually run the update
    perl -e 'use C4::Installer; warn Data::Dumper::Dumper(C4::Installer::run_db_rev("installer/data/mysql/db_revs/221200003.pl"));'
3 - Edit patron permissions
4 - Note they now have edit_any_item permission
5 - Remove that permission
6 - Run the update again
7 - Edit patron permissions
8 - They have edit_any_item again - remove it
9 - Apply patch
10 - Run the update
11 - Edit patron permissions
12 - No new permissions added!
13 - sudo koha-mysql kohadev
     DELETE FROM permissions WHERE code = 'edit_any_item'
14 - Run the update again
15 - Edit patron permissions
16 - They do have edit_any_item

Signed-off-by: Émily-Rose Francoeur <emily-rose.francoeur@inLibro.com>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
2023-09-15 15:50:41 -03:00

36 lines
1.3 KiB
Perl
Executable file

use Modern::Perl;
return {
bug_number => "20256",
description => "Add ability to limit editing of items to home library",
up => sub {
my ($args) = @_;
my ($dbh, $out) = @$args{qw(dbh out)};
my $permission_added = $dbh->do(q{
INSERT IGNORE INTO permissions (module_bit, code, description) VALUES ( 9, 'edit_any_item', 'Edit any item reguardless of home library');
});
if( $permission_added == 1 ){
say $out "Added new permission 'edit_any_item'";
$dbh->do(q{
INSERT IGNORE INTO user_permissions ( borrowernumber, module_bit, code )
SELECT borrowernumber, '9', 'edit_any_item'
FROM user_permissions
WHERE module_bit = '9'
AND code = 'edit_items'
});
say $out "Added 'edit_any_item' permission to users with edit items permission";
}
if ( !column_exists( 'library_groups', 'ft_limit_item_editing' ) ) {
$dbh->do(q{
ALTER TABLE library_groups
ADD COLUMN ft_limit_item_editing tinyint(1) NOT NULL DEFAULT 0 AFTER ft_hide_patron_info
});
say $out "Added column 'library_groups.ft_limit_item_editing'";
}
},
};