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

Craig Kaiser craig at bestpractical.com
Fri Jan 19 17:38:39 EST 2018


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

- Log -----------------------------------------------------------------
commit 350a53162a6e256fa4c17e5bc956f82afd3a1dec
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..dea3cce73 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,42 @@ 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;
+    return (0, $self->loc("Article Included updated to [_1]", $value));
+}
 
 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..6e2ba792b 100644
--- a/share/html/Admin/Queues/Modify.html
+++ b/share/html/Admin/Queues/Modify.html
@@ -80,6 +80,13 @@
 % }
 </td></tr>
 
+
+
+<tr><td class='label' valign="right"><&|/l&>Article Included</&>:</td>
+<td class="messagebox-container">
+<& /Articles/Elements/BeforeMessageBox, %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 +176,22 @@ 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;
+
+my @ArticlesIncluded = grep {/Articles-Include-Article-(.+)/} keys %ARGS;
+
+foreach(@ArticlesIncluded){
+    if( $ARGS{$_} eq 'Go' && length $ARGS{$_} ){
+        $_ =~ /Articles-Include-Article-(.+)/;
+        $ARGS{'ArticleIncluded'} = $1;
+    }elsif ( $ARGS{$_} ){
+        $ARGS{'ArticleIncluded'} = $ARGS{$_};
+    }
+}
+
 $EnabledChecked = 'checked="checked"';
 
 unless ($Create) {
@@ -189,7 +209,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 +229,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 +274,7 @@ push @results, @no_redirect_results;
 
 
 <%ARGS>
+$QueueObj => undef
 $id => undef
 $result => undef
 $Name => undef
@@ -264,6 +283,7 @@ $Description => undef
 $CorrespondAddress => undef
 $CommentAddress => undef
 $SetSLAEnabled => undef
+$ArticleIncluded => undef
 $SetEnabled => undef
 $SetCrypt => undef
 $SLAEnabled => undef
diff --git a/share/html/Articles/Elements/BeforeMessageBox b/share/html/Articles/Elements/BeforeMessageBox
index 972688d19..6708058db 100644
--- a/share/html/Articles/Elements/BeforeMessageBox
+++ b/share/html/Articles/Elements/BeforeMessageBox
@@ -65,9 +65,17 @@
 <tr>
 <td><&|/l&>Select an Article to include</&></td>
 <td><select name="<% $name_prefix %>Articles-Include-Article-Named-Hotlist" onchange="this.form.submit()">
-<option value="" selected><&|/l&>-</&></option>
+% my $QueueObj = $ARGS{QueueObj};
+<option value="" selected><&|/l&><% $QueueObj? $QueueObj->ArticleIncluded? $QueueObj->ArticleIncluded: '-':'-'%></&></option>
+% if ( $QueueObj && $QueueObj->ArticleIncluded ) {
+<option value="undef">-</option>
+% }
 % while (my $article = $hotlist->Next) {
-<option value="<% $article->Id %>"><%$article->Name|| loc('(no name)')%>: <%$article->Summary || ''%></option>
+% if( $QueueObj ) { unless( $article->Name eq $QueueObj->ArticleIncluded ){
+<option value="<% $article->Id %>"><% $article->Name|| loc('(no name)')%>: <%$article->Summary || ''%></option>
+% } }else{
+<option value="<% $article->Id %>"><% $article->Name|| loc('(no name)')%>: <%$article->Summary || ''%></option>
+% }
 % }
 </select>
 </td>
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 a463f51276c4fad552ddfea7a5e8a29748e99d23
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..9aba4ccfd
--- /dev/null
+++ b/t/ticket/include-article-by-queue.t
@@ -0,0 +1,31 @@
+use strict;
+use warnings;
+
+use RT::Test tests => undef;
+use Data::Printer;
+
+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