[Rt-commit] rt branch, 4.6/select-queue-in-ticket-create, created. rt-4.4.4-707-g1df7a27498

Aaron Trevena ast at bestpractical.com
Thu Jan 23 08:28:39 EST 2020


The branch, 4.6/select-queue-in-ticket-create has been created
        at  1df7a27498a22a53d1133cebd9f20945d01f34ab (commit)

- Log -----------------------------------------------------------------
commit 771c36decfefb6002c89f539584529723d61d859
Author: Aaron Trevena <ast at bestpractical.com>
Date:   Tue Jan 7 20:07:58 2020 +0000

    Select Queue in Ticket Create page
    
    Allow Queue to be selected in the create ticket page, using defaults
    from configuration if none provided
    Existing urls for queue creation will still work, and previous ticket
    create button and modal are possible by over-riding template
    Auto-complete lookup will be used if configured in place of selectbox
    in ticket create page in same way as previous modal

diff --git a/share/html/Elements/CreateTicket b/share/html/Elements/CreateTicket
index 22a2e45937..72800892ef 100644
--- a/share/html/Elements/CreateTicket
+++ b/share/html/Elements/CreateTicket
@@ -54,8 +54,7 @@
 % }
 
 % my $button_start = '<input type="submit" class="button btn btn-primary form-control" value="';
-% my $button_start_modal = '<input type="submit" class="button btn btn-primary form-control ticket-create-modal" value="';
-% my $button_only_start_modal = '<input type="submit" class="btn btn-primary ticket-create-modal" value="';
+% my $button_only_start = '<input type="submit" class="btn btn-primary" value="';
 % my $button_end = '" />';
 % my $queue_selector = $m->scomp('/Elements/SelectNewTicketQueue', AutoSubmit => 1, SendTo => $SendTo, Placeholder => loc('Queue'), Hyperlink => $Hyperlink );
 
@@ -64,13 +63,13 @@
 % }
 % elsif ($ButtonOnly) {
 <div class="create-wide">
-<&|/l_unsafe, $button_only_start_modal, $button_end &>[_1]Create new ticket[_2]</&>
+<&|/l_unsafe, $button_only_start, $button_end &>[_1]Create new ticket[_2]</&>
 </div>
 <div class="create-medium">
-<&|/l_unsafe, $button_start_modal, $button_end &>[_1]Create[_2]</&>
+<&|/l_unsafe, $button_start, $button_end &>[_1]Create[_2]</&>
 </div>
 <div class="create-narrow">
-<&|/l_unsafe, $button_start_modal, $button_end &>[_1]+[_2]</&>
+<&|/l_unsafe, $button_start, $button_end &>[_1]+[_2]</&>
 </div>
 % }
 % else {
@@ -78,10 +77,10 @@
 <&|/l_unsafe, $button_start, $button_end, $queue_selector &>[_1]New ticket in[_2] [_3]</&>
 </div>
 <div class="create-medium">
-<&|/l_unsafe, $button_start_modal, $button_end &>[_1]New ticket[_2]</&>
+<&|/l_unsafe, $button_start, $button_end &>[_1]New ticket[_2]</&>
 </div>
 <div class="create-narrow">
-<&|/l_unsafe, $button_start_modal, $button_end &>[_1]+[_2]</&>
+<&|/l_unsafe, $button_start, $button_end &>[_1]+[_2]</&>
 </div>
 % }
 
diff --git a/share/html/Elements/SelectObject b/share/html/Elements/SelectObject
index 37db75ea46..48622fbdbd 100644
--- a/share/html/Elements/SelectObject
+++ b/share/html/Elements/SelectObject
@@ -70,9 +70,12 @@
 %     }
 %     for my $object ($default_entry || (), @{$session{$cache_key}{objects}}) {
   <option value="<% ($NamedValues ? $object->{Name} : $object->{Id}) %>"\
-% if ($object->{Id} eq ($Default||'') || $object->{Name} eq ($Default||'')) {
+% if ( $object->{Id} eq ($Default||'') || $object->{Name} eq ($Default||'')) {
  selected="selected"\
 % }
+% elsif ( defined($SelectedId) && $object->{Id} eq $SelectedId ) {
+  selected="selected"\
+% }
 ><%$object->{Name}%>\
 %             if ($Verbose and $object->{Description}) {
  (<%$object->{Description}%>)\
@@ -81,6 +84,7 @@
 %     }
 </select>
 % }
+
 <%args>
 $ObjectType
 $CheckRight => undef
@@ -99,8 +103,10 @@ $Class => ""
 $CacheNeedsUpdate => undef
 $Hyperlink => undef
 $AccessKey => undef
+$SelectedId => undef
 </%args>
 <%init>
+
 $ObjectType = "RT::$ObjectType" unless $ObjectType =~ /::/;
 $Class    ||= "select-" . CSSClass("\L$1") if $ObjectType =~ /RT::(.+)$/;
 
diff --git a/share/html/Elements/SelectQueue b/share/html/Elements/SelectQueue
index 412f95e2f5..59e91bf8ea 100644
--- a/share/html/Elements/SelectQueue
+++ b/share/html/Elements/SelectQueue
@@ -45,6 +45,7 @@
 %# those contributions and any derivatives thereof.
 %#
 %# END BPS TAGGED BLOCK }}}
+<input type="hidden" name="QueueChanged" id="QueueChanged" value="0"/>
 %if (RT->Config->Get("AutocompleteQueues", $session{'CurrentUser'})) {
 <& SelectQueueAutocomplete, %ARGS, &>
 %} else {
@@ -60,7 +61,9 @@
 $CheckQueueRight => 'CreateTicket'
 $ShowAllQueues   => 1
 $AutoSubmit      => 0
+$SelectedId      => undef
 </%args>
 <%init>
-$ARGS{OnChange} = "jQuery(this).closest('form').submit();" if $AutoSubmit;
+$ARGS{OnChange} = q{jQuery('#QueueChanged').val(1);};
+$ARGS{OnChange} .= "jQuery(this).closest('form').submit();" if ($AutoSubmit);
 </%init>
diff --git a/share/html/Elements/SelectQueueAutocomplete b/share/html/Elements/SelectQueueAutocomplete
index 903ea7d2cb..bca077a881 100644
--- a/share/html/Elements/SelectQueueAutocomplete
+++ b/share/html/Elements/SelectQueueAutocomplete
@@ -55,21 +55,36 @@ $ShowAllQueues   => 1
 $CheckQueueRight => 'CreateTicket'
 $AutoSubmit      => 0
 $Return          => 'Name'
+$SelectedId      => undef
 </%args>
 <%init>
-my $DefaultQueue = RT::Queue->new($session{'CurrentUser'});
-$DefaultQueue->Load( $Default );
+
+my $Value = '';
+if ($SelectedId) {
+    my $SelectedQueue = RT::Queue->new($session{'CurrentUser'});
+    $SelectedQueue->Load( $SelectedId );
+    $Value = $SelectedQueue->Name;
+} elsif ($Default) {
+    my $DefaultQueue = RT::Queue->new($session{'CurrentUser'});
+    $DefaultQueue->Load( $Default );
+    if ($DefaultQueue->id) {
+        $Value = $DefaultQueue->Name;
+    }
+}
 
 undef $CheckQueueRight if $ShowAllQueues;
 </%init>
 <input name="<% $Name %>"
        type="text"
        size="25"
-       value="<% $DefaultQueue->id ? $DefaultQueue->Name : "" %>"
+       value="<% $Value %>"
        class="<% $Class %>"
        data-autocomplete="Queues"
        placeholder="<% $Placeholder %>"
        data-autocomplete-checkright="<% $CheckQueueRight %>"
        data-autocomplete-return="<% $Return %>"
-       <% $AutoSubmit ? 'data-autocomplete-autosubmit=1' : '' %>
+% if ($AutoSubmit) {
+       data-autocomplete-autosubmit=1
+       onInput="jQuery('#QueueChanged').val(1);"
+% }
 />
diff --git a/share/html/Helpers/CreateInQueue b/share/html/Helpers/CreateInQueue
deleted file mode 100644
index b1ab4b8f46..0000000000
--- a/share/html/Helpers/CreateInQueue
+++ /dev/null
@@ -1,61 +0,0 @@
-%# BEGIN BPS TAGGED BLOCK {{{
-%#
-%# COPYRIGHT:
-%#
-%# This software is Copyright (c) 1996-2016 Best Practical Solutions, LLC
-%#                                          <sales at bestpractical.com>
-%#
-%# (Except where explicitly superseded by other copyright notices)
-%#
-%#
-%# LICENSE:
-%#
-%# This work is made available to you under the terms of Version 2 of
-%# the GNU General Public License. A copy of that license should have
-%# been provided with this software, but in any event can be snarfed
-%# from www.gnu.org.
-%#
-%# This work 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
-%# General Public License for more details.
-%#
-%# You should have received a copy of the GNU General Public License
-%# along with this program; if not, write to the Free Software
-%# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-%# 02110-1301 or visit their web page on the internet at
-%# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
-%#
-%#
-%# CONTRIBUTION SUBMISSION POLICY:
-%#
-%# (The following paragraph is not intended to limit the rights granted
-%# to you to modify and distribute this software under the terms of
-%# the GNU General Public License and is only of importance to you if
-%# you choose to contribute your changes and enhancements to the
-%# community by submitting them to Best Practical Solutions, LLC.)
-%#
-%# By intentionally submitting any modifications, corrections or
-%# derivatives to this work, or any other work intended for use with
-%# Request Tracker, to Best Practical Solutions, LLC, you confirm that
-%# you are the copyright holder for those contributions and you grant
-%# Best Practical Solutions,  LLC a nonexclusive, worldwide, irrevocable,
-%# royalty-free, perpetual, license to use, copy, create derivative
-%# works based on those contributions, and sublicense and distribute
-%# those contributions and any derivatives thereof.
-%#
-%# END BPS TAGGED BLOCK }}}
-<div class="modal-dialog modal-dialog-centered" role="document">
-  <div class="modal-content">
-    <div class="modal-header">
-      <h5 class="modal-title"><&|/l&>Select Queue</&></h5>
-      <a href="javascript:void(0)" class="close" data-dismiss="modal" aria-label="Close">
-        <span aria-hidden="true">×</span>
-      </a>
-    </div>
-    <div class="modal-body">
-      <& /Elements/CreateInQueue &>
-    </div>
-  </div>
-</div>
-% $m->abort;
diff --git a/share/html/Ticket/Create.html b/share/html/Ticket/Create.html
index 1e2de412da..588b63c6a6 100644
--- a/share/html/Ticket/Create.html
+++ b/share/html/Ticket/Create.html
@@ -72,7 +72,6 @@
 
 <div id="ticket-create-metadata">
     <&| /Widgets/TitleBox, title => loc("Basics"), class=>'ticket-info-basics' &>
-    <input type="hidden" class="hidden" name="Queue" value="<% $QueueObj->Id %>" />
     <div>
     <& /Ticket/Elements/EditBasics,
         InTable => 1,
@@ -80,10 +79,12 @@
         defaults => \%ARGS,
         fields  => [
             {   name => 'Queue',
-                comp => '/Ticket/Elements/ShowQueue',
+                comp => '/Elements/SelectQueue',
                 args => {
-                    QueueObj => $QueueObj,
-                    Wrap => 1,
+                    Wrap        => 1,
+                    SelectedId  => $Queue,
+                    AutoSubmit  => 1,
+                    Name        => 'Queue'
                 },
             },
             {   name => 'Status',
@@ -238,8 +239,8 @@
 <div class="row">
 <div class="boxcontainer col-md-6">
     <div class="ticket-info-basics">
-          <&| /Widgets/TitleBox, title => loc('The Basics'), 
-                title_class=> 'inverse',  
+          <&| /Widgets/TitleBox, title => loc('The Basics'),
+                title_class=> 'inverse',
                 color => "#993333" &>
 <div>
 
@@ -278,7 +279,7 @@
 <br />
 <div class="ticket-info-dates">
 <&|/Widgets/TitleBox, title => loc("Dates"),
-  title_class=> 'inverse',  
+  title_class=> 'inverse',
   color => "#663366" &>
 
 <div>
@@ -325,7 +326,33 @@
 
 <%INIT>
 $m->callback( CallbackName => "Init", ARGSRef => \%ARGS );
+
 my $Queue = $ARGS{Queue};
+
+# Use default queue from config site or user prefs if none provided
+unless ($Queue) {
+    $Queue = RT->Config->Get("DefaultQueue", $session{'CurrentUser'});
+    if (RT->Config->Get("RememberDefaultQueue", $session{'CurrentUser'})) {
+        if (my $session_default = $session{'DefaultQueue'}) {
+            $Queue = $session_default;
+        }
+    }
+}
+
+# pick first in list in normal order unless queue provided from form/url/defaults
+unless ($Queue) {
+    my $cache_key = SetObjectSessionCache(
+        ObjectType => 'Queue',
+        CheckRight => 1,
+        CacheNeedsUpdate => 0,
+     );
+
+     $Queue = $session{$cache_key}{objects}[0]->{Id};
+     if (not $Queue) {
+        Abort(loc("Queue [_1] could not be loaded.", ''), Code => HTTP::Status::HTTP_BAD_REQUEST);
+     }
+}
+
 $session{DefaultQueue} = $Queue;
 
 my $current_user = $session{'CurrentUser'};
@@ -466,14 +493,14 @@ if ( !exists $ARGS{'AddMoreAttach'} && ($ARGS{'id'}||'') eq 'new' ) {
 }
 
 my $skip_create = 0;
-$m->callback( CallbackName => 'BeforeCreate', ARGSRef => \%ARGS, skip_create => \$skip_create, 
+$m->callback( CallbackName => 'BeforeCreate', ARGSRef => \%ARGS, skip_create => \$skip_create,
               checks_failure => $checks_failure, results => \@results );
 
 $m->comp( '/Articles/Elements/CheckSkipCreate', ARGSRef => \%ARGS, skip_create => \$skip_create,
               checks_failure => $checks_failure, results => \@results );
 
 if ((!exists $ARGS{'AddMoreAttach'}) and (!exists $ARGS{'Go'}) and (defined($ARGS{'id'}) and $ARGS{'id'} eq 'new')) { # new ticket?
-    if ( !$checks_failure && !$skip_create ) {
+    if ( !$checks_failure && !$skip_create && !$ARGS{'QueueChanged'} ) {
         $m->comp('Display.html', %ARGS);
         $RT::Logger->crit("After display call; error is $@");
         $m->abort();
diff --git a/share/static/js/util.js b/share/static/js/util.js
index 2092d7200b..507a497008 100644
--- a/share/static/js/util.js
+++ b/share/static/js/util.js
@@ -621,14 +621,6 @@ jQuery(function() {
         return false;
     });
 
-    jQuery(".ticket-create-modal").click(function(ev){
-        ev.preventDefault();
-        jQuery.get(
-            RT.Config.WebHomePath + "/Helpers/CreateInQueue",
-            showModal
-        );
-    });
-
     jQuery("#articles-create, .article-create-modal").click(function(ev){
         ev.preventDefault();
         jQuery.get(

commit 1df7a27498a22a53d1133cebd9f20945d01f34ab
Author: Aaron Trevena <ast at bestpractical.com>
Date:   Tue Jan 7 20:09:07 2020 +0000

    Select Queue in Ticket Create page Tests and test dependancies
    
    Added new tests for creating tickets with custom fields and
     lifecycles, and with or without queue specified

diff --git a/etc/cpanfile b/etc/cpanfile
index 5de533a7f2..4efa10b566 100644
--- a/etc/cpanfile
+++ b/etc/cpanfile
@@ -128,6 +128,7 @@ on 'develop' => sub {
     requires 'Test::NoWarnings';
     requires 'Test::Pod';
     requires 'Test::Warn';
+    requires 'Test::HTML::Form', '>= 1.01';
     requires 'Test::WWW::Mechanize', '>= 1.30';
     requires 'Test::WWW::Mechanize::PSGI';
     requires 'WWW::Mechanize', '>= 1.80';
diff --git a/t/customfields/access_via_queue.t b/t/customfields/access_via_queue.t
index 300e777b8b..e90e4dac01 100644
--- a/t/customfields/access_via_queue.t
+++ b/t/customfields/access_via_queue.t
@@ -2,7 +2,7 @@
 use strict;
 use warnings;
 
-use RT::Test nodata => 1, tests => 47;
+use RT::Test nodata => 1, tests => 48;
 use RT::Ticket;
 use RT::CustomField;
 
@@ -96,10 +96,7 @@ ok $m->login( tester => 'password' ), 'logged in';
 
 diag "check that we don't have the cf on create";
 {
-    $m->submit_form(
-        form_name => "CreateTicketInQueue",
-        fields => { Queue => $queue->Name },
-    );
+    $m->get_ok( '/Ticket/Create.html?Queue='.$queue->id, 'go to ticket create page with queue id' );
 
     my $form = $m->form_name("TicketCreate");
     my $cf_field = "Object-RT::Ticket--CustomField-". $cf->id ."-Value";
diff --git a/t/customfields/sort_order.t b/t/customfields/sort_order.t
index 4a84ec5955..e905354c96 100644
--- a/t/customfields/sort_order.t
+++ b/t/customfields/sort_order.t
@@ -2,7 +2,7 @@
 use strict;
 use warnings;
 
-use RT::Test tests => 20;
+use RT::Test tests => 21;
 use RT::Ticket;
 use RT::CustomField;
 
@@ -64,10 +64,7 @@ diag "reorder CFs: C, A and B";
 
 diag "check ticket create, display and edit pages";
 {
-    $m->submit_form(
-        form_name => "CreateTicketInQueue",
-        fields => { Queue => $queue->Name },
-    );
+    $m->get_ok( '/Ticket/Create.html?Queue='.$queue->id, 'go to ticket create page with queue id' );
 
     my @tmp = ($m->content =~ /(CF [ABC])/g);
     is_deeply(\@tmp, ['CF C', 'CF A', 'CF B']);
diff --git a/t/security/CVE-2011-2084-attach-tickets.t b/t/security/CVE-2011-2084-attach-tickets.t
index 6b1366a5f5..0b35af50b9 100644
--- a/t/security/CVE-2011-2084-attach-tickets.t
+++ b/t/security/CVE-2011-2084-attach-tickets.t
@@ -48,10 +48,14 @@ $m->warning_like(qr/no permission/i, 'no permission warning');
 RT::Test->clean_caught_mails;
 
 # Ticket Create is just one example of where this is vulnerable
+my $queue = RT::Test->load_or_create_queue( Name => 'General' );
+ok $queue && $queue->id, 'loaded or created queue';
 $m->get_ok('/Ticket/Create.html?Queue=1');
+my $form = $m->form_name("TicketCreate");
 $m->submit_form_ok({
     form_name   => 'TicketCreate',
     fields      => {
+        Queue           => 1,
         Subject         => 'ticket C',
         AttachTickets   => $ticket_b->id,
     },
diff --git a/t/web/cf_access.t b/t/web/cf_access.t
index aa707f5dc6..c0cd071138 100644
--- a/t/web/cf_access.t
+++ b/t/web/cf_access.t
@@ -1,7 +1,7 @@
 use strict;
 use warnings;
 
-use RT::Test tests => 32;
+use RT::Test tests => 36;
 
 my ($baseurl, $m) = RT::Test->started_ok;
 
@@ -91,6 +91,7 @@ diag "Create a CF";
     $m->text_contains('Illegal value for Name');
 }
 
+
 diag "apply the CF to General queue";
 my ( $cf, $cfid, $tid );
 {
@@ -123,13 +124,12 @@ RT::Test->set_rights(
 );
 ok $m->login( $tester->Name, 123456, logout => 1), 'logged in';
 
+my $queue = RT::Test->load_or_create_queue( Name => 'General' );
+ok $queue && $queue->id, 'loaded or created queue';
 diag "check that we have no the CF on the create"
     ." ticket page when user has no SeeCustomField right";
 {
-    $m->submit_form(
-        form_name => "CreateTicketInQueue",
-        fields => { Queue => 'General' },
-    );
+    $m->get_ok( '/Ticket/Create.html?Queue='.$queue->id, 'go to ticket create page with queue id' );
     $m->content_lacks('Upload multiple images', 'has no upload image field');
 
     my $form = $m->form_name("TicketCreate");
@@ -156,10 +156,7 @@ RT::Test->set_rights(
 diag "check that we have no the CF on the create"
     ." ticket page when user has no ModifyCustomField right";
 {
-    $m->submit_form(
-        form_name => "CreateTicketInQueue",
-        fields => { Queue => 'General' },
-    );
+    $m->get_ok( '/Ticket/Create.html?Queue='.$queue->id, 'go to ticket create page with queue id' );
     $m->content_lacks('Upload multiple images', 'has no upload image field');
 
     my $form = $m->form_name("TicketCreate");
@@ -188,10 +185,8 @@ RT::Test->set_rights(
 
 diag "create a ticket with an image";
 {
-    $m->submit_form(
-        form_name => "CreateTicketInQueue",
-        fields => { Queue => 'General' },
-    );
+
+    $m->get_ok( '/Ticket/Create.html?Queue='.$queue->id, 'go to ticket create page with queue id' );
     $m->content_contains('Upload multiple images', 'has a upload image field');
 
     $cf =~ /(\d+)$/ or die "Hey this is impossible dude";
diff --git a/t/web/cf_date.t b/t/web/cf_date.t
index b3b7dcc288..ab53121544 100644
--- a/t/web/cf_date.t
+++ b/t/web/cf_date.t
@@ -54,10 +54,7 @@ diag 'check valid inputs with various timezones in ticket create page';
 {
     my ( $ticket, $id );
 
-    $m->submit_form(
-        form_name => "CreateTicketInQueue",
-        fields    => { Queue => 'General' },
-    );
+    $m->get_ok( '/Ticket/Create.html?Queue='.$queue->id, 'go to ticket create page with queue id' );
     $m->content_contains('Select date', 'has cf field' );
 
     $m->submit_form(
@@ -165,10 +162,7 @@ diag 'check search build page';
 
 diag 'check invalid inputs';
 {
-    $m->submit_form(
-        form_name => "CreateTicketInQueue",
-        fields    => { Queue => 'General' },
-    );
+    $m->get_ok( '/Ticket/Create.html?Queue='.$queue->id, 'go to ticket create page with queue id' );
     my $form = $m->form_name("TicketCreate");
 
     $m->submit_form(
@@ -212,10 +206,7 @@ diag 'retain values when adding attachments';
     $txn_cf->AddToObject(RT::Queue->new(RT->SystemUser));
     my $txn_cfid = $txn_cf->id;
 
-    $m->submit_form(
-        form_name => "CreateTicketInQueue",
-        fields    => { Queue => 'General' },
-    );
+    $m->get_ok( '/Ticket/Create.html?Queue='.$queue->id, 'go to ticket create page with queue id' );
     $m->content_contains('test cf date', 'has cf' );
     $m->content_contains('test txn cf date', 'has txn cf' );
 
diff --git a/t/web/cf_datetime.t b/t/web/cf_datetime.t
index 044555358a..4de4565c38 100644
--- a/t/web/cf_datetime.t
+++ b/t/web/cf_datetime.t
@@ -62,10 +62,7 @@ diag 'check valid inputs with various timezones in ticket create page';
 {
     my ( $ticket, $id );
 
-    $m->submit_form(
-        form_name => "CreateTicketInQueue",
-        fields => { Queue => 'General' },
-    );
+    $m->get_ok( '/Ticket/Create.html?Queue='.$queue->id, 'go to ticket create page with queue id' );
     $m->content_contains('Select datetime', 'has cf field');
 
     $m->submit_form(
@@ -103,10 +100,7 @@ diag 'check valid inputs with various timezones in ticket create page';
             'cf datetime value respects user timezone' );
     }
 
-    $m->submit_form(
-        form_name => "CreateTicketInQueue",
-        fields => { Queue => 'General' },
-    );
+    $m->get_ok( '/Ticket/Create.html?Queue='.$queue->id, 'go to ticket create page with queue id' );
     $m->submit_form(
         form_name => "TicketCreate",
         fields    => {
@@ -192,10 +186,7 @@ diag 'check search build page';
 
 diag 'check invalid inputs';
 {
-    $m->submit_form(
-        form_name => "CreateTicketInQueue",
-        fields => { Queue => 'General' },
-    );
+    $m->get_ok( '/Ticket/Create.html?Queue='.$queue->id, 'go to ticket create page with queue id' );
     my $form = $m->form_name("TicketCreate");
 
     $m->submit_form(
@@ -238,10 +229,7 @@ diag 'retain values when adding attachments';
     $txn_cf->AddToObject(RT::Queue->new(RT->SystemUser));
     my $txn_cfid = $txn_cf->id;
 
-    $m->submit_form(
-        form_name => "CreateTicketInQueue",
-        fields    => { Queue => 'General' },
-    );
+    $m->get_ok( '/Ticket/Create.html?Queue='.$queue->id, 'go to ticket create page with queue id' );
     $m->content_contains('test cf datetime', 'has cf' );
     $m->content_contains('test txn cf datetime', 'has txn cf' );
 
diff --git a/t/web/cf_image.t b/t/web/cf_image.t
index 7c294b8479..de9815fbab 100644
--- a/t/web/cf_image.t
+++ b/t/web/cf_image.t
@@ -25,11 +25,9 @@ $m->tick( "AddCustomField-2", 0 );
 $m->click_ok( "UpdateObjs" );
 $m->content_contains("Globally added custom field Images");
 
-
-$m->submit_form_ok({
-    form_name => "CreateTicketInQueue",
-    fields    => { Queue => 'General' },
-});
+my $queue = RT::Test->load_or_create_queue( Name => 'General' );
+ok $queue && $queue->id, 'loaded or created queue';
+$m->get_ok( '/Ticket/Create.html?Queue='.$queue->id, 'go to ticket create page with queue id' );
 $m->content_contains("Upload one image");
 $m->submit_form_ok({
     form_name => "TicketCreate",
diff --git a/t/web/cf_set_initial.t b/t/web/cf_set_initial.t
index 0cf4f68b3c..3b57fd20fd 100644
--- a/t/web/cf_set_initial.t
+++ b/t/web/cf_set_initial.t
@@ -28,13 +28,13 @@ RT::Test->set_rights(
 );
 ok $m->login( $tester->Name, 123456, logout => 1), 'logged in';
 
+my $queue = RT::Test->load_or_create_queue( Name => 'General' );
+ok $queue && $queue->id, 'loaded or created queue';
+
 diag "check that we have no CFs on the create"
     ." ticket page when user has no SetInitialCustomField right";
 {
-    $m->submit_form(
-        form_name => "CreateTicketInQueue",
-        fields => { Queue => 'General' },
-    );
+    $m->get_ok( '/Ticket/Create.html?Queue='.$queue->id, 'go to ticket create page with queue id' );
     $m->content_lacks('Test Set Initial CF', 'has no CF input');
     $m->content_lacks('Multi Set Initial CF', 'has no CF input');
 
@@ -66,10 +66,7 @@ RT::Test->set_rights(
 diag "check that we have the CF on the create"
     ." ticket page when user has SetInitialCustomField but no SeeCustomField";
 {
-    $m->submit_form(
-        form_name => "CreateTicketInQueue",
-        fields => { Queue => 'General' },
-    );
+    $m->get_ok( '/Ticket/Create.html?Queue='.$queue->id, 'go to ticket create page with queue id' );
     $m->content_contains('Test Set Initial CF', 'has CF input');
     $m->content_contains('Multi Set Initial CF', 'has CF input');
 
diff --git a/t/web/csrf.t b/t/web/csrf.t
index 4abfb4d14d..92f4f925bb 100644
--- a/t/web/csrf.t
+++ b/t/web/csrf.t
@@ -2,6 +2,7 @@ use strict;
 use warnings;
 
 use RT::Test tests => undef;
+use Test::HTML::Form;
 
 my $ticket = RT::Ticket->new(RT::CurrentUser->new('root'));
 my ($ok, $msg) = $ticket->Create(Queue => 1, Owner => 'nobody', Subject => 'bad music');
@@ -143,14 +144,12 @@ $m->content_contains("your browser did not supply a Referrer header");
 $m->title_is('Possible cross-site request forgery');
 
 # Sending a wrong CSRF is just a normal request.  We'll make a request
-# with just an invalid token, which means no Queue=, which means
-# Create.html errors out.
+# with just an invalid token, which means no Queue=x so default queue used
 my $link = $m->find_link(text_regex => qr{resume your request});
 (my $broken_url = $link->url) =~ s/(CSRF_Token)=\w+/$1=crud/;
 $m->get($broken_url);
-$m->content_like(qr/Queue\s+could not be loaded/);
-$m->title_is('RT Error');
-$m->warning_like(qr/Queue\s+could not be loaded/);
+$m->content_like(qr/Create\sa\snew\sticket\sin\sGeneral/);
+$m->title_is('Create a new ticket in General');
 
 # The token doesn't work for other pages, or other arguments to the same page.
 $m->add_header(Referer => undef);
@@ -173,8 +172,8 @@ $m->title_is('Configuration for queue test');
 $m->get_ok("/Ticket/Create.html?Queue=$other_queue_id&CSRF_Token=$token");
 $m->content_lacks("Possible cross-site request forgery");
 $m->title_is('Create a new ticket in General');
-$m->text_unlike(qr/Queue:\s*Other queue/);
-$m->text_like(qr/Queue:\s*General/);
+form_select_field_matches($m, { field_name => 'Queue', selected => 1, form_name => 'TicketCreate'}, 'Queue selection dropdown populated and pre-selected');
+
 
 # Ensure that file uploads work across the interstitial
 $m->delete_header('Referer');
diff --git a/t/web/group_summary.t b/t/web/group_summary.t
index 22977b667c..ffc87259d0 100644
--- a/t/web/group_summary.t
+++ b/t/web/group_summary.t
@@ -29,7 +29,7 @@ diag( 'Group Summary access and ticket creation' );
 
     $m->submit_form_ok({ form_name => 'CreateTicket' },
                          "Submitted form to create ticket with group $group_id as Cc" );
-    like( $m->uri, qr{/Ticket/Create\.html\?AddGroupCc=$group_id&Queue=1$},
+    like( $m->uri, qr{/Ticket/Create\.html\?AddGroupCc=$group_id&QueueChanged=0&Queue=1$},
           "now on /Ticket/Create\.html with param AddGroupCc=$group_id" );
 
     my $subject = 'test AddGroupCc ticket';
diff --git a/t/web/ticket_create.t b/t/web/ticket_create.t
new file mode 100644
index 0000000000..ad5600c738
--- /dev/null
+++ b/t/web/ticket_create.t
@@ -0,0 +1,86 @@
+use strict;
+use warnings;
+use Test::HTML::Form;
+
+use RT::Test tests => undef;
+use RT::Lifecycle;
+
+# populate lifecycles
+my $lifecycles = RT->Config->Get('Lifecycles');
+RT->Config->Set( Lifecycles => %{$lifecycles},
+                 foo => {
+                     initial  => ['initial'],
+                     active   => ['open'],
+                     inactive => ['resolved'],
+                 }
+);
+RT::Lifecycle->FillCache();
+
+# populate test queues and test user
+my $queue1 = RT::Test->load_or_create_queue( Name => 'General' );
+my $queue2 = RT::Test->load_or_create_queue( Name => 'Specific' );
+my $queue3 = RT::Test->load_or_create_queue( Name => 'Bugs' );
+my $queue4 = RT::Test->load_or_create_queue( Name => 'Another queue' );
+my $queue5 = RT::Test->load_or_create_queue( Name => 'Yet Another queue' );
+my $user = RT::Test->load_or_create_user(
+    Name     => 'user',
+    Password => 'password',
+);
+
+my ( $baseurl, $m ) = RT::Test->started_ok;
+
+#set up lifecycle for one of the queues
+ok $m->login;
+$m->get_ok( '/Admin/Queues/Modify.html?id='.$queue1->id );
+$m->form_name('ModifyQueue');
+$m->submit_form( fields => { Lifecycle => 'foo' } );
+
+# set up custom field
+my $cf = RT::Test->load_or_create_custom_field( Name => 'test_cf', Queue => $queue1->Name, Type => 'FreeformSingle' );
+my $cf_form_id = 'Object-RT::Ticket--CustomField-'.$cf->Id.'-Value';
+my $cf_test_value = "some string for test_cf $$";
+
+# load initial ticket create page without specifying queue
+# should have default queue with no custom fields
+note('load create ticket page with defaults');
+$m->get_ok( '/');
+$m->submit_form(
+    form_name => "CreateTicketInQueue",
+);
+no_tag($m,'input',{ name => $cf_form_id }, 'no custom field');
+form_select_field_matches($m, { field_name => 'Queue', selected => $queue3->id,
+                                form_name => 'TicketCreate'}, 'Queue selection dropdown populated');
+form_select_field_matches($m, { field_name => 'Status', selected => "new",
+                                form_name => 'TicketCreate'}, 'Status selection dropdown populated');
+
+
+$m->get_ok( '/Ticket/Create.html', 'go to ticket create page with no queue id' );
+no_tag($m,'input',{ name => $cf_form_id }, 'no custom field');
+form_select_field_matches($m, { field_name => 'Queue', selected => $queue3->id,
+                                form_name => 'TicketCreate'}, 'Queue selection dropdown populated');
+form_select_field_matches($m, { field_name => 'Status', selected => "new",
+                                form_name => 'TicketCreate'}, 'Status selection dropdown populated');
+
+# test ticket creation on reload from selected queue, specifying queue with custom fields
+note('reload ticket create page with selected queue');
+$m->get_ok( '/Ticket/Create.html?QueueChanged=1&Queue='.$queue1->id,
+            'go to ticket create page' );
+
+form_select_field_matches($m, { field_name => 'Queue', selected => $queue1->id,
+                                form_name => 'TicketCreate'}, 'Queue selection dropdown populated and pre-selected');
+form_field_value_matches($m, $cf_form_id, "", 'TicketCreate', 'custom field is present');
+
+my $form = $m->form_name('TicketCreate');
+my $status_input = $form->find_input('Status');
+is_deeply( [ $status_input->possible_values ], [ 'initial', 'open', 'resolved' ], 'status selectbox shows custom lifecycle for queue' );
+
+note('submit populated form');
+$m->submit_form( fields => { Subject => 'ticket foo', 'Queue' => $queue1->id, $cf_form_id => $cf_test_value } );
+$m->text_contains('test_cf', 'custom field populated in display');
+$m->text_contains($cf_test_value, 'custom field populated in display');
+
+my $ticket = RT::Test->last_ticket;
+ok( $ticket->id, 'ticket is created' );
+is($ticket->QueueObj->id, $queue1->id, 'Ticket created with correct queue');
+
+done_testing();
diff --git a/t/web/ticket_txn_cf.t b/t/web/ticket_txn_cf.t
index 42a37720ad..717ab30cda 100644
--- a/t/web/ticket_txn_cf.t
+++ b/t/web/ticket_txn_cf.t
@@ -51,11 +51,7 @@ ok $queue && $queue->id, 'loaded or created queue';
 my ( $ticket, $id );
 diag 'submit value on ticket create page';
 {
-
-    $m->submit_form(
-        form_name => "CreateTicketInQueue",
-        fields    => { Queue => 'General' },
-    );
+    $m->get_ok( '/Ticket/Create.html?Queue='.$queue->id, 'go to ticket create page with queue id' );
     $m->content_contains($cf_name, 'has cf field' );
 
     $m->submit_form(

-----------------------------------------------------------------------


More information about the rt-commit mailing list