[open-ils-commits] r11418 - in trunk/Open-ILS/src/perlmods/OpenILS/Application: . Actor
svn at svn.open-ils.org
svn at svn.open-ils.org
Fri Dec 5 12:10:31 EST 2008
Author: erickson
Date: 2008-12-05 12:10:29 -0500 (Fri, 05 Dec 2008)
New Revision: 11418
Added:
trunk/Open-ILS/src/perlmods/OpenILS/Application/Actor/Friends.pm
Modified:
trunk/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm
Log:
initial friend (delegates) management code
Added: trunk/Open-ILS/src/perlmods/OpenILS/Application/Actor/Friends.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Actor/Friends.pm (rev 0)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Actor/Friends.pm 2008-12-05 17:10:29 UTC (rev 11418)
@@ -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;
Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm 2008-12-05 16:29:20 UTC (rev 11417)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Actor.pm 2008-12-05 17:10:29 UTC (rev 11418)
@@ -28,11 +28,12 @@
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 @@
+__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;
More information about the open-ils-commits
mailing list