View | Details | Raw Unified | Return to bug 7295
Collapse All | Expand All

(-)a/C4/Acquisition.pm (-2 / +147 lines)
Lines 48-53 BEGIN { Link Here
48
        &GetBasketsByBookseller &GetBasketsByBasketgroup
48
        &GetBasketsByBookseller &GetBasketsByBasketgroup
49
        &GetBasketsInfosByBookseller
49
        &GetBasketsInfosByBookseller
50
50
51
        &GetBasketUsers &ModBasketUsers
52
        &CanUserManageBasket
53
51
        &ModBasketHeader
54
        &ModBasketHeader
52
55
53
        &ModBasketgroup &NewBasketgroup &DelBasketgroup &GetBasketgroup &CloseBasketgroup
56
        &ModBasketgroup &NewBasketgroup &DelBasketgroup &GetBasketgroup &CloseBasketgroup
Lines 156-163 sub GetBasket { Link Here
156
    my $dbh        = C4::Context->dbh;
159
    my $dbh        = C4::Context->dbh;
157
    my $query = "
160
    my $query = "
158
        SELECT  aqbasket.*,
161
        SELECT  aqbasket.*,
159
                concat( b.firstname,' ',b.surname) AS authorisedbyname,
162
                concat( b.firstname,' ',b.surname) AS authorisedbyname
160
                b.branchcode AS branch
161
        FROM    aqbasket
163
        FROM    aqbasket
162
        LEFT JOIN borrowers b ON aqbasket.authorisedby=b.borrowernumber
164
        LEFT JOIN borrowers b ON aqbasket.authorisedby=b.borrowernumber
163
        WHERE basketno=?
165
        WHERE basketno=?
Lines 603-608 sub GetBasketsInfosByBookseller { Link Here
603
    return $sth->fetchall_arrayref({});
605
    return $sth->fetchall_arrayref({});
604
}
606
}
605
607
608
=head3 GetBasketUsers
609
610
    $basketusers_ids = &GetBasketUsers($basketno);
611
612
Returns a list of all borrowernumbers that are in basket users list
613
614
=cut
615
616
sub GetBasketUsers {
617
    my $basketno = shift;
618
619
    return unless $basketno;
620
621
    my $query = qq{
622
        SELECT borrowernumber
623
        FROM aqbasketusers
624
        WHERE basketno = ?
625
    };
626
    my $dbh = C4::Context->dbh;
627
    my $sth = $dbh->prepare($query);
628
    $sth->execute($basketno);
629
    my $results = $sth->fetchall_arrayref( {} );
630
    $sth->finish();
631
632
    my @borrowernumbers;
633
    foreach (@$results) {
634
        push @borrowernumbers, $_->{'borrowernumber'};
635
    }
636
637
    return @borrowernumbers;
638
}
639
640
=head3 ModBasketUsers
641
642
    my @basketusers_ids = (1, 2, 3);
643
    &ModBasketUsers($basketno, @basketusers_ids);
644
645
Delete all users from basket users list, and add users in C<@basketusers_ids>
646
to this users list.
647
648
=cut
649
650
sub ModBasketUsers {
651
    my ($basketno, @basketusers_ids) = @_;
652
653
    return unless $basketno;
654
655
    my $dbh = C4::Context->dbh;
656
    my $query = qq{
657
        DELETE FROM aqbasketusers
658
        WHERE basketno = ?
659
    };
660
    my $sth = $dbh->prepare($query);
661
    $sth->execute($basketno);
662
    $sth->finish();
663
664
    $query = qq{
665
        INSERT INTO aqbasketusers (basketno, borrowernumber)
666
        VALUES (?, ?)
667
    };
668
    $sth = $dbh->prepare($query);
669
    foreach my $basketuser_id (@basketusers_ids) {
670
        $sth->execute($basketno, $basketuser_id);
671
    }
672
}
673
674
=head3 CanUserManageBasket
675
676
    my $bool = CanUserManageBasket($borrower, $basket[, $userflags]);
677
    my $bool = CanUserManageBasket($borrowernumber, $basketno[, $userflags]);
678
679
Check if a borrower can manage a basket, according to system preference
680
AcqViewBaskets, user permissions and basket properties (creator, users list,
681
branch).
682
683
First parameter can be either a borrowernumber or a hashref as returned by
684
C4::Members::GetMember.
685
686
Second parameter can be either a basketno or a hashref as returned by
687
C4::Acquisition::GetBasket.
688
689
The third parameter is optional. If given, it should be a hashref as returned
690
by C4::Auth::getuserflags. If not, getuserflags is called.
691
692
If user is authorised to manage basket, returns 1.
693
Otherwise returns 0.
694
695
=cut
696
697
sub CanUserManageBasket {
698
    my ($borrower, $basket, $userflags) = @_;
699
700
    if (!ref $borrower) {
701
        $borrower = C4::Members::GetMember(borrowernumber => $borrower);
702
    }
703
    if (!ref $basket) {
704
        $basket = GetBasket($basket);
705
    }
706
707
    return 0 unless ($basket and $borrower);
708
709
    my $borrowernumber = $borrower->{borrowernumber};
710
    my $basketno = $basket->{basketno};
711
712
    my $AcqViewBaskets = C4::Context->preference('AcqViewBaskets');
713
714
    if (!defined $userflags) {
715
        my $dbh = C4::Context->dbh;
716
        my $sth = $dbh->prepare("SELECT flags FROM borrowers WHERE borrowernumber = ?");
717
        $sth->execute($borrowernumber);
718
        my ($flags) = $sth->fetchrow_array;
719
        $sth->finish;
720
721
        $userflags = C4::Auth::getuserflags($flags, $borrower->{userid}, $dbh);
722
    }
723
724
    unless ($userflags->{superlibrarian}
725
    || (ref $userflags->{acquisition} && $userflags->{acquisition}->{order_manage_all})
726
    || (!ref $userflags->{acquisition} && $userflags->{acquisition}))
727
    {
728
        if (not exists $userflags->{acquisition}) {
729
            return 0;
730
        }
731
732
        if ( (ref $userflags->{acquisition} && !$userflags->{acquisition}->{order_manage})
733
        || (!ref $userflags->{acquisition} && !$userflags->{acquisition}) ) {
734
            return 0;
735
        }
736
737
        if ($AcqViewBaskets eq 'user'
738
        && $basket->{authorisedby} != $borrowernumber
739
        && grep($borrowernumber, GetBasketUsers($basketno)) == 0) {
740
            return 0;
741
        }
742
743
        if ($AcqViewBaskets eq 'branch' && defined $basket->{branch}
744
        && $basket->{branch} ne $borrower->{branchcode}) {
745
            return 0;
746
        }
747
    }
748
749
    return 1;
750
}
606
751
607
#------------------------------------------------------------#
752
#------------------------------------------------------------#
608
753
(-)a/acqui/aqbasketuser_search.pl (+77 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# script to find a basket user
4
5
# Copyright 2012 BibLibre SARL
6
#
7
# This file is part of Koha.
8
#
9
# Koha is free software; you can redistribute it and/or modify it under the
10
# terms of the GNU General Public License as published by the Free Software
11
# Foundation; either version 2 of the License, or (at your option) any later
12
# version.
13
#
14
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
15
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
17
#
18
# You should have received a copy of the GNU General Public License along
19
# with Koha; if not, write to the Free Software Foundation, Inc.,
20
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21
22
use Modern::Perl;
23
24
use CGI;
25
use C4::Auth;
26
use C4::Output;
27
use C4::Members;
28
29
my $input = new CGI;
30
31
my $dbh = C4::Context->dbh;
32
33
my ( $template, $loggedinuser, $cookie, $staff_flags ) = get_template_and_user(
34
    {   template_name   => "acqui/aqbasketuser_search.tmpl",
35
        query           => $input,
36
        type            => "intranet",
37
        authnotrequired => 0,
38
        flagsrequired   => { acquisition => 'order_manage' },
39
    }
40
);
41
42
my $q = $input->param('q') || '';
43
my $op = $input->param('op') || '';
44
45
if( $op eq "do_search" ) {
46
    my $results = C4::Members::Search( $q, "surname");
47
48
    my @users_loop;
49
    my $nresults = 0;
50
    foreach my $res (@$results) {
51
        my $perms = haspermission( $res->{userid} );
52
        my $subperms = get_user_subpermissions( $res->{userid} );
53
54
        if( $perms->{superlibrarian} == 1
55
         || $perms->{acquisition} == 1
56
         || $subperms->{acquisition}->{'order_manage'} ) {
57
            my %row = (
58
                borrowernumber  => $res->{borrowernumber},
59
                cardnumber      => $res->{cardnumber},
60
                surname         => $res->{surname},
61
                firstname       => $res->{firstname},
62
                categorycode    => $res->{categorycode},
63
                branchcode      => $res->{branchcode},
64
            );
65
            push( @users_loop, \%row );
66
            $nresults ++;
67
        }
68
    }
69
70
    $template->param(
71
        q           => $q,
72
        nresults    => $nresults,
73
        users_loop  => \@users_loop,
74
    );
75
}
76
77
output_html_with_http_headers( $input, $cookie, $template->output );
(-)a/acqui/basket.pl (-2 / +51 lines)
Lines 28-33 use C4::Output; Link Here
28
use CGI;
28
use CGI;
29
use C4::Acquisition;
29
use C4::Acquisition;
30
use C4::Budgets;
30
use C4::Budgets;
31
use C4::Branch;
31
use C4::Bookseller qw( GetBookSellerFromId);
32
use C4::Bookseller qw( GetBookSellerFromId);
32
use C4::Debug;
33
use C4::Debug;
33
use C4::Biblio;
34
use C4::Biblio;
Lines 80-92 my ( $template, $loggedinuser, $cookie, $userflags ) = get_template_and_user( Link Here
80
);
81
);
81
82
82
my $basket = GetBasket($basketno);
83
my $basket = GetBasket($basketno);
84
$booksellerid = $basket->{booksellerid} unless $booksellerid;
85
my ($bookseller) = GetBookSellerFromId($booksellerid);
86
87
unless (CanUserManageBasket($loggedinuser, $basket, $userflags)) {
88
    $template->param(
89
        cannot_manage_basket => 1,
90
        basketno => $basketno,
91
        basketname => $basket->{basketname},
92
        booksellerid => $booksellerid,
93
        name => $bookseller->{name}
94
    );
95
    output_html_with_http_headers $query, $cookie, $template->output;
96
    exit;
97
}
83
98
84
# FIXME : what about the "discount" percentage?
99
# FIXME : what about the "discount" percentage?
85
# FIXME : the query->param('booksellerid') below is probably useless. The bookseller is always known from the basket
100
# FIXME : the query->param('booksellerid') below is probably useless. The bookseller is always known from the basket
86
# if no booksellerid in parameter, get it from basket
101
# if no booksellerid in parameter, get it from basket
87
# warn "=>".$basket->{booksellerid};
102
# warn "=>".$basket->{booksellerid};
88
$booksellerid = $basket->{booksellerid} unless $booksellerid;
89
my ($bookseller) = GetBookSellerFromId($booksellerid);
90
my $op = $query->param('op');
103
my $op = $query->param('op');
91
if (!defined $op) {
104
if (!defined $op) {
92
    $op = q{};
105
    $op = q{};
Lines 190-195 if ( $op eq 'delete_confirm' ) { Link Here
190
    $basket->{closedate} = undef;
203
    $basket->{closedate} = undef;
191
    ModBasket($basket);
204
    ModBasket($basket);
192
    print $query->redirect('/cgi-bin/koha/acqui/basket.pl?basketno='.$basket->{'basketno'})
205
    print $query->redirect('/cgi-bin/koha/acqui/basket.pl?basketno='.$basket->{'basketno'})
206
} elsif ( $op eq 'mod_users' ) {
207
    my $basketusers_ids = $query->param('basketusers_ids');
208
    my @basketusers = split( /:/, $basketusers_ids );
209
    ModBasketUsers($basketno, @basketusers);
210
    print $query->redirect("/cgi-bin/koha/acqui/basket.pl?basketno=$basketno");
211
    exit;
212
} elsif ( $op eq 'mod_branch' ) {
213
    my $branch = $query->param('branch');
214
    $branch = undef if(defined $branch and $branch eq '');
215
    ModBasket({
216
        basketno => $basket->{basketno},
217
        branch   => $branch
218
    });
219
    print $query->redirect("/cgi-bin/koha/acqui/basket.pl?basketno=$basketno");
220
    exit;
193
} else {
221
} else {
194
    # get librarian branch...
222
    # get librarian branch...
195
    if ( C4::Context->preference("IndependantBranches") ) {
223
    if ( C4::Context->preference("IndependantBranches") ) {
Lines 205-210 if ( $op eq 'delete_confirm' ) { Link Here
205
            }
233
            }
206
        }
234
        }
207
    }
235
    }
236
    # get branches
237
    my $branches = C4::Branch::GetBranches;
238
    my @branches_loop;
239
    foreach my $branch (sort keys %$branches) {
240
        push @branches_loop, {
241
            branchcode => $branch,
242
            branchname => $branches->{$branch}->{branchname},
243
            selected => (defined $basket->{branch} and $branch eq $basket->{branch}) ? 1 : 0
244
        };
245
    }
246
208
#if the basket is closed,and the user has the permission to edit basketgroups, display a list of basketgroups
247
#if the basket is closed,and the user has the permission to edit basketgroups, display a list of basketgroups
209
    my ($basketgroup, $basketgroups);
248
    my ($basketgroup, $basketgroups);
210
    my $member = GetMember(borrowernumber => $loggedinuser);
249
    my $member = GetMember(borrowernumber => $loggedinuser);
Lines 241-246 if ( $op eq 'delete_confirm' ) { Link Here
241
      "loggedinuser: $loggedinuser; creationdate: %s; authorisedby: %s",
280
      "loggedinuser: $loggedinuser; creationdate: %s; authorisedby: %s",
242
      $basket->{creationdate}, $basket->{authorisedby};
281
      $basket->{creationdate}, $basket->{authorisedby};
243
282
283
    my @basketusers_ids = GetBasketUsers($basketno);
284
    my @basketusers;
285
    foreach my $basketuser_id (@basketusers_ids) {
286
        my $basketuser = GetMember(borrowernumber => $basketuser_id);
287
        push @basketusers, $basketuser if $basketuser;
288
    }
289
244
    #to get active currency
290
    #to get active currency
245
    my $cur = GetCurrency();
291
    my $cur = GetCurrency();
246
292
Lines 320-328 if ( $op eq 'delete_confirm' ) { Link Here
320
        basketbooksellernote => $basket->{booksellernote},
366
        basketbooksellernote => $basket->{booksellernote},
321
        basketcontractno     => $basket->{contractnumber},
367
        basketcontractno     => $basket->{contractnumber},
322
        basketcontractname   => $contract->{contractname},
368
        basketcontractname   => $contract->{contractname},
369
        branches_loop        => \@branches_loop,
323
        creationdate         => $basket->{creationdate},
370
        creationdate         => $basket->{creationdate},
324
        authorisedby         => $basket->{authorisedby},
371
        authorisedby         => $basket->{authorisedby},
325
        authorisedbyname     => $basket->{authorisedbyname},
372
        authorisedbyname     => $basket->{authorisedbyname},
373
        basketusers_ids      => join(':', @basketusers_ids),
374
        basketusers          => \@basketusers,
326
        closedate            => $basket->{closedate},
375
        closedate            => $basket->{closedate},
327
        estimateddeliverydate=> $estimateddeliverydate,
376
        estimateddeliverydate=> $estimateddeliverydate,
328
        deliveryplace        => C4::Branch::GetBranchName( $basket->{deliveryplace} ),
377
        deliveryplace        => C4::Branch::GetBranchName( $basket->{deliveryplace} ),
(-)a/acqui/booksellers.pl (-22 / +4 lines)
Lines 56-68 use C4::Biblio; Link Here
56
use C4::Output;
56
use C4::Output;
57
use CGI;
57
use CGI;
58
58
59
use C4::Acquisition qw/ GetBasketsInfosByBookseller /;
59
use C4::Acquisition qw/ GetBasketsInfosByBookseller CanUserManageBasket /;
60
use C4::Bookseller qw/ GetBookSellerFromId GetBookSeller /;
60
use C4::Bookseller qw/ GetBookSellerFromId GetBookSeller /;
61
use C4::Members qw/GetMember/;
61
use C4::Members qw/GetMember/;
62
use C4::Context;
62
use C4::Context;
63
63
64
my $query = CGI->new;
64
my $query = CGI->new;
65
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
65
my ( $template, $loggedinuser, $cookie, $userflags ) = get_template_and_user(
66
    {   template_name   => 'acqui/booksellers.tmpl',
66
    {   template_name   => 'acqui/booksellers.tmpl',
67
        query           => $query,
67
        query           => $query,
68
        type            => 'intranet',
68
        type            => 'intranet',
Lines 98-108 if ($loggedinuser) { Link Here
98
    $uid = GetMember( borrowernumber => $loggedinuser )->{userid};
98
    $uid = GetMember( borrowernumber => $loggedinuser )->{userid};
99
}
99
}
100
100
101
my $userenv = C4::Context::userenv;
102
my $viewbaskets = C4::Context->preference('AcqViewBaskets');
103
104
my $userbranch = $userenv->{branch};
105
106
#build result page
101
#build result page
107
my $loop_suppliers = [];
102
my $loop_suppliers = [];
108
103
Lines 112-132 for my $vendor (@suppliers) { Link Here
112
    my $loop_basket = [];
107
    my $loop_basket = [];
113
108
114
    for my $basket ( @{$baskets} ) {
109
    for my $basket ( @{$baskets} ) {
115
        my $authorisedby = $basket->{authorisedby};
110
        if (CanUserManageBasket($loggedinuser, $basket, $userflags)) {
116
        my $basketbranch = ''; # set a blank branch to start with
111
            my $member = GetMember( borrowernumber => $basket->{authorisedby} );
117
        my $member = GetMember( borrowernumber => $authorisedby );
118
        if ( $member ) {
119
           $basketbranch = $member->{branchcode};
120
        }
121
122
        if ($userenv->{'flags'} & 1 || #user is superlibrarian
123
               (haspermission( $uid, { acquisition => q{*} } ) && #user has acq permissions and
124
                   ($viewbaskets eq 'all' || #user is allowed to see all baskets
125
                   ($viewbaskets eq 'branch' && $authorisedby && $userbranch eq $basketbranch) || #basket belongs to user's branch
126
                   ($basket->{authorisedby} &&  $viewbaskets eq 'user' && $authorisedby == $loggedinuser) #user created this basket
127
                   ) 
128
                ) 
129
           ) { 
130
            foreach (qw(total_items total_biblios expected_items)) {
112
            foreach (qw(total_items total_biblios expected_items)) {
131
                $basket->{$_} ||= 0;
113
                $basket->{$_} ||= 0;
132
            }
114
            }
(-)a/installer/data/mysql/de-DE/mandatory/userpermissions.sql (+1 lines)
Lines 16-21 INSERT INTO permissions (module_bit, code, description) VALUES Link Here
16
   (11, 'budget_modify', 'Konten verändern (keine neuen anlegen, aber bestehende ändern)'),
16
   (11, 'budget_modify', 'Konten verändern (keine neuen anlegen, aber bestehende ändern)'),
17
   (11, 'planning_manage', 'Etatplanung verwalten'),
17
   (11, 'planning_manage', 'Etatplanung verwalten'),
18
   (11, 'order_manage', 'Bestellungen verwalten'),
18
   (11, 'order_manage', 'Bestellungen verwalten'),
19
   (11, 'order_manage_all', 'Manage all orders & baskets'),
19
   (11, 'group_manage', 'Bestellgruppen vewalten'),
20
   (11, 'group_manage', 'Bestellgruppen vewalten'),
20
   (11, 'order_receive', 'Lieferungen verwalten'),
21
   (11, 'order_receive', 'Lieferungen verwalten'),
21
   (11, 'budget_add_del', 'Konten hinzufügen/ändern, aber bestehende nicht ändern'),
22
   (11, 'budget_add_del', 'Konten hinzufügen/ändern, aber bestehende nicht ändern'),
(-)a/installer/data/mysql/en/mandatory/userpermissions.sql (+1 lines)
Lines 16-21 INSERT INTO permissions (module_bit, code, description) VALUES Link Here
16
   (11, 'budget_modify', 'Modify budget (can''t create lines, but can modify existing ones)'),
16
   (11, 'budget_modify', 'Modify budget (can''t create lines, but can modify existing ones)'),
17
   (11, 'planning_manage', 'Manage budget plannings'),
17
   (11, 'planning_manage', 'Manage budget plannings'),
18
   (11, 'order_manage', 'Manage orders & basket'),
18
   (11, 'order_manage', 'Manage orders & basket'),
19
   (11, 'order_manage_all', 'Manage all orders & baskets'),
19
   (11, 'group_manage', 'Manage orders & basketgroups'),
20
   (11, 'group_manage', 'Manage orders & basketgroups'),
20
   (11, 'order_receive', 'Manage orders & basket'),
21
   (11, 'order_receive', 'Manage orders & basket'),
21
   (11, 'budget_add_del', 'Add and delete budgets (but cant modify budgets)'),
22
   (11, 'budget_add_del', 'Add and delete budgets (but cant modify budgets)'),
(-)a/installer/data/mysql/es-ES/mandatory/userpermissions.sql (+1 lines)
Lines 16-21 INSERT INTO permissions (module_bit, code, description) VALUES Link Here
16
   (11, 'budget_modify', 'Modify budget (can''t create lines, but can modify existing ones)'),
16
   (11, 'budget_modify', 'Modify budget (can''t create lines, but can modify existing ones)'),
17
   (11, 'planning_manage', 'Manage budget plannings'),
17
   (11, 'planning_manage', 'Manage budget plannings'),
18
   (11, 'order_manage', 'Manage orders & basket'),
18
   (11, 'order_manage', 'Manage orders & basket'),
19
   (11, 'order_manage_all', 'Manage all orders & baskets'),
19
   (11, 'group_manage', 'Manage orders & basketgroups'),
20
   (11, 'group_manage', 'Manage orders & basketgroups'),
20
   (11, 'order_receive', 'Manage orders & basket'),
21
   (11, 'order_receive', 'Manage orders & basket'),
21
   (11, 'budget_add_del', 'Add and delete budgets (but cant modify budgets)'),
22
   (11, 'budget_add_del', 'Add and delete budgets (but cant modify budgets)'),
(-)a/installer/data/mysql/fr-FR/1-Obligatoire/userpermissions.sql (+1 lines)
Lines 33-38 INSERT INTO permissions (module_bit, code, description) VALUES Link Here
33
   (11, 'budget_modify', 'Modifier les budgets (impossible de créer les lignes, mais possible de modifier celles qui existent'),
33
   (11, 'budget_modify', 'Modifier les budgets (impossible de créer les lignes, mais possible de modifier celles qui existent'),
34
   (11, 'planning_manage', 'Gérer de la planification des budgets'),
34
   (11, 'planning_manage', 'Gérer de la planification des budgets'),
35
   (11, 'order_manage', 'Gérer les commandes et les paniers'),
35
   (11, 'order_manage', 'Gérer les commandes et les paniers'),
36
   (11, 'order_manage_all', 'Gérer toutes les commandes et panier'),
36
   (11, 'group_manage', 'Gérer les commandes et les bons de commande'),
37
   (11, 'group_manage', 'Gérer les commandes et les bons de commande'),
37
   (11, 'order_receive', 'Gérer les réceptions'),
38
   (11, 'order_receive', 'Gérer les réceptions'),
38
   (11, 'budget_add_del', 'Ajouter et supprimer les budgets (mais pas modifier)'),
39
   (11, 'budget_add_del', 'Ajouter et supprimer les budgets (mais pas modifier)'),
(-)a/installer/data/mysql/it-IT/necessari/userpermissions.sql (+1 lines)
Lines 18-23 INSERT INTO permissions (module_bit, code, description) VALUES Link Here
18
   (11, 'budget_modify', 'Modifica budget (non li crea ma modifica gli esistenti)'),
18
   (11, 'budget_modify', 'Modifica budget (non li crea ma modifica gli esistenti)'),
19
   (11, 'planning_manage', 'Intervieni sulla pianificazione dei budgets'),
19
   (11, 'planning_manage', 'Intervieni sulla pianificazione dei budgets'),
20
   (11, 'order_manage', 'Gestisci ordini e raccoglitori'),
20
   (11, 'order_manage', 'Gestisci ordini e raccoglitori'),
21
   (11, 'order_manage_all', 'Manage all orders & baskets'),
21
   (11, 'group_manage', 'Gestisci ordini e raccoglitori raggruppati'),
22
   (11, 'group_manage', 'Gestisci ordini e raccoglitori raggruppati'),
22
   (11, 'order_receive', 'Gestisci arrivi'),
23
   (11, 'order_receive', 'Gestisci arrivi'),
23
   (11, 'budget_add_del', 'Aggiungi e cancella budgets (senza modificarli)'),
24
   (11, 'budget_add_del', 'Aggiungi e cancella budgets (senza modificarli)'),
(-)a/installer/data/mysql/kohastructure.sql (+15 lines)
Lines 2591-2596 CREATE TABLE `aqbasket` ( -- stores data about baskets in acquisitions Link Here
2591
  `basketgroupid` int(11), -- links this basket to its group (aqbasketgroups.id)
2591
  `basketgroupid` int(11), -- links this basket to its group (aqbasketgroups.id)
2592
  `deliveryplace` varchar(10) default NULL, -- basket delivery place
2592
  `deliveryplace` varchar(10) default NULL, -- basket delivery place
2593
  `billingplace` varchar(10) default NULL, -- basket billing place
2593
  `billingplace` varchar(10) default NULL, -- basket billing place
2594
  branch varchar(10) default NULL, -- basket branch
2594
  PRIMARY KEY  (`basketno`),
2595
  PRIMARY KEY  (`basketno`),
2595
  KEY `booksellerid` (`booksellerid`),
2596
  KEY `booksellerid` (`booksellerid`),
2596
  KEY `basketgroupid` (`basketgroupid`),
2597
  KEY `basketgroupid` (`basketgroupid`),
Lines 2598-2603 CREATE TABLE `aqbasket` ( -- stores data about baskets in acquisitions Link Here
2598
  CONSTRAINT `aqbasket_ibfk_1` FOREIGN KEY (`booksellerid`) REFERENCES `aqbooksellers` (`id`) ON UPDATE CASCADE,
2599
  CONSTRAINT `aqbasket_ibfk_1` FOREIGN KEY (`booksellerid`) REFERENCES `aqbooksellers` (`id`) ON UPDATE CASCADE,
2599
  CONSTRAINT `aqbasket_ibfk_2` FOREIGN KEY (`contractnumber`) REFERENCES `aqcontract` (`contractnumber`),
2600
  CONSTRAINT `aqbasket_ibfk_2` FOREIGN KEY (`contractnumber`) REFERENCES `aqcontract` (`contractnumber`),
2600
  CONSTRAINT `aqbasket_ibfk_3` FOREIGN KEY (`basketgroupid`) REFERENCES `aqbasketgroups` (`id`) ON UPDATE CASCADE
2601
  CONSTRAINT `aqbasket_ibfk_3` FOREIGN KEY (`basketgroupid`) REFERENCES `aqbasketgroups` (`id`) ON UPDATE CASCADE
2602
  CONSTRAINT aqbasket_ibfk_4 FOREIGN KEY (branch) REFERENCES branches (branchcode) ON UPDATE CASCADE ON DELETE SET NULL,
2603
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2604
2605
--
2606
-- Table structure for table aqbasketusers
2607
--
2608
2609
DROP TABLE IF EXISTS aqbasketusers;
2610
CREATE TABLE aqbasketusers (
2611
  basketno int(11) NOT NULL,
2612
  borrowernumber int(11) NOT NULL,
2613
  PRIMARY KEY (basketno,borrowernumber),
2614
  CONSTRAINT aqbasketusers_ibfk_1 FOREIGN KEY (basketno) REFERENCES aqbasket (basketno) ON UPDATE CASCADE ON DELETE CASCADE,
2615
  CONSTRAINT aqbasketusers_ibfk_2 FOREIGN KEY (borrowernumber) REFERENCES borrowers (borrowernumber) ON UPDATE CASCADE ON DELETE CASCADE
2601
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2616
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2602
2617
2603
--
2618
--
(-)a/installer/data/mysql/nb-NO/1-Obligatorisk/userpermissions.sql (+1 lines)
Lines 36-41 INSERT INTO permissions (module_bit, code, description) VALUES Link Here
36
   (11, 'budget_modify', 'Endre budsjetter (kan ikke legge til kontolinjer, men endre eksisterende)'),
36
   (11, 'budget_modify', 'Endre budsjetter (kan ikke legge til kontolinjer, men endre eksisterende)'),
37
   (11, 'planning_manage', 'Administrere budsjettplaner'),
37
   (11, 'planning_manage', 'Administrere budsjettplaner'),
38
   (11, 'order_manage', 'Administrere bestillinger og kurver'),
38
   (11, 'order_manage', 'Administrere bestillinger og kurver'),
39
   (11, 'order_manage_all', 'Manage all orders & baskets'),
39
   (11, 'group_manage', 'Administrere bestillinger og kurv-grupper'),
40
   (11, 'group_manage', 'Administrere bestillinger og kurv-grupper'),
40
   (11, 'order_receive', 'Administrere bestillinger og kurver'),
41
   (11, 'order_receive', 'Administrere bestillinger og kurver'),
41
   (11, 'budget_add_del', 'Legge til og slette budsjetter (men ikke endre budsjetter)'),
42
   (11, 'budget_add_del', 'Legge til og slette budsjetter (men ikke endre budsjetter)'),
(-)a/installer/data/mysql/pl-PL/mandatory/userpermissions.sql (+1 lines)
Lines 16-21 INSERT INTO permissions (module_bit, code, description) VALUES Link Here
16
   (11, 'budget_modify', 'Modify budget (can''t create lines, but can modify existing ones)'),
16
   (11, 'budget_modify', 'Modify budget (can''t create lines, but can modify existing ones)'),
17
   (11, 'planning_manage', 'Manage budget plannings'),
17
   (11, 'planning_manage', 'Manage budget plannings'),
18
   (11, 'order_manage', 'Manage orders & basket'),
18
   (11, 'order_manage', 'Manage orders & basket'),
19
   (11, 'order_manage_all', 'Manage all orders & baskets'),
19
   (11, 'group_manage', 'Manage orders & basketgroups'),
20
   (11, 'group_manage', 'Manage orders & basketgroups'),
20
   (11, 'order_receive', 'Manage orders & basket'),
21
   (11, 'order_receive', 'Manage orders & basket'),
21
   (11, 'budget_add_del', 'Add and delete budgets (but cant modify budgets)'),
22
   (11, 'budget_add_del', 'Add and delete budgets (but cant modify budgets)'),
(-)a/installer/data/mysql/ru-RU/mandatory/permissions_and_user_flags.sql (+1 lines)
Lines 41-46 INSERT INTO permissions (module_bit, code, description) VALUES Link Here
41
   (11, 'budget_modify', 'Modify budget (can''t create lines, but can modify existing ones)'),
41
   (11, 'budget_modify', 'Modify budget (can''t create lines, but can modify existing ones)'),
42
   (11, 'planning_manage', 'Manage budget plannings'),
42
   (11, 'planning_manage', 'Manage budget plannings'),
43
   (11, 'order_manage', 'Manage orders & basket'),
43
   (11, 'order_manage', 'Manage orders & basket'),
44
   (11, 'order_manage_all', 'Manage all orders & baskets'),
44
   (11, 'group_manage', 'Manage orders & basketgroups'),
45
   (11, 'group_manage', 'Manage orders & basketgroups'),
45
   (11, 'order_receive', 'Manage orders & basket'),
46
   (11, 'order_receive', 'Manage orders & basket'),
46
   (11, 'budget_add_del', 'Add and delete budgets (but cant modify budgets)'),
47
   (11, 'budget_add_del', 'Add and delete budgets (but cant modify budgets)'),
(-)a/installer/data/mysql/uk-UA/mandatory/permissions_and_user_flags.sql (+1 lines)
Lines 41-46 INSERT INTO permissions (module_bit, code, description) VALUES Link Here
41
   (11, 'budget_modify', 'Modify budget (can''t create lines, but can modify existing ones)'),
41
   (11, 'budget_modify', 'Modify budget (can''t create lines, but can modify existing ones)'),
42
   (11, 'planning_manage', 'Manage budget plannings'),
42
   (11, 'planning_manage', 'Manage budget plannings'),
43
   (11, 'order_manage', 'Manage orders & basket'),
43
   (11, 'order_manage', 'Manage orders & basket'),
44
   (11, 'order_manage_all', 'Manage all orders & baskets'),
44
   (11, 'group_manage', 'Manage orders & basketgroups'),
45
   (11, 'group_manage', 'Manage orders & basketgroups'),
45
   (11, 'order_receive', 'Manage orders & basket'),
46
   (11, 'order_receive', 'Manage orders & basket'),
46
   (11, 'budget_add_del', 'Add and delete budgets (but cant modify budgets)'),
47
   (11, 'budget_add_del', 'Add and delete budgets (but cant modify budgets)'),
(-)a/installer/data/mysql/updatedatabase.pl (+33 lines)
Lines 6771-6776 if ( CheckVersion($DBversion) ) { Link Here
6771
   SetVersion ($DBversion);
6771
   SetVersion ($DBversion);
6772
}
6772
}
6773
6773
6774
$DBversion = "3.11.00.XXX";
6775
if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
6776
    $dbh->do("
6777
        ALTER TABLE aqbasket ADD branch varchar(10) default NULL
6778
    ");
6779
    $dbh->do("
6780
        ALTER TABLE aqbasket
6781
        ADD CONSTRAINT aqbasket_ibfk_4 FOREIGN KEY (branch)
6782
            REFERENCES branches (branchcode)
6783
            ON UPDATE CASCADE ON DELETE SET NULL
6784
    ");
6785
    $dbh->do("
6786
        DROP TABLE IF EXISTS aqbasketusers
6787
    ");
6788
    $dbh->do("
6789
        CREATE TABLE aqbasketusers (
6790
            basketno int(11) NOT NULL,
6791
            borrowernumber int(11) NOT NULL,
6792
            PRIMARY KEY (basketno,borrowernumber),
6793
            CONSTRAINT aqbasketusers_ibfk_1 FOREIGN KEY (basketno) REFERENCES aqbasket (basketno) ON DELETE CASCADE ON UPDATE CASCADE,
6794
            CONSTRAINT aqbasketusers_ibfk_2 FOREIGN KEY (borrowernumber) REFERENCES borrowers (borrowernumber) ON DELETE CASCADE ON UPDATE CASCADE
6795
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
6796
    ");
6797
    $dbh->do("
6798
        INSERT INTO permissions (module_bit, code, description)
6799
        VALUES (11, 'order_manage_all', 'Manage all orders & baskets')
6800
    ");
6801
6802
    print "Upgrade to $DBversion done (Add branch and users list to baskets. "
6803
        . "New permission order_manage_all)\n";
6804
    SetVersion($DBversion);
6805
}
6806
6774
6807
6775
=head1 FUNCTIONS
6808
=head1 FUNCTIONS
6776
6809
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/aqbasketuser_search.tt (+79 lines)
Line 0 Link Here
1
[% INCLUDE 'doc-head-open.inc' %]
2
<title>Koha &rsaquo; Basket User Search</title>
3
[% INCLUDE 'doc-head-close.inc' %]
4
5
<style type="text/css">
6
    #custom-doc {
7
        width:44.46em;
8
        *width:43.39em;
9
        min-width:578px;
10
        margin:auto;
11
        text-align:left;
12
    }
13
</style>
14
15
<script type="text/javascript">
16
//<![CDATA[
17
    // modify parent window owner element
18
    function add_user(borrowernumber, borrowername) {
19
        var p = window.opener;
20
        if(p.add_basket_user(borrowernumber, borrowername) < 0) {
21
            alert(_("Borrower '" + borrowername + "' is already in the list."));
22
        }
23
    }
24
//]]>
25
</script>
26
27
</head>
28
<body>
29
<div id="custom-doc" class="yui-t7">
30
  <div id="bd">
31
    <div class="yui-g">
32
33
      <h3>Search for Basket User</h3>
34
      <form action="/cgi-bin/koha/acqui/aqbasketuser_search.pl" method="post">
35
        <fieldset>
36
          <input type="hidden" name="op" id="op" value="do_search" />
37
          <input type="text" name="q" id="q" value="[% q %]" class="focus" />
38
          <input type="submit" class="button" value="Search" />
39
        </fieldset>
40
        <div class="hint">Only staff with superlibrarian or acquisitions permissions (or order_manage permission if granular permissions are enabled) are returned in the search results</div>
41
      </form>
42
43
[% IF (q) %]
44
    <p>Searched for <span class="ex">[% q %]</span>, [% nresults %] patron(s) found.</p>
45
[% END %]
46
[% IF ( users_loop ) %]
47
    <table>
48
      <thead>
49
        <tr>
50
            <th>Cardnumber</th>
51
            <th>Name</th>
52
            <th>Branch</th>
53
            <th>Categorycode</th>
54
            <th>Select?</th>
55
        </tr>
56
      </thead>
57
      <tbody>
58
        [% FOREACH user IN users_loop %]
59
          [% IF ( user.toggle ) %]
60
            <tr>
61
          [% ELSE %]
62
            <tr class="highlight">
63
          [% END %]
64
                <td>[% user.cardnumber %]</td>
65
                <td>[% user.surname %], [% user.firstname %]</td>
66
                <td>[% user.branchcode %]</td>
67
                <td>[% user.categorycode %]</td>
68
                <td>
69
                    <a style="cursor:pointer" onclick="add_user('[% user.borrowernumber %]', '[% user.firstname %] [% user.surname %]');">Add</a>
70
                </td>
71
            </tr>
72
        [% END %]
73
    </table>
74
[% END %]
75
76
<div id="closewindow"><a href="#" class="close">Close</a></div>
77
</div>
78
</div>
79
[% INCLUDE 'intranet-bottom.inc' %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt (-2 / +79 lines)
Lines 114-122 Link Here
114
            confirm_reopen();
114
            confirm_reopen();
115
        });
115
        });
116
    });
116
    });
117
118
    function basketUserSearchPopup(f) {
119
        window.open(
120
            "/cgi-bin/koha/acqui/aqbasketuser_search.pl",
121
            'BasketUserSearchPopup',
122
            'width=740,height=450,toolbar=no,'
123
         );
124
    }
125
126
    function add_basket_user(borrowernumber, borrowername) {
127
        var ids = $("#basketusers_ids").val();
128
        if(ids.length > 0) {
129
            ids = ids.split(':');
130
        } else {
131
            ids = new Array;
132
        }
133
        if (ids.indexOf(borrowernumber) < 0) {
134
            ids.push(borrowernumber);
135
            $("#basketusers_ids").val(ids.join(':'));
136
            var li = '<li id="user_'+borrowernumber+'">'+borrowername
137
                + ' [<a style="cursor:pointer" onclick="del_basket_user('+borrowernumber+');">'
138
                + _('Delete user') + '</a>]</li>';
139
            $("#basketusers_names").append(li);
140
            return 0;
141
        }
142
        return -1;
143
    }
144
145
    function del_basket_user(borrowernumber) {
146
      $("#user_"+borrowernumber).remove();
147
      var ids = $("#basketusers_ids").val().split(':');
148
      ids.splice(ids.indexOf(borrowernumber.toString()), 1);
149
      $("#basketusers_ids").val(ids.join(':'));
150
    }
117
//]]>
151
//]]>
118
</script>
152
</script>
119
120
<style type="text/css">
153
<style type="text/css">
121
.sortmsg {font-size: 80%;}
154
.sortmsg {font-size: 80%;}
122
</style>
155
</style>
Lines 132-137 Link Here
132
165
133
<div id="bd">
166
<div id="bd">
134
    <div id="yui-main">
167
    <div id="yui-main">
168
    [% IF (cannot_manage_basket) %]
169
        <div class="yui-b">
170
            <p class="error">You are not authorised to manage this basket.</p>
171
        </div>
172
    [% ELSE %]
135
    <div class="yui-b">
173
    <div class="yui-b">
136
        [% UNLESS ( confirm_close ) %]
174
        [% UNLESS ( confirm_close ) %]
137
        [% UNLESS ( selectbasketg ) %]
175
        [% UNLESS ( selectbasketg ) %]
Lines 194-200 Link Here
194
                [% END %]
232
                [% END %]
195
                [% IF ( deliveryplace ) %]<li><span class="label">Delivery place:</span> [% deliveryplace %]</li>[% END %]
233
                [% IF ( deliveryplace ) %]<li><span class="label">Delivery place:</span> [% deliveryplace %]</li>[% END %]
196
                [% IF ( billingplace ) %]<li><span class="label">Billing place:</span> [% billingplace %]</li>[% END %]
234
                [% IF ( billingplace ) %]<li><span class="label">Billing place:</span> [% billingplace %]</li>[% END %]
197
                [% IF ( authorisedbyname ) %]<li><span class="label">Managed by:</span>  [% authorisedbyname %]</li>[% END %]
235
                [% IF ( authorisedbyname ) %]<li><span class="label">Created by:</span>  [% authorisedbyname %]</li>[% END %]
236
                <li>
237
                    <form action="" method="post">
238
                        <span class="label">Managed by:</span>
239
                        <div style="float:left">
240
                            <ul id="basketusers_names" style="padding-left:0">
241
                              [% FOREACH user IN basketusers %]
242
                                <li id="user_[% user.borrowernumber %]">
243
                                    [% user.firstname %] [% user.surname %]
244
                                    [<a onclick="del_basket_user([% user.borrowernumber %]);" style="cursor:pointer">Delete user</a>]
245
                                </li>
246
                              [% END %]
247
                            </ul>
248
                            <input type="hidden" id="basketno" name="basketno" value="[% basketno %]" />
249
                            <input type="hidden" id="basketusers_ids" name="basketusers_ids" value="[% basketusers_ids %]" />
250
                            <input type="hidden" id="op" name="op" value="mod_users" />
251
                            <input type="button" id="add_user" onclick="basketUserSearchPopup();" value="Add user" />
252
                            <input type="submit" value="Save changes" />
253
                        </div>
254
                    </form>
255
                </li>
256
                <li>
257
                    <form action="" method="post">
258
                        <span class="label">Branch:</span>
259
                        <select id="branch" name="branch">
260
                            <option value="">No branch</option>
261
                            [% FOREACH branch IN branches_loop %]
262
                                [% IF (branch.selected) %]
263
                                    <option selected="selected" value="[% branch.branchcode %]"> [% branch.branchname %]</option>
264
                                [% ELSE %]
265
                                    <option value="[% branch.branchcode %]"> [% branch.branchname %]</option>
266
                                [% END %]
267
                            [% END %]
268
                        </select>
269
                        <input type="hidden" id="basketno" name="basketno" value="[% basketno %]" />
270
                        <input type="hidden" id="op" name="op" value="mod_branch" />
271
                        <input type="submit" value="Save" />
272
                    </form>
273
                </li>
198
                [% IF ( creationdate ) %]<li><span class="label">Opened on:</span>  [% creationdate | $KohaDates %]</li>[% END %]
274
                [% IF ( creationdate ) %]<li><span class="label">Opened on:</span>  [% creationdate | $KohaDates %]</li>[% END %]
199
                [% IF ( closedate ) %]<li><span class="label">Closed on:</span> [% closedate | $KohaDates %]</li>[% END %]
275
                [% IF ( closedate ) %]<li><span class="label">Closed on:</span> [% closedate | $KohaDates %]</li>[% END %]
200
                [% IF ( estimateddeliverydate ) %]<li><span class="label">Estimated delivery date:</span> [% estimateddeliverydate | $KohaDates  %]</li>[% END %]
276
                [% IF ( estimateddeliverydate ) %]<li><span class="label">Estimated delivery date:</span> [% estimateddeliverydate | $KohaDates  %]</li>[% END %]
Lines 472-477 Link Here
472
        </div>
548
        </div>
473
    [% END %]
549
    [% END %]
474
</div>
550
</div>
551
[% END %][%# IF (cannot_manage_basket) %]
475
</div>
552
</div>
476
<div class="yui-b">
553
<div class="yui-b">
477
[% INCLUDE 'acquisitions-menu.inc' %]
554
[% INCLUDE 'acquisitions-menu.inc' %]
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/acquisitions.pref (-1 / +1 lines)
Lines 22-28 Acquisitions: Link Here
22
            - Show baskets
22
            - Show baskets
23
            - pref: AcqViewBaskets
23
            - pref: AcqViewBaskets
24
              choices:
24
              choices:
25
                  user: created by staff member.
25
                  user: created or managed by staff member.
26
                  branch: from staff member's library.
26
                  branch: from staff member's library.
27
                  all: in system, regardless of owner.
27
                  all: in system, regardless of owner.
28
        -
28
        -
(-)a/t/Acquisition/CanUserManageBasket.t (-1 / +204 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
use Modern::Perl;
4
use Test::MockModule;
5
use Test::More tests => 42;
6
7
use C4::Acquisition;
8
9
my $C4_Acquisition_module = new Test::MockModule('C4::Acquisition');
10
$C4_Acquisition_module->mock('GetBasketUsers', \&Mock_GetBasketUsers);
11
my $C4_Context_module = new Test::MockModule('C4::Context');
12
$C4_Context_module->mock('preference', \&Mock_preference);
13
14
my $AcqViewBaskets;
15
my %basketusers = (
16
    1 => [],
17
    2 => [1, 2],
18
    3 => [],
19
    4 => [1, 2],
20
);
21
22
# Borrowers
23
my $borrower1 = {
24
    borrowernumber => 1,
25
    branchcode => 'B1',
26
};
27
28
my $borrower2 = {
29
    borrowernumber => 2,
30
    branchcode => 'B2',
31
};
32
33
# Baskets
34
my $basket1 = {
35
    basketno => 1,
36
    authorisedby => 1
37
};
38
39
my $basket2 = {
40
    basketno => 2,
41
    authorisedby => 2,
42
};
43
44
my $basket3 = {
45
    basketno => 3,
46
    authorisedby => 3,
47
    branch => 'B1'
48
};
49
50
my $basket4 = {
51
    basketno => 4,
52
    authorisedby => 4,
53
    branch => 'B1'
54
};
55
56
57
my $flags = {
58
    acquisition => {
59
        order_manage => 1
60
    }
61
};
62
63
#################
64
# Start testing #
65
#################
66
67
# ----------------------
68
# AcqViewBaskets = 'all'
69
# ----------------------
70
71
$AcqViewBaskets = 'all';
72
73
# Simple cases where user can't manage basket
74
ok( not CanUserManageBasket($borrower1, $basket1, {}) );
75
ok( not CanUserManageBasket($borrower1, $basket1, {
76
    acquisition => 0
77
}) );
78
ok( not CanUserManageBasket($borrower1, $basket1, {
79
    acquisition => {
80
        order_manage => 0
81
    }
82
}) );
83
84
# Simple cases where user can manage basket
85
ok( CanUserManageBasket($borrower1, $basket1, {
86
    superlibrarian => 1
87
}) );
88
ok( CanUserManageBasket($borrower1, $basket1, {
89
    acquisition => 1
90
}) );
91
ok( CanUserManageBasket($borrower1, $basket1, {
92
    acquisition => {
93
        order_manage_all => 1
94
    }
95
}) );
96
97
ok( CanUserManageBasket($borrower1, $basket1, $flags) );
98
ok( CanUserManageBasket($borrower1, $basket2, $flags) );
99
ok( CanUserManageBasket($borrower1, $basket3, $flags) );
100
ok( CanUserManageBasket($borrower1, $basket4, $flags) );
101
ok( CanUserManageBasket($borrower2, $basket1, $flags) );
102
ok( CanUserManageBasket($borrower2, $basket2, $flags) );
103
ok( CanUserManageBasket($borrower2, $basket3, $flags) );
104
ok( CanUserManageBasket($borrower2, $basket4, $flags) );
105
106
# -------------------------
107
# AcqViewBaskets = 'branch'
108
# -------------------------
109
110
$AcqViewBaskets = 'branch';
111
112
# Simple cases where user can't manage basket
113
ok( not CanUserManageBasket($borrower1, $basket1, {}) );
114
ok( not CanUserManageBasket($borrower1, $basket1, {
115
    acquisition => 0
116
}) );
117
ok( not CanUserManageBasket($borrower1, $basket1, {
118
    acquisition => {
119
        order_manage => 0
120
    }
121
}) );
122
123
# Simple cases where user can manage basket
124
ok( CanUserManageBasket($borrower1, $basket1, {
125
    superlibrarian => 1
126
}) );
127
ok( CanUserManageBasket($borrower1, $basket1, {
128
    acquisition => 1
129
}) );
130
ok( CanUserManageBasket($borrower1, $basket1, {
131
    acquisition => {
132
        order_manage_all => 1
133
    }
134
}) );
135
136
ok( CanUserManageBasket($borrower1, $basket1, $flags) );
137
ok( CanUserManageBasket($borrower1, $basket2, $flags) );
138
ok( CanUserManageBasket($borrower1, $basket3, $flags) );
139
ok( CanUserManageBasket($borrower1, $basket4, $flags) );
140
ok( CanUserManageBasket($borrower2, $basket1, $flags) );
141
ok( CanUserManageBasket($borrower2, $basket2, $flags) );
142
# borrower2 is not on the same branch as basket3 and basket4
143
ok( not CanUserManageBasket($borrower2, $basket3, $flags) );
144
ok( not CanUserManageBasket($borrower2, $basket4, $flags) );
145
146
# -----------------------
147
# AcqViewBaskets = 'user'
148
# -----------------------
149
150
$AcqViewBaskets = 'user';
151
152
# Simple cases where user can't manage basket
153
ok( not CanUserManageBasket($borrower1, $basket1, {}) );
154
ok( not CanUserManageBasket($borrower1, $basket1, {
155
    acquisition => 0
156
}) );
157
ok( not CanUserManageBasket($borrower1, $basket1, {
158
    acquisition => {
159
        order_manage => 0
160
    }
161
}) );
162
163
# Simple cases where user can manage basket
164
ok( CanUserManageBasket($borrower1, $basket1, {
165
    superlibrarian => 1
166
}) );
167
ok( CanUserManageBasket($borrower1, $basket1, {
168
    acquisition => 1
169
}) );
170
ok( CanUserManageBasket($borrower1, $basket1, {
171
    acquisition => {
172
        order_manage_all => 1
173
    }
174
}) );
175
176
ok( CanUserManageBasket($borrower1, $basket1, $flags) );
177
ok( CanUserManageBasket($borrower1, $basket2, $flags) );
178
# basket3 is not managed or created by borrower1
179
ok( not CanUserManageBasket($borrower1, $basket3, $flags) );
180
ok( CanUserManageBasket($borrower1, $basket4, $flags) );
181
# basket 1 is not managed or created by borrower2
182
ok( not CanUserManageBasket($borrower2, $basket1, $flags) );
183
ok( CanUserManageBasket($borrower2, $basket2, $flags) );
184
# basket 3 is not managed or created by borrower2
185
ok( not CanUserManageBasket($borrower2, $basket3, $flags) );
186
ok( CanUserManageBasket($borrower2, $basket4, $flags) );
187
188
189
# Mocked subs
190
191
# C4::Acquisition::GetBasketUsers
192
sub Mock_GetBasketUsers {
193
    my ($basketno) = @_;
194
195
    return @{ $basketusers{$basketno} };
196
}
197
198
# C4::Context->preference
199
sub Mock_preference {
200
    my ($self, $variable) = @_;
201
    if (lc($variable) eq 'acqviewbaskets') {
202
        return $AcqViewBaskets;
203
    }
204
}

Return to bug 7295