%# A LISP programmer knows the value of everything, but the cost of nothing.
% if ($IsAdmin) { % }
<& EditQueueWatchers, QueueObj => $QueueObj, Watchers => $QueueObj->AdminCc, Nonempty => 1, ReadOnly => !$IsAdmin, RoleCache => $RoleCache, Role => 'AdminCc' &> <& EditQueueWatchers, QueueObj => $QueueObj, Watchers => $QueueObj->Cc, ReadOnly => !$IsAdmin, RoleCache => $RoleCache, Role => 'Cc' &>
<&|/l&>Admins
<&|/l&>Members
% if ($Users) { % while (my $u = $Users->Next ) { % } % }
<&|/l&>Edit Staff
<&|/l&>Find people whose <& SelectUsers &>
<&|/l&>User <&|/l&>Role
<%$u->Name%> % if ($u->IsPublic('RealName')) { (<%$u->RealName%>) % } <& SelectWatcherType, Name => "Queue-AddWatcher-Principal-".$u->PrincipalId, Scope => 'queue', Disabled => ($u->Id == $MyPrincipalId), Default => $RoleCache->{$u->Id}, RoleMap => $RoleMap, &>
 
% foreach (@InviteResult) { % } <%DOC> % my $Tickets = RT::Tickets->new($RT::SystemUser); % my $Date = RT::Date->new($RT::SystemUser); % $Date->Set(Format => 'unix', Value => time - (14 * 86400) ); % $Tickets->LimitQueue( VALUE => RT::Queue->NameToId('MemberChange') ); % $Tickets->LimitCreated( OPERATOR => '>', VALUE => $Date->ISO ); % $Tickets->LimitSubject( OPERATOR => '=', VALUE => join(' ', "Invite", $_, $QueueObj->Id, $QueueObj->Name) ) for qw(AdminCc Cc); % $Tickets->OrderBy( FIELD => 'Id', ORDER => 'DESC' ); % my %seen; % while (my $Ticket = $Tickets->Next) { % my $Email = $Ticket->OwnerObj->Name; % next if $seen{$Email}++ or $Email !~ /\@/; % my $UserObj = RT::User->new($RT::SystemUser); % $UserObj->LoadByCol( EmailAddress => $Email ); % my $Name = $UserObj->Name; % $Name = '' if $Name eq $Email; % my $Role = (split(/\s+/, $Ticket->Subject, 3))[1]; % }
<&|/l&>Invite External Staff
* <% $_ %>
<&|/l&>Email
<&|/l&>Invite Letter
<&|/l&>Role
<&|/l&>Past Invitees
<&|/l&>User Id <&|/l&>Email <&|/l&>Role <&|/l&>Status
<% $Name %> <% $Email %> <% loc($RoleMap->{$Name ? $RoleCache->{$UserObj->Id} : $Role}) %> <% loc($Name ? ($UserObj->Disabled ? 'Disabled' : 'Registered') : 'Unregistered') %>

<%INIT> my $current_tab; my ($field, $User, $Users, $Groups, $watcher); my $IsAdmin = $QueueObj->HasAdminCc($session{CurrentUser}->UserObj) || $session{CurrentUser}->HasRight( Right => 'SuperUser', Object => $QueueObj ); $QueueObj->CurrentUser($RT::SystemUser); # instant priv escalation! my $MyPrincipalId = $session{CurrentUser}->UserObj->PrincipalObj->Id; my @InviteResult; if ($IsAdmin and $ARGS{'Action-Invite'}) { INVITE: { # First, make sure we have a valid email. use Email::Valid; $InviteEmail = Email::Valid->address( -address => $InviteEmail ); if (!$InviteEmail) { push @InviteResult, loc("Invalid email address"); last INVITE; } # Next, make sure that email does not already exist in the system. my $User = RT::User->new($RT::SystemUser); $User->LoadByEmail( $InviteEmail ); if ($User->Id and $User->Privileged) { ($UserField, $UserOp, $UserString) = ('Name', '=', $User->Name); push @InviteResult, loc("This email address already exists"), loc("Please use the form above to add this staff directly"); last INVITE; } # Then, make sure we did not already send an invitation mail. if ($User->Id) { my $Tickets = RT::Tickets->new($RT::SystemUser); my $Date = RT::Date->new($RT::SystemUser); $Date->Set(Format => 'unix', Value => time - (14 * 86400) ); $Tickets->LimitQueue( VALUE => RT::Queue->NameToId('MemberChange') ); $Tickets->LimitCreated( OPERATOR => '>', VALUE => $Date->ISO ); $Tickets->LimitOwner( OPERATOR => '=', VALUE => $User->Id ); $Tickets->LimitSubject( OPERATOR => '=', VALUE => join(' ', "Invite", $_, $QueueObj->Id, $QueueObj->Name) ) for qw(AdminCc Cc); if ($Tickets->Count) { push @InviteResult, loc("This person has already received an invitation letter"); last INVITE; } } else { $User->Create( Name => $InviteEmail, EmailAddress => $InviteEmail, Privileged => 0 ); } my $MemberChange = RT::Queue->new($RT::SystemUser); $MemberChange->Load('MemberChange') or die "Cannot load MemberChange"; $User->PrincipalObj->GrantRight(Object => $MemberChange, Right => 'OwnTicket'); # Finally, send out the invitation ticket. my $TicketObj = RT::Ticket->new($session{'CurrentUser'}); $TicketObj->Create( Queue => 'MemberChange', Subject => join(' ', 'Invite', $InviteRole, $QueueObj->Id, $QueueObj->Name), Requestor => [ $session{CurrentUser}->UserObj->Id ], Owner => $User->Id, ); push @InviteResult, loc("Invitation sent to [_1]", $InviteEmail), '(' . loc("This invitation will expire in 14 days.") . ')'; $InviteEmail = $InviteRole = ''; } } elsif ($IsAdmin) { my ($code, $msg); # Delete deletable watchers foreach my $key (keys %ARGS) { my $id = $QueueObj->Id; my $Principal; next unless $key =~ /^Queue-$id-DelWatcher-Type-.*?-Principal-(\d*)$/ or ($key =~ /^Queue-AddWatcher-Principal-(\d*)$/ and !$ARGS{$key}); next if $1 == $MyPrincipalId; my $code; $code ||= ($QueueObj->DeleteWatcher( Type => $_, PrincipalId => $1, ))[0] for qw(AdminCc Cc); my $TicketObj = RT::Ticket->new($session{'CurrentUser'}); $TicketObj->Create( Queue => 'MemberChange', Subject => join(' ', 'Delete', 0, $QueueObj->Id, $QueueObj->Name), Requestor => [ $session{CurrentUser}->UserObj->Id ], Owner => $1, ) if $code; } # Add new watchers foreach my $key (keys %ARGS) { # They're in this order because otherwise $1 gets clobbered :/ next unless $ARGS{$key} =~ /^(AdminCc|Cc)$/ and $key =~ /^Queue-AddWatcher-Principal-(\d*)$/ and $1 != $MyPrincipalId; $RT::Logger->debug("Adding a watcher $1 to ".$ARGS{$key}."\n"); if ($ARGS{$key} eq 'AdminCc') { next if $QueueObj->HasAdminCc($1); } else { next if $QueueObj->HasCc($1); } # First, clear away the other status ($code, $msg) = $QueueObj->DeleteWatcher( Type => ( ($ARGS{$key} eq 'AdminCc') ? 'Cc' : 'AdminCc' ), PrincipalId => $1 ); my $verb = ($code ? 'Edit' : 'Add'); ($code, $msg) = $QueueObj->AddWatcher( Type => $ARGS{$key}, PrincipalId => $1 ); my $TicketObj = RT::Ticket->new($session{'CurrentUser'}); $TicketObj->Create( Queue => 'MemberChange', Subject => join(' ', $verb, $ARGS{$key}, $QueueObj->Id, $QueueObj->Name), Requestor => [ $session{CurrentUser}->UserObj->Id ], Owner => $1, ) if $code and $verb; } } if (length $UserString) { $Users = RT::Users->new($session{'CurrentUser'}); $Users->LimitToPrivileged; $Users->Limit( FIELD => $UserField, VALUE => $UserString, OPERATOR => $UserOp ); } $current_tab = 'Admin/Queues/People.html?id='.$QueueObj->id; my $RoleCache = {}; my $RoleMap = { Cc => 'Member', AdminCc => 'Admin', '' => 'none', }; <%ARGS> $UserField => 'Name' $UserOp => '=' $UserString => undef $InviteEmail => '' $InviteRole => 'Cc' $InviteLetter => '' $Type => undef $QueueObj