check is implied by the authtoken. /,
params => [
{desc => 'authtoken', type => 'string'},
- {desc => 'permission name', type => 'string'}
+ {desc => 'permission name', type => 'string'},
+ {desc => 'options hash, including "descendants", which will include all child orgs of the found perm orgs', type => 'hash'}
],
return => {desc => 'An array of org IDs'}
}
);
sub check_user_work_perms {
- my($self, $conn, $auth, $perm) = @_;
+ my($self, $conn, $auth, $perm, $options) = @_;
my $e = new_editor(authtoken=>$auth);
return $e->event unless $e->checkauth;
- return $U->find_highest_work_orgs($e, $perm);
+ return $U->find_highest_work_orgs($e, $perm, $options);
}
__PACKAGE__->register_method(
method => 'usrname_exists',
api_name => 'open-ils.actor.username.exists',
signature => q/
- Returns the user ID of the requested username if that username exists, returns null otherwise
+ Returns 1 if the requested username exists, returns 0 otherwise
/
);
return $e->event unless $e->checkauth;
my $a = $e->search_actor_user({usrname => $usrname, deleted=>'f'}, {idlist=>1});
return $$a[0] if $a and @$a;
- return undef;
+ return 0;
}
__PACKAGE__->register_method(
method => 'barcode_exists',
api_name => 'open-ils.actor.barcode.exists',
signature => q/
- Returns the user ID for the requested barcode if that barcode exists, returns null otherwise
+ Returns 1 if the requested barcode exists, returns 0 otherwise
/
);
my $e = new_editor(authtoken=>$auth);
return $e->event unless $e->checkauth;
my $card = $e->search_actor_card({barcode => $barcode});
- return undef unless @$card;
- return $card->[0]->usr;
+ return 0 unless @$card;
+ return $card->[0]->usr;
}
sub find_highest_work_orgs {
- my($self, $e, $perm) = @_;
+ my($self, $e, $perm, $options) = @_;
my $work_orgs = $self->get_user_work_ou_ids($e, $e->requestor->id);
$logger->debug("found work orgs @$work_orgs");
$logger->debug("work org looking at $org");
my $org_list = $self->get_org_full_path($org, $org_depth);
+ my $found = 0;
for my $sub_org (@$org_list) {
- $logger->debug("work org looking at sub-org $sub_org");
- my $org_unit = $self->find_org($org_tree, $sub_org);
- my ($ou_type) = grep { $_->id == $org_unit->ou_type } @$org_types;
- if($ou_type->depth >= $org_depth) {
- push(@allowed_orgs, $sub_org);
- last;
- }
+ if(not $found) {
+ $logger->debug("work org looking at sub-org $sub_org");
+ my $org_unit = $self->find_org($org_tree, $sub_org);
+ my ($ou_type) = grep { $_->id == $org_unit->ou_type } @$org_types;
+ if($ou_type->depth >= $org_depth) {
+ push(@allowed_orgs, $sub_org);
+ $found = 1;
+ }
+ } else {
+ last unless $$options{descendants};
+ push(@allowed_orgs, $sub_org);
+ }
}
}