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

Craig Kaiser craig at bestpractical.com
Tue Jan 30 14:16:49 EST 2018


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

- Log -----------------------------------------------------------------
commit fcdc384510865950e0ff3623a2228d28a394719d
Author: Craig Kaiser <craig at bestpractical.com>
Date:   Mon Jan 29 12:16:22 2018 -0500

    Add Default Article option for Queues
    
    Currently there is not a simple way to apply boilerplate text to
    tickets automatically. By selecting a Default Article for a Queue, any
    ticket created in that Queue will automatically have the Article content
    added to the Ticket content.

diff --git a/lib/RT/Queue.pm b/lib/RT/Queue.pm
index 4c2f5fb62..d8570de7b 100644
--- a/lib/RT/Queue.pm
+++ b/lib/RT/Queue.pm
@@ -155,6 +155,7 @@ sub Create {
         CorrespondAddress => '',
         CommentAddress    => '',
         Lifecycle         => 'default',
+        DefaultArticle    => undef,
         SubjectTag        => undef,
         Sign              => undef,
         SignAuto          => undef,
@@ -198,8 +199,7 @@ sub Create {
         $self->_NewTransaction( Type => "Create" );
     }
     $RT::Handle->Commit;
-
-    for my $attr (qw/Sign SignAuto Encrypt SLA/) {
+    for my $attr (qw/Sign SignAuto Encrypt SLA DefaultArticle/) {
         next unless defined $args{$attr};
         my $set = "Set" . $attr;
         my ($status, $msg) = $self->$set( $args{$attr} );
@@ -212,7 +212,33 @@ sub Create {
     return ( $id, $self->loc("Queue created") );
 }
 
+sub DefaultArticle {
+    my $self = shift;
+
+    my $attr = $self->FirstAttribute('DefaultArticle') ;
+    my $content = $attr ? $attr->Content : undef;
+    return $content;
+}
+
+sub SetDefaultArticle{
+    my $self = shift;
+    my $value = shift;
+
+    return (0, $self->loc("No permission to set Queue attributes"))
+        unless $self->CurrentUserHasRight('AdminQueue');
+
+    my $myArticle = RT::Article->new(RT->SystemUser);
+    $myArticle->LoadByCol( id => $value );
+
+    my ($status, $msg) = $self->SetAttribute(
+        Name        => 'DefaultArticle',
+        Content     => $value,
+    );
+    return ($status, $msg) unless $status;
 
+    if ($value){ return (1, $self->loc("Default Article updated to [_1]", $myArticle->Name)); }
+    return (1, $self->loc("Default Article removed"));
+}
 
 sub Delete {
     my $self = shift;
diff --git a/share/html/Admin/Queues/Modify.html b/share/html/Admin/Queues/Modify.html
index 75b0e658a..c476eda59 100644
--- a/share/html/Admin/Queues/Modify.html
+++ b/share/html/Admin/Queues/Modify.html
@@ -80,6 +80,12 @@
 % }
 </td></tr>
 
+
+
+<tr><td align="right"><&|/l&>Default Article</&>:</td><td colspan="3">
+<& /Elements/ArticleSelect, %ARGS &>
+</td></tr>
+
 <tr><td align="right"><&|/l&>Subject Tag</&>:</td>
 <td colspan="3"><input name="SubjectTag" value="<% $ARGS{'SubjectTag'} || ($Create ? "" : $QueueObj->SubjectTag || '' ) %>" size="60" /></td>
 </tr>
@@ -169,9 +175,10 @@ checked="checked"
 
 <%INIT>
 my ($title, @results, @no_redirect_results, $Disabled, $EnabledChecked);
-my $QueueObj = RT::Queue->new( $session{'CurrentUser'} );
+$QueueObj = RT::Queue->new( $session{'CurrentUser'} );
 $QueueObj->Load( $id ) if !$id || $id eq 'new';
 
+$ARGS{QueueObj} = $QueueObj;
 $EnabledChecked = 'checked="checked"';
 
 unless ($Create) {
@@ -189,7 +196,7 @@ unless ($Create) {
 if ( $QueueObj->Id ) {
     $title = loc('Configuration for queue [_1]', $QueueObj->Name );
     my @attribs= qw(Description CorrespondAddress CommentAddress Name SortOrder
-        Sign SignAuto Encrypt Lifecycle SubjectTag SLADisabled Disabled);
+        Sign SignAuto Encrypt Lifecycle DefaultArticle SubjectTag SLADisabled Disabled);
 
     # we're asking about enabled on the web page but really care about disabled
     if ( $SetEnabled ) {
@@ -209,13 +216,11 @@ if ( $QueueObj->Id ) {
         AttributesRef => \@attribs,
         ARGSRef => \%ARGS,
     );
-
     push @results, UpdateRecordObject(
         AttributesRef => \@attribs,
         Object => $QueueObj,
         ARGSRef => \%ARGS
     );
-
     $Disabled = $ARGS{'Disabled'} = $Enabled? 0: 1;
 
     $EnabledChecked = "" if $QueueObj->Disabled;
@@ -256,6 +261,7 @@ push @results, @no_redirect_results;
 
 
 <%ARGS>
+$QueueObj => undef
 $id => undef
 $result => undef
 $Name => undef
@@ -264,6 +270,7 @@ $Description => undef
 $CorrespondAddress => undef
 $CommentAddress => undef
 $SetSLAEnabled => undef
+$DefaultArticle => undef
 $SetEnabled => undef
 $SetCrypt => undef
 $SLAEnabled => undef
diff --git a/share/html/Elements/ArticleSelect b/share/html/Elements/ArticleSelect
new file mode 100644
index 000000000..25a7e2964
--- /dev/null
+++ b/share/html/Elements/ArticleSelect
@@ -0,0 +1,67 @@
+%# BEGIN BPS TAGGED BLOCK {{{
+%#
+%# COPYRIGHT:
+%#
+%# This software is Copyright (c) 1996-2017 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.
+%#
+
+<& "SelectArticle$Widget", %ARGS &>
+
+<%INIT>
+
+my $hotlist = RT::Articles->new( $session{'CurrentUser'} );
+$hotlist->LimitHotlistClasses;
+$hotlist->LimitAppliedClasses( Queue => $QueueObj );
+$ARGS{'hotlist'} = $hotlist;
+
+my $dropdown_limit = 50;
+$m->callback( CallbackName => 'ModifyDropdownLimit', DropdownLimit => \$dropdown_limit );
+
+my $dropdown = 1 unless ( $hotlist->Count > $dropdown_limit);
+my $Widget = $dropdown ? 'Dropdown' : 'Search';
+
+</%INIT>
+
+<%ARGS>
+$QueueObj => undef
+</%ARGS>
diff --git a/share/html/Elements/SelectArticleDropdown b/share/html/Elements/SelectArticleDropdown
new file mode 100644
index 000000000..0e26ac6ca
--- /dev/null
+++ b/share/html/Elements/SelectArticleDropdown
@@ -0,0 +1,68 @@
+%# BEGIN BPS TAGGED BLOCK {{{
+%#
+%# COPYRIGHT:
+%#
+%# This software is Copyright (c) 1996-2017 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 }}}
+
+<select name='DefaultArticle'>
+<option value="undef" selected><&|/l&><% $myArticle->Name? $myArticle->Name: '-'%></&></option>
+% if ( $QueueObj && $QueueObj->DefaultArticle ) {
+<option value="">-</option>
+% }
+% while (my $article = $hotlist->Next) {
+% unless ( !$article && $article->Id eq $myArticle->Id) {
+<option value="<% $article->Id %>"><% $article->Name|| loc('(no name)')%><%$article->Summary || ''%></option>
+% }
+% }
+</select>
+
+<%INIT>
+my $myArticle = RT::Article->new(RT->SystemUser);
+$myArticle->LoadByCol( id => $QueueObj->DefaultArticle );
+</%INIT>
+<%ARGS>
+$QueueObj => undef
+$hotlist => undef
+</%ARGS>
diff --git a/share/html/Elements/SelectArticleSearch b/share/html/Elements/SelectArticleSearch
new file mode 100644
index 000000000..30682e4c4
--- /dev/null
+++ b/share/html/Elements/SelectArticleSearch
@@ -0,0 +1,56 @@
+%# BEGIN BPS TAGGED BLOCK {{{
+%#
+%# COPYRIGHT:
+%#
+%# This software is Copyright (c) 1996-2017 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 }}}
+
+<input name='DefaultArticle' value="" selected placeholder="<% $myArticle? $myArticle->Name: ''%>">
+<%INIT>
+my $myArticle = RT::Article->new(SystemUser);
+$myArticle->LoadByCol( id => $QueueObj->DefaultArticle );
+</%INIT>
+<%ARGS>
+$QueueObj => undef
+</%ARGS>
\ No newline at end of file

commit 430984079afb25bdf1b0405157cd3f57968335e0
Author: Craig Kaiser <craig at bestpractical.com>
Date:   Mon Jan 29 12:18:53 2018 -0500

    Make default Article content show on Ticket create
    
    It is important that, if a default Article is selected for a Queue. Then
    on Create.html, the content of the Article should be shown for any
    Ticket created in the Queue.

diff --git a/share/html/Ticket/Create.html b/share/html/Ticket/Create.html
index 26dc216b0..4fda1a054 100644
--- a/share/html/Ticket/Create.html
+++ b/share/html/Ticket/Create.html
@@ -512,6 +512,21 @@ if ((!exists $ARGS{'AddMoreAttach'}) and (defined($ARGS{'id'}) and $ARGS{'id'} e
         $m->abort();
     }
 }
+
+if ( $QueueObj->DefaultArticle ) {
+    my $myArticles = RT::Articles->new(RT->SystemUser);
+    $myArticles->LimitCustomField( OPERATOR => 'NOT LIKE', VALUE => 'undef' );
+
+    my %validArticles;
+    while (my $articles = $myArticles->Next){
+        $validArticles{$articles->Id}++;
+    }
+
+    my $ObjectCustomFieldValue = RT::ObjectCustomFieldValue->new(RT->SystemUser);
+    $ObjectCustomFieldValue->LoadByCols(ObjectId => $QueueObj->DefaultArticle);
+    if ($ObjectCustomFieldValue->id and $validArticles{$ObjectCustomFieldValue->id}) { $ARGS{Content} = $ObjectCustomFieldValue->Content(); }
+}
+
 PageMenu->child( basics => raw_html =>  q[<a href="#basics" onclick="return switchVisibility('Ticket-Create-basics','Ticket-Create-details');">] . loc('Basics') . q[</a>]);
 PageMenu->child( details => raw_html =>  q[<a href="#details" onclick="return switchVisibility('Ticket-Create-details','Ticket-Create-basics');">] . loc('Details') . q[</a>]);
 </%INIT>

commit 907fb9f52a75202a4182d5133fd6b79afe00d318
Author: Craig Kaiser <craig at bestpractical.com>
Date:   Mon Jan 29 12:20:47 2018 -0500

    Add test for default Article content on create.html
    
    Test to ensure that the default Articles content is rendered on
    Create.html for Tickets in that Queue.

diff --git a/t/ticket/include-article-by-queue.t b/t/ticket/include-article-by-queue.t
new file mode 100644
index 000000000..449ad3915
--- /dev/null
+++ b/t/ticket/include-article-by-queue.t
@@ -0,0 +1,30 @@
+use strict;
+use warnings;
+
+use RT::Test tests => undef;
+
+my $m = RT::Test->started_ok;
+my $url = $m->rt_base_url;
+diag('Started server at ' . $url);
+
+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->SetDefaultArticle($article->id);
+ok( $ret, $msg );
+
+ok $m->login(root => 'password'), "logged in";
+$m->goto_create_ticket('General');
+$m->scraped_id_is('Content', 'My Article Test Content');
+
+done_testing;

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


More information about the rt-commit mailing list