From: erickson Date: Fri, 5 Dec 2008 17:10:29 +0000 (+0000) Subject: initial friend (delegates) management code X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=52be1851b481526967def0292116f49505d6c015;p=Evergreen.git initial friend (delegates) management code git-svn-id: svn://svn.open-ils.org/ILS/trunk@11418 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm b/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm index c16f3e4f5b..3ad6625a3f 100644 --- a/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm +++ b/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm @@ -28,11 +28,12 @@ use OpenILS::Const qw/:const/; use OpenILS::Application::Actor::Container; use OpenILS::Application::Actor::ClosedDates; +use OpenILS::Application::Actor::UserGroups; +use OpenILS::Application::Actor::Friends; use OpenILS::Utils::CStoreEditor qw/:funcs/; use OpenILS::Utils::Penalty; -use OpenILS::Application::Actor::UserGroups; sub initialize { OpenILS::Application::Actor::Container->initialize(); OpenILS::Application::Actor::UserGroups->initialize(); @@ -3057,5 +3058,30 @@ sub merge_users { +__PACKAGE__->register_method ( + method => 'retrieve_friends', + api_name => 'open-ils.actor.friends.retrieve', + signature => { + desc => q/ + returns { confirmed: [], pending_out: [], pending_in: []} + pending_out are users I'm requesting friendship with + pending_in are users requesting friendship with me + / + } +); + +sub retrieve_friends { + my($self, $conn, $auth, $user_id) = @_; + my $e = new_editor(authtoken => $auth); + return $e->event unless $e->checkauth; + $user_id ||= $e->requestor->id; + if($user_id != $e->requestor->id) { + my $user = $e->retrieve_actor_user($user_id) or return $e->event; + return $e->event unless $e->allowed('VIEW_USER', $user->home_ou); + } + + return OpenILS::Application::Actor::Friends->retrieve_friends($e, $user_id); +} + 1; diff --git a/Open-ILS/src/perlmods/OpenILS/Application/Actor/Friends.pm b/Open-ILS/src/perlmods/OpenILS/Application/Actor/Friends.pm new file mode 100644 index 0000000000..b15c1bb042 --- /dev/null +++ b/Open-ILS/src/perlmods/OpenILS/Application/Actor/Friends.pm @@ -0,0 +1,87 @@ +package OpenILS::Application::Actor::Friends; +use strict; use warnings; +use OpenILS::Application::AppUtils; +use OpenILS::Utils::CStoreEditor q/:funcs/; +use OpenSRF::Utils::Logger q/$logger/; +my $U = "OpenILS::Application::AppUtils"; + +# ---------------------------------------------------------------- +# Shared Friend utilities. Thar be no methods published here... +# ---------------------------------------------------------------- + +# export these fields for friend display +my @keep_user_fields = qw/usrname first_given_name second_given_name family_name alias/; + +my $out_links_query = { + select => {cubi => ['target_user']}, + from => { + cub => { + cubi => {field => 'bucket', fkey => 'id'} + } + }, + where => { + '+cub' => {btype => 'folks', owner => undef} + } +}; + +my $in_links_query = { + select => {cub => ['owner'] }, + from => { + cub => { + cubi => {field => 'bucket', fkey => 'id'} + } + }, + where => { + '+cubi' => {target_user => undef}, + '+cub' => {btype => 'folks'} + } +}; + + +sub retrieve_friends { + my($self, $e, $user_id) = @_; + + # users I have links to + $out_links_query->{where}->{'+cub'}->{owner} = $user_id; + my @out_linked = map {$_->{target_user}} @{$e->json_query($out_links_query)}; + + # users who link to me + $in_links_query->{where}->{'+cubi'}->{target_user} = $user_id; + my @in_linked = map {$_->{owner}} @{$e->json_query($in_links_query)}; + + my @confirmed; + my @pending_out; + my @pending_in; + + for my $out_link (@out_linked) { + if(grep {$_ == $out_link} @in_linked) { + push(@confirmed, $out_link); + } else { + push(@pending_out, $out_link); + } + } + + for my $in_link (@in_linked) { + push(@pending_in, $in_link) + unless grep {$_ == $in_link} @confirmed; + } + + my $select = {select => {au => \@keep_user_fields}}; + + my $confirmed = (@confirmed) ? + $e->search_actor_user([{id => \@confirmed}, $select]) : []; + + my $pending_out = (@pending_out) ? + $e->search_actor_user([{id => \@pending_out}, $select]) : []; + + my $pending_in = (@pending_in) ? + $e->search_actor_user([{id => \@pending_in}, $select]) : []; + + return { + confirmed => $confirmed, + pending_out => $pending_out, + pending_in =>$pending_in + }; +} + +23;