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

Craig Kaiser craig at bestpractical.com
Thu Dec 28 11:29:06 EST 2017


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

- Log -----------------------------------------------------------------
commit 3c24b415be32a4f4b7f9518182130fc5009127f2
Author: Craig Kaiser <craig at bestpractical.com>
Date:   Thu Dec 28 11:26:41 2017 -0500

    Include Article on ticket create, based on queue
    
    Add functionality to include an Articles content automatically on Ticket create
    for the specified Queue. This feature can be set on Queue create and
    Queue modify.

diff --git a/lib/RT/Queue.pm b/lib/RT/Queue.pm
index 4c2f5fb..f1b457f 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,28 @@ 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;
+
+    return ( 0, $self->loc('Permission Denied') )
+        unless $self->CurrentUserHasRight('AdminQueue');
 
+    my ($status, $msg) = $self->SetAttribute(
+        Name        => 'ArticleIncluded',
+        Description => 'Include Article on ticket create, for Queue.',
+        Content     => $value,
+    );
+    return ($status, $msg) unless $status;
+}
 
 sub Delete {
     my $self = shift;
@@ -906,6 +927,16 @@ Returns (1, 'Status message') on success and (0, 'Error Message') on failure.
 
 =cut
 
+=head2 ArticleIncluded
+
+The article name to be included on create of any ticket created in the queue.
+The ID value of the article will be loaded from the name, and used to get the article content in Ticket.pm.
+
+
+==head2 SetArticleIncluded
+
+Takes a name value and sets the ArticleIncluded attr for the queue to that name.
+
 =head2 SubjectTag
 
 Returns the current value of SubjectTag. 
diff --git a/lib/RT/Ticket.pm b/lib/RT/Ticket.pm
index 08169fb..418a2bb 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,
         @_
     );
 
@@ -280,6 +281,16 @@ sub Create {
         $args{'Status'} = $cycle->DefaultOnCreate;
     }
 
+    if ( $QueueObj->ArticleIncluded ) {
+        my $MyArticle = RT::Article->new(RT->SystemUser);
+        my $ObjectCustomFieldValue = RT::ObjectCustomFieldValue->new(RT->SystemUser);
+        my $MIMEObj = $args{'MIMEObj'};
+        $MyArticle->LoadByCols(Name => $QueueObj->ArticleIncluded);
+        $ObjectCustomFieldValue->LoadByCols(ObjectId => $MyArticle->id);
+        my $ArticleContent = MIME::Entity->build( Type => "text/plain" , Data => $ObjectCustomFieldValue->Content() );
+        $MIMEObj->add_part($ArticleContent);
+    }
+
     $args{'Status'} = lc $args{'Status'};
     unless ( $cycle->IsValid( $args{'Status'} ) ) {
         return ( 0, 0,
diff --git a/share/html/Admin/Queues/Modify.html b/share/html/Admin/Queues/Modify.html
index 75b0e65..979e599 100644
--- a/share/html/Admin/Queues/Modify.html
+++ b/share/html/Admin/Queues/Modify.html
@@ -80,6 +80,10 @@
 % }
 </td></tr>
 
+<tr><td align="right"><&|/l&>Include Article</&>:</td>
+  <td colspan="3"><input name="ArticleIncluded" value="<% $ARGS{'ArticleIncluded'} || ($Create ? "" : $QueueObj->ArticleIncluded || '' ) %>" size="20"/></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>
@@ -189,7 +193,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 ) {
@@ -264,6 +268,7 @@ $Description => undef
 $CorrespondAddress => undef
 $CommentAddress => undef
 $SetSLAEnabled => undef
+$ArticleIncluded => undef
 $SetEnabled => undef
 $SetCrypt => undef
 $SLAEnabled => undef

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


More information about the rt-commit mailing list