Line 0
Link Here
|
0 |
- |
1 |
use Modern::Perl; |
|
|
2 |
use Array::Utils qw( array_minus ); |
3 |
|
4 |
return { |
5 |
bug_number => "29509", |
6 |
description => "Update users with list_borrowers permission where required", |
7 |
up => sub { |
8 |
my ($args) = @_; |
9 |
my ( $dbh, $out ) = @$args{qw(dbh out)}; |
10 |
|
11 |
# Users to exclude from update, (superlibrarians or borrowers flags) |
12 |
my $sth = $dbh->prepare("SELECT borrowernumber FROM borrowers WHERE flags = 1 OR (flags & 4) > 0"); |
13 |
$sth->execute(); |
14 |
my @exclusions = map { $_->[0] } @{ $sth->fetchall_arrayref }; |
15 |
|
16 |
# Prepare insert |
17 |
my $insert_sth = |
18 |
$dbh->prepare("INSERT IGNORE INTO user_permissions (borrowernumber, module_bit, code) VALUES (?, ?, ?)"); |
19 |
|
20 |
# Check for 'borrowers' or 'borrowers > edit_borrowers' permission |
21 |
my $sth2 = $dbh->prepare("SELECT borrowernumber FROM user_permissions WHERE code = 'edit_borrowers'"); |
22 |
$sth2->execute(); |
23 |
my @edit_borrowers = map { $_->[0] } @{ $sth2->fetchall_arrayref }; |
24 |
my @reduced = array_minus( @edit_borrowers, @exclusions ); |
25 |
my @rows_to_insert = ( map { [ $_, 4, "list_borrowers" ] } array_minus( @edit_borrowers, @exclusions ) ); |
26 |
foreach my $row (@rows_to_insert) { $insert_sth->execute( @{$row} ); } |
27 |
say $out "list_borrowers added to all users with edit_borrowers"; |
28 |
|
29 |
# Check for 'circulate' or 'circulate > manage_bookings' permission |
30 |
my $sth3 = $dbh->prepare("SELECT borrowernumber FROM user_permissions WHERE code = 'manage_bookings'"); |
31 |
$sth3->execute(); |
32 |
my @manage_bookings = map { $_->[0] } @{ $sth3->fetchall_arrayref }; |
33 |
@rows_to_insert = ( map { [ $_, 4, "list_borrowers" ] } array_minus( @manage_bookings, @exclusions ) ); |
34 |
foreach my $row (@rows_to_insert) { $insert_sth->execute( @{$row} ); } |
35 |
say $out "list_borrowers added to all users with manage_bookings"; |
36 |
|
37 |
# Check for 'tools' or 'tools > label_creator' permission |
38 |
my $sth4 = $dbh->prepare("SELECT borrowernumber FROM user_permissions WHERE code = 'label_creator'"); |
39 |
$sth4->execute(); |
40 |
my @label_creator = map { $_->[0] } @{ $sth4->fetchall_arrayref }; |
41 |
@rows_to_insert = ( map { [ $_, 4, "list_borrowers" ] } array_minus( @label_creator, @exclusions ) ); |
42 |
foreach my $row (@rows_to_insert) { $insert_sth->execute( @{$row} ); } |
43 |
say $out "list_borrowers added to all users with label_creator"; |
44 |
|
45 |
# Check for 'serials' or 'serials > routing' permission |
46 |
my $sth5 = $dbh->prepare("SELECT borrowernumber FROM user_permissions WHERE code = 'routing'"); |
47 |
$sth5->execute(); |
48 |
my @routing = map { $_->[0] } @{ $sth5->fetchall_arrayref }; |
49 |
@rows_to_insert = ( map { [ $_, 4, "list_borrowers" ] } array_minus( @routing, @exclusions ) ); |
50 |
foreach my $row (@rows_to_insert) { $insert_sth->execute( @{$row} ); } |
51 |
say $out "list_borrowers added to all users with routing"; |
52 |
|
53 |
# Check for 'acquisitions' or 'acquisitions > order_manage' permission |
54 |
my $sth6 = $dbh->prepare("SELECT borrowernumber FROM user_permissions WHERE code = 'order_manage'"); |
55 |
$sth6->execute(); |
56 |
my @order_manage = map { $_->[0] } @{ $sth6->fetchall_arrayref }; |
57 |
@rows_to_insert = ( map { [ $_, 4, "list_borrowers" ] } array_minus( @order_manage, @exclusions ) ); |
58 |
foreach my $row (@rows_to_insert) { $insert_sth->execute( @{$row} ); } |
59 |
say $out "list_borrowers added to all users with order_manage"; |
60 |
}, |
61 |
}; |