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

Craig Kaiser craig at bestpractical.com
Fri Jan 12 08:41:36 EST 2018


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

- Log -----------------------------------------------------------------
commit b78185488e6776d52c71fbe34a2ca8e9e43f9453
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 modifying Queue or
    in RT_SiteConfig.

diff --git a/lib/RT/Queue.pm b/lib/RT/Queue.pm
index 4c2f5fb62..bd2308fe6 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,34 @@ 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 $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;
@@ -906,6 +933,21 @@ 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.
+Can also set the article to be included in RT_SiteConfig.pm:
+    Set(%ArticleIncluded,
+        'MyQueue'   =>  'MyArticle',
+        'General'   =>  'General Info'
+    );
+
 =head2 SubjectTag
 
 Returns the current value of SubjectTag. 
diff --git a/lib/RT/Ticket.pm b/lib/RT/Ticket.pm
index 08169fb9c..a51adbd56 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,20 @@ sub Create {
         $args{'Status'} = $cycle->DefaultOnCreate;
     }
 
+    my %config = RT->Config->Get('ArticleIncluded') unless ( !RT->Config->Get('ArticleIncluded') );
+    if ( $QueueObj->ArticleIncluded || exists($config{$QueueObj->Name})) {
+        my $MyArticle = RT::Article->new(RT->SystemUser);
+        if ( $MyArticle->ValidateName($config{$QueueObj->Name}) and $config{$QueueObj->Name} ) {
+            return (0, 0, "Invalid Article Name: $config{$QueueObj->Name}, check your RT_SiteConfig.pm");
+        }
+        my $ObjectCustomFieldValue = RT::ObjectCustomFieldValue->new(RT->SystemUser);
+        my $MIMEObj = $args{'MIMEObj'};
+        $MyArticle->LoadByCols(Name => $QueueObj->ArticleIncluded ? $QueueObj->ArticleIncluded : $config{$QueueObj->Name} );
+        $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,
@@ -688,6 +703,14 @@ sub AddWatcher {
     }
 }
 
+=head2 ArticleIncluded
+
+Provide a hash %ArticleIncluded where the Queue and the article name are specified.
+    Set(%ArticleIncluded,
+        General => MyArticle,
+    );
+
+=cut
 
 =head2 DeleteWatcher
 
diff --git a/share/html/Admin/Queues/Modify.html b/share/html/Admin/Queues/Modify.html
index 75b0e658a..74b0feb3f 100644
--- a/share/html/Admin/Queues/Modify.html
+++ b/share/html/Admin/Queues/Modify.html
@@ -80,6 +80,16 @@
 % }
 </td></tr>
 
+<td><&|/l&>Include Article:</&></td>
+<td><select name="ArticleIncluded">
+    <option value="<% $ARGS{'ArticleInclduded'} || ($Create ? "" : $QueueObj->ArticleIncluded || '') %>"><% $ARGS{'ArticleIncluded'} || ($QueueObj->ArticleIncluded || '-') %></option>
+<option value="">-</option>
+% while (my $article = $hotlist->Next) {
+<option value="<% $article->Name %>"><% $article->Name %></option>
+% }
+</select>
+</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>
@@ -172,6 +182,10 @@ my ($title, @results, @no_redirect_results, $Disabled, $EnabledChecked);
 my $QueueObj = RT::Queue->new( $session{'CurrentUser'} );
 $QueueObj->Load( $id ) if !$id || $id eq 'new';
 
+my $hotlist = RT::Articles->new( $session{'CurrentUser'});
+$hotlist->LimitHotlistClasses;
+$hotlist->LimitAppliedClasses ( Queue => $QueueObj );
+
 $EnabledChecked = 'checked="checked"';
 
 unless ($Create) {
@@ -185,11 +199,10 @@ unless ($Create) {
         $QueueObj->Load($id) || $QueueObj->Load($Name) || Abort(loc("Couldn't load queue '[_1]'", $Name));
     }
 }
-
 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 ) {
@@ -215,7 +228,6 @@ if ( $QueueObj->Id ) {
         Object => $QueueObj,
         ARGSRef => \%ARGS
     );
-
     $Disabled = $ARGS{'Disabled'} = $Enabled? 0: 1;
 
     $EnabledChecked = "" if $QueueObj->Disabled;
@@ -264,6 +276,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