SelectDefaultQueue

From Request Tracker Wiki
Revision as of 16:37, 6 April 2016 by Admin (talk | contribs) (3 revisions imported)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Instead of patching RT, this is easily done globally (or per user in preferences) using the DefaultQueue config option

What This Is

This patch, along with a user-based custom field named "Default Queue", allows per-user specification of which queue is selected by default in queue name drop down lists. Additionally, it allows you to set [=DefaultQueueId] in RT_SiteConfig.pm to choose a default queue for users without a default queue setting.

This includes the queue name drop down in the Search Page. If you find that annoying, you'll need to add an arg (e.g. NoUserDefQueue), then modify the unless ($Default) conditional, and finally modify the Search/Build.html page to set your new arg properly.

Note: If you want to allow users to choose their own default queue, have a look at the DisplayCustomFieldsInUserPrefs contribution.

The patch below was made against RT 3.5.5; I suspect the logic can be transplanted as far back as 3.2, though.

How To Install This

  1. Create a custom field named 'Default Queue' which applies to Users; it should be a "Select one value" field whose values are exactly the same as your queue names in spelling, case, and whitespace, if any.
  2. Save the patch below in /tmp/SelectQueue.patch
  3. mkdir /path/to/rt/local/html/Elements
  4. cd /path/to/rt/local/html/Elements
  5. cp /path/to/rt/share/html/Elements/SelectQueue .
  6. patch -p3 < /tmp/SelectQueue.patch

Patch for RT 3.5.5

--- share/html/Elements/SelectQueue     2005-07-31 09:27:38.000000000 -0700
  +++ local/html/Elements/SelectQueue     2005-11-23 15:28:54.000000000 -0800
  @@ -52,9 +52,9 @@
   <select name="<%$Name%>">
   %     if ($ShowNullOption) {
     <option value="">-</option>
   %     }
  -%     for my $queue (@{$cache{$cache_key}}) {
  +%     for my $queue (@{$cache{$queue_list_cache}}) {
     <option value="<% ($NamedValues ? $queue->{Name} : $queue->{Id}) %>" <% ($queue->{Id} eq $Default ? 'selected="selected"' : '') |n %>>
       <%$queue->{Name}%>
   %             if ($Verbose and $queue->{Description}) {
       (<%$queue->{Description}%>)
  @@ -65,8 +65,9 @@
   % }
   <%once>
   my %cache;
   </%once>
  +
   <%args>
   $CheckQueueRight => 'CreateTicket'
   $ShowNullOption => 1
   $ShowAllQueues => 1
  @@ -75,24 +76,43 @@
   $NamedValues => 0
   $Default => 0
   $Lite => 0
   </%args>
  +
   <%init>
  -my $cache_key = "SelectQueue---"
  +my $queue_list_cache = "SelectQueue---"
                   . $session{'CurrentUser'}->Id
                   . "---$CheckQueueRight---$ShowAllQueues";
  
  -if (not defined $cache{$cache_key} and not $Lite) {
  +if (not defined $cache{$queue_list_cache} and not $Lite) {
       my $q = new RT::Queues($session{'CurrentUser'});
       $q->UnLimit;
  
       while (my $queue = $q->Next) {
           if ($ShowAllQueues || $queue->CurrentUserHasRight($CheckQueueRight)) {
  -            push @{$cache{$cache_key}}, {
  +            push @{$cache{$queue_list_cache}}, {
                   Id          => $queue->Id,
                   Name        => $queue->Name,
                   Description => $queue->Description,
               };
           }
       }
   }
  +
  +unless ($Default) {
  +  my $default_queue_cache = "SelectQueue---"
  +                . $session{'CurrentUser'}->Id
  +                . "---DefaultQueueId";
  +  unless (defined($cache{$default_queue_cache})) {
  +    $cache{$default_queue_cache} = 0;
  +    my $sess_user = $session{'CurrentUser'};
  +    my $user = RT::User->new($sess_user);
  +    $user->Load($sess_user->Id);
  +
  +    my $def_queue = RT::Queue->new($sess_user);
  +    $def_queue->Load($user->CustomFieldValues('Default Queue')->First->Content) if $user->CustomFieldValues('Default Queue')->First;
  +    $cache{$default_queue_cache} = $def_queue->Id if $def_queue->Id;
  +  }
  +
  +  $Default = $cache{$default_queue_cache} || $RT::DefaultQueueId || 1;
  +}
   </%init>