%# God isn't dead, he just couldn't find a parking place. <& /Work/Elements/104Header, Title => 'My Delegates' &> % if ($RT::OIN104) {

<&|/l&>Ticket Type

% }

<& List, Prefix => $Prefix, List => $List, Item => $Item, Delegates => $Delegates, Category => $Category, Width => '100%' &> |  | <& Info, Item => $Item, Users => $Users, User => $User, Disabled => $Disabled, Category => $Category, CurrentUser => $CurrentUser, Delegates => $Delegates &>

<& /Work/Elements/104Footer &> <%INIT> my %Categories; my $Queues = RT::Queues->new($session{'CurrentUser'}); $Queues->OrderBy(FIELD => 'Name'); $Queues->UnLimit; require Test::MockObject; my $DefaultQueue = Test::MockObject->new; $DefaultQueue->set_always( Id => -1 ); $DefaultQueue->set_always( Name => loc('(fallback delegate)') ); my $List = [ $DefaultQueue ]; while (my $queue = $Queues->Next) { my $descr = $queue->Description; $Categories{$descr}++ if length $descr; next if length $Category and $descr ne $Category; push @$List, $queue; } my $Item = $RT::Nothing; my $Users = []; if ($Queue == -1) { $Item = $DefaultQueue; } elsif ($Queue) { $Item = RT::Queue->new($session{'CurrentUser'}); $Item->Load($Queue); } # XXX - the user below should be currentuser, if not for missing # on legacy code that has wrong companyspecific code. - XXX my $Groups = RT::Groups->new($RT::SystemUser); $Groups->LimitToPersonalGroupsFor($CurrentUser->PrincipalId); $Groups->{find_disabled_rows}++; my $Delegates = {}; while ( my $Group = $Groups->Next) { $Group->UpdateCompany($session{CurrentUser}->UserObj->Attribute('Company')) if $Group->can('UpdateCompany'); $Delegates->{$Group->Name} = $Group; } my $Group = $Delegates->{$Item->Id}; if ($ARGS{'Action-Clear'} and $Item) { $Group->Delete if $Group; delete $Delegates->{$Item->Id}; $Group = undef; } elsif ($ARGS{'Action-Save'} and $Item) { if (!$Group) { $Group = RT::Group->new($session{'CurrentUser'}); $Group->UpdateCompany if $Group->can('UpdateCompany'); $Group->CreatePersonalGroup( Name => $Item->Id, PrincipalId => $CurrentUser->PrincipalId, ); $Delegates->{$Item->Id} = $Group; } if (exists $ARGS{SetDelegate} and 0) { my $Id = $ARGS{SetDelegate}; $Group->SetDescription($Id); foreach my $User (@{$Group->UserMembersObj->ItemsArrayRef}) { $Group->DeleteMember($User->PrincipalId); } $Group->AddMember($Id) if $Id; } if (exists $ARGS{SetDisabled}) { $Group->SetDisabled($ARGS{SetDisabled}); } $ARGS{SetStarts} =~ s{[^\d/-]}{}g; $ARGS{SetDue} =~ s{[^\d/-]}{}g; $Group->SetStarts($ARGS{SetStarts}); $Group->SetDue($ARGS{SetDue}); $Group->Load($Group->Id); } my $Disabled = $Group->Disabled if $Group; my $User = $RT::Nothing; if (my $id = eval { $Group->Description }) { $User = RT::User->new($session{'CurrentUser'}); $User->Load( $id ); $User = $RT::Nothing unless $User->Id; } return ( List => $List, Item => $Item, Delegates => $Delegates, Category => $Category, Prefix => $Prefix, Users => $Users, User => $User, Disabled => $Disabled, Details => !$NoUI, CurrentUser => $CurrentUser, ) if $NoUI; <%ARGS> $Category => '' $Begin => 0 $Prefix => '' $Queue => '' $NoUI => 0 $CurrentUser => $session{'CurrentUser'}->UserObj