# Copyright (c) 2008-2010 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: SiteAdminSubstituteUserForm.pm,v 1.6 2010/10/01 21:10:41 schellj Exp $ package Bivio::Biz::Model::SiteAdminSubstituteUserForm; use strict; use Bivio::Base 'Model.AdmSubstituteUserForm'; our($VERSION) = sprintf('%d.%02d', q$Revision: 1.6 $ =~ /\d+/g); my($_C) = b_use('FacadeComponent.Constant'); sub can_substitute_user { my($self, $user_id) = @_; my($req) = $self->req; return 0 unless my $users = $req->cache_for_auth_user( [], sub { return undef if $req->is_substitute_user; my($auid) = $req->get('auth_user_id'); my($auth_is_admin); my($res) = {@{$self->new_other('GroupUserList') ->map_iterate( sub { my($uid, $roles) = shift->get(qw(RealmUser.user_id roles)); $auth_is_admin++ if $uid eq $auid && grep($_->eq_administrator, @$roles); return ($uid => 1); }, 'unauth_iterate_start', { auth_id => $_C->get_value('site_admin_realm_id', $req), }, ), }}; return undef unless $auth_is_admin || $req->is_super_user; $self->new_other('AdmSuperUserList') ->do_iterate(sub { delete($res->{shift->get('RealmUser.user_id')}); return 1; }); return $res; }, ); return $users->{$user_id} || 0; } 1;