Skip to content

Commit 43b7532

Browse files
committed
Migrate Description custom field to ticket's core Description field
1 parent c0508ec commit 43b7532

5 files changed

Lines changed: 121 additions & 22 deletions

File tree

etc/RTIR_Config.pm

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,7 @@ Set(%PageLayouts,
678678
{ Layout => 'col-md-6',
679679
Title => 'Ticket metadata',
680680
Elements => [
681-
[ 'Basics', 'Times', 'CustomFieldCustomGroupings', 'Dates', 'Attachments', 'Requestors' ],
681+
[ 'Basics', 'Times', 'Description', 'CustomFieldCustomGroupings', 'Dates', 'Attachments', 'Requestors' ],
682682
[ 'Articles', 'LinkedQueues', 'Assets', 'LinkedArticles', 'CVEDetails' ],
683683
],
684684
},
@@ -690,7 +690,7 @@ Set(%PageLayouts,
690690
{ Layout => 'col-md-6',
691691
Title => 'Ticket metadata',
692692
Elements => [
693-
[ 'Basics', 'Times', 'CustomFieldCustomGroupings', 'LinkedArticles', 'CVEDetails', 'Attachments' ],
693+
[ 'Basics', 'Times', 'Description', 'CustomFieldCustomGroupings', 'LinkedArticles', 'CVEDetails', 'Attachments' ],
694694
[ 'People', 'Articles', 'Dates', 'Assets', 'Requestors' ],
695695
],
696696
},
@@ -702,7 +702,7 @@ Set(%PageLayouts,
702702
{ Layout => 'col-md-6',
703703
Title => 'Ticket metadata',
704704
Elements => [
705-
[ 'Basics', 'Times', 'CustomFieldCustomGroupings', 'LinkedArticles', 'CVEDetails', 'Attachments' ],
705+
[ 'Basics', 'Times', 'Description', 'CustomFieldCustomGroupings', 'LinkedArticles', 'CVEDetails', 'Attachments' ],
706706
[ 'People', 'Articles', 'Dates', 'Assets', 'Requestors' ],
707707
],
708708
},
@@ -714,7 +714,7 @@ Set(%PageLayouts,
714714
{ Layout => 'col-md-6',
715715
Title => 'Ticket metadata',
716716
Elements => [
717-
[ 'Basics', 'Times', 'CustomFieldCustomGroupings', 'LinkedArticles', 'CVEDetails', 'Attachments' ],
717+
[ 'Basics', 'Times', 'Description', 'CustomFieldCustomGroupings', 'LinkedArticles', 'CVEDetails', 'Attachments' ],
718718
[ 'People', 'Articles', 'Dates', 'Assets', 'Requestors' ],
719719
],
720720
},
@@ -728,31 +728,31 @@ Set(%PageLayouts,
728728
{ Layout => 'col-md-7,col-md-5',
729729
Elements => [
730730
[ 'Message', 'Submit' ],
731-
[ 'Basics', 'Assets', 'CustomFieldCustomGroupings', 'Dates', 'Times' ],
731+
[ 'Basics', 'Assets', 'Description', 'CustomFieldCustomGroupings', 'Dates', 'Times' ],
732732
],
733733
},
734734
],
735735
'Incident Reports' => [
736736
{ Layout => 'col-md-7,col-md-5',
737737
Elements => [
738738
[ 'Message', 'Submit' ],
739-
[ 'Basics', 'Assets', 'CustomFieldCustomGroupings', 'Dates', 'Times' ],
739+
[ 'Basics', 'Assets', 'Description', 'CustomFieldCustomGroupings', 'Dates', 'Times' ],
740740
],
741741
},
742742
],
743743
Investigations => [
744744
{ Layout => 'col-md-7,col-md-5',
745745
Elements => [
746746
[ 'Message', 'Submit' ],
747-
[ 'Basics', 'Assets', 'CustomFieldCustomGroupings', 'Dates', 'Times', 'AttachReports' ],
747+
[ 'Basics', 'Assets', 'Description', 'CustomFieldCustomGroupings', 'Dates', 'Times', 'AttachReports' ],
748748
],
749749
},
750750
],
751751
Countermeasures => [
752752
{ Layout => 'col-md-7,col-md-5',
753753
Elements => [
754754
[ 'Message', 'Submit' ],
755-
[ 'Basics', 'Assets', 'CustomFieldCustomGroupings', 'Dates', 'Times' ],
755+
[ 'Basics', 'Assets', 'Description', 'CustomFieldCustomGroupings', 'Dates', 'Times' ],
756756
],
757757
},
758758
],
@@ -860,31 +860,31 @@ Set(%CustomFieldGroupings,
860860
'Incidents' => [
861861
'Networking' => [ 'IP', 'Domain' ],
862862
'Details' => [
863-
'How Reported', 'Reporter Type', 'Customer', 'Description',
863+
'How Reported', 'Reporter Type', 'Customer',
864864
'Resolution', 'Function', 'Classification', 'CVE ID',
865865
'Customer', 'Netmask', 'Port', 'Where Blocked'
866866
],
867867
],
868868
'Incident Reports' => [
869869
'Networking' => [ 'IP', 'Domain' ],
870870
'Details' => [
871-
'How Reported', 'Reporter Type', 'Customer', 'Description',
871+
'How Reported', 'Reporter Type', 'Customer',
872872
'Resolution', 'Function', 'Classification', 'CVE ID',
873873
'Customer', 'Netmask', 'Port', 'Where Blocked'
874874
],
875875
],
876876
'Investigations' => [
877877
'Networking' => [ 'IP', 'Domain' ],
878878
'Details' => [
879-
'How Reported', 'Reporter Type', 'Customer', 'Description',
879+
'How Reported', 'Reporter Type', 'Customer',
880880
'Resolution', 'Function', 'Classification', 'CVE ID',
881881
'Customer', 'Netmask', 'Port', 'Where Blocked'
882882
],
883883
],
884884
'Countermeasures' => [
885885
'Networking' => [ 'IP', 'Domain' ],
886886
'Details' => [
887-
'How Reported', 'Reporter Type', 'Customer', 'Description',
887+
'How Reported', 'Reporter Type', 'Customer',
888888
'Resolution', 'Function', 'Classification', 'CVE ID',
889889
'Customer', 'Netmask', 'Port', 'Where Blocked'
890890
],

etc/initialdata

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,6 @@ die "Please add RT::IR to your Plugins configuration before initializing the dat
4242
'If set, defines the default WHOIS server for an RTIR Queue',
4343
ApplyTo => [ map { $_->{Name} } @Queues ]
4444
},
45-
{ Name => 'Description',
46-
Type => 'FreeformSingle',
47-
Queue => 'Incidents',
48-
Disabled => 0,
49-
Description => 'Description for Incidents RTIR queue',
50-
},
5145
{ Name => 'Resolution',
5246
Type => 'SelectSingle',
5347
RenderType => 'Dropdown',

etc/upgrade/5.9.1/content

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
use strict;
2+
use warnings;
3+
4+
our @Final = (
5+
sub {
6+
# Migrate Description custom fields to core Description field
7+
my $incident = RT::Queue->new( RT->SystemUser );
8+
$incident->Load('Incidents');
9+
if ( !$incident->Id ) {
10+
RT->Logger->error("Incidents queue not found");
11+
return;
12+
}
13+
14+
my $cfs = RT::CustomFields->new( RT->SystemUser );
15+
$cfs->FindAllRows;
16+
$cfs->LimitToQueue( $incident->Id );
17+
$cfs->Limit( FIELD => 'Name', VALUE => 'Description', CASESENSITIVE => 0 );
18+
if ( my $cf = $cfs->Next ) {
19+
my $tickets = RT::Tickets->new( RT->SystemUser );
20+
$tickets->UnLimit;
21+
$tickets->FromSQL(q{Queue.Lifecycle='incidents'});
22+
while ( my $ticket = $tickets->Next ) {
23+
my $description = $ticket->FirstCustomFieldValue($cf);
24+
if ( defined $description && length $description ) {
25+
RT::Interface::Web::EscapeHTML( \$description );
26+
my ( $ret, $msg ) = $ticket->__Set( Field => 'Description', Value => $description );
27+
if ( !$ret ) {
28+
RT->Logger->error( "Couldn't set description for ticket #" . $ticket->Id . ": $msg" );
29+
}
30+
}
31+
}
32+
my $txns = RT::Transactions->new( RT->SystemUser );
33+
$txns->Limit( FIELD => 'ObjectType', VALUE => 'RT::Ticket' );
34+
$txns->Limit( FIELD => 'Type', VALUE => 'CustomField' );
35+
$txns->Limit( FIELD => 'Field', VALUE => $cf->Id );
36+
while ( my $txn = $txns->Next ) {
37+
my $old_value = $txn->OldValue;
38+
RT::Interface::Web::EscapeHTML( \$old_value ) if $old_value;
39+
my $new_value = $txn->NewValue;
40+
RT::Interface::Web::EscapeHTML( \$new_value ) if $new_value;
41+
my %data = (
42+
Type => 'Set',
43+
Field => 'Description',
44+
OldValue => $old_value,
45+
NewValue => $new_value,
46+
ReferenceType => undef,
47+
);
48+
49+
for my $field ( sort keys %data ) {
50+
next if ( $txn->__Value($field) // '' ) eq ( $data{$field} // '' );
51+
my ( $ret, $msg ) = $txn->__Set( Field => $field, Value => $data{$field} );
52+
if ( !$ret ) {
53+
RT->Logger->error(
54+
"Couldn't set $field to $data{$field} for transaction #" . $txn->Id . ": $msg" );
55+
}
56+
}
57+
}
58+
59+
# Migrate RTIR saved searches
60+
my $search_contents = RT::ObjectContents->new( RT->SystemUser );
61+
$search_contents->Limit( FIELD => 'ObjectType', VALUE => 'RT::SavedSearch' );
62+
$search_contents->Limit( FIELD => 'ContentEncoding', VALUE => 'json' );
63+
$search_contents->Limit( FIELD => 'Content', VALUE => q{"ExtraQueryParams":"RTIR"}, OPERATOR => 'LIKE' );
64+
while ( my $search_content = $search_contents->Next ) {
65+
my $content = $search_content->DecodedContent;
66+
if ( $content->{Query} =~ s!\bCF\.\{?Description\b\}?!Description!gi ) {
67+
my ( $encoding, $new_content ) = $search_content->_EncodeContent( $content );
68+
my %data = (
69+
ContentEncoding => $encoding,
70+
Content => $new_content,
71+
);
72+
73+
for my $field ( sort keys %data ) {
74+
next if ( $search_content->__Value($field) // '' ) eq ( $data{$field} // '' );
75+
my ( $ret, $msg ) = $search_content->__Set( Field => $field, Value => $data{$field} );
76+
if ( !$ret ) {
77+
RT->Logger->error( "Couldn't set $field to $data{$field} for ObjectContent #"
78+
. $search_content->Id
79+
. ": $msg" );
80+
}
81+
}
82+
}
83+
}
84+
85+
if ( !$cf->Disabled ) {
86+
my ( $ret, $msg ) = $cf->SetDisabled(1);
87+
if ( !$ret ) {
88+
RT->Logger->error("Couldn't disable Description custom field: $msg");
89+
}
90+
}
91+
}
92+
else {
93+
RT->Logger->warning("Couldn't find Description custom field for Incidents");
94+
}
95+
},
96+
);

t/001-basic-RTIR.t

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,27 @@ diag 'Test the creation of an incident with investigation';
5454
$agent->goto_create_rtir_ticket('Incidents');
5555
$agent->form_name('TicketCreate');
5656
$agent->field('Subject', 'Incident with an Investigation');
57+
$agent->field('Description', 'Description of Incident with an Investigation');
5758
$agent->field('Content', 'Content of Incident with an Investigation');
5859
$agent->field('Requestors', 'root@localhost');
5960
$agent->field('InvestigationRequestors', 'root@localhost');
6061
$agent->field('InvestigationSubject', 'Investigation created for test incident');
62+
$agent->field('InvestigationDescription', 'Description of the Investigation');
6163
$agent->field('InvestigationContent', 'Content of the Investigation');
6264
$agent->click('InvestigationSubmitTicket');
6365
$agent->content_like(qr/Incident #\d+: Incident with an Investigation/, 'Incident number generated');
6466
$agent->content_like(qr/Ticket \d+ created in queue 'Incidents'/, 'Incident created message');
6567
$agent->content_like(qr/Ticket \d+ created in queue 'Investigations'/, 'Investigation created message');
6668
$agent->content_like(qr/Ticket \d+ member of Ticket \d+/, 'Investigation linked to Incident');
69+
is( $agent->dom->at('.ticket-description span.rt-value')->text,
70+
'Description of Incident with an Investigation',
71+
'Incident description is correct'
72+
);
6773
$agent->follow_link_ok({text => 'Investigation created for test incident'}, 'Followed link to investigation');
6874
$agent->content_contains('Content of the Investigation', 'Investigation content is correct');
75+
is( $agent->dom->at('.ticket-description span.rt-value')->text,
76+
'Description of the Investigation',
77+
'Investigation description is correct'
78+
);
6979

70-
undef $agent;
7180
done_testing;

t/custom-fields/defaults-config.t

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use RT::IR::Test tests => undef;
77

88
my $defaults = {};
99
$defaults->{'How Reported'} = 'Telephone'; # IRs
10-
$defaults->{'Description'} = 'Bloody mess'; # Incs
10+
$defaults->{'Resolution'} = 'no resolution reached'; # Incs
1111
$defaults->{'IP'} = '127.0.0.1'; # Invs and all
1212
$defaults->{'Where Blocked'} = 'On the Moon'; # Countermeasures
1313

@@ -23,14 +23,14 @@ foreach my $cf_name ( keys %{$defaults} ) {
2323

2424
my %test_on = (
2525
'Incident Reports' => 'How Reported',
26-
'Incidents' => 'Description',
26+
'Incidents' => 'Resolution',
2727
'Investigations' => 'IP',
2828
'Countermeasures' => 'Where Blocked',
2929
);
3030

3131
my %replace_with = (
3232
'How Reported' => 'Email',
33-
'Description' => 'Lucky Incident',
33+
'Resolution' => 'successfully resolved',
3434
'IP' => '172.16.0.1',
3535
'Where Blocked' => 'On the Sun',
3636
);

0 commit comments

Comments
 (0)