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

Craig Kaiser craig at bestpractical.com
Mon Jan 22 15:28:30 EST 2018


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

- Log -----------------------------------------------------------------
commit f6d27cb7585e14f3e9eb02a4a704b37e872f914c
Author: Craig Kaiser <craig at bestpractical.com>
Date:   Thu Dec 28 11:26:41 2017 -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..10ba19926 100644
--- a/lib/RT/Queue.pm
+++ b/lib/RT/Queue.pm
@@ -155,6 +155,7 @@ sub Create {
         CorrespondAddress => '',
         CommentAddress    => '',
         Lifecycle         => 'default',
+        ArticleIncluded   => 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 ArticleIncluded/) {
         next unless defined $args{$attr};
         my $set = "Set" . $attr;
         my ($status, $msg) = $self->$set( $args{$attr} );
@@ -212,7 +212,43 @@ sub Create {
     return ( $id, $self->loc("Queue created") );
 }
 
+sub ArticleIncluded {
+    my $self = shift;
+    my $value = shift;
+
+    my $attr = $self->FirstAttribute('ArticleIncluded') or return 0;
+    return $attr->Content;
+}
+
+sub SetArticleIncluded {
+    my $self = shift;
+    my $value = shift;
+
+    my $MyArticle = RT::Article->new(RT->SystemUser);
+    unless ( $value =~ /^\d+$/ ) {
+        $MyArticle->LoadByCols( name => $value)
+    }else {
+        $MyArticle->LoadByCols( id => $value)
+    }
+    $value = $MyArticle->Name;
 
+    return ( 0, $self->loc('Permission Denied') )
+        unless $self->CurrentUserHasRight('AdminQueue');
+
+        $MyArticle = RT::Article->new(RT->SystemUser);
+        if ( $MyArticle->ValidateName($value) and $value ){
+            return (0, $self->loc("Invalid Article Name [_1]", $value));
+    }
+
+    my ($status, $msg) = $self->SetAttribute(
+        Name        => 'ArticleIncluded',
+        Description => 'Include Article on ticket create, for Queue.',
+        Content     => $value,
+    );
+    return ($status, $msg) unless $status;
+    if ($value){ return (1, $self->loc("Article Included updated to [_1]", $value)); }
+    return (1, $self->loc("Article Included removed"));
+}
 
 sub Delete {
     my $self = shift;
diff --git a/lib/RT/Ticket.pm b/lib/RT/Ticket.pm
index 08169fb9c..66ddada35 100644
--- a/lib/RT/Ticket.pm
+++ b/lib/RT/Ticket.pm
@@ -239,6 +239,7 @@ sub Create {
         SLA                => undef,
         MIMEObj            => undef,
         _RecordTransaction => 1,
+        ArticleIncluded    => undef,
         @_
     );
 
@@ -279,7 +280,6 @@ sub Create {
     unless ( defined $args{'Status'} && length $args{'Status'} ) {
         $args{'Status'} = $cycle->DefaultOnCreate;
     }
-
     $args{'Status'} = lc $args{'Status'};
     unless ( $cycle->IsValid( $args{'Status'} ) ) {
         return ( 0, 0,
@@ -688,7 +688,6 @@ sub AddWatcher {
     }
 }
 
-
 =head2 DeleteWatcher
 
 Applies access control checking, then calls
diff --git a/share/html/Admin/Queues/Modify.html b/share/html/Admin/Queues/Modify.html
index 75b0e658a..545ec3ea4 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 ArticleIncluded 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
+$ArticleIncluded => 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..464adfb0b
--- /dev/null
+++ b/share/html/Elements/ArticleSelect
@@ -0,0 +1,72 @@
+%# 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 $count = 0;
+while (my $article = $hotlist->Next){
+    $count +=1;
+}
+
+my $dropdown_limit = 50;
+$m->callback( CallbackName => 'ModifyDropdownLimit', DropdownLimit => \$dropdown_limit );
+
+my $dropdown = 1 unless ( $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..52c217458
--- /dev/null
+++ b/share/html/Elements/SelectArticleDropdown
@@ -0,0 +1,66 @@
+%# 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='ArticleIncluded'>
+<option value="undef" selected><&|/l&><% $QueueObj? $QueueObj->ArticleIncluded? $QueueObj->ArticleIncluded: '-':'-'%></&></option>
+% if ( $QueueObj && $QueueObj->ArticleIncluded ) {
+<option value="">-</option>
+% }
+% while (my $article = $hotlist->Next) {
+% unless ($article->Name eq $QueueObj->ArticleIncluded) {
+<option value="<% $article->Id %>"><% $article->Name|| loc('(no name)')%><%$article->Summary || ''%></option>
+% }
+% }
+</select>
+
+<%ARGS>
+$id => undef
+$QueueObj => undef
+$hotlist => undef
+$ArticleIncluded => undef
+</%ARGS>
diff --git a/share/html/Elements/SelectArticleSearch b/share/html/Elements/SelectArticleSearch
new file mode 100644
index 000000000..0171f1438
--- /dev/null
+++ b/share/html/Elements/SelectArticleSearch
@@ -0,0 +1,55 @@
+%# 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 value="" selected placeholder="<% $QueueObj->ArticleIncluded? $QueueObj->ArticleIncluded: ''%>">
+<%ARGS>
+$id => undef
+$QueueObj => undef
+$hotlist => undef
+$ArticleIncluded => undef
+</%ARGS>
\ No newline at end of file
diff --git a/share/html/Ticket/Create.html b/share/html/Ticket/Create.html
index 26dc216b0..815203b1c 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->ArticleIncluded ) {
+    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 $myArticle = RT::Article->new(RT->SystemUser);
+    my $ObjectCustomFieldValue = RT::ObjectCustomFieldValue->new(RT->SystemUser);
+    $myArticle->LoadByCols(name => $QueueObj->ArticleIncluded );
+    $ObjectCustomFieldValue->LoadByCols(ObjectId => $myArticle->id);
+    if ($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 9592a5675a5a025b4bdcb9093338d18c27711c2e
Author: Craig Kaiser <craig at bestpractical.com>
Date:   Fri Jan 19 16:17:34 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