]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/perlmods/OpenILS/Application/Actor/UserGroups.pm
added address links method
[Evergreen.git] / Open-ILS / src / perlmods / OpenILS / Application / Actor / UserGroups.pm
1 package OpenILS::Application::Actor::UserGroups;
2 use base 'OpenSRF::Application';
3 use strict; use warnings;
4 use OpenILS::Application::AppUtils;
5 use OpenILS::Utils::Editor;
6 use OpenSRF::Utils::Logger q/$logger/;
7 use OpenSRF::EX qw(:try);
8 my $U = "OpenILS::Application::AppUtils";
9
10 sub initialize { return 1; }
11
12
13 __PACKAGE__->register_method(
14         method => 'get_users_from_usergroup',
15         api_name        => 'open-ils.actor.usergroup.members.retrieve',
16         signature       => q/
17                 Returns a list of ids for users that are in the given usergroup
18         /
19 );
20
21
22 sub get_users_from_usergroup {
23         my( $self, $conn, $auth, $usergroup ) = @_;
24         my $e = OpenILS::Utils::Editor->new(authtoken=>$auth);
25         return $e->event unless $e->checkauth;
26         return $e->event unless $e->allowed('VIEW_USER'); # XXX reley on editor perm
27         return $e->search_actor_user({usrgroup => $usergroup}, {idlist => 1});
28 }
29
30
31
32 __PACKAGE__->register_method(
33         method => 'get_address_members',
34         api_name        => 'open-ils.actor.address.members',
35         signature       => q/
36                 Returns a list of ids for users that link to the given address
37                 @param auth
38                 @param addrid The address id
39         /
40 );
41
42 sub get_address_members {
43         my( $self, $conn, $auth, $addrid ) = @_;
44
45         my $e = OpenILS::Utils::Editor->new(authtoken=>$auth);
46         return $e->event unless $e->checkauth;
47         return $e->event unless $e->allowed('VIEW_USER'); # XXX reley on editor perm
48
49         my $ad = $e->retrieve_actor_user_address($addrid) or return $e->event;
50         my $ma = $e->search_actor_user({mailing_address => $addrid}, {idlist => 1});
51         my $ba = $e->search_actor_user({billing_address => $addrid}, {idlist => 1});
52
53         my @list = (@$ma, @$ba, $ad->usr);
54         my %dedup = map { $_ => 1 } @list;
55         return [ keys %dedup ];
56 }
57
58 1;