# Copyright (c) 2005 bivio Software, Inc. All Rights Reserved. # # Visit http://www.bivio.biz for more info. # # This library is free software; you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as # published by the Free Software Foundation; either version 2.1 of the # License, or (at your option) any later version. # # This library is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with this library; If not, you may get a copy from: # http://www.opensource.org/licenses/lgpl-license.html # # $Id: RealmlessRedirect.pm,v 1.5 2008/11/10 00:59:19 nagler Exp $ package Bivio::Biz::Action::RealmlessRedirect; use strict; use Bivio::Base 'Bivio::Biz::Action'; our($VERSION) = sprintf('%d.%02d', q$Revision: 1.5 $ =~ /\d+/g); my($_DT) = Bivio::Type->get_instance('DateTime'); sub execute { my($proto, $req) = @_; # Always returns false. my($us, $t) = $req->get(qw(user_state task)); return $us->equals_by_name('JUST_VISITOR') ? 'visitor_task' : $req->get('auth_user') ? _set_realm($proto, $req, $t->get_attr_as_id('home_task')) || 'unauth_task' : Bivio::Agent::TaskId->LOGIN; } sub _choose_realm { my($proto, $req, $task) = @_; my($res) = sort { $_DT->compare( $a->{'RealmUser.creation_date_time'}, $b->{'RealmUser.creation_date_time'}) || $a->{'RealmOwner.name'} cmp $b->{'RealmOwner.name'}; } @{$req->map_user_realms( sub {shift}, {'RealmOwner.realm_type' => $task->get('realm_type')->self_or_any_group}, )}; return $res && $res->{'RealmUser.realm_id'}; } sub _set_realm { my($proto, $req, $task) = @_; $task = Bivio::Agent::Task->get_by_id($task); $req->set_realm(_choose_realm($proto, $req, $task) || return); return $task->get('id'); } 1;