canUse should check whether the driver is enabled or not.
PayDrivers update the local object cache on update.
This commit is contained in:
parent
f9c917e426
commit
dc226e3268
3 changed files with 35 additions and 7 deletions
|
|
@ -4,6 +4,8 @@
|
|||
- fixed #10662: Manage Clipboard / delete item
|
||||
- fixed #10637: shelf displays assets it shouldn't
|
||||
- fixed #10660: Crud doesn't like 0
|
||||
- fixed #10668: shop pay drivers
|
||||
- fixed Pay Drivers update their objects
|
||||
|
||||
7.7.15
|
||||
- fixed #10629: WebGUI::ProfileField create new field bug
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ use WebGUI::Macro;
|
|||
use WebGUI::User;
|
||||
use WebGUI::Shop::Cart;
|
||||
use JSON;
|
||||
use Clone qw/clone/;
|
||||
use Scalar::Util qw/blessed/;
|
||||
|
||||
=head1 NAME
|
||||
|
|
@ -87,7 +88,9 @@ sub cancelRecurringPayment {
|
|||
|
||||
=head2 canUse ( user )
|
||||
|
||||
Checks to see if the user can use this Payment Driver.
|
||||
Checks to see if the user can use this Payment Driver. Ability to use
|
||||
is based on whether or not this user has the correct privileges, and if
|
||||
the driver is enabled or not.
|
||||
|
||||
=head3 user
|
||||
|
||||
|
|
@ -107,6 +110,7 @@ A user object that will be used directly.
|
|||
|
||||
sub canUse {
|
||||
my $self = shift;
|
||||
return 0 unless $self->get('enabled');
|
||||
my $user = shift;
|
||||
my $userObject;
|
||||
if (!defined $user or ref($user) ne 'HASH') {
|
||||
|
|
@ -304,7 +308,7 @@ sub get {
|
|||
return $options->{ $param };
|
||||
}
|
||||
else {
|
||||
return { %$options };
|
||||
return { %{ $options } };
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -729,6 +733,8 @@ sub update {
|
|||
$jsonOptions,
|
||||
$self->paymentGatewayId
|
||||
]);
|
||||
my $storedProperties = clone $properties;
|
||||
$options{ id $self } = $storedProperties;
|
||||
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ my $session = WebGUI::Test->session;
|
|||
#----------------------------------------------------------------------------
|
||||
# Tests
|
||||
|
||||
my $tests = 46;
|
||||
my $tests = 54;
|
||||
plan tests => 1 + $tests;
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
|
@ -415,7 +415,7 @@ TODO: {
|
|||
|
||||
#######################################################################
|
||||
#
|
||||
# update
|
||||
# update, get
|
||||
#
|
||||
#######################################################################
|
||||
|
||||
|
|
@ -438,27 +438,47 @@ my $newOptions = {
|
|||
};
|
||||
|
||||
$driver->update($newOptions);
|
||||
my $storedOptions = $session->db->quickScalar('select options from paymentGateway where paymentGatewayId=?', [
|
||||
my $storedJson = $session->db->quickScalar('select options from paymentGateway where paymentGatewayId=?', [
|
||||
$driver->getId,
|
||||
]);
|
||||
cmp_deeply(
|
||||
$newOptions,
|
||||
from_json($storedOptions),
|
||||
from_json($storedJson),
|
||||
,
|
||||
'update() actually stores data',
|
||||
);
|
||||
|
||||
is( $driver->get('receiptMessage'), 'Dropjes!', '... updates object, receiptMessage');
|
||||
is( $driver->get('group'), 4, '... updates object, group');
|
||||
is( $driver->get('enabled'), 0, '... updates object, enabled');
|
||||
is( $driver->get('label'), 'Yet another label', '... updates object, label');
|
||||
|
||||
$newOptions->{label} = 'Safe reference';
|
||||
is( $driver->get('label'), 'Yet another label', '... safe reference check');
|
||||
|
||||
my $storedOptions = $driver->get();
|
||||
$storedOptions->{label} = 'Safe reference';
|
||||
is( $driver->get('label'), 'Yet another label', 'get: safe reference check');
|
||||
|
||||
#######################################################################
|
||||
#
|
||||
# canUse
|
||||
#
|
||||
#######################################################################
|
||||
$options = $driver->get();
|
||||
$options->{enabled} = 1;
|
||||
$driver->update($options);
|
||||
|
||||
$session->user({userId => 3});
|
||||
ok($driver->canUse, 'canUse: session->user is used if no argument is passed');
|
||||
ok( $driver->canUse, 'canUse: session->user is used if no argument is passed');
|
||||
ok(!$driver->canUse({userId => 1}), 'canUse: userId explicit works, visitor cannot use this driver');
|
||||
|
||||
$options = $driver->get();
|
||||
$options->{enabled} = 0;
|
||||
$driver->update($options);
|
||||
ok( !$driver->get('enabled'), 'driver is disabled');
|
||||
ok( !$driver->canUse({userId => 3}), '... driver cannot be used');
|
||||
|
||||
TODO: {
|
||||
local $TODO = 'tests for canUse';
|
||||
ok(0, 'Test other users and groups');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue