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

Craig Kaiser craig at bestpractical.com
Tue Jan 16 14:39:55 EST 2018


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

- Log -----------------------------------------------------------------
commit 2dc903d4fbf4e382e8123a6eeee73225300acf9c
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..5a40bd2b8 100644
--- a/share/html/Ticket/Create.html
+++ b/share/html/Ticket/Create.html
@@ -512,6 +512,15 @@ if ((!exists $ARGS{'AddMoreAttach'}) and (defined($ARGS{'id'}) and $ARGS{'id'} e
         $m->abort();
     }
 }
+
+if ( $QueueObj->ArticleIncluded ) {
+    my $MyArticle = RT::Article->new(RT->SystemUser);
+    my $ObjectCustomFieldValue = RT::ObjectCustomFieldValue->new(RT->SystemUser);
+    $MyArticle->LoadByCols(name => $QueueObj->ArticleIncluded );
+    $ObjectCustomFieldValue->LoadByCols(ObjectId => $MyArticle->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>

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


More information about the rt-commit mailing list