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

Craig Kaiser craig at bestpractical.com
Thu Jan 25 17:07:01 EST 2018


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

- Log -----------------------------------------------------------------
commit 578be5b016295365ee2214184fd55af70eceaee2
Author: Craig Kaiser <craig at bestpractical.com>
Date:   Thu Jan 25 17:04:49 2018 -0500

     Include Article on Ticket create per Queue
    
    Can add a default Article to Queues. Where the content of the Article
    will be added to each Ticket created in that Queue, on create. The Article to be
    included per Queue can be set in the web UI page for modify Queue.

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..6b4321c00 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&>Article Included</&>:</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 9ee482f4ea7b61904a42180c1ee9c49005f298d6
Author: Craig Kaiser <craig at bestpractical.com>
Date:   Thu Jan 25 17:05:16 2018 -0500

    Add Default Article content if applied to Queue
    
    If the Queue that the Ticket is being created on has a default Article
    set, then the content for the article will be rendered on the create
    page.

diff --git a/share/html/Ticket/Create.html b/share/html/Ticket/Create.html
index e1b347d7a..179935cc4 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 ($validArticles{$ObjectCustomFieldValue}) { $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 689786899f1d50a8485e446772991f5fd706aa69
Author: Craig Kaiser <craig at bestpractical.com>
Date:   Thu Jan 25 17:06:29 2018 -0500

    Add test for including Article content for Queue
    
    Add a test to place an Article on a Queue and ensure that the content of
    the Article is rendered to Create.html.

diff --git a/t/ticket/include-article-by-queue.t b/t/ticket/include-article-by-queue.t
new file mode 100644
index 000000000..6e2c4aa29
--- /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->SetArticleIncluded($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