[Rt-commit] rt branch, 4.2/allow-times-for-ical-feeds, created. rt-4.0.8-332-g95fbf58

Alex Vandiver alexmv at bestpractical.com
Fri Nov 2 13:23:02 EDT 2012


The branch, 4.2/allow-times-for-ical-feeds has been created
        at  95fbf58c14f0c7e7aa57777fbccf0efeabb49309 (commit)

- Log -----------------------------------------------------------------
commit 4069bf1b6232db66f6e6a050591249350641bcce
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Tue Aug 28 10:45:03 2012 -0400

    Add time as an option for iCal feed entries
    
    Allow time to be optionally included in iCal feed events
    so these events will show up in the calendar at the specific
    start or due time from the ticket rather than being all-day
    events. This is a global config option which can also be
    set individually by users.

diff --git a/etc/RT_Config.pm.in b/etc/RT_Config.pm.in
index 43618c5..9ed8126 100755
--- a/etc/RT_Config.pm.in
+++ b/etc/RT_Config.pm.in
@@ -2054,6 +2054,20 @@ minutes.  Note that this only effects entry, not display.
 
 Set($DefaultTimeUnitsToHours, 0);
 
+=item C<$TimeInICal>
+
+By default, events in the iCal feed on the ticket search page
+contain only dates, making them all day calendar events. Set
+C<$TimeInICal> if you have start or due dates on tickets that
+have significant time values and you want those times to be
+included in the events in the iCal feed.
+
+This option can also be set as an individual user preference.
+
+=cut
+
+Set($TimeInICal, 0);
+
 =back
 
 
diff --git a/lib/RT/Config.pm b/lib/RT/Config.pm
index a507f1d..70f6266 100644
--- a/lib/RT/Config.pm
+++ b/lib/RT/Config.pm
@@ -220,6 +220,16 @@ our %META = (
             $self->Set('WebDefaultStylesheet', 'aileron');
         },
     },
+    TimeInICal => {
+        Section     => 'General',
+        Overridable => 1,
+        SortOrder   => 5,
+        Widget      => '/Widgets/Form/Boolean',
+        WidgetArguments => {
+            Description => 'Include time in iCal feed events?', # loc
+            Hints       => 'Formats iCal feed events with date and time' #loc
+        }
+    },
     UseSideBySideLayout => {
         Section => 'Ticket composition',
         Overridable => 1,
diff --git a/share/html/NoAuth/iCal/dhandler b/share/html/NoAuth/iCal/dhandler
index 0e9e812..a4c5c51 100644
--- a/share/html/NoAuth/iCal/dhandler
+++ b/share/html/NoAuth/iCal/dhandler
@@ -101,16 +101,24 @@ while (my $t = $tickets->Next) {
        'last-modified' => $t->LastUpdatedObj->iCal,
     ) for $start, $end;
 
+    my %time = ( Time => 0 );
+    my %ical_value = ( value => 'DATE' );
+
+    if ( RT->Config->Get('TimeInICal', $user) ){
+        $time{Time} = 1;
+        $ical_value{value} = 'DATE-TIME';
+    }
+
     $start->add_properties(
-        summary   => "Start: ".$t->Subject,
-        dtstart   => [$starttime->iCal( Time => 0 ) => { value => 'DATE' }],
-        dtend     => [$starttime->iCal( Time => 0 ) => { value => 'DATE'}],
-    );
+                           summary   => "Start: ".$t->Subject,
+                           dtstart   => [$starttime->iCal( %time ) => \%ical_value ],
+                           dtend     => [$starttime->iCal( %time ) => \%ical_value ],
+                           );
     $end->add_properties(
-        summary   => "Due: ".$t->Subject,
-        dtstart   => [$t->DueObj->iCal( Time => 0 ) => { value => 'DATE' }],
-        dtend     => [$t->DueObj->iCal( Time => 0 ) => { value => 'DATE' }],
-    );
+                         summary   => "Due: ".$t->Subject,
+                         dtstart   => [$t->DueObj->iCal( %time ) => \%ical_value ],
+                         dtend     => [$t->DueObj->iCal( %time ) => \%ical_value ],
+                         );
 
     $feed->add_entry($start);
     $feed->add_entry($end);
diff --git a/t/web/search_ical.t b/t/web/search_ical.t
new file mode 100644
index 0000000..841ac35
--- /dev/null
+++ b/t/web/search_ical.t
@@ -0,0 +1,118 @@
+#!/usr/bin/perl
+
+use strict;
+
+use Data::ICal;
+use RT::Test tests => 44;
+
+my $start_obj = RT::Date->new( RT->SystemUser );
+$start_obj->SetToNow;
+my $start = $start_obj->iCal( Time => 1);
+
+my $due_obj = RT::Date->new( RT->SystemUser );
+$due_obj->SetToNow;
+$due_obj->AddDays(2);
+my $due = $due_obj->iCal( Time => 1);
+
+diag 'Test iCal with date only';
+{
+    my ($baseurl, $agent) = RT::Test->started_ok;
+
+    my $ticket = RT::Ticket->new(RT->SystemUser);
+
+    for ( 1 .. 5 ) {
+        $ticket->Create(
+                        Subject   => 'Ticket ' . $_,
+                        Queue     => 'General',
+                        Owner     => 'root',
+                        Requestor => 'ical at localhost',
+                        Starts    => $start_obj->ISO,
+                        Due       => $due_obj->ISO,
+                       );
+    }
+
+    ok $agent->login('root', 'password'), 'logged in as root';
+
+    $agent->get_ok('/Search/Build.html');
+    $agent->form_name('BuildQuery');
+    $agent->field('idOp', '>');
+    $agent->field('ValueOfid', '0');
+    $agent->submit('DoSearch');
+    $agent->follow_link_ok({id => 'page-results'});
+
+    for ( 1 .. 5 ) {
+        $agent->content_contains('Ticket ' . $_);
+    }
+
+    $agent->follow_link_ok( { text => 'iCal' } );
+
+    is( $agent->content_type, 'text/calendar', 'content type is text/calendar' );
+
+    for ( 1 .. 5 ) {
+        $agent->content_like(qr/URL\:$baseurl\/\?q=$_/);
+    }
+
+    my $ical = Data::ICal->new(data => $agent->content);
+
+    my @entries = $ical->entries;
+    my $ical_count = @{$entries[0]};
+    is( $ical_count, 10, "Got $ical_count ical entries");
+
+    my $prop_ref = $entries[0]->[0]->properties;
+    my $start = $start_obj->ISO( Time => 0);
+    $start =~ s/-//g;
+    is($prop_ref->{'dtstart'}->[0]->value, $start, "Got start date: $start");
+    like( $prop_ref->{'dtstart'}->[0]->as_string, qr/VALUE=DATE\:/, 'Got DATE value');
+
+    $prop_ref = $entries[0]->[1]->properties;
+    my $due = $due_obj->ISO( Time => 0);
+    $due =~ s/-//g;
+    is($prop_ref->{'dtend'}->[0]->value, $due, "Got due date: $due");
+    like( $prop_ref->{'dtend'}->[0]->as_string, qr/VALUE=DATE\:/, 'Got DATE value');
+}
+
+RT::Test->stop_server;
+
+diag 'Test iCal with date and time';
+{
+    RT->Config->Set(TimeInICal =>1);
+    my ($baseurl, $agent) = RT::Test->started_ok;
+
+    ok $agent->login('root', 'password'), 'logged in as root';
+
+    $agent->get_ok('/Search/Build.html');
+    $agent->form_name('BuildQuery');
+    $agent->field('idOp', '>');
+    $agent->field('ValueOfid', '0');
+    $agent->submit('DoSearch');
+    $agent->follow_link_ok({id => 'page-results'});
+
+    for ( 1 .. 5 ) {
+        $agent->content_contains('Ticket ' . $_);
+    }
+
+    my $link = $agent->find_link( text => 'iCal' ); # use $link later
+    $agent->get_ok($link->url);
+
+    is( $agent->content_type, 'text/calendar', 'content type is text/calendar' );
+
+    for ( 1 .. 5 ) {
+        $agent->content_like(qr/URL\:$baseurl\/\?q=$_/);
+    }
+
+    my $ical = Data::ICal->new(data => $agent->content);
+
+    my @entries = $ical->entries;
+    my $ical_count = @{$entries[0]};
+    is( $ical_count, 10, "Got $ical_count ical entries");
+
+    my $prop_ref = $entries[0]->[0]->properties;
+    $start =~ s/-//g;
+    is($prop_ref->{'dtstart'}->[0]->value, $start, "Got start date with time: $start");
+    like( $prop_ref->{'dtstart'}->[0]->as_string, qr/VALUE=DATE-TIME\:/, 'Got DATE-TIME value');
+
+    $prop_ref = $entries[0]->[1]->properties;
+    $due =~ s/-//g;
+    is($prop_ref->{'dtend'}->[0]->value, $due, "Got due date with time: $due");
+    like( $prop_ref->{'dtend'}->[0]->as_string, qr/VALUE=DATE-TIME\:/, 'Got DATE-TIME value');
+}

commit 31ab9c76f2bb5f30f98f929e62c12a1eafaf9b08
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Tue Aug 28 16:24:14 2012 -0400

    Provide time in iCal feed based on query param
    
    Even if both the global Time config option and the user
    config options are false, adding ?Time=1 to the iCal feed
    URL will provide events with time in them.

diff --git a/share/html/NoAuth/iCal/dhandler b/share/html/NoAuth/iCal/dhandler
index a4c5c51..e61cec4 100644
--- a/share/html/NoAuth/iCal/dhandler
+++ b/share/html/NoAuth/iCal/dhandler
@@ -104,7 +104,8 @@ while (my $t = $tickets->Next) {
     my %time = ( Time => 0 );
     my %ical_value = ( value => 'DATE' );
 
-    if ( RT->Config->Get('TimeInICal', $user) ){
+    if ( defined $ARGS{Time} ?
+         $ARGS{Time} : RT->Config->Get('TimeInICal', $user) ) {
         $time{Time} = 1;
         $ical_value{value} = 'DATE-TIME';
     }
diff --git a/t/web/search_ical.t b/t/web/search_ical.t
index 841ac35..04c5a7e 100644
--- a/t/web/search_ical.t
+++ b/t/web/search_ical.t
@@ -3,7 +3,7 @@
 use strict;
 
 use Data::ICal;
-use RT::Test tests => 44;
+use RT::Test tests => 65;
 
 my $start_obj = RT::Date->new( RT->SystemUser );
 $start_obj->SetToNow;
@@ -73,7 +73,7 @@ diag 'Test iCal with date only';
 
 RT::Test->stop_server;
 
-diag 'Test iCal with date and time';
+diag 'Test iCal with date and time with config option';
 {
     RT->Config->Set(TimeInICal =>1);
     my ($baseurl, $agent) = RT::Test->started_ok;
@@ -116,3 +116,49 @@ diag 'Test iCal with date and time';
     is($prop_ref->{'dtend'}->[0]->value, $due, "Got due date with time: $due");
     like( $prop_ref->{'dtend'}->[0]->as_string, qr/VALUE=DATE-TIME\:/, 'Got DATE-TIME value');
 }
+
+RT::Test->stop_server;
+
+diag 'Test iCal with date and time using query param';
+{
+    RT->Config->Set(TimeInICal =>0);
+    my ($baseurl, $agent) = RT::Test->started_ok;
+
+    ok $agent->login('root', 'password'), 'logged in as root';
+
+    $agent->get_ok('/Search/Build.html');
+    $agent->form_name('BuildQuery');
+    $agent->field('idOp', '>');
+    $agent->field('ValueOfid', '0');
+    $agent->submit('DoSearch');
+    $agent->follow_link_ok({id => 'page-results'});
+
+    for ( 1 .. 5 ) {
+        $agent->content_contains('Ticket ' . $_);
+    }
+
+    my $link = $agent->find_link( text => 'iCal' );
+    $agent->get_ok($link->url . '?Time=1');
+
+    is( $agent->content_type, 'text/calendar', 'content type is text/calendar' );
+
+    for ( 1 .. 5 ) {
+        $agent->content_like(qr/URL\:$baseurl\/\?q=$_/);
+    }
+
+    my $ical = Data::ICal->new(data => $agent->content);
+
+    my @entries = $ical->entries;
+    my $ical_count = @{$entries[0]};
+    is( $ical_count, 10, "Got $ical_count ical entries");
+
+    my $prop_ref = $entries[0]->[0]->properties;
+    $start =~ s/-//g;
+    is($prop_ref->{'dtstart'}->[0]->value, $start, "Got start date with time: $start");
+    like( $prop_ref->{'dtstart'}->[0]->as_string, qr/VALUE=DATE-TIME\:/, 'Got DATE-TIME value');
+
+    $prop_ref = $entries[0]->[1]->properties;
+    $due =~ s/-//g;
+    is($prop_ref->{'dtend'}->[0]->value, $due, "Got due date with time: $due");
+    like( $prop_ref->{'dtend'}->[0]->as_string, qr/VALUE=DATE-TIME\:/, 'Got DATE-TIME value');
+}

commit 95fbf58c14f0c7e7aa57777fbccf0efeabb49309
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Tue Aug 28 16:39:02 2012 -0400

    Add single event option to iCal feed
    
    Add a SingleEvent mode to the iCal feed such that if you pass
    SingleEvent=1 as a query parameter, each ticket in the feed will
    create a single calendar event with the start and due date
    rather than the default two events.

diff --git a/share/html/NoAuth/iCal/dhandler b/share/html/NoAuth/iCal/dhandler
index e61cec4..a48002c 100644
--- a/share/html/NoAuth/iCal/dhandler
+++ b/share/html/NoAuth/iCal/dhandler
@@ -110,19 +110,28 @@ while (my $t = $tickets->Next) {
         $ical_value{value} = 'DATE-TIME';
     }
 
-    $start->add_properties(
-                           summary   => "Start: ".$t->Subject,
-                           dtstart   => [$starttime->iCal( %time ) => \%ical_value ],
-                           dtend     => [$starttime->iCal( %time ) => \%ical_value ],
-                           );
-    $end->add_properties(
-                         summary   => "Due: ".$t->Subject,
-                         dtstart   => [$t->DueObj->iCal( %time ) => \%ical_value ],
-                         dtend     => [$t->DueObj->iCal( %time ) => \%ical_value ],
-                         );
-
-    $feed->add_entry($start);
-    $feed->add_entry($end);
+    if( $ARGS{SingleEvent} ){
+        $start->add_properties(
+                               summary   => $t->Subject,
+                               dtstart   => [$starttime->iCal( %time ) => \%ical_value ],
+                               dtend     => [$t->DueObj->iCal( %time ) => \%ical_value ],
+                              );
+        $feed->add_entry($start);
+    }
+    else{
+        $start->add_properties(
+                               summary   => "Start: ".$t->Subject,
+                               dtstart   => [$starttime->iCal( %time ) => \%ical_value ],
+                               dtend     => [$starttime->iCal( %time ) => \%ical_value ],
+                              );
+        $end->add_properties(
+                             summary   => "Due: ".$t->Subject,
+                             dtstart   => [$t->DueObj->iCal( %time ) => \%ical_value ],
+                             dtend     => [$t->DueObj->iCal( %time ) => \%ical_value ],
+                            );
+        $feed->add_entry($start);
+        $feed->add_entry($end);
+    }
 }
 
 $m->clear_buffer;
diff --git a/t/web/search_ical.t b/t/web/search_ical.t
index 04c5a7e..210bb2c 100644
--- a/t/web/search_ical.t
+++ b/t/web/search_ical.t
@@ -3,7 +3,7 @@
 use strict;
 
 use Data::ICal;
-use RT::Test tests => 65;
+use RT::Test tests => 77;
 
 my $start_obj = RT::Date->new( RT->SystemUser );
 $start_obj->SetToNow;
@@ -161,4 +161,33 @@ diag 'Test iCal with date and time using query param';
     $due =~ s/-//g;
     is($prop_ref->{'dtend'}->[0]->value, $due, "Got due date with time: $due");
     like( $prop_ref->{'dtend'}->[0]->as_string, qr/VALUE=DATE-TIME\:/, 'Got DATE-TIME value');
+
+    diag 'Test iCal with date and time in single events';
+
+    my $url = $link->url . '?SingleEvent=1&Time=1';
+    $agent->get_ok($url);
+
+    is( $agent->content_type, 'text/calendar', 'content type is text/calendar' );
+
+    for ( 1 .. 5 ) {
+        $agent->content_like(qr/URL\:$baseurl\/\?q=$_/);
+    }
+
+    $ical = Data::ICal->new(data => $agent->content);
+
+    @entries = $ical->entries;
+    $ical_count = @{$entries[0]};
+
+    # Only 5 entries in single event mode
+    is( $ical_count, 5, "Got $ical_count ical entries");
+
+    $prop_ref = $entries[0]->[0]->properties;
+    $start =~ s/-//g;
+    is($prop_ref->{'dtstart'}->[0]->value, $start, "Got start date with time: $start");
+    like( $prop_ref->{'dtstart'}->[0]->as_string, qr/VALUE=DATE-TIME\:/, 'Got DATE-TIME value');
+
+    $prop_ref = $entries[0]->[1]->properties;
+    $due =~ s/-//g;
+    is($prop_ref->{'dtend'}->[0]->value, $due, "Got due date with time: $due");
+    like( $prop_ref->{'dtend'}->[0]->as_string, qr/VALUE=DATE-TIME\:/, 'Got DATE-TIME value');
 }

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


More information about the Rt-commit mailing list