[Rt-commit] rtir branch, 5.0/use-core-custom-field-default-values, created. 4.0.1rc1-158-g3d13b147

Craig Kaiser craig at bestpractical.com
Wed Jun 3 17:53:25 EDT 2020


The branch, 5.0/use-core-custom-field-default-values has been created
        at  3d13b147a7ebfe53e4c44875db410633b1648e9d (commit)

- Log -----------------------------------------------------------------
commit fb3a29c16bfbbcee094f6a4d6d2d24b5694a00bc
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 bb507a89..c4e57de8 100644
--- a/etc/RTIR_Config.pm
+++ b/etc/RTIR_Config.pm
@@ -599,21 +599,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 default value for Resolution if there is no value when an RTIR 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/4.9.1/content b/etc/upgrade/4.9.1/content
new file mode 100644
index 00000000..d83b5360
--- /dev/null
+++ b/etc/upgrade/4.9.1/content
@@ -0,0 +1,25 @@
+use strict;
+use warnings;
+
+our @Final = sub {
+    my $custom_field = RT::CustomField->new( RT->SystemUser );
+
+    my $custom_field_defaults = RT->Config->Get('RTIR_CustomFieldsDefaults') || ();
+
+    foreach my $cf_name ( keys %{$custom_field_defaults} ) {
+        next if ref $cf_name eq 'HASH';
+
+        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" );
+        }
+    }
+};
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>

commit 3d13b147a7ebfe53e4c44875db410633b1648e9d
Author: craig kaiser <craig at bestpractical.com>
Date:   Fri May 22 14:20:35 2020 -0400

    Update tests to use core default CF values feature

diff --git a/t/custom-fields/defaults-config.t b/t/custom-fields/defaults-config.t
index 4289e0ca..b40746f5 100644
--- a/t/custom-fields/defaults-config.t
+++ b/t/custom-fields/defaults-config.t
@@ -5,12 +5,22 @@ use warnings;
 
 use RT::IR::Test tests => undef;
 
-my $defaults = RT->Config->Get('RTIR_CustomFieldsDefaults');
+my $defaults = ();
 $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 $custom_field = RT::CustomField->new( RT->SystemUser );
+foreach my $cf_name ( keys %{$defaults} ) {
+
+    my ($ret, $msg) = $custom_field->LoadByName( Name => $cf_name );
+    ok $ret, "Load custom field '$cf_name'";
+
+    ($ret, $msg) = $custom_field->SetDefaultValues( Values => $defaults->{$cf_name} );
+    ok $ret, "Set custom field $cf_name default value to $defaults->{$cf_name}"
+}
+
 my %test_on = (
     'Incident Reports' => 'How Reported',
     'Incidents'        => 'Description',
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