[Rt-commit] rt branch, 4.0/allow-times-for-ical-feeds, created. rt-4.0.6-250-g93c0eb8

Jim Brandt jbrandt at bestpractical.com
Wed Aug 8 11:28:59 EDT 2012


The branch, 4.0/allow-times-for-ical-feeds has been created
        at  93c0eb8333f42e997c24f16cdb31fe40b9108cde (commit)

- Log -----------------------------------------------------------------
commit 93c0eb8333f42e997c24f16cdb31fe40b9108cde
Author: Jim Brandt <jbrandt at bestpractical.com>
Date:   Wed Aug 8 11:01:59 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.

diff --git a/etc/RT_Config.pm.in b/etc/RT_Config.pm.in
index 784d76c..435bdb9 100755
--- a/etc/RT_Config.pm.in
+++ b/etc/RT_Config.pm.in
@@ -2039,6 +2039,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 ba338bb..e9b655a 100644
--- a/lib/RT/Config.pm
+++ b/lib/RT/Config.pm
@@ -215,6 +215,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 c86f4cf..6f33929 100644
--- a/share/html/NoAuth/iCal/dhandler
+++ b/share/html/NoAuth/iCal/dhandler
@@ -101,15 +101,18 @@ while (my $t = $tickets->Next) {
        'last-modified' => $t->LastUpdatedObj->iCal,
     ) for $start, $end;
 
+    my %time = ( Time => 0 );
+    $time{Time} = 1 if RT->Config->Get('TimeInICal', $user);
+
     $start->add_properties(
         summary   => "Start: ".$t->Subject,
-        dtstart   => [$starttime->iCal( Time => 0 ) => { value => 'DATE' }],
-        dtend     => [$starttime->iCal( Time => 0 ) => { value => 'DATE'}],
+        dtstart   => [$starttime->iCal( %time ) => { value => 'DATE' }],
+        dtend     => [$starttime->iCal( %time ) => { value => 'DATE' }],
     );
     $end->add_properties(
         summary   => "Due: ".$t->Subject,
-        dtstart   => [$t->DueObj->iCal( Time => 0 ) => { value => 'DATE' }],
-        dtend     => [$t->DueObj->iCal( Time => 0 ) => { value => 'DATE' }],
+        dtstart   => [$t->DueObj->iCal( %time ) => { value => 'DATE' }],
+        dtend     => [$t->DueObj->iCal( %time ) => { value => 'DATE' }],
     );
 
     $feed->add_entry($start);
diff --git a/t/web/search_ical.t b/t/web/search_ical.t
new file mode 100644
index 0000000..d08ffe8
--- /dev/null
+++ b/t/web/search_ical.t
@@ -0,0 +1,115 @@
+#!/usr/bin/perl
+
+use strict;
+
+use Data::ICal;
+use RT::Test tests => 40;
+
+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");
+
+    $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");
+}
+
+RT::Test->stop_server;
+
+diag 'Test iCal with date and time';
+{
+    RT->Config->Set(TimeInICal =>1);
+    my ($baseurl, $agent) = RT::Test->started_ok;
+
+    my $ticket = RT::Ticket->new(RT->SystemUser);
+
+    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;
+    $start =~ s/-//g;
+    is($prop_ref->{'dtstart'}->[0]->value, $start, "Got start date with time: $start");
+
+    $prop_ref = $entries[0]->[1]->properties;
+    $due =~ s/-//g;
+    is($prop_ref->{'dtend'}->[0]->value, $due, "Got due date with time: $due");
+}

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


More information about the Rt-commit mailing list