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

BPS Git Server git at git.bestpractical.com
Thu Jan 13 16:02:54 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  032a99cd5c6d15e4ed44a18c193d31ae615a533c (commit)

- Log -----------------------------------------------------------------
commit 032a99cd5c6d15e4ed44a18c193d31ae615a533c
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
    
    The TODO is for apache+worker/event tests(because of localization of TZ
    env), the same as others in the file.

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 f969209f476099d5d4264d25e4907107e2d85a80
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..39eff18f58 100644
--- a/share/html/Ticket/Create.html
+++ b/share/html/Ticket/Create.html
@@ -419,10 +419,21 @@ 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' ) {
+                # Convert to user timezone. 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 98c171c5fa5db8f512d41adc4b72be52b44a9d49
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.
    
    Note that the removed code was from 10e46b34e0f to "keep the input value
    for cf date/datetime", but the removed code wasn't actually related to
    that purpose and should have been put in an extra commit with message
    like "Avoid adding repeated datetime cf values"(similar to cdcc492960).
    As HasEntry canonicalizes values too(since cdcc492960), there is no need
    to keep it.

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