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

Blaine Motsinger blaine at bestpractical.com
Tue Mar 24 21:04:44 EDT 2020


The branch, 4.2/configurable-linked-queue-portlets has been created
        at  ae130c4984cf10ab2ae36830fc3ece25c7e2b198 (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 ae130c4984cf10ab2ae36830fc3ece25c7e2b198
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..1d3f7bdc
--- /dev/null
+++ b/t/incident/linked_queue_portlets.t
@@ -0,0 +1,48 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use RT::IR::Test tests => undef;
+
+RT::Test->started_ok;
+my $agent = default_agent();
+my $rtir_user = rtir_user();
+
+# create incident, incident report, investigation, and countermeasure
+my $incident_id        = $agent->create_rtir_ticket_ok( 'Incidents', { Subject => 'test incident' } );
+my $incident_report_id = $agent->create_rtir_ticket_ok( 'Incident Reports', { Subject => 'test incident report' } );
+my $investigation_id   = $agent->create_rtir_ticket_ok( 'Investigations', { Subject => 'test investigation', Requestors => $rtir_user->EmailAddress } );
+my $countermeasure_id  = $agent->create_rtir_ticket_ok( 'Countermeasures', { Subject => 'test countermeasure', Incident => $incident_id } );
+
+# link them as members of the incident
+my $incident = RT::Ticket->new( RT->SystemUser );
+$incident->Load( $incident_id );
+ok( $incident->AddLink( Type => 'HasMember', Target => $incident_report_id ), 'Linked Incident Report to Incident' );
+ok( $incident->AddLink( Type => 'HasMember', Target => $investigation_id   ), 'Linked Investigation to Incident' );
+
+# ensure the default portlets are visible in the incident ticket
+$agent->display_ticket( $incident_id );
+$agent->content_contains( 'tickets-list-report', 'Incident Reports portlet is visible on the Incident' );
+$agent->content_contains( 'tickets-list-investigation', 'Investigations portlet is visible on the Incident' );
+$agent->content_contains( 'tickets-list-countermeasure', 'Countermeasures portlet is visible on the Incident' );
+
+# ensure they all show up on the incident page in their specific portlet
+$agent->display_ticket( $incident_id );
+like(
+    $agent->dom->at( 'div.tickets-list-report' )->content,
+    qr/Ticket\/Display\.html\?id=$incident_report_id/,
+    'Incident Report portlet contains link to Incident Report'
+);
+like(
+    $agent->dom->at( 'div.tickets-list-investigation' )->content,
+    qr/Ticket\/Display\.html\?id=$investigation_id/,
+    'Investigation portlet contains link to Investigation' 
+);
+like(
+    $agent->dom->at( 'div.tickets-list-countermeasure' )->content,
+    qr/Ticket\/Display\.html\?id=$countermeasure_id/,
+    'Countermeasure portlet contains link to Countermeasure'
+);
+
+done_testing();

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


More information about the rt-commit mailing list