[Rt-commit] rt branch 4.4/datetime-cf-timezone created. rt-4.4.5-20-g4a903910a2

BPS Git Server git at git.bestpractical.com
Wed Jan 12 15:05:21 UTC 2022


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "rt".

The branch, 4.4/datetime-cf-timezone has been created
        at  4a903910a29b5189b7d5c27e2940d1e397be0d85 (commit)

- Log -----------------------------------------------------------------
commit 4a903910a29b5189b7d5c27e2940d1e397be0d85
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Wed Jan 12 22:00:24 2022 +0800

    Test datetime cfs edits on ticket clone and edit pages

diff --git a/t/web/cf_datetime.t b/t/web/cf_datetime.t
index 1eade0633b..d5dd5cbf3c 100644
--- a/t/web/cf_datetime.t
+++ b/t/web/cf_datetime.t
@@ -141,6 +141,52 @@ diag 'check valid inputs with various timezones in ticket create page';
     }
 }
 
+diag 'check ticket clone feature';
+{
+    $m->follow_link_ok( { text => 'Create', url_regex => qr/RefersTo-new=/ } );
+    TODO: {
+        local $TODO = $why;
+        $m->text_contains( 'Wed May 05 19:00:01 2010',
+            'cf datetime value in ticket clone form respects user timezone' );
+    }
+
+    $m->submit_form(form_name => "TicketCreate");
+    $m->text_like( qr/Ticket (\d+) created/, 'ticket created' );
+
+    TODO: {
+        local $TODO = $why;
+        $m->text_contains( 'Wed May 05 19:00:01 2010',
+            'cf datetime value respects user timezone' );
+    }
+}
+
+diag 'check ticket edit page';
+{
+    my $ticket = RT::Test->last_ticket;
+    my $id = $ticket->Id;
+    $m->follow_link_ok( { text => 'Basics' } );
+    $m->submit_form(
+        form_name => 'TicketModify',
+        fields    => {
+            "Object-RT::Ticket-$id-CustomField-$cfid-Values" => '2010-05-06 15:00:01',
+        },
+        button => 'SubmitTicket',
+    );
+    TODO: {
+        local $TODO = $why;
+        $m->text_contains("$cf_name Wed May 05 19:00:01 2010 changed to Thu May 06 15:00:01 2010");
+    }
+
+    $m->submit_form(
+        form_name => 'TicketModify',
+        fields    => {
+            "Object-RT::Ticket-$id-CustomField-$cfid-Values" => '2021-06-07 15:05:10',
+        },
+        button => 'SubmitTicket',
+    );
+    # no matter if localizing $ENV{TZ} works or not, the old value is always "2010-05-06 15:00:01" to user
+    $m->text_contains("$cf_name Thu May 06 15:00:01 2010 changed to Mon Jun 07 15:05:10 2021");
+}
 
 diag 'check search build page';
 {
@@ -174,7 +220,7 @@ diag 'check search build page';
     $m->login( 'shanghai', 'password', logout => 1 );
 
     is_results_number( { $cf_op->name => '<', $cf_field->name => '2010-05-07', }, 2 );
-    is_results_number( { $cf_op->name => '>', $cf_field->name => '2010-05-04', }, 2 );
+    is_results_number( { $cf_op->name => '>', $cf_field->name => '2010-05-04', }, 3 );
 
     TODO: {
         local $TODO = $why;

commit 0da1fb9e1856364b95fe96986f433eeab6bc2d4c
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Wed Jan 12 06:19:13 2022 +0800

    Convert datetime cf values to user timezone on ticket clone
    
    The inputs are supposed to be in user timezone.

diff --git a/share/html/Ticket/Create.html b/share/html/Ticket/Create.html
index 18991bde22..c3f459e225 100644
--- a/share/html/Ticket/Create.html
+++ b/share/html/Ticket/Create.html
@@ -419,10 +419,19 @@ if ($CloneTicket) {
             push @cf_values, $cf_value->Content;
         }
 
+        next unless @cf_values;
+
         if ( @cf_values > 1 && $cf->Type eq 'Select' ) {
             $clone->{GetCustomFieldInputName( CustomField => $cf )} = \@cf_values;
         }
         else {
+            if ( $cf->Type eq 'DateTime' ) {
+                # DateTime doesn't have multiple values, so only need to take care of $cf_values[0]
+                my $date = RT::Date->new( $session{'CurrentUser'} );
+                $date->Set( Format => 'ISO', Value => $cf_values[0] );
+                $cf_values[0] = $date->ISO( Timezone => 'user' );
+            }
+
             $clone->{GetCustomFieldInputName( CustomField => $cf )} = join "\n",
               @cf_values;
         }

commit 4c3cb4673e70804122f82e5a011cb9cba0458676
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Wed Jan 12 06:10:08 2022 +0800

    Drop the harmful extra canonicalization code as HasEntry canonicalizes too
    
    This repetition could prevent users from updating datetime cfs to some
    special values, e.g. users in EST(UTC -5) were not able to update
    datetime from "2022-01-01 12:00:00" to "20221-01-01 07:00:00", because
    after 2 canonicalizations, "20221-01-01 07:00:00"(EST) becomes
    "20221-01-01 17:00:00"(UTC), which is "2022-01-01 12:00:00"(EST), the
    old value.

diff --git a/lib/RT/Interface/Web.pm b/lib/RT/Interface/Web.pm
index 8db5b7b32b..23c95140eb 100644
--- a/lib/RT/Interface/Web.pm
+++ b/lib/RT/Interface/Web.pm
@@ -3380,14 +3380,7 @@ sub _ProcessObjectCustomFieldUpdates {
 
             my %values_hash;
             foreach my $value (@values) {
-                my $value_in_db = $value;
-                if ( $cf->Type eq 'DateTime' ) {
-                    my $date = RT::Date->new($session{CurrentUser});
-                    $date->Set(Format => 'unknown', Value => $value);
-                    $value_in_db = $date->ISO;
-                }
-
-                if ( my $entry = $cf_values->HasEntry($value_in_db) ) {
+                if ( my $entry = $cf_values->HasEntry($value) ) {
                     $values_hash{ $entry->id } = 1;
                     next;
                 }

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


hooks/post-receive
-- 
rt


More information about the rt-commit mailing list