%# BEGIN BPS TAGGED BLOCK {{{ %# %# COPYRIGHT: %# %# This software is Copyright (c) 1996-2026 Best Practical Solutions, LLC %# %# %# (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 }}} <%INIT> if ($SelectedTicket) { $ARGS{id} = $SelectedTicket; $ARGS{'Status'} = "open"; } Abort('No incident specified') unless $ARGS{id} ; my $TicketObj = LoadTicket( $ARGS{id} ); if ($Child) { my $ChildObj = RT::Ticket->new( $session{'CurrentUser'} ); $ChildObj->Load($Child); $m->callback( CallbackName => 'ThisLinkedToIR', ARGSRef => \%ARGS, Child => $ChildObj ); } my $take_or_steal = sub { my $owner = $_[0]->Owner; return () if $owner == $session{'CurrentUser'}->id; my $action = 'Steal'; $action = 'Take' if $owner == $RT::Nobody->id; my ($res, $msg) = $_[0]->$action(); return $msg || (); }; my $deleted_links = 0; my $DoLinks = sub { my ( $child, $parent ) = @_; my %args = (); if ( RT::IR->StrictConstituencyLinking ) { if ( ( RT::IR->ConstituencyFor($child) || '' ) ne ( RT::IR->ConstituencyFor($parent) || '' ) ) { return loc( "Link failed: Ticket #[_1] is associated with a different constituency", $child->id ); } } # Countermeasure or Incident Reports can have multiple incidents my $Type = RT::IR::TicketType( Ticket => $child ); my $config = RT->Config->Get('RTIR_IncidentChildren')->{$Type}; unless ( $config->{'Multiple'} ) { my $incidents = RT::IR->Incidents( $child, Exclude => $parent ); while ( my $incident = $incidents->Next ) { $deleted_links = 1; $args{ 'DeleteLink--MemberOf-' . $incident->id } = ''; } } my @results; # if we don't own any of ends, take or steal parent unless ( $parent->Owner == $session{'CurrentUser'}->id || $child->Owner == $session{'CurrentUser'}->id ) { push @results, $take_or_steal->($parent); } # turn off strict check locally my $strict_acl = RT->Config->Set( StrictLinkACL => 0 ); $args{ $child->Id . '-MemberOf' } = $parent->Id; push @results, ProcessTicketLinks( TicketObj => $child, ARGSRef => \%args ); RT->Config->Set( StrictLinkACL => $strict_acl ); return map { loc( "Ticket [_1]: [_2]", $child->Id, $_ ) } @results; }; my @results; if ( $ARGS{'BulkLink'} || $Child ) { my @link; push @link, @SelectedTickets if $ARGS{'BulkLink'}; push @link, $Child if $Child; foreach my $id ( grep $_, @link ) { my $child = RT::Ticket->new( $session{'CurrentUser'} ); $child->Load( $id ); unless( $child->id ) { push @results, loc("Couldn't load ticket #[_1] for linking.", $id); next; } push @results, $DoLinks->( $child, $TicketObj ); } } # If we deleted any links, check if what we deleted from still has children if ( $deleted_links && !RT::IR->IncidentChildren($TicketObj)->Count ) { push @results, loc( "WARNING: Incident [_1] has no children.", $ARGS{id} ); } MaybeRedirectForResults( Actions => \@results, Arguments => { map { /^(?:SelectedTicket|BulkLink|Child|LinkChild)$/ ? () : ( $_ => $ARGS{$_} ) } keys %ARGS }, ); $m->comp( '/Ticket/Display.html', %ARGS ); <%ARGS> $id => undef $Child => undef $SelectedTicket => undef @SelectedTickets => ()