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

? sunnavy sunnavy at bestpractical.com
Thu Jun 4 13:18:06 EDT 2020


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

- Log -----------------------------------------------------------------
commit fb731e9f67926a22ef35c158aeb1e5271f2f3038
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 2a51e7ed..835381c0 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..4a4b5c3f
--- /dev/null
+++ b/etc/upgrade/4.9.1/content
@@ -0,0 +1,31 @@
+use strict;
+use warnings;
+
+our @Final = sub {
+    my $custom_field_defaults = RT->Config->Get('RTIR_CustomFieldsDefaults') or return;
+
+    my $custom_field = RT::CustomField->new( RT->SystemUser );
+    foreach my $cf_name ( keys %{$custom_field_defaults} ) {
+        my $value = $custom_field_defaults->{$cf_name};
+        next unless defined $value && length $value && ( !ref($value) || ref($value) eq 'ARRAY' );
+
+        my ($ret, $msg) = $custom_field->LoadByName( Name => $cf_name );
+        unless ( $ret ) {
+            RT->Logger->error( "Could not load custom field '$cf_name' : $msg" );
+            next;
+        }
+
+        if ( $custom_field->DefaultValues ) {
+            RT->Logger->debug("$cf_name already has default values, skipping");
+            next;
+        }
+
+        ($ret, $msg) = $custom_field->SetDefaultValues( Values => $value );
+        if ( $ret ) {
+            RT->Logger->debug( "Set default value for $cf_name to $value" );
+        }
+        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 e9fd1892f9a9e93a2b66a0c0fc6cd0ef92d4de38
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..20eea253 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',

commit 99a2f4720de14d68f38c81210f14fdfda27c58e2
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Thu Jun 4 22:30:06 2020 +0800

    Drop unnecessary Constituency CF default value set in tests
    
    The file tests SkipNotification feature, which is unrelated to
    Constituency, not mentioning the CF name is obsolete too.

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();

commit cba2a5b93f848ea2cf6254797dc5350fa082edd3
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Thu Jun 4 22:53:25 2020 +0800

    Note config %RTIR_CustomFieldsDefaults changes in UPGRADING doc

diff --git a/docs/UPGRADING-5.0 b/docs/UPGRADING-5.0
index a513dab2..42ee5e2b 100644
--- a/docs/UPGRADING-5.0
+++ b/docs/UPGRADING-5.0
@@ -55,6 +55,13 @@ hidden. Visibility of these two menus is now managed with a new right in
 RT. The RT 5.0 upgrade process grants these rights to all Privileged users,
 but you can revoke these rights to restore the previous RTIR menu.
 
+=item *
+
+As RT already supports to set default values for custom fields, the
+config C<%RTIR_CustomFieldsDefaults> has been simplified. To set default
+values, now you need to go to custom field admin page instead. The
+conditional default values like "Resolution" is still retained.
+
 =back
 
 =cut

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


More information about the rt-commit mailing list