Bug 8435: (follow-up) handle lack of userenv gracefully
C4::Serials::can_edit_subscription now deals with C4::Context->userenv. Signed-off-by: Galen Charlton <gmc@esilibrary.com>
This commit is contained in:
parent
019049fc51
commit
5248f12a0e
2 changed files with 17 additions and 10 deletions
|
@ -2805,6 +2805,7 @@ Return 1 if the subscription is editable by the current logged user (or a given
|
|||
|
||||
sub can_edit_subscription {
|
||||
my ( $subscription, $userid ) = @_;
|
||||
return 0 unless C4::Context->userenv;
|
||||
my $flags = C4::Context->userenv->{flags};
|
||||
$userid ||= C4::Context->userenv->{'id'};
|
||||
my $independent_branches = C4::Context->preference('IndependentBranches');
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
#!/usr/bin/perl
|
||||
use Modern::Perl;
|
||||
|
||||
use Test::More tests => 4;
|
||||
use Test::More tests => 5;
|
||||
|
||||
use MARC::Record;
|
||||
|
||||
use C4::Biblio qw( AddBiblio );
|
||||
use C4::Context;
|
||||
use_ok('C4::Serials');
|
||||
use_ok('C4::Budgets');
|
||||
|
||||
|
@ -12,6 +14,7 @@ my $dbh = C4::Context->dbh;
|
|||
$dbh->{AutoCommit} = 0;
|
||||
$dbh->{RaiseError} = 1;
|
||||
|
||||
|
||||
my $supplierlist=eval{GetSuppliersWithLateIssues()};
|
||||
ok(length($@)==0,"No SQL problem in GetSuppliersWithLateIssues");
|
||||
|
||||
|
@ -39,16 +42,19 @@ my $budget_id = AddBudget({
|
|||
});
|
||||
|
||||
my $subscriptionid = NewSubscription(
|
||||
undef, "", undef, undef, $budget_id, $biblionumber, '01-01-2013',undef,
|
||||
undef, undef, undef, undef, undef, undef, undef, undef,
|
||||
undef, undef, undef, undef, undef, undef, undef, undef,
|
||||
undef, undef, undef, undef, undef, undef, undef, 1,
|
||||
"notes", undef, undef, undef, undef, undef, undef, 0,
|
||||
"intnotes", 0, undef, undef, 0, undef, '12-31-2013',
|
||||
undef, "", undef, undef, $budget_id, $biblionumber,
|
||||
'2013-01-01', undef, undef, undef, undef,
|
||||
undef, undef, undef, undef, undef, undef,
|
||||
1, "notes",undef, '2013-01-01', undef, undef,
|
||||
undef, undef, 0, "intnotes", 0,
|
||||
undef, undef, 0, undef, '2013-12-31', 0
|
||||
);
|
||||
die unless $subscriptionid;
|
||||
|
||||
# Can edit a subscription
|
||||
|
||||
my $subscription = GetSubscription( $subscriptionid );
|
||||
is( C4::Serials::can_edit_subscription($subscription), 0, "cannot edit a subscription without userenv set");
|
||||
|
||||
my @USERENV = (
|
||||
1,
|
||||
'test',
|
||||
|
@ -62,9 +68,9 @@ my @USERENV = (
|
|||
|
||||
C4::Context->_new_userenv ('DUMMY_SESSION_ID');
|
||||
C4::Context->set_userenv ( @USERENV );
|
||||
my $userenv = C4::Context->userenv;
|
||||
|
||||
my $subscription = GetSubscription( $subscriptionid );
|
||||
# Can edit a subscription
|
||||
my $userenv = C4::Context->userenv;
|
||||
|
||||
is( C4::Serials::can_edit_subscription($subscription), 1, "User can edit a subscription with an empty branchcode");
|
||||
#TODO add UT when C4::Auth->set_permissions (or setuserflags) will exist.
|
||||
|
|
Loading…
Reference in a new issue