[Rt-commit] rt branch, 4.4/include-article-queue, created. rt-4.4.2-75-g3c27b7ffb

Craig Kaiser craig at bestpractical.com
Wed Feb 21 12:53:38 EST 2018


The branch, 4.4/include-article-queue has been created
        at  3c27b7ffb931c1b73da0edd2c7d463e7a9e438ff (commit)

- Log -----------------------------------------------------------------
commit 33ac84399e2ebc1c03893e5e94da67dbbf190a8f
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Fri Jan 26 23:36:27 2018 +0800

    find idle port for ldap test server
    
    previously we don't check if the ldap test server port is in use or not,
    and tests hang if the port is already in use. switch to the same
    strategy we find idle web server port in tests.

diff --git a/lib/RT/Test.pm b/lib/RT/Test.pm
index 7ff4d68ea..656cced22 100644
--- a/lib/RT/Test.pm
+++ b/lib/RT/Test.pm
@@ -109,6 +109,7 @@ problem in Perl that hides the top-level optree from L<Devel::Cover>.
 
 our $port;
 our @SERVERS;
+my @ports; # keep track of all the random ports we used
 
 BEGIN {
     delete $ENV{$_} for qw/LANGUAGE LC_ALL LC_MESSAGES LANG/;
@@ -146,7 +147,7 @@ sub import {
 
     $class->bootstrap_tempdir;
 
-    $class->bootstrap_port;
+    $port = $class->find_idle_port;
 
     $class->bootstrap_plugins_paths( %args );
 
@@ -229,7 +230,7 @@ sub db_requires_no_dba {
     return 1 if $db_type eq 'SQLite';
 }
 
-sub bootstrap_port {
+sub find_idle_port {
     my $class = shift;
 
     my %ports;
@@ -245,6 +246,7 @@ sub bootstrap_port {
 
     # Pick a random port, checking that the port isn't in our in-use
     # list, and that something isn't already listening there.
+    my $port;
     {
         $port = 1024 + int rand(10_000) + $$ % 1024;
         redo if $ports{$port};
@@ -271,6 +273,8 @@ sub bootstrap_port {
     truncate(PORTS, 0);
     print PORTS "$_\n" for sort {$a <=> $b} keys %ports;
     close(PORTS) or die "Can't close ports file: $!";
+    push @ports, $port;
+    return $port;
 }
 
 sub bootstrap_tempdir {
@@ -1809,7 +1813,7 @@ END {
 
     # Drop our port from t/tmp/ports; do this after dropping the
     # database, as our port lock is also a lock on the database name.
-    if ($port) {
+    if (@ports) {
         my %ports;
         my $portfile = "$tmp{'directory'}/../ports";
         sysopen(PORTS, $portfile, O_RDWR|O_CREAT)
@@ -1817,7 +1821,7 @@ END {
         flock(PORTS, LOCK_EX)
             or die "Can't write-lock ports file $portfile: $!";
         $ports{$_}++ for split ' ', join("",<PORTS>);
-        delete $ports{$port};
+        delete $ports{$_} for @ports;
         seek(PORTS, 0, 0);
         truncate(PORTS, 0);
         print PORTS "$_\n" for sort {$a <=> $b} keys %ports;
diff --git a/t/externalauth/ldap.t b/t/externalauth/ldap.t
index 5c148ad4e..1e0516fab 100644
--- a/t/externalauth/ldap.t
+++ b/t/externalauth/ldap.t
@@ -8,7 +8,7 @@ eval { require RT::Authen::ExternalAuth; require Net::LDAP::Server::Test; 1; } o
 };
 
 
-my $ldap_port = 1024 + int rand(10000) + $$ % 1024;
+my $ldap_port = RT::Test->find_idle_port;
 ok( my $server = Net::LDAP::Server::Test->new( $ldap_port, auto_schema => 1 ),
     "spawned test LDAP server on port $ldap_port" );
 
diff --git a/t/externalauth/ldap_escaping.t b/t/externalauth/ldap_escaping.t
index 5598d6042..b46c3ffe6 100644
--- a/t/externalauth/ldap_escaping.t
+++ b/t/externalauth/ldap_escaping.t
@@ -8,7 +8,7 @@ eval { require RT::Authen::ExternalAuth; require Net::LDAP::Server::Test; 1; } o
 };
 
 
-my $ldap_port = 1024 + int rand(10000) + $$ % 1024;
+my $ldap_port = RT::Test->find_idle_port;
 ok( my $server = Net::LDAP::Server::Test->new( $ldap_port, auto_schema => 1 ),
     "spawned test LDAP server on port $ldap_port" );
 
diff --git a/t/externalauth/ldap_group.t b/t/externalauth/ldap_group.t
index cc6b7bd45..168c37b07 100644
--- a/t/externalauth/ldap_group.t
+++ b/t/externalauth/ldap_group.t
@@ -13,7 +13,7 @@ eval { require RT::Authen::ExternalAuth; require Net::LDAP::Server::Test; 1; } o
 };
 
 
-my $ldap_port = 1024 + int rand(10000) + $$ % 1024;
+my $ldap_port = RT::Test->find_idle_port;
 ok( my $server = Net::LDAP::Server::Test->new( $ldap_port, auto_schema => 1 ),
     "spawned test LDAP server on port $ldap_port" );
 
diff --git a/t/externalauth/ldap_privileged.t b/t/externalauth/ldap_privileged.t
index 544440996..02e760bf3 100644
--- a/t/externalauth/ldap_privileged.t
+++ b/t/externalauth/ldap_privileged.t
@@ -7,7 +7,7 @@ eval { require RT::Authen::ExternalAuth; require Net::LDAP::Server::Test; 1; } o
     plan skip_all => 'Unable to test without Net::LDAP and Net::LDAP::Server::Test';
 };
 
-my $ldap_port = 1024 + int rand(10000) + $$ % 1024;
+my $ldap_port = RT::Test->find_idle_port;
 ok( my $server = Net::LDAP::Server::Test->new( $ldap_port, auto_schema => 1 ),
     "spawned test LDAP server on port $ldap_port" );
 
diff --git a/t/ldapimport/group-callbacks.t b/t/ldapimport/group-callbacks.t
index 8a7a689ec..272d32921 100644
--- a/t/ldapimport/group-callbacks.t
+++ b/t/ldapimport/group-callbacks.t
@@ -10,7 +10,7 @@ eval { require RT::LDAPImport; require Net::LDAP::Server::Test; 1; } or do {
 my $importer = RT::LDAPImport->new;
 isa_ok($importer,'RT::LDAPImport');
 
-my $ldap_port = 1024 + int rand(10000) + $$ % 1024;
+my $ldap_port = RT::Test->find_idle_port;
 ok( my $server = Net::LDAP::Server::Test->new( $ldap_port, auto_schema => 1 ),
     "spawned test LDAP server on port $ldap_port");
 my $ldap = Net::LDAP->new("localhost:$ldap_port");
diff --git a/t/ldapimport/group-import.t b/t/ldapimport/group-import.t
index 76db1bb20..b87bc97c0 100644
--- a/t/ldapimport/group-import.t
+++ b/t/ldapimport/group-import.t
@@ -10,7 +10,7 @@ eval { require RT::LDAPImport; require Net::LDAP::Server::Test; 1; } or do {
 my $importer = RT::LDAPImport->new;
 isa_ok($importer,'RT::LDAPImport');
 
-my $ldap_port = 1024 + int rand(10000) + $$ % 1024;
+my $ldap_port = RT::Test->find_idle_port;
 ok( my $server = Net::LDAP::Server::Test->new( $ldap_port, auto_schema => 1 ),
     "spawned test LDAP server on port $ldap_port");
 my $ldap = Net::LDAP->new("localhost:$ldap_port");
diff --git a/t/ldapimport/group-member-import.t b/t/ldapimport/group-member-import.t
index 4e0ce8f66..651f5ab6c 100644
--- a/t/ldapimport/group-member-import.t
+++ b/t/ldapimport/group-member-import.t
@@ -10,7 +10,7 @@ eval { require RT::LDAPImport; require Net::LDAP::Server::Test; 1; } or do {
 my $importer = RT::LDAPImport->new;
 isa_ok($importer,'RT::LDAPImport');
 
-my $ldap_port = 1024 + int rand(10000) + $$ % 1024;
+my $ldap_port = RT::Test->find_idle_port;
 ok( my $server = Net::LDAP::Server::Test->new( $ldap_port, auto_schema => 1 ),
     "spawned test LDAP server on port $ldap_port");
 my $ldap = Net::LDAP->new("localhost:$ldap_port");
diff --git a/t/ldapimport/group-rename.t b/t/ldapimport/group-rename.t
index 06207d448..786533ef9 100644
--- a/t/ldapimport/group-rename.t
+++ b/t/ldapimport/group-rename.t
@@ -10,7 +10,7 @@ eval { require RT::LDAPImport; require Net::LDAP::Server::Test; 1; } or do {
 my $importer = RT::LDAPImport->new;
 isa_ok($importer,'RT::LDAPImport');
 
-my $ldap_port = 1024 + int rand(10000) + $$ % 1024;
+my $ldap_port = RT::Test->find_idle_port;
 ok( my $server = Net::LDAP::Server::Test->new( $ldap_port, auto_schema => 1 ),
     "spawned test LDAP server on port $ldap_port");
 my $ldap = Net::LDAP->new("localhost:$ldap_port");
diff --git a/t/ldapimport/user-import-cfs.t b/t/ldapimport/user-import-cfs.t
index 6a157ab55..a0c723ee0 100644
--- a/t/ldapimport/user-import-cfs.t
+++ b/t/ldapimport/user-import-cfs.t
@@ -25,7 +25,7 @@ eval { require RT::LDAPImport; require Net::LDAP::Server::Test; 1; } or do {
 my $importer = RT::LDAPImport->new;
 isa_ok($importer,'RT::LDAPImport');
 
-my $ldap_port = 1024 + int rand(10000) + $$ % 1024;
+my $ldap_port = RT::Test->find_idle_port;
 ok( my $server = Net::LDAP::Server::Test->new( $ldap_port, auto_schema => 1 ),
     "spawned test LDAP server on port $ldap_port");
 
diff --git a/t/ldapimport/user-import-privileged.t b/t/ldapimport/user-import-privileged.t
index 44aeff359..4b155eea7 100644
--- a/t/ldapimport/user-import-privileged.t
+++ b/t/ldapimport/user-import-privileged.t
@@ -10,7 +10,7 @@ eval { require RT::LDAPImport; require Net::LDAP::Server::Test; 1; } or do {
 my $importer = RT::LDAPImport->new;
 isa_ok($importer,'RT::LDAPImport');
 
-my $ldap_port = 1024 + int rand(10000) + $$ % 1024;
+my $ldap_port = RT::Test->find_idle_port;
 ok( my $server = Net::LDAP::Server::Test->new( $ldap_port, auto_schema => 1 ),
     "spawned test LDAP server on port $ldap_port");
 
diff --git a/t/ldapimport/user-import.t b/t/ldapimport/user-import.t
index c404bb556..aafbd954d 100644
--- a/t/ldapimport/user-import.t
+++ b/t/ldapimport/user-import.t
@@ -10,7 +10,7 @@ eval { require RT::LDAPImport; require Net::LDAP::Server::Test; 1; } or do {
 my $importer = RT::LDAPImport->new;
 isa_ok($importer,'RT::LDAPImport');
 
-my $ldap_port = 1024 + int rand(10000) + $$ % 1024;
+my $ldap_port = RT::Test->find_idle_port;
 ok( my $server = Net::LDAP::Server::Test->new( $ldap_port, auto_schema => 1 ),
     "spawned test LDAP server on port $ldap_port");
 

commit 83262b6f4105661814ec541def865427d84212b3
Author: craig Kaiser <craig at bestpractical.com>
Date:   Wed Feb 21 12:17:20 2018 -0500

    Add Article as a Queue Default value
    
    Add an Article as a Default value for Tickets created in Queue. Render
    the content of the Article on Ticket create, in the message box.

diff --git a/lib/RT/Queue.pm b/lib/RT/Queue.pm
index 4c2f5fb62..896885423 100644
--- a/lib/RT/Queue.pm
+++ b/lib/RT/Queue.pm
@@ -1176,13 +1176,28 @@ sub SetDefaultValue {
         $old_value = $old_content->{$args{Name}};
     }
 
+    $new_value = $args{Value};
+    unless ( defined $new_value && length $new_value ) {
+        $new_value = $self->loc( '(no value)' );
+    }
+
     unless ( defined $old_value && length $old_value ) {
         $old_value = $self->loc('(no value)');
     }
 
-    $new_value = $args{Value};
-    unless ( defined $new_value && length $new_value ) {
-        $new_value = $self->loc( '(no value)' );
+    if ( $args{Name} eq 'Article' && $args{Value} ) {
+        my $article = RT::Article->new($self->CurrentUser);
+        my ($ret, $msg) = $article->LoadByCols( Name => $args{Value} );
+
+        return ($ret, $msg) unless $ret;
+        $args{Value} = $article->Id;
+    }
+
+    if ( $args{Name} eq 'Article' && $old_value =~ /^\d+?$/ ) {
+        my $article = RT::Article->new($self->CurrentUser);
+        my ($ret, $msg) = $article->Load( $old_value );
+
+        $old_value = $article->Name;
     }
 
     return 1 if $new_value eq $old_value;
diff --git a/share/html/Admin/Queues/DefaultValues.html b/share/html/Admin/Queues/DefaultValues.html
index aff93cc0b..ccb4fd5a5 100644
--- a/share/html/Admin/Queues/DefaultValues.html
+++ b/share/html/Admin/Queues/DefaultValues.html
@@ -71,6 +71,11 @@
         Grouping => 'Basics',
         InTable => 1,
     &>
+
+    <tr><td class="label"><&|/l&>Article</&>:</td>
+        <td><& /Elements/SelectArticle, QueueObj => $queue &>
+    </td></tr>
+
     </table>
     </&>
 </div>
@@ -149,7 +154,7 @@ if ( $ARGS{Reset} ) {
     }
 }
 elsif ( $ARGS{Update} ) {
-    for my $field ( qw/InitialPriority FinalPriority Starts Due/ ) {
+    for my $field ( qw/InitialPriority FinalPriority Starts Due Article/ ) {
         my ($ret, $msg) = $queue->SetDefaultValue(
             Name => $field,
             Value => $ARGS{$field},
diff --git a/share/html/Articles/Elements/IncludeArticle b/share/html/Articles/Elements/IncludeArticle
index 5307875cf..9619dbdf3 100644
--- a/share/html/Articles/Elements/IncludeArticle
+++ b/share/html/Articles/Elements/IncludeArticle
@@ -49,6 +49,8 @@
 
 my $parent_args = $m->caller_args(-1);
 
+my @articles;
+
 my $name_prefix = '';
 $name_prefix = $ARGS{'Name'} .'-'
     if $ARGS{'Name'}
@@ -78,8 +80,26 @@ foreach my $arg ( keys %$parent_args ) {
         Value => $parent_args->{$arg},
         Queue => $Queue->Id,
     );
+
     next unless $article && $article->id;
+    push (@articles, $article);
+}
+
+if ( ( !$parent_args->{id} || $parent_args->{id} eq 'new' ) && $parent_args->{'Queue'} ) {
+    my $queue_id = $parent_args->{'Queue'};
+    my $article = RT::Article->new($session{'CurrentUser'});
+    my $QueueObj = RT::Queue->new($session{'CurrentUser'});
+    my ($ret, $msg) = $QueueObj->Load( $queue_id );
+    return ($ret, $msg) unless $ret;
 
+    if ($QueueObj->DefaultValue('Article') ){
+        my ($ret, $msg) = $article->Load( $QueueObj->DefaultValue('Article') );
+        return ($ret, $msg) unless $ret;
+        push (@articles, $article);
+    }
+}
+
+foreach my $article (@articles) {
     my $formatted_article = $m->scomp('/Articles/Article/Elements/Preformatted',
         Article => $article, Ticket => $Ticket
     );
@@ -93,7 +113,6 @@ foreach my $arg ( keys %$parent_args ) {
         $formatted_article =~ s/\n/\n<br \/>/g;
     }
     $m->print($formatted_article);
-
 }
 return;
 </%INIT>
diff --git a/share/html/Articles/Elements/IncludeArticle b/share/html/Elements/SelectArticle
similarity index 56%
copy from share/html/Articles/Elements/IncludeArticle
copy to share/html/Elements/SelectArticle
index 5307875cf..cedc88057 100644
--- a/share/html/Articles/Elements/IncludeArticle
+++ b/share/html/Elements/SelectArticle
@@ -45,55 +45,38 @@
 %# those contributions and any derivatives thereof.
 %#
 %# END BPS TAGGED BLOCK }}}
-<%INIT>
-
-my $parent_args = $m->caller_args(-1);
-
-my $name_prefix = '';
-$name_prefix = $ARGS{'Name'} .'-'
-    if $ARGS{'Name'}
-    && grep rindex($_, "$ARGS{'Name'}-Articles-", 0) == 0,
-        keys %$parent_args;
-
-foreach my $arg ( keys %$parent_args ) {
-    next if $name_prefix && substr($arg, 0, length($name_prefix)) ne $name_prefix;
-
-    my $Ticket = $ARGS{Ticket};
-    if ( !$Ticket and $parent_args->{id} and $parent_args->{id} ne 'new' ) {
-        $Ticket = RT::Ticket->new($session{'CurrentUser'});
-        $Ticket->Load($parent_args->{id});
-        unless ( $Ticket->id ) {
-            $RT::Logger->error("Couldn't load ticket ". $parent_args->{id} )
-        }
-    }
+<select name='Article'>
+<option value="">-</option>
+% while (my $article = $articles->Next) {
+<option <% ( $article->Name eq $Default) ? qq[ selected="selected"] : '' |n %>
+    value="<%$article->Name%>"
+><% $article->Name %></option>
+% }
+</select>
 
-    my $Queue = RT::Queue->new($session{CurrentUser});
-    if ($Ticket && $Ticket->Id) {
-        $Queue = $Ticket->QueueObj;
-    }
+<%INIT>
+my $articles = RT::Articles->new( $session{'CurrentUser'} );
+$articles->LimitHotlistClasses;
+$articles->LimitAppliedClasses( Queue => $QueueObj );
 
-    my $article = RT::Article->new($session{'CurrentUser'});
-    $article->LoadByInclude(
-        Field => substr($arg, length($name_prefix)),
-        Value => $parent_args->{$arg},
-        Queue => $Queue->Id,
-    );
-    next unless $article && $article->id;
+my $dropdown_limit = 0;
+$m->callback( CallbackName => 'ModifyDropdownLimit', DropdownLimit => \$dropdown_limit );
 
-    my $formatted_article = $m->scomp('/Articles/Article/Elements/Preformatted',
-        Article => $article, Ticket => $Ticket
-    );
+my $Default = '';
 
-    $m->callback( Article => $article, Ticket => $Ticket, formatted_article => \$formatted_article );
+my $default_article = RT::Article->new($session{'CurrentUser'});
 
-    if (RT->Config->Get('MessageBoxRichText',  $session{'CurrentUser'})) {
-        $formatted_article =~ s/>/>/g;
-        $formatted_article =~ s/</</g;
-        $formatted_article =~ s/&/&/g;
-        $formatted_article =~ s/\n/\n<br \/>/g;
+if ( $QueueObj->DefaultValue($Name) ) {
+    my ($ret, $msg) = $default_article->Load( $QueueObj->DefaultValue($Name) );
+    if ($ret) {
+         $Default = $default_article->Name;
+    } else{
+        RT::Logger->error($msg);
     }
-    $m->print($formatted_article);
-
 }
-return;
 </%INIT>
+
+<%ARGS>
+$QueueObj
+$Name => 'Article'
+</%ARGS>

commit 6e0ff050767132e988569c616b856a8c1529812c
Author: craig Kaiser <craig at bestpractical.com>
Date:   Wed Feb 21 12:18:53 2018 -0500

    Add Autocomplete for Articles

diff --git a/share/html/Elements/SelectArticle b/share/html/Elements/SelectArticle
index cedc88057..cdac7974b 100644
--- a/share/html/Elements/SelectArticle
+++ b/share/html/Elements/SelectArticle
@@ -45,6 +45,9 @@
 %# those contributions and any derivatives thereof.
 %#
 %# END BPS TAGGED BLOCK }}}
+% if ( $autocomplete ) {
+<& "SelectArticleAutocomplete", articles => $articles, QueueObj => $QueueObj, Default => $Default &>
+% } else {
 <select name='Article'>
 <option value="">-</option>
 % while (my $article = $articles->Next) {
@@ -53,6 +56,7 @@
 ><% $article->Name %></option>
 % }
 </select>
+% }
 
 <%INIT>
 my $articles = RT::Articles->new( $session{'CurrentUser'} );
@@ -64,6 +68,8 @@ $m->callback( CallbackName => 'ModifyDropdownLimit', DropdownLimit => \$dropdown
 
 my $Default = '';
 
+my $autocomplete =  $articles->Count > $dropdown_limit ? 1 : 0;
+
 my $default_article = RT::Article->new($session{'CurrentUser'});
 
 if ( $QueueObj->DefaultValue($Name) ) {
diff --git a/share/html/Elements/SelectArticle b/share/html/Elements/SelectArticleAutocomplete
similarity index 69%
copy from share/html/Elements/SelectArticle
copy to share/html/Elements/SelectArticleAutocomplete
index cedc88057..5d4749a40 100644
--- a/share/html/Elements/SelectArticle
+++ b/share/html/Elements/SelectArticleAutocomplete
@@ -45,38 +45,9 @@
 %# those contributions and any derivatives thereof.
 %#
 %# END BPS TAGGED BLOCK }}}
-<select name='Article'>
-<option value="">-</option>
-% while (my $article = $articles->Next) {
-<option <% ( $article->Name eq $Default) ? qq[ selected="selected"] : '' |n %>
-    value="<%$article->Name%>"
-><% $article->Name %></option>
-% }
-</select>
-
-<%INIT>
-my $articles = RT::Articles->new( $session{'CurrentUser'} );
-$articles->LimitHotlistClasses;
-$articles->LimitAppliedClasses( Queue => $QueueObj );
-
-my $dropdown_limit = 0;
-$m->callback( CallbackName => 'ModifyDropdownLimit', DropdownLimit => \$dropdown_limit );
-
-my $Default = '';
-
-my $default_article = RT::Article->new($session{'CurrentUser'});
-
-if ( $QueueObj->DefaultValue($Name) ) {
-    my ($ret, $msg) = $default_article->Load( $QueueObj->DefaultValue($Name) );
-    if ($ret) {
-         $Default = $default_article->Name;
-    } else{
-        RT::Logger->error($msg);
-    }
-}
-</%INIT>
+<input id='SelectArticleAutocomplete' data-autocomplete="Articles" data-autocomplete-queue=<% $QueueObj->Id %> data-autocomplete-return="Name" name='Article' value="<% $Default %>">
 
 <%ARGS>
-$QueueObj
-$Name => 'Article'
-</%ARGS>
+$QueueObj => ""
+$Default => ""
+</%ARGS>
\ No newline at end of file
diff --git a/share/html/Elements/SelectArticle b/share/html/Helpers/Autocomplete/Articles
similarity index 63%
copy from share/html/Elements/SelectArticle
copy to share/html/Helpers/Autocomplete/Articles
index cedc88057..7fa2d5b09 100644
--- a/share/html/Elements/SelectArticle
+++ b/share/html/Helpers/Autocomplete/Articles
@@ -45,38 +45,51 @@
 %# those contributions and any derivatives thereof.
 %#
 %# END BPS TAGGED BLOCK }}}
-<select name='Article'>
-<option value="">-</option>
-% while (my $article = $articles->Next) {
-<option <% ( $article->Name eq $Default) ? qq[ selected="selected"] : '' |n %>
-    value="<%$article->Name%>"
-><% $article->Name %></option>
-% }
-</select>
-
+% $r->content_type('application/json; charset=utf-8');
+<% JSON( \@suggestions ) |n %>
+% $m->abort;
+<%ARGS>
+$term       => undef
+$max        => 10
+$op         => 'STARTSWITH'
+$right      => undef
+$return     => 'Name'
+$queue => undef
+</%ARGS>
 <%INIT>
-my $articles = RT::Articles->new( $session{'CurrentUser'} );
-$articles->LimitHotlistClasses;
-$articles->LimitAppliedClasses( Queue => $QueueObj );
+# Only allow certain return fields
+$return = 'Name'
+    unless $return =~ /^(?:id|Name)$/;
 
-my $dropdown_limit = 0;
-$m->callback( CallbackName => 'ModifyDropdownLimit', DropdownLimit => \$dropdown_limit );
+$m->abort unless defined $return
+             and defined $term
+             and length $term;
 
-my $Default = '';
+# Sanity check the operator
+$op = 'STARTSWITH' unless $op =~ /^(?:LIKE|(?:START|END)SWITH|=|!=)$/i;
 
-my $default_article = RT::Article->new($session{'CurrentUser'});
+$m->callback( CallbackName => 'ModifyMaxResults', max => \$max );
 
-if ( $QueueObj->DefaultValue($Name) ) {
-    my ($ret, $msg) = $default_article->Load( $QueueObj->DefaultValue($Name) );
-    if ($ret) {
-         $Default = $default_article->Name;
-    } else{
-        RT::Logger->error($msg);
-    }
+my $articles = RT::Articles->new( $session{CurrentUser} );
+$articles->LimitHotlistClasses;
+if( $queue ) {
+    $articles->LimitAppliedClasses( Queue => $queue );
 }
-</%INIT>
 
-<%ARGS>
-$QueueObj
-$Name => 'Article'
-</%ARGS>
+$articles->RowsPerPage( $max );
+$articles->Limit(
+    FIELD           => 'Name',
+    OPERATOR        => $op,
+    VALUE           => $term,
+    ENTRYAGGREGATOR => 'OR',
+    CASESENSITIVE   => 0,
+);
+
+my @suggestions;
+while (my $a = $articles->Next) {
+    next if $right and not $a->CurrentUserHasRight($right);
+    my $value = $a->$return;
+    push @suggestions, { label => $a->Name, value => $value };
+    $m->callback( CallbackName => "ModifySuggestion", suggestions => @suggestions, label => $a );
+}
+</%INIT>
\ No newline at end of file
diff --git a/share/static/js/autocomplete.js b/share/static/js/autocomplete.js
index cd8ab2b0d..c4362edb1 100644
--- a/share/static/js/autocomplete.js
+++ b/share/static/js/autocomplete.js
@@ -5,7 +5,8 @@ window.RT.Autocomplete.Classes = {
     Users: 'user',
     Groups: 'group',
     Tickets: 'tickets',
-    Queues: 'queues'
+    Queues: 'queues',
+    Articles: 'articles'
 };
 
 window.RT.Autocomplete.bind = function(from) {
@@ -84,6 +85,9 @@ window.RT.Autocomplete.bind = function(from) {
             };
         }
 
+        var queue = input.attr("data-autocomplete-queue");
+        if (queue) queryargs.push("queue=" + queue);
+
         var checkRight = input.attr("data-autocomplete-checkright");
         if (checkRight) queryargs.push("right=" + checkRight);
 

commit 3c27b7ffb931c1b73da0edd2c7d463e7a9e438ff
Author: craig Kaiser <craig at bestpractical.com>
Date:   Wed Feb 21 12:19:05 2018 -0500

    Add tests for Default Article content on create

diff --git a/t/web/ticket-create-utf8.t b/t/web/ticket-create-utf8.t
index ebb2d5eab..76a7360b7 100644
--- a/t/web/ticket-create-utf8.t
+++ b/t/web/ticket-create-utf8.t
@@ -2,7 +2,7 @@
 use strict;
 use warnings;
 
-use RT::Test tests => 43;
+use RT::Test tests => 49;
 
 my $ru_test = "\x{442}\x{435}\x{441}\x{442}";
 my $ru_support = "\x{43f}\x{43e}\x{434}\x{434}\x{435}\x{440}\x{436}\x{43a}\x{430}";
@@ -86,3 +86,23 @@ foreach my $test_str ( $ru_test, $l1_test ) {
     }
 }
 
+my $article = RT::Article->new($RT::SystemUser);
+my ( $id, $msg ) = $article->Create(
+    Class   => 'General',
+    Name    => 'My Article',
+    'CustomField-Content' => 'My Article Test Content',
+);
+ok( $id, $msg );
+(my $ret, $msg) = $article->Load(1);
+ok ($ret, $msg);
+
+my $queue = RT::Queue->new(RT->SystemUser);
+$queue->Load('General');
+ok( $queue, 'Loaded General Queue' );
+($ret, $msg) = $queue->SetDefaultValue( Name => 'Article', Value => $article->Id);
+ok( $ret, $msg );
+
+ok $m->login(root => 'password'), "logged in";
+$m->goto_create_ticket('General');
+$m->scraped_id_is('Content', '#1: My Article <br />-------------- <br />Content: <br />------- <br />My Article Test Content <br />');
+

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


More information about the rt-commit mailing list