From c587b5fdc7175c2a752558efccfc3f424cff6c0d Mon Sep 17 00:00:00 2001 From: mark Date: Sat, 1 Jan 2011 00:47:01 +0000 Subject: [PATCH] limit ticket creation queue dropdowns based on ACL, RT#7778 --- FS/FS/TicketSystem/RT_Internal.pm | 29 ++++++++ httemplate/view/cust_main/tickets.html | 5 +- rt/FREESIDE_MODIFIED | 15 +++- rt/Makefile.in | 1 + rt/configure.ac | 3 +- rt/lib/RT/Interface/Web.pm | 2 - rt/lib/RT/Principal_Overlay.pm | 4 ++ rt/lib/RT/Queue_Overlay.pm | 4 ++ rt/lib/RT/System.pm | 22 ++++++ rt/lib/RT/Test.pm | 3 + rt/sbin/rt-session-viewer.in | 121 +++++++++++++++++++++++++++++++++ rt/share/html/Elements/SelectQueue | 17 +++-- rt/share/html/Ticket/Create.html | 1 + 13 files changed, 217 insertions(+), 10 deletions(-) create mode 100644 rt/sbin/rt-session-viewer.in diff --git a/FS/FS/TicketSystem/RT_Internal.pm b/FS/FS/TicketSystem/RT_Internal.pm index befafb847..6ae8881a4 100644 --- a/FS/FS/TicketSystem/RT_Internal.pm +++ b/FS/FS/TicketSystem/RT_Internal.pm @@ -301,6 +301,35 @@ sub correspond_ticket { $Ticket->Correspond( Content => $param{'content'} ); } +=item queues SESSION_HASHREF [, ACL ] + +Retrieve a list of queues. Pass the name of an RT access control right, +such as 'CreateTicket', to return only queues on which the current user +has that right. Otherwise this will return all queues with the 'SeeQueue' +right. + +=cut + +sub queues { + my( $self, $session, $acl ) = @_; + $session = $self->session($session); + + my $showall = $acl ? 0 : 1; + my @result = (); + my $q = new RT::Queues($session->{'CurrentUser'}); + $q->UnLimit; + while (my $queue = $q->Next) { + if ($showall || $queue->CurrentUserHasRight($acl)) { + push @result, { + Id => $queue->Id, + Name => $queue->Name, + Description => $queue->Description, + }; + } + } + return map { $_->{Id} => $_->{Name} } @result; +} + #shameless false laziness w/RT::Interface::Web::AttemptExternalAuth # to get logged into RT from afar sub _web_external_auth { diff --git a/httemplate/view/cust_main/tickets.html b/httemplate/view/cust_main/tickets.html index e90ae5276..eea5a7f98 100644 --- a/httemplate/view/cust_main/tickets.html +++ b/httemplate/view/cust_main/tickets.html @@ -11,7 +11,9 @@ function updateTicketLink() { Create new ticket in queue -% my %queues = FS::TicketSystem->queues(); +%# fetch list of queues in which the user can create tickets +% my $session = FS::TicketSystem->session(); +% my %queues = FS::TicketSystem->queues($session, 'CreateTicket'); % if( $conf->exists('ticket_system-force_default_queueid') ) { <% $queues{$new_param{'Queue'}} %> @@ -19,7 +21,6 @@ function updateTicketLink() { % else {