[Rt-commit] rt branch, cf-date, updated. rt-3.8.8-184-g3f3eb89

? sunnavy sunnavy at bestpractical.com
Fri Jul 23 05:58:33 EDT 2010


The branch, cf-date has been updated
       via  3f3eb8908b1790a1ed46af41e7b22b7cbdf5642f (commit)
       via  3cf583c6c1614053f105f80492b8e00ea63d300a (commit)
       via  e48fe729291aa1fd2c45627e72ee4ed352bdcd4d (commit)
       via  5149fbb17546a414cb103b2c458851eb040d9a4f (commit)
      from  66950ec3d14066c3066a550dcac8527a604c8fda (commit)

Summary of changes:
 lib/RT/CustomField_Overlay.pm                      |   16 ++-
 lib/RT/Interface/Web.pm                            |    3 +
 lib/RT/Record.pm                                   |   31 ++++-
 lib/RT/Tickets_Overlay.pm                          |   91 +++++++++----
 .../Elements/{Checkbox => EditCustomFieldDate}     |   29 ++--
 .../{ShowCustomFieldText => ShowCustomFieldDate}   |   15 +-
 share/html/Search/Elements/PickCFs                 |   49 +++++--
 t/web/cf_date.t                                    |  146 ++++++++++++++++++++
 8 files changed, 316 insertions(+), 64 deletions(-)
 copy share/html/Elements/{Checkbox => EditCustomFieldDate} (81%)
 mode change 100755 => 100644
 copy share/html/Elements/{ShowCustomFieldText => ShowCustomFieldDate} (88%)
 create mode 100644 t/web/cf_date.t

- Log -----------------------------------------------------------------
commit 5149fbb17546a414cb103b2c458851eb040d9a4f
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Thu Jul 22 12:54:37 2010 +0800

    cf date support, see also #8721

diff --git a/lib/RT/CustomField_Overlay.pm b/lib/RT/CustomField_Overlay.pm
index e156227..76b15f6 100755
--- a/lib/RT/CustomField_Overlay.pm
+++ b/lib/RT/CustomField_Overlay.pm
@@ -97,6 +97,11 @@ our %FieldTypes = (
         'Enter one value with autocompletion',            # loc
         'Enter up to [_1] values with autocompletion',    # loc
     ],
+    Date => [
+        'Select multiple dates',	# loc
+        'Select date',			# loc
+        'Select up to [_1] dates',	# loc
+    ],
 );
 
 
@@ -830,7 +835,7 @@ Returns an array of all possible composite values for custom fields.
 
 sub TypeComposites {
     my $self = shift;
-    return grep !/(?:[Tt]ext|Combobox)-0/, map { ("$_-1", "$_-0") } $self->Types;
+    return grep !/(?:[Tt]ext|Combobox|Date)-0/, map { ("$_-1", "$_-0") } $self->Types;
 }
 
 =head2 SetLookupType
@@ -1161,6 +1166,15 @@ sub AddValueForObject {
             $extra_values--;
         }
     }
+    # For date, we need to store Content as ISO date
+    if ($self->Type eq 'Date') {
+        my $DateObj = new RT::Date( $self->CurrentUser );
+        $DateObj->Set(
+            Format => 'unknown',
+            Value  => $args{'Content'},
+        );
+        $args{'Content'} = $DateObj->ISO;
+    }
     my $newval = RT::ObjectCustomFieldValue->new( $self->CurrentUser );
     my $val    = $newval->Create(
         ObjectType   => ref($obj),
diff --git a/lib/RT/Interface/Web.pm b/lib/RT/Interface/Web.pm
index 7e5f975..c5f3e26 100755
--- a/lib/RT/Interface/Web.pm
+++ b/lib/RT/Interface/Web.pm
@@ -1737,6 +1737,9 @@ sub _ProcessObjectCustomFieldUpdates {
                 $values_hash{$val} = 1 if $val;
             }
 
+            # For Date Cfs, @values is empty when there is no changes (no datas in form input)
+            return @results if ( $cf->Type eq 'Date' && ! @values );
+
             $cf_values->RedoSearch;
             while ( my $cf_value = $cf_values->Next ) {
                 next if $values_hash{ $cf_value->id };
diff --git a/lib/RT/Record.pm b/lib/RT/Record.pm
index 9ecad76..877c04c 100755
--- a/lib/RT/Record.pm
+++ b/lib/RT/Record.pm
@@ -1713,6 +1713,25 @@ sub _AddCustomFieldValue {
         }
 
         my $new_content = $new_value->Content;
+
+        # For date, we need to display them in "human" format in result message
+        if ($cf->Type eq 'Date') {
+            my $DateObj = new RT::Date( $self->CurrentUser );
+            $DateObj->Set(
+                Format => 'ISO',
+                Value  => $new_content,
+            );
+            $new_content = $DateObj->AsString;
+
+            if ( defined $old_content && length $old_content ) {
+                $DateObj->Set(
+                    Format => 'ISO',
+                    Value  => $old_content,
+                );
+                $old_content = $DateObj->AsString;
+            }
+        }
+
         unless ( defined $old_content && length $old_content ) {
             return ( $new_value_id, $self->loc( "[_1] [_2] added", $cf->Name, $new_content ));
         }
@@ -1801,11 +1820,21 @@ sub DeleteCustomFieldValue {
         return ( 0, $self->loc( "Couldn't create a transaction: [_1]", $Msg ) );
     }
 
+    my $old_value = $TransactionObj->OldValue;
+    # For date, we need to display them in "human" format in result message
+    if ( $cf->Type eq 'Date' ) {
+        my $DateObj = new RT::Date( $self->CurrentUser );
+        $DateObj->Set(
+            Format => 'ISO',
+            Value  => $old_value,
+        );
+        $old_value = $DateObj->AsString;
+    }
     return (
         $TransactionId,
         $self->loc(
             "[_1] is no longer a value for custom field [_2]",
-            $TransactionObj->OldValue, $cf->Name
+            $old_value, $cf->Name
         )
     );
 }
diff --git a/lib/RT/Tickets_Overlay.pm b/lib/RT/Tickets_Overlay.pm
index e8d350d..0d3264c 100755
--- a/lib/RT/Tickets_Overlay.pm
+++ b/lib/RT/Tickets_Overlay.pm
@@ -136,6 +136,7 @@ our %FIELD_METADATA = (
     QueueAdminCc     => [ 'WATCHERFIELD'    => 'AdminCc' => 'Queue', ], #loc_left_pair
     QueueWatcher     => [ 'WATCHERFIELD'    => undef     => 'Queue', ], #loc_left_pair
     CustomFieldValue => [ 'CUSTOMFIELD', ], #loc_left_pair
+    DateCustomFieldValue => [ 'DATECUSTOMFIELD', ],
     CustomField      => [ 'CUSTOMFIELD', ], #loc_left_pair
     CF               => [ 'CUSTOMFIELD', ], #loc_left_pair
     Updated          => [ 'TRANSDATE', ], #loc_left_pair
@@ -160,6 +161,7 @@ our %dispatch = (
     WATCHERFIELD    => \&_WatcherLimit,
     MEMBERSHIPFIELD => \&_WatcherMembershipLimit,
     CUSTOMFIELD     => \&_CustomFieldLimit,
+    DATECUSTOMFIELD => \&_DateCustomFieldLimit,
     HASATTRIBUTE    => \&_HasAttributeLimit,
 );
 our %can_bundle = ();# WATCHERFIELD => "yes", );
@@ -1340,6 +1342,101 @@ sub _CustomFieldJoin {
     return ($TicketCFs, $CFs);
 }
 
+=head2 _DateCustomFieldLimit
+
+Limit based on CustomFields of type Date
+
+Meta Data:
+  none
+
+=cut
+
+sub _DateCustomFieldLimit {
+    my ( $self, $_field, $op, $value, %rest ) = @_;
+
+    my $field = $rest{'SUBKEY'} || die "No field specified";
+
+    # For our sanity, we can only limit on one queue at a time
+
+    my ($queue, $cfid, $column);
+    ($queue, $field, $cfid, $column) = $self->_CustomFieldDecipher( $field );
+
+# If we're trying to find custom fields that don't match something, we
+# want tickets where the custom field has no value at all.  Note that
+# we explicitly don't include the "IS NULL" case, since we would
+# otherwise end up with a redundant clause.
+
+    my $null_columns_ok;
+    if ( ( $op =~ /^NOT LIKE$/i ) or ( $op eq '!=' ) ) {
+        $null_columns_ok = 1;
+    }
+
+    my $cfkey = $cfid ? $cfid : "$queue.$field";
+    my ($TicketCFs, $CFs) = $self->_CustomFieldJoin( $cfkey, $cfid, $field );
+
+    $self->_OpenParen;
+
+    if ( $CFs && !$cfid ) {
+        $self->SUPER::Limit(
+            ALIAS           => $CFs,
+            FIELD           => 'Name',
+            VALUE           => $field,
+            ENTRYAGGREGATOR => 'AND',
+        );
+    }
+
+    $self->_OpenParen if $null_columns_ok;
+
+    my $date = RT::Date->new( $self->CurrentUser );
+    $date->Set( Format => 'unknown', Value => $value );
+
+    if ( $op eq "=" ) {
+
+        # if we're specifying =, that means we want everything on a
+        # particular single day.  in the database, we need to check for >
+        # and < the edges of that day.
+
+        $date->SetToMidnight( Timezone => 'server' );
+        my $daystart = $date->ISO;
+        $date->AddDay;
+        my $dayend = $date->ISO;
+
+        $self->_OpenParen;
+
+        $self->_SQLLimit(
+            ALIAS    => $TicketCFs,
+            FIELD    => 'Content',
+            OPERATOR => ">=",
+            VALUE    => $daystart,
+            %rest,
+        );
+
+        $self->_SQLLimit(
+            ALIAS    => $TicketCFs,
+            FIELD    => 'Content',
+            OPERATOR => "<=",
+            VALUE    => $dayend,
+            %rest,
+            ENTRYAGGREGATOR => 'AND',
+        );
+
+        $self->_CloseParen;
+
+    }
+    else {
+        $self->_SQLLimit(
+            ALIAS    => $TicketCFs,
+            FIELD    => 'Content',
+            OPERATOR => $op,
+            VALUE    => $date->ISO,
+            %rest,
+        );
+    }
+
+    $self->_CloseParen;
+
+}
+
 =head2 _CustomFieldLimit
 
 Limit based on CustomFields
@@ -2667,6 +2764,11 @@ sub LimitCustomField {
         $args{CUSTOMFIELD} = $CF->Id;
     }
 
+    # Handle special customfields types
+    if ($CF->Type eq 'Date') {
+        $args{FIELD} = 'DateCustomFieldValue';
+    }
+
     #If we are looking to compare with a null value.
     if ( $args{'OPERATOR'} =~ /^is$/i ) {
         $args{'DESCRIPTION'}
diff --git a/share/html/Elements/EditCustomFieldDate b/share/html/Elements/EditCustomFieldDate
new file mode 100644
index 0000000..9df469f
--- /dev/null
+++ b/share/html/Elements/EditCustomFieldDate
@@ -0,0 +1,62 @@
+%# BEGIN BPS TAGGED BLOCK {{{
+%# 
+%# COPYRIGHT:
+%#  
+%# This software is Copyright (c) 1996-2008 Best Practical Solutions, LLC 
+%#                                          <jesse at bestpractical.com>
+%# 
+%# (Except where explicitly superseded by other copyright notices)
+%# 
+%# 
+%# LICENSE:
+%# 
+%# This work is made available to you under the terms of Version 2 of
+%# the GNU General Public License. A copy of that license should have
+%# been provided with this software, but in any event can be snarfed
+%# from www.gnu.org.
+%# 
+%# This work is distributed in the hope that it will be useful, but
+%# WITHOUT ANY WARRANTY; without even the implied warranty of
+%# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+%# General Public License for more details.
+%# 
+%# You should have received a copy of the GNU General Public License
+%# along with this program; if not, write to the Free Software
+%# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+%# 02110-1301 or visit their web page on the internet at
+%# http://www.gnu.org/copyleft/gpl.html.
+%# 
+%# 
+%# CONTRIBUTION SUBMISSION POLICY:
+%# 
+%# (The following paragraph is not intended to limit the rights granted
+%# to you to modify and distribute this software under the terms of
+%# the GNU General Public License and is only of importance to you if
+%# you choose to contribute your changes and enhancements to the
+%# community by submitting them to Best Practical Solutions, LLC.)
+%# 
+%# By intentionally submitting any modifications, corrections or
+%# derivatives to this work, or any other work intended for use with
+%# Request Tracker, to Best Practical Solutions, LLC, you confirm that
+%# you are the copyright holder for those contributions and you grant
+%# Best Practical Solutions,  LLC a nonexclusive, worldwide, irrevocable,
+%# royalty-free, perpetual, license to use, copy, create derivative
+%# works based on those contributions, and sublicense and distribute
+%# those contributions and any derivatives thereof.
+%# 
+%# END BPS TAGGED BLOCK }}}
+% my $name = $NamePrefix.$CustomField->Id.'-Values';
+<& /Elements/SelectDate, Name => "$name", current => 0 &> (<%$DateObj->AsString%>)
+
+<%INIT>
+my $DateObj = new RT::Date ( $session{'CurrentUser'} );
+$DateObj->Set( Format => 'ISO', Value => $Default );
+</%INIT>
+<%ARGS>
+$Object => undef
+$CustomField => undef
+$NamePrefix => undef
+$Default => undef
+$Values => undef
+$MaxValues => 1
+</%ARGS>
diff --git a/share/html/Elements/ShowCustomFieldDate b/share/html/Elements/ShowCustomFieldDate
new file mode 100644
index 0000000..4e8ad67
--- /dev/null
+++ b/share/html/Elements/ShowCustomFieldDate
@@ -0,0 +1,57 @@
+%# BEGIN BPS TAGGED BLOCK {{{
+%# 
+%# COPYRIGHT:
+%#  
+%# This software is Copyright (c) 1996-2008 Best Practical Solutions, LLC 
+%#                                          <jesse at bestpractical.com>
+%# 
+%# (Except where explicitly superseded by other copyright notices)
+%# 
+%# 
+%# LICENSE:
+%# 
+%# This work is made available to you under the terms of Version 2 of
+%# the GNU General Public License. A copy of that license should have
+%# been provided with this software, but in any event can be snarfed
+%# from www.gnu.org.
+%# 
+%# This work is distributed in the hope that it will be useful, but
+%# WITHOUT ANY WARRANTY; without even the implied warranty of
+%# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+%# General Public License for more details.
+%# 
+%# You should have received a copy of the GNU General Public License
+%# along with this program; if not, write to the Free Software
+%# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+%# 02110-1301 or visit their web page on the internet at
+%# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
+%# 
+%# 
+%# CONTRIBUTION SUBMISSION POLICY:
+%# 
+%# (The following paragraph is not intended to limit the rights granted
+%# to you to modify and distribute this software under the terms of
+%# the GNU General Public License and is only of importance to you if
+%# you choose to contribute your changes and enhancements to the
+%# community by submitting them to Best Practical Solutions, LLC.)
+%# 
+%# By intentionally submitting any modifications, corrections or
+%# derivatives to this work, or any other work intended for use with
+%# Request Tracker, to Best Practical Solutions, LLC, you confirm that
+%# you are the copyright holder for those contributions and you grant
+%# Best Practical Solutions,  LLC a nonexclusive, worldwide, irrevocable,
+%# royalty-free, perpetual, license to use, copy, create derivative
+%# works based on those contributions, and sublicense and distribute
+%# those contributions and any derivatives thereof.
+%# 
+%# END BPS TAGGED BLOCK }}}
+<%INIT>
+ my $content = $Object->Content;
+ my $DateObj = new RT::Date ( $session{'CurrentUser'} );
+ $DateObj->Set( Format => 'ISO', Value => $content );
+ $content = $DateObj->AsString;
+</%INIT>
+<%$content|n%>
+<%ARGS>
+$Object
+</%ARGS>
diff --git a/share/html/Search/Elements/PickCFs b/share/html/Search/Elements/PickCFs
index ba25cde..beda9f7 100644
--- a/share/html/Search/Elements/PickCFs
+++ b/share/html/Search/Elements/PickCFs
@@ -78,20 +78,41 @@ while ( my $CustomField = $CustomFields->Next ) {
     my %line;
     $line{'Name'} = "'CF.{" . $CustomField->Name . "}'";
     $line{'Field'} = $CustomField->Name;
-    $line{'Op'} = {
-        Type => 'component',
-        Path => '/Elements/SelectCustomFieldOperator',
-        Arguments => { True => loc("is"),
-                       False => loc("isn't"),
-                       TrueVal=> '=',
-                       FalseVal => '!=',
-                     },
-    };
-    $line{'Value'} = {
-        Type => 'component',
-        Path => '/Elements/SelectCustomFieldValue',
-        Arguments => { CustomField => $CustomField },
-    };
+
+    # Op
+    if ($CustomField->Type eq 'Date') {
+        $line{'Op'} = {
+            Type => 'component',
+            Path => '/Elements/SelectDateRelation',
+            Arguments => {},
+        };
+    } else {
+        $line{'Op'} = {
+            Type => 'component',
+            Path => '/Elements/SelectCustomFieldOperator',
+            Arguments => { True => loc("is"),
+                           False => loc("isn't"),
+                           TrueVal=> '=',
+                           FalseVal => '!=',
+                         },
+        };
+    }
+
+    # Value
+    if ($CustomField->Type eq 'Date') {
+        $line{'Value'} = {
+            Type => 'component',
+            Path => '/Elements/SelectDate',
+            Arguments => {},
+        };
+    } else {
+        $line{'Value'} = {
+            Type => 'component',
+            Path => '/Elements/SelectCustomFieldValue',
+            Arguments => { CustomField => $CustomField },
+        };
+    }
+
     push @lines, \%line;
 }
 

commit e48fe729291aa1fd2c45627e72ee4ed352bdcd4d
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Thu Jul 22 13:41:24 2010 +0800

    cf date test

diff --git a/t/web/cf_date.t b/t/web/cf_date.t
new file mode 100644
index 0000000..293988c
--- /dev/null
+++ b/t/web/cf_date.t
@@ -0,0 +1,99 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use RT::Test tests => 19;
+
+my ($baseurl, $m) = RT::Test->started_ok;
+ok $m->login, 'logged in as root';
+
+my $cf_name = 'test cf date';
+
+my $cfid;
+diag "Create a CF" if $ENV{'TEST_VERBOSE'};
+{
+    $m->follow_link( text => 'Configuration' );
+    $m->title_is(q/RT Administration/, 'admin screen');
+    $m->follow_link( text => 'Custom Fields' );
+    $m->title_is(q/Select a Custom Field/, 'admin-cf screen');
+    $m->follow_link( text => 'Create' );
+    $m->submit_form(
+        form_name => "ModifyCustomField",
+        fields => {
+            Name          => $cf_name,
+            TypeComposite => 'Date-1',
+            LookupType    => 'RT::Queue-RT::Ticket',
+        },
+    );
+    $m->content_like( qr/Object created/, 'created CF sucessfully' );
+    $cfid = $m->form_name('ModifyCustomField')->value('id');
+    ok $cfid, "found id of the CF in the form, it's #$cfid";
+}
+
+diag "apply the CF to General queue" if $ENV{'TEST_VERBOSE'};
+my $queue = RT::Test->load_or_create_queue( Name => 'General' );
+ok $queue && $queue->id, 'loaded or created queue';
+
+{
+    $m->follow_link( text => 'Queues' );
+    $m->title_is(q/Admin queues/, 'admin-queues screen');
+    $m->follow_link( text => 'General' );
+    $m->title_is(q/Editing Configuration for queue General/, 'admin-queue: general');
+    $m->follow_link( text => 'Ticket Custom Fields' );
+    $m->title_is(q/Edit Custom Fields for General/, 'admin-queue: general cfid');
+
+    $m->form_name('EditCustomFields');
+    $m->tick( "AddCustomField" => $cfid );
+    $m->click('UpdateCFs');
+
+    $m->content_like( qr/Object created/, 'TCF added to the queue' );
+}
+
+diag 'check if we have cf in ticket create page' if $ENV{'TEST_VERBOSE'};
+{
+    $m->submit_form(
+        form_name => "CreateTicketInQueue",
+        fields => { Queue => 'General' },
+    );
+    $m->content_like(qr/Select date/, 'has cf field');
+    # Calendar link is added via js, so can't test it as link
+    $m->content_like(qr/Calendar/, 'has Calendar');
+
+    my $form = $m->form_name("TicketCreate");
+
+    $m->submit_form(
+        form_name => "TicketCreate",
+        fields    => {
+            Subject                                       => 'test',
+            Content                                       => 'test',
+            "Object-RT::Ticket--CustomField-$cfid-Values" => '2010-05-04',
+        },
+    );
+    $m->content_like(qr/Ticket \d+ created/, "a ticket is created succesfully");
+
+    $m->content_like(qr/test cf date:/, 'has no cf date field on the page');
+    $m->content_like(qr/Tue May 04 00:00:00 2010/, 'has cf date value on the page');
+}
+
+diag 'check invalid inputs' if $ENV{'TEST_VERBOSE'};
+{
+    $m->submit_form(
+        form_name => "CreateTicketInQueue",
+        fields => { Queue => 'General' },
+    );
+    my $form = $m->form_name("TicketCreate");
+
+    $m->submit_form(
+        form_name => "TicketCreate",
+        fields    => {
+            Subject                                       => 'test',
+            Content                                       => 'test',
+            "Object-RT::Ticket--CustomField-$cfid-Values" => 'foodate',
+        },
+    );
+    $m->content_like(qr/Ticket \d+ created/, "a ticket is created succesfully");
+
+    $m->content_like(qr/test cf date:/, 'has no cf date field on the page');
+    $m->content_unlike(qr/foodate/, 'invalid dates not set');
+}

commit 3cf583c6c1614053f105f80492b8e00ea63d300a
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Fri Jul 23 16:06:33 2010 +0800

    more tests

diff --git a/t/web/cf_date.t b/t/web/cf_date.t
index 293988c..18885fd 100644
--- a/t/web/cf_date.t
+++ b/t/web/cf_date.t
@@ -3,10 +3,12 @@
 use strict;
 use warnings;
 
-use RT::Test tests => 19;
-
+use RT::Test tests => 29;
+RT->Config->Set( 'Timezone' => 'US/Eastern' );
 my ($baseurl, $m) = RT::Test->started_ok;
 ok $m->login, 'logged in as root';
+my $root = RT::User->new( $RT::SystemUser );
+ok( $root->Load('root'), 'load root user' );
 
 my $cf_name = 'test cf date';
 
@@ -50,8 +52,10 @@ ok $queue && $queue->id, 'loaded or created queue';
     $m->content_like( qr/Object created/, 'TCF added to the queue' );
 }
 
-diag 'check if we have cf in ticket create page' if $ENV{'TEST_VERBOSE'};
+diag 'check valid inputs with various timezones in ticket create page' if $ENV{'TEST_VERBOSE'};
 {
+    my ( $ticket, $id );
+
     $m->submit_form(
         form_name => "CreateTicketInQueue",
         fields => { Queue => 'General' },
@@ -60,22 +64,64 @@ diag 'check if we have cf in ticket create page' if $ENV{'TEST_VERBOSE'};
     # Calendar link is added via js, so can't test it as link
     $m->content_like(qr/Calendar/, 'has Calendar');
 
-    my $form = $m->form_name("TicketCreate");
+    $m->submit_form(
+        form_name => "TicketCreate",
+        fields    => {
+            Subject                                       => 'test',
+            Content                                       => 'test',
+            "Object-RT::Ticket--CustomField-$cfid-Values" => '2010-05-04 08:00:00',
+        },
+    );
+    ok( ($id) = $m->content =~ /Ticket (\d+) created/,
+        "created ticket $id" );
+
+    $ticket = RT::Ticket->new( $RT::SystemUser );
+    $ticket->Load($id);
+    is(
+        $ticket->CustomFieldValues($cfid)->First->Content,
+        '2010-05-04 12:00:00',
+        'date in db is in UTC'
+    );
 
+    $m->content_like(qr/test cf date:/, 'has no cf date field on the page');
+    $m->content_like(qr/Tue May 04 08:00:00 2010/, 'has cf date value on the page');
+
+    $root->SetTimezone( 'Asia/Shanghai' ); # +08:00
+    # interesting that $m->reload doesn't work
+    $m->get_ok( $m->uri );
+    $m->content_like(qr/Tue May 04 20:00:00 2010/, 'cf date value respects user timezone');
+
+    $m->submit_form(
+        form_name => "CreateTicketInQueue",
+        fields => { Queue => 'General' },
+    );
     $m->submit_form(
         form_name => "TicketCreate",
         fields    => {
             Subject                                       => 'test',
             Content                                       => 'test',
-            "Object-RT::Ticket--CustomField-$cfid-Values" => '2010-05-04',
+            "Object-RT::Ticket--CustomField-$cfid-Values" => '2010-05-04 08:00:00',
         },
     );
-    $m->content_like(qr/Ticket \d+ created/, "a ticket is created succesfully");
+    ok( ($id) = $m->content =~ /Ticket (\d+) created/,
+        "created ticket $id" );
+    $ticket = RT::Ticket->new( $RT::SystemUser );
+    $ticket->Load($id);
+    is(
+        $ticket->CustomFieldValues($cfid)->First->Content,
+        '2010-05-04 00:00:00',
+        'date in db is in UTC'
+    );
 
     $m->content_like(qr/test cf date:/, 'has no cf date field on the page');
-    $m->content_like(qr/Tue May 04 00:00:00 2010/, 'has cf date value on the page');
+    $m->content_like(qr/Tue May 04 08:00:00 2010/, 'cf date input respects user timezone');
+    $root->SetTimezone( 'US/Eastern' ); # back to -04:00
+    $m->get_ok( $m->uri );
+    $m->content_like(qr/Mon May 03 20:00:00 2010/, 'cf date value respects user timezone');
 }
 
+
+
 diag 'check invalid inputs' if $ENV{'TEST_VERBOSE'};
 {
     $m->submit_form(
@@ -97,3 +143,4 @@ diag 'check invalid inputs' if $ENV{'TEST_VERBOSE'};
     $m->content_like(qr/test cf date:/, 'has no cf date field on the page');
     $m->content_unlike(qr/foodate/, 'invalid dates not set');
 }
+

commit 3f3eb8908b1790a1ed46af41e7b22b7cbdf5642f
Author: sunnavy <sunnavy at bestpractical.com>
Date:   Fri Jul 23 16:07:31 2010 +0800

    previous patch for search did not work

diff --git a/lib/RT/Tickets_Overlay.pm b/lib/RT/Tickets_Overlay.pm
index 0d3264c..9bc069b 100755
--- a/lib/RT/Tickets_Overlay.pm
+++ b/lib/RT/Tickets_Overlay.pm
@@ -136,7 +136,6 @@ our %FIELD_METADATA = (
     QueueAdminCc     => [ 'WATCHERFIELD'    => 'AdminCc' => 'Queue', ], #loc_left_pair
     QueueWatcher     => [ 'WATCHERFIELD'    => undef     => 'Queue', ], #loc_left_pair
     CustomFieldValue => [ 'CUSTOMFIELD', ], #loc_left_pair
-    DateCustomFieldValue => [ 'DATECUSTOMFIELD', ],
     CustomField      => [ 'CUSTOMFIELD', ], #loc_left_pair
     CF               => [ 'CUSTOMFIELD', ], #loc_left_pair
     Updated          => [ 'TRANSDATE', ], #loc_left_pair
@@ -161,7 +160,6 @@ our %dispatch = (
     WATCHERFIELD    => \&_WatcherLimit,
     MEMBERSHIPFIELD => \&_WatcherMembershipLimit,
     CUSTOMFIELD     => \&_CustomFieldLimit,
-    DATECUSTOMFIELD => \&_DateCustomFieldLimit,
     HASATTRIBUTE    => \&_HasAttributeLimit,
 );
 our %can_bundle = ();# WATCHERFIELD => "yes", );
@@ -1342,101 +1340,6 @@ sub _CustomFieldJoin {
     return ($TicketCFs, $CFs);
 }
 
-=head2 _DateCustomFieldLimit
-
-Limit based on CustomFields of type Date
-
-Meta Data:
-  none
-
-=cut
-
-sub _DateCustomFieldLimit {
-    my ( $self, $_field, $op, $value, %rest ) = @_;
-
-    my $field = $rest{'SUBKEY'} || die "No field specified";
-
-    # For our sanity, we can only limit on one queue at a time
-
-    my ($queue, $cfid, $column);
-    ($queue, $field, $cfid, $column) = $self->_CustomFieldDecipher( $field );
-
-# If we're trying to find custom fields that don't match something, we
-# want tickets where the custom field has no value at all.  Note that
-# we explicitly don't include the "IS NULL" case, since we would
-# otherwise end up with a redundant clause.
-
-    my $null_columns_ok;
-    if ( ( $op =~ /^NOT LIKE$/i ) or ( $op eq '!=' ) ) {
-        $null_columns_ok = 1;
-    }
-
-    my $cfkey = $cfid ? $cfid : "$queue.$field";
-    my ($TicketCFs, $CFs) = $self->_CustomFieldJoin( $cfkey, $cfid, $field );
-
-    $self->_OpenParen;
-
-    if ( $CFs && !$cfid ) {
-        $self->SUPER::Limit(
-            ALIAS           => $CFs,
-            FIELD           => 'Name',
-            VALUE           => $field,
-            ENTRYAGGREGATOR => 'AND',
-        );
-    }
-
-    $self->_OpenParen if $null_columns_ok;
-
-    my $date = RT::Date->new( $self->CurrentUser );
-    $date->Set( Format => 'unknown', Value => $value );
-
-    if ( $op eq "=" ) {
-
-        # if we're specifying =, that means we want everything on a
-        # particular single day.  in the database, we need to check for >
-        # and < the edges of that day.
-
-        $date->SetToMidnight( Timezone => 'server' );
-        my $daystart = $date->ISO;
-        $date->AddDay;
-        my $dayend = $date->ISO;
-
-        $self->_OpenParen;
-
-        $self->_SQLLimit(
-            ALIAS    => $TicketCFs,
-            FIELD    => 'Content',
-            OPERATOR => ">=",
-            VALUE    => $daystart,
-            %rest,
-        );
-
-        $self->_SQLLimit(
-            ALIAS    => $TicketCFs,
-            FIELD    => 'Content',
-            OPERATOR => "<=",
-            VALUE    => $dayend,
-            %rest,
-            ENTRYAGGREGATOR => 'AND',
-        );
-
-        $self->_CloseParen;
-
-    }
-    else {
-        $self->_SQLLimit(
-            ALIAS    => $TicketCFs,
-            FIELD    => 'Content',
-            OPERATOR => $op,
-            VALUE    => $date->ISO,
-            %rest,
-        );
-    }
-
-    $self->_CloseParen;
-
-}
-
 =head2 _CustomFieldLimit
 
 Limit based on CustomFields
@@ -1521,38 +1424,77 @@ sub _CustomFieldLimit {
             );
         }
         elsif ( $op eq '=' || $op eq '!=' || $op eq '<>' ) {
-            unless ( length( Encode::encode_utf8($value) ) > 255 ) {
-                $self->_SQLLimit(
-                    ALIAS      => $TicketCFs,
-                    FIELD      => 'Content',
-                    OPERATOR   => $op,
-                    VALUE      => $value,
-                    %rest
-                );
-            } else {
+            my $cf = RT::CustomField->new( $self->CurrentUser );
+            $cf->Load($field);
+            if ( $op eq '=' && $cf->Type eq 'Date' ) {
+
+               # if we're specifying =, that means we want everything on a
+               # particular single day.  in the database, we need to check for >
+               # and < the edges of that day.
+
+                my $date = RT::Date->new( $self->CurrentUser );
+                $date->Set( Format => 'unknown', Value => $value );
+                $date->SetToMidnight( Timezone => 'server' );
+                my $daystart = $date->ISO;
+                $date->AddDay;
+                my $dayend = $date->ISO;
+
                 $self->_OpenParen;
+
                 $self->_SQLLimit(
-                    ALIAS      => $TicketCFs,
-                    FIELD      => 'Content',
-                    OPERATOR   => '=',
-                    VALUE      => '',
-                    ENTRYAGGREGATOR => 'OR'
-                );
-                $self->_SQLLimit(
-                    ALIAS      => $TicketCFs,
-                    FIELD      => 'Content',
-                    OPERATOR   => 'IS',
-                    VALUE      => 'NULL',
-                    ENTRYAGGREGATOR => 'OR'
+                    ALIAS    => $TicketCFs,
+                    FIELD    => 'Content',
+                    OPERATOR => ">=",
+                    VALUE    => $daystart,
+                    %rest,
                 );
-                $self->_CloseParen;
+
                 $self->_SQLLimit(
-                    ALIAS => $TicketCFs,
-                    FIELD => 'LargeContent',
-                    OPERATOR => $fix_op->($op),
-                    VALUE => $value,
+                    ALIAS    => $TicketCFs,
+                    FIELD    => 'Content',
+                    OPERATOR => "<=",
+                    VALUE    => $dayend,
+                    %rest,
                     ENTRYAGGREGATOR => 'AND',
                 );
+
+                $self->_CloseParen;
+            }
+            else {
+                unless ( length( Encode::encode_utf8($value) ) > 255 ) {
+                    $self->_SQLLimit(
+                        ALIAS    => $TicketCFs,
+                        FIELD    => 'Content',
+                        OPERATOR => $op,
+                        VALUE    => $value,
+                        %rest
+                    );
+                }
+                else {
+                    $self->_OpenParen;
+                    $self->_SQLLimit(
+                        ALIAS           => $TicketCFs,
+                        FIELD           => 'Content',
+                        OPERATOR        => '=',
+                        VALUE           => '',
+                        ENTRYAGGREGATOR => 'OR'
+                    );
+                    $self->_SQLLimit(
+                        ALIAS           => $TicketCFs,
+                        FIELD           => 'Content',
+                        OPERATOR        => 'IS',
+                        VALUE           => 'NULL',
+                        ENTRYAGGREGATOR => 'OR'
+                    );
+                    $self->_CloseParen;
+                    $self->_SQLLimit(
+                        ALIAS           => $TicketCFs,
+                        FIELD           => 'LargeContent',
+                        OPERATOR        => $fix_op->($op),
+                        VALUE           => $value,
+                        ENTRYAGGREGATOR => 'AND',
+                    );
+                }
             }
         }
         else {
@@ -2764,11 +2706,6 @@ sub LimitCustomField {
         $args{CUSTOMFIELD} = $CF->Id;
     }
 
-    # Handle special customfields types
-    if ($CF->Type eq 'Date') {
-        $args{FIELD} = 'DateCustomFieldValue';
-    }
-
     #If we are looking to compare with a null value.
     if ( $args{'OPERATOR'} =~ /^is$/i ) {
         $args{'DESCRIPTION'}

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


More information about the Rt-commit mailing list