[Rt-commit] rtir branch, 4.2/configurable-linked-queue-portlets, created. 4.0.1rc1-114-g6da13e7d

Blaine Motsinger blaine at bestpractical.com
Fri Mar 20 19:22:01 EDT 2020


The branch, 4.2/configurable-linked-queue-portlets has been created
        at  6da13e7d8c36ddd036162467f1ffe544319040e0 (commit)

- Log -----------------------------------------------------------------
commit 90996de4204b83eaf693584458d23786c3a713d5
Author: Maureen E. Mirville <maureen at bestpractical.com>
Date:   Fri Nov 9 13:22:22 2018 -0500

    Update RTIR Incidents to use a callback for displaying queue portlets
    
    RT was updated so users can now add portlets by queue on any ticket,
    like the RTIR Incident page that displays linked Incident Reports,
    Investigations, and Countermeasures. With this change to RT, RTIR code
    was updated accordingly.

diff --git a/MANIFEST b/MANIFEST
index e4ac3361..5f96ce7b 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -114,7 +114,6 @@ html/RTIR/Incident/Create.html
 html/RTIR/Incident/Display.html
 html/RTIR/Incident/Elements/Create
 html/RTIR/Incident/Elements/ReplyForm
-html/RTIR/Incident/Elements/ShowChildren
 html/RTIR/Incident/Reply/index.html
 html/RTIR/Incident/Reply/Refine.html
 html/RTIR/Incident/Split.html
diff --git a/etc/RTIR_Config.pm b/etc/RTIR_Config.pm
index b0534476..1420a4ae 100644
--- a/etc/RTIR_Config.pm
+++ b/etc/RTIR_Config.pm
@@ -230,6 +230,25 @@ Set(
     },
 );
 
+=item C<%LinkedQueuePortlets%>
+
+This config adds portlets, containing a list of linked
+tickets by queue (Incident Reports, Investigations,
+Countermeasures) to each Incident display page. By
+default, all link types are shown. Additional accepted
+link types include, 'DependsOn', 'DependedOnBy',
+'HasMember' (children), 'MemberOf' (parents), 'RefersTo',
+and 'ReferredToBy'.
+
+=cut
+
+Set( %LinkedQueuePortlets, (
+    Incidents   => [
+        { 'Incident Reports'  => [ 'All' ] },
+        { Investigations      => [ 'All' ] },
+        { Countermeasures     => [ 'All' ] },
+    ],
+));
 
 =item C<%RTIR_IncidentChildren>
 
diff --git a/html/Callbacks/RTIR/Ticket/Elements/ShowLinkedQueues/MassageQueries b/html/Callbacks/RTIR/Ticket/Elements/ShowLinkedQueues/MassageQueries
new file mode 100644
index 00000000..77762436
--- /dev/null
+++ b/html/Callbacks/RTIR/Ticket/Elements/ShowLinkedQueues/MassageQueries
@@ -0,0 +1,21 @@
+<%INIT>
+my $queue = RT::Queue->new($session{CurrentUser});
+$queue->Load($Queue);
+my $lifecycle = $queue->Lifecycle;
+return unless $lifecycle;
+
+return if $lifecycle eq RT::IR->lifecycle_countermeasure && RT->Config->Get('RTIR_DisableCountermeasures');
+
+my $friendly_lifecycle = RT::IR::FriendlyLifecycle($lifecycle);
+
+@$EmptyMessages
+    = ( loc( '(No active [_1])', loc($friendly_lifecycle) ), loc( '(No inactive [_1])', loc($friendly_lifecycle) ) );
+
+</%INIT>
+
+<%ARGS>
+$ARGSRef
+$Queue
+$Queries
+$EmptyMessages
+</%ARGS>
diff --git a/html/Callbacks/RTIR/Ticket/Elements/ShowLinkedQueues/MassageTitleBox b/html/Callbacks/RTIR/Ticket/Elements/ShowLinkedQueues/MassageTitleBox
new file mode 100644
index 00000000..31674779
--- /dev/null
+++ b/html/Callbacks/RTIR/Ticket/Elements/ShowLinkedQueues/MassageTitleBox
@@ -0,0 +1,48 @@
+<%INIT>
+my @queues = ( 'Incident Reports','Investigations', 'Countermeasures' );
+
+my %lifecycles = (
+    'Incident Reports'  => 'incident_reports',
+    'Investigations'    => 'investigations',
+    'Countermeasures'   => 'countermeasures',
+);
+
+my $id = $ARGSRef->{ TicketObj }->id;
+
+foreach my $queue ( @queues ) {
+    if( $queue eq $$title ) {
+        my $lifecycle = $lifecycles{ $queue };
+        $$class = 'tickets-list-'. lc(RT::IR::TicketType( Lifecycle => $lifecycle ));
+        $$title_href = RT::IR->HREFTo("Incident/Children/?Lifecycle=$lifecycle&id=$id");
+
+    my @titleright_raw;
+    if( $ARGSRef->{ TicketObj }->CurrentUserHasRight('ModifyTicket') ) {
+        if (1) { # XXX TODO RESTORE THIS ACL CHECK
+        # $QueueObj->Id and $QueueObj->CurrentUserHasRight('CreateTicket') ) {
+            push @titleright_raw, {
+                title => $lifecycle ne RT::IR->lifecycle_investigation? loc('Create') : loc('Launch'),
+                class => 'create_child' . ($lifecycle ? '_'.$lifecycle : ''),
+                path => RT::IR->HREFTo("CreateInQueue.html?Incident=$id&Lifecycle=".$lifecycle),
+            };
+        }
+        push @titleright_raw, {
+            title => loc('Link'),
+            path  => RT::IR->HREFTo("Link/FromIncident/?id=$id&Lifecycle=".$lifecycle),
+        };
+    }
+
+    $$titleright_raw = join ' 'x3,
+        map q{<a href="} . $_->{'path'} . ( $_->{'class'} ? q{" class="} . $_->{'class'} : '' ) . q{">}
+            . $m->interp->apply_escapes( $_->{title}, 'h' ) . q{</a>},
+        @titleright_raw;
+    }
+}
+</%INIT>
+
+<%ARGS>
+$ARGSRef
+$title
+$class => undef
+$title_href => undef
+$titleright_raw => undef
+</%ARGS>
diff --git a/html/RTIR/Incident/Display.html b/html/RTIR/Incident/Display.html
index bf1a0489..fd4d7c65 100644
--- a/html/RTIR/Incident/Display.html
+++ b/html/RTIR/Incident/Display.html
@@ -160,12 +160,9 @@
   <div class="boxcontainer col-md-6">
 % $m->callback( %ARGS, Ticket => $TicketObj, CallbackName => 'RightColumnStart' );
 
-% foreach my $lifecycle ( RT::IR->lifecycle_report, RT::IR->lifecycle_investigation, RT::IR->lifecycle_countermeasure ) {
-<& /RTIR/Incident/Elements/ShowChildren,
-    IncidentObj => $TicketObj,
-    Lifecycle   => $lifecycle
+<& /Ticket/Elements/ShowLinkedQueues,
+    TicketObj => $TicketObj,
 &>
-% }
 
 <& /RTIR/Elements/ShowArticles, Ticket => $TicketObj &>
 % $m->callback( %ARGS, Ticket => $TicketObj, CallbackName => 'RightColumnEnd' );
diff --git a/html/RTIR/Incident/Elements/ShowChildren b/html/RTIR/Incident/Elements/ShowChildren
deleted file mode 100644
index 31584955..00000000
--- a/html/RTIR/Incident/Elements/ShowChildren
+++ /dev/null
@@ -1,139 +0,0 @@
-%# BEGIN BPS TAGGED BLOCK {{{
-%#
-%# COPYRIGHT:
-%#
-%# This software is Copyright (c) 1996-2018 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 }}}
-<&| /Widgets/TitleBox, 
-    title       => loc( $FriendlyLifecycle ), 
-    title_href  => RT::IR->HREFTo("Incident/Children/?Lifecycle=". $Lifecycle ."&id=".$id),
-    titleright_raw => $box_actions,
-    title_class    => 'inverse',
-    class => 'tickets-list-'. lc(RT::IR::TicketType( Lifecycle => $Lifecycle )),
-&>
-
-<& /RTIR/Elements/ShowChildren,
-    Ticket           => $IncidentObj, 
-    Lifecycle        => $Lifecycle,
-    Rows             => $Rows,
-    Statuses         => \@active_statuses,
-    NoTicketsCaption => loc('No active [_1]', loc( $FriendlyLifecycle )),
-&>
-% if ( $active->CountAll < $Rows ) {
-<& /RTIR/Elements/ShowChildren,
-    Ticket           => $IncidentObj,
-    Lifecycle        => $Lifecycle,
-    Rows             => $Rows - $active->CountAll,
-    Statuses         => \@inactive_statuses,
-    NoTicketsCaption => loc('No inactive [_1]', loc( $FriendlyLifecycle )),
-&>
-% }
-</&>
-
-<%ARGS>
-$IncidentObj
-$Lifecycle
-
-$OrderBy => 'Due'
-
-$Rows  => 8
-</%ARGS>
-<%INIT>
-
-
-return if $Lifecycle eq RT::IR->lifecycle_countermeasure && RT->Config->Get('RTIR_DisableCountermeasures');
-
-
-my $FriendlyLifecycle = RT::IR::FriendlyLifecycle($Lifecycle);
-
-my $id = $IncidentObj->id;
-
-my @active_statuses = RT::IR->Statuses( Lifecycle => $Lifecycle);
-my @inactive_statuses = RT::IR->Statuses( Lifecycle => $Lifecycle, Initial => 0, Active => 0, Inactive => 1 );
-
-my $active = RT::Tickets->new( $session{'CurrentUser'} );
-$active->FromSQL( RT::IR->Query(
-    Lifecycle => $Lifecycle,
-    MemberOf => $IncidentObj,
-    Status   => \@active_statuses,
-));
-
-my $inactive = RT::Tickets->new( $session{'CurrentUser'} );
-$inactive->FromSQL( RT::IR->Query(
-    Lifecycle => $Lifecycle,
-    MemberOf => $IncidentObj,
-    Status   => \@inactive_statuses,
-));
-
-my $total_count = $active->CountAll + $inactive->CountAll;
-
-
-my @box_actions;
-if ( $IncidentObj->CurrentUserHasRight('ModifyTicket') ) {
-    if (1) { # XXX TODO RESTORE THIS ACL CHECK
-    # $QueueObj->Id and $QueueObj->CurrentUserHasRight('CreateTicket') ) {
-        push @box_actions, {
-            title => $Lifecycle ne RT::IR->lifecycle_investigation? loc('Create') : loc('Launch'),
-            class => 'create_child' . ($Lifecycle ? '_'.$Lifecycle : ''),
-            path => RT::IR->HREFTo("CreateInQueue.html?Incident=$id&Lifecycle=".$Lifecycle),
-        };
-    }
-    push @box_actions, {
-        title => loc('Link'),
-        path  => RT::IR->HREFTo("Link/FromIncident/?id=$id&Lifecycle=".$Lifecycle),
-    };
-}
-
-if ( $total_count > $Rows ) {
-    push @box_actions, {
-        title => loc("More... ([_1] total)", $total_count),
-        path => RT::IR->HREFTo('Incident/Children/?Lifecycle='. $Lifecycle .'&id='. $id)
-    };
-}
-my $box_actions = join ' 'x3,
-    map q{<a href="} . $_->{'path'} . ( $_->{'class'} ? q{" class="} . $_->{'class'} : '' ) . q{">}
-        . $m->interp->apply_escapes( $_->{title}, 'h' ) . q{</a>},
-    @box_actions;
-
-</%INIT>

commit 6da13e7d8c36ddd036162467f1ffe544319040e0
Author: Blaine Motsinger <blaine at bestpractical.com>
Date:   Fri Mar 20 18:20:47 2020 -0500

    Add test for Linked Queue Portlets

diff --git a/t/incident/linked_queue_portlets.t b/t/incident/linked_queue_portlets.t
new file mode 100644
index 00000000..ed2cd2b9
--- /dev/null
+++ b/t/incident/linked_queue_portlets.t
@@ -0,0 +1,93 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use RT::IR::Test tests => undef;
+use Test::Deep;
+
+my $expected_linked_queue_portlets = {
+    Incidents   => [
+        { 'Incident Reports'  => [ 'All' ] },
+        { Investigations      => [ 'All' ] },
+        { Countermeasures     => [ 'All' ] },
+    ],
+};
+my $linked_queue_portlets = RT->Config->Get( 'LinkedQueuePortlets' );
+cmp_deeply( $linked_queue_portlets, $expected_linked_queue_portlets, 'LinkedQueuePortlets config enables all initial RTIR queues for Incidents by default' );
+
+RT::Test->started_ok;
+my $agent = default_agent();
+my $rtir_user = rtir_user();
+
+my $incident_id = $agent->create_incident({
+    Subject => 'test incident'
+});
+$agent->display_ticket( $incident_id );
+
+$agent->content_contains( 'tickets-list-report', 'Incident Reports portlet is visible on the incident ticket' );
+$agent->content_contains( 'tickets-list-investigation', 'Investigations portlet is visible on the incident ticket' );
+$agent->content_contains( 'tickets-list-countermeasure', 'Countermeasures portlet is visible on the incident ticket' );
+
+undef $agent;
+RT::Test->stop_server;
+
+# create test queue and test ticket in it
+my $queue_name = 'test queue';
+my $queue      = RT::Queue->new( RT->SystemUser );
+my $queue_id   = $queue->Create(
+    Name        => $queue_name,
+    Description => $queue_name,
+);
+ok( $queue_id, 'created "test queue" queue' );
+
+$rtir_user->PrincipalObj->GrantRight( Right => 'CreateTicket' );
+$rtir_user->PrincipalObj->GrantRight( Right => 'OwnTicket' );
+$rtir_user->PrincipalObj->GrantRight( Right => 'ShowTicket' );
+$rtir_user->PrincipalObj->GrantRight( Right => 'SeeQueue' );
+
+my $ticket_one = RT::Ticket->new( RT->SystemUser );
+my ( $ticket_one_id ) = $ticket_one->Create(
+    Subject => 'test ticket in "' . $queue_name . '" queue',
+    Queue   => $queue_name,
+    Owner   => $rtir_user,
+);
+ok( $ticket_one_id, 'created ticket in "' . $queue_name . '" queue' );
+
+# enable the test queue to display in incidents
+push @{ $linked_queue_portlets->{ Incidents } }, { $queue_name => [ 'All' ] };
+RT->Config->Set(
+    LinkedQueuePortlets => %{ $linked_queue_portlets },
+);
+my $updated_linked_queue_portlets = {
+    RT->Config->Get( 'LinkedQueuePortlets' )
+};
+cmp_deeply( $updated_linked_queue_portlets, $linked_queue_portlets, 'LinkedQueuePortlets config setting updated to display "' . $queue_name . '" for Incidents' );
+
+# test content in the incident ticket for the test queue without linked tickets
+RT::Test->started_ok;
+$agent = default_agent();
+
+my $linked_queue_class = 'linked-queue';
+
+$agent->display_ticket( $incident_id );
+$agent->content_contains( $linked_queue_class, 'Incident ticket contains linked queue portlet for "' . $queue_name . '" queue' );
+
+# link RT ticket in test queue with incident so the ticket shows up in the linked queue portlet
+my $rtir_ticket_one = RT::Ticket->new( RT->SystemUser );
+my $rtir_ticket_one_id = $rtir_ticket_one->Load( $incident_id );
+
+my $link = RT::Link->new( RT->SystemUser );
+my ( $link_id, $msg ) = $link->Create( Base => $ticket_one->URI, Target => $rtir_ticket_one->URI, Type => 'RefersTo' );
+ok( $link_id, 'created "RefersTo" link between tickets' );
+
+# test if the ticket is visible on incident
+$agent->display_ticket( $incident_id );
+like(
+    $agent->dom->at( 'div.ticket-info-links.' . $linked_queue_class )->content,
+    qr/Ticket\/Display\.html\?id=$ticket_one_id/,
+    'linked queue portlet contains link to ticket in "' . $queue_name . '" queue'
+);
+
+undef $agent;
+done_testing();

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


More information about the rt-commit mailing list