[Rt-commit] rtir branch, 5.0/use-core-custom-field-default-values, created. 4.0.1rc1-121-gd45583df
Craig Kaiser
craig at bestpractical.com
Thu May 21 10:02:40 EDT 2020
The branch, 5.0/use-core-custom-field-default-values has been created
at d45583df0234b03092748e93254c0c64f7f2c3c3 (commit)
- Log -----------------------------------------------------------------
commit 37f1206c8402acf4f57744dc620b9f137ee9dce9
Author: craig kaiser <craig at bestpractical.com>
Date: Thu May 21 08:56:22 2020 -0400
Use core default values instead of RTIR_CustomFieldsDefaults config
diff --git a/etc/RTIR_Config.pm b/etc/RTIR_Config.pm
index b0534476..48f0eb70 100644
--- a/etc/RTIR_Config.pm
+++ b/etc/RTIR_Config.pm
@@ -553,21 +553,13 @@ Set(@Active_MakeClicky, qw(httpurl_overwrite ip email domain));
=item C<%RTIR_CustomFieldsDefaults>
-Set the defaults for RTIR custom fields. Values are case-sensitive.
+Set the defaults value for Resolution if there is no value when ticket
+is set to resolved or rejected.
=cut
Set(
%RTIR_CustomFieldsDefaults,
- 'How Reported' => "",
- 'Reporter Type' => "",
- IP => "",
- Netmask => "",
- Port => "",
- 'Where Blocked' => "",
- Function => "",
- Classification => "",
- Description => "",
Resolution => {
resolved => "successfully resolved",
rejected => "no resolution reached",
diff --git a/etc/upgrade/5.0.0/content b/etc/upgrade/5.0.0/content
new file mode 100644
index 00000000..d1916ad7
--- /dev/null
+++ b/etc/upgrade/5.0.0/content
@@ -0,0 +1,27 @@
+our @Final = sub {
+ my $custom_field = RT::CustomField->new( RT->SystemUser );
+
+ my $custom_field_defaults = RT->Config->Get('RTIR_CustomFieldsDefaults') || ();
+ unless ( scalar keys %{$custom_field} ) {
+ RT->Logger->error( "To set custom field defaults the %RTIR_CustomFieldsDefaults must be present, if there is a configuration for this value that was removed re-enable it and re-run this script." );
+ return;
+ }
+
+ foreach my $cf_name ( keys %{$custom_field_defaults} ) {
+ next if $cf_name eq 'Resolution';
+
+ my ($ret, $msg) = $custom_field->LoadByName( Name => $cf_name );
+ unless ( $ret ) {
+ RT->Logger->error( "Could not load custom field '$cf_name' : $msg" );
+ next;
+ }
+ ($ret, $msg) = $custom_field->SetDefaultValues( Values => $custom_field_defaults->{$cf_name} );
+ if ( $ret ) {
+ RT->Logger->debug( "Set default value for $cf_name to $custom_field_defaults->{$cf_name}" );
+ }
+ else {
+ RT->Logger->error( "Could not set default value for $cf_name custom field $msg" );
+ }
+ }
+ RT->Logger->info( "Custom field defaults are now handled in the web UI on the custom field admin page, only Resolution needs to be set in \%RTIR_CustomFieldsDefaults." );
+};
diff --git a/html/RTIR/Elements/EditCustomFields b/html/RTIR/Elements/EditCustomFields
index f892eeda..381e9961 100644
--- a/html/RTIR/Elements/EditCustomFields
+++ b/html/RTIR/Elements/EditCustomFields
@@ -59,7 +59,6 @@
unless ( $TicketObj && $TicketObj->Id ) {
# no ticket, we need to find defaults of cfs
my $CustomFields = $QueueObj->TicketCustomFields();
- my %ConfigDefaults = RT->Config->Get('RTIR_CustomFieldsDefaults');
while ( my $CustomField = $CustomFields->Next ) {
my $name = $CustomField->Name;
@@ -77,16 +76,6 @@ unless ( $TicketObj && $TicketObj->Id ) {
if ( $ARGS{"$name-Value"} ) {
$CFDefaults->{"CustomField-".$CustomField->Id} = $ARGS{"$name-Value"};
}
- elsif ( defined $ConfigDefaults{ $name } ) {
-# if $ConfigDefaults{$name} is ref, it should be treated carefully
- unless ( ref $ConfigDefaults{ $name } ) {
- $CFDefaults->{"CustomField-".$CustomField->Id} = $ConfigDefaults{ $name };
- }
- elsif ( ref $ConfigDefaults{ $name } eq 'ARRAY' ) {
- $CFDefaults->{"CustomField-".$CustomField->id} =
- join "\n", @{$ConfigDefaults{ $name }};
- }
- }
}
}
</%INIT>
diff --git a/html/RTIR/Incident/Elements/ReplyForm b/html/RTIR/Incident/Elements/ReplyForm
index 832f8144..585063aa 100644
--- a/html/RTIR/Incident/Elements/ReplyForm
+++ b/html/RTIR/Incident/Elements/ReplyForm
@@ -82,8 +82,7 @@
QueueObj => $TicketObj->QueueObj,
Name => 'Resolution',
Default => (
- $TicketObj->FirstCustomFieldValue('Resolution') ||
- RT->Config->Get('RTIR_CustomFieldsDefaults')->{'Resolution'}{$Status}
+ $TicketObj->FirstCustomFieldValue('Resolution')
),
Rows => 1,
&>
commit d45583df0234b03092748e93254c0c64f7f2c3c3
Author: craig kaiser <craig at bestpractical.com>
Date: Thu May 21 09:32:06 2020 -0400
Update tests to reflect using core default CF values feature
diff --git a/t/custom-fields/defaults-config.t b/t/custom-fields/defaults-config.t
deleted file mode 100644
index 4289e0ca..00000000
--- a/t/custom-fields/defaults-config.t
+++ /dev/null
@@ -1,85 +0,0 @@
-#!/usr/bin/perl
-
-use strict;
-use warnings;
-
-use RT::IR::Test tests => undef;
-
-my $defaults = RT->Config->Get('RTIR_CustomFieldsDefaults');
-$defaults->{'How Reported'} = 'Telephone'; # IRs
-$defaults->{'Description'} = 'Bloody mess'; # Incs
-$defaults->{'IP'} = '127.0.0.1'; # Invs and all
-$defaults->{'Where Blocked'} = 'On the Moon'; # Countermeasures
-
-my %test_on = (
- 'Incident Reports' => 'How Reported',
- 'Incidents' => 'Description',
- 'Investigations' => 'IP',
- 'Countermeasures' => 'Where Blocked',
-);
-
-my %replace_with = (
- 'How Reported' => 'Email',
- 'Description' => 'Lucky Incident',
- 'IP' => '172.16.0.1',
- 'Where Blocked' => 'On the Sun',
-);
-
-RT::Test->started_ok;
-my $agent = default_agent();
-
-{
- my $incident_id; # countermeasure couldn't be created without incident id
- foreach my $queue( 'Incidents', 'Incident Reports', 'Investigations', 'Countermeasures' ) {
- my $cf_name = $test_on{ $queue };
- my $cf_default = $defaults->{ $cf_name };
- my $cf_replace = $replace_with{ $cf_name };
-
- diag "goto ${queue}' create page and check fields' defaults" if $ENV{'TEST_VERBOSE'};
- {
- $agent->goto_create_rtir_ticket( $queue );
- my $input = $agent->custom_field_input( $queue, $cf_name );
- ok $input, 'found input for the field';
- is $agent->value($input), $cf_default, "correct value";
- }
-
- diag "create a ticket in ${queue} queue and check fields' values" if $ENV{'TEST_VERBOSE'};
- {
- my $id = $agent->create_rtir_ticket_ok(
- $queue,
- {
- Subject => "test",
- ( $queue eq 'Countermeasures' ? ( Incident => $incident_id ) : () ),
- },
- );
- $incident_id = $id if $queue eq 'Incidents';
-
- my $ticket = RT::Ticket->new( $RT::SystemUser );
- $ticket->Load( $id );
- ok( $ticket->id, 'loaded ticket' );
- is( $ticket->FirstCustomFieldValue($cf_name), $cf_default, 'correct value' );
- }
-
- diag "create a ticket in ${queue} queue and check fields' values" if $ENV{'TEST_VERBOSE'};
- {
- my $id = $agent->create_rtir_ticket_ok(
- $queue,
- {
- Subject => "test",
- ( $queue eq 'Countermeasures' ? ( Incident => $incident_id ) : () ),
- },
- { $cf_name => $cf_replace }
- );
- $incident_id = $id if $queue eq 'Incidents';
-
- my $ticket = RT::Ticket->new( $RT::SystemUser );
- $ticket->Load( $id );
- ok( $ticket->id, 'loaded ticket' );
- is( $ticket->FirstCustomFieldValue($cf_name), $cf_replace, 'correct value' );
- }
- }
-}
-
-
-undef $agent;
-done_testing;
diff --git a/t/mail/skip_notification.t b/t/mail/skip_notification.t
index 8ac61194..1f53ce9a 100644
--- a/t/mail/skip_notification.t
+++ b/t/mail/skip_notification.t
@@ -5,8 +5,6 @@ use warnings;
use RT::IR::Test tests => undef;
-RT->Config->Get('RTIR_CustomFieldsDefaults')->{'Constituency'} = 'EDUNET';
-
my ($baseurl) = RT::Test->started_ok;
my $agent = default_agent();
my $rtir_user = rtir_user();
-----------------------------------------------------------------------
More information about the rt-commit
mailing list