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

@ -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