Add group privilege checking to the Shipping Drivers

This commit is contained in:
Colin Kuskie 2009-06-18 23:24:33 +00:00
parent 0a004d72a0
commit a85924d07b
9 changed files with 166 additions and 20 deletions

View file

@ -125,7 +125,8 @@ sub canUse {
}
return $userObject->isInGroup($self->get('groupToUse'));
}
#-------------------------------------------------------------------
#-------------------------------------------------------------------
=head2 className ( )

View file

@ -104,6 +104,7 @@ sub getOptions {
$self->session->log->warn($e->error);
next SHIPPER;
}
next SHIPPER unless $shipper->canUse;
$options{$shipper->getId} = {
label => $shipper->get("label"),
price => $price,
@ -151,8 +152,10 @@ sub getShippers {
my @drivers = ();
my $sth = $self->session->db->prepare('select shipperId from shipper');
$sth->execute();
while (my $driver = $sth->hashRef()) {
push @drivers, $self->getShipper($driver->{shipperId});
SHIPPER: while (my $driver = $sth->hashRef()) {
my $shipper = $self->getShipper($driver->{shipperId});
next SHIPPER unless $shipper->canUse;
push @drivers, $shipper;
}
$sth->finish;
return \@drivers;

View file

@ -50,6 +50,49 @@ sub calculate {
#-------------------------------------------------------------------
=head2 canUse ( user )
Checks to see if the user can use this Payment Driver.
=head3 user
A hashref containing user information. The user referenced will be checked
to see if they can use the Shipping Driver. If missing, then $session->user
will be used.
=head4 userId
A userId used to build a user object.
=head4 user
A user object that will be used directly.
=cut
sub canUse {
my $self = shift;
my $user = shift;
my $userObject;
if (!defined $user or ref($user) ne 'HASH') {
$userObject = $self->session->user;
}
else {
if (exists $user->{user}) {
$userObject = $user->{user};
}
elsif (exists $user->{userId}) {
$userObject = WebGUI::User->new($self->session, $user->{userId});
}
else {
WebGUI::Error::InvalidParam->throw(error => q{Must provide user information})
}
}
return $userObject->isInGroup($self->get('groupToUse'));
}
#-------------------------------------------------------------------
=head2 create ( $session, $options )
Constructor for new WebGUI::Shop::ShipperDriver objects. Returns a WebGUI::Shop::ShipperDriver object.
@ -114,6 +157,12 @@ sub definition {
hoverHelp => $i18n->get('enabled help'),
defaultValue => 1,
},
groupToUse => {
fieldType => 'group',
label => $i18n->get('who can use'),
hoverHelp => $i18n->get('who can use help'),
defaultValue => 7,
},
);
my %properties = (
name => 'Shipper Driver',
@ -295,7 +344,8 @@ Accessor for the session object. Returns the session object.
=head2 update ( $options )
Setter for user configurable options in the ship objects.
Setter for user configurable options in the ship objects. It does not support updating subsets
of the options. If a currently set option is missing from the set of passed in options, it will be lost.
=head4 $options

View file

@ -26,6 +26,18 @@ our $I18N = {
lastUpdated => 1203569582,
},
'who can use' => {
message => q|Group to use this shipping driver|,
lastUpdate => 0,
context => q|Label for the group to use option.|,
},
'who can use help' => {
message => q|Specifies which group is allowed to use this shipping driver.|,
lastUpdated => 0,
context => q|Hover help for the group to use option.|,
},
};
1;