diff --git a/inc/caldav-REPORT-calquery.php b/inc/caldav-REPORT-calquery.php
index f33db985..5bdfc07b 100644
--- a/inc/caldav-REPORT-calquery.php
+++ b/inc/caldav-REPORT-calquery.php
@@ -257,6 +257,14 @@ function BuildSqlFilter( $filter ) {
*/
$responses = array();
+$collection = new DAVResource($request->path);
+$bound_from = $collection->bound_from();
+if ( !$collection->Exists() ) {
+ $request->DoResponse( 404 );
+}
+if ( ! ($collection->IsCalendar() || $collection->IsSchedulingCollection()) ) {
+ $request->DoResponse( 403, translate('The calendar-query report must be run against a collection') );
+}
/**
* @todo Once we are past DB version 1.2.1 we can change this query more radically. The best performance to
@@ -266,16 +274,16 @@ $responses = array();
* AND caldav_data.caldav_type = 'VEVENT' ORDER BY caldav_data.user_no, caldav_data.dav_name;
*/
-$where = " WHERE caldav_data.user_no = $request->user_no AND caldav_data.dav_name ~ ".qpg("^".$request->path)." ";
+$where = " WHERE caldav_data.collection_id = " . $collection->resource_id();
if ( is_array($qry_filters) ) {
dbg_log_array( "calquery", "qry_filters", $qry_filters, true );
$where .= BuildSqlFilter( $qry_filters );
}
-if ( ! $request->AllowedTo('all') ) {
+if ( $collection->Privileges() != privilege_to_bits('DAV::all') ) {
$where .= "AND (calendar_item.class != 'PRIVATE' OR calendar_item.class IS NULL) ";
}
-if ( isset($c->hide_TODO) && $c->hide_TODO && ! $request->AllowedTo('all') ) {
+if ( isset($c->hide_TODO) && $c->hide_TODO && ! $collection->HavePrivilegeTo('DAV::write-content') ) {
$where .= "AND caldav_data.caldav_type NOT IN ('VTODO') ";
}
@@ -285,10 +293,13 @@ if ( isset($c->hide_older_than) && intval($c->hide_older_than > 0) ) {
$sql = "SELECT * FROM caldav_data INNER JOIN calendar_item USING(dav_id,user_no,dav_name)". $where;
if ( isset($c->strict_result_ordering) && $c->strict_result_ordering ) $sql .= " ORDER BY dav_id";
-$qry = new PgQuery( $sql );
-if ( $qry->Exec("calquery",__LINE__,__FILE__) && $qry->rows > 0 ) {
+$qry = new AwlQuery( $sql );
+if ( $qry->Exec("calquery",__LINE__,__FILE__) && $qry->rows() > 0 ) {
while( $calendar_object = $qry->Fetch() ) {
if ( !$need_post_filter || apply_filter( $qry_filters, $calendar_object ) ) {
+ if ( $bound_from != $collection->dav_name() ) {
+ $calendar_object->dav_name = str_replace( $bound_from, $collection->dav_name(), $calendar_object->dav_name);
+ }
if ( $need_expansion ) {
$ics = new iCalComponent($calendar_object->caldav_data);
$expanded = expand_event_instances($ics, $expand_range_start, $expand_range_end);
diff --git a/testing/tests/regression-suite/969-REPORT-bound.result b/testing/tests/regression-suite/969-REPORT-bound.result
new file mode 100644
index 00000000..d20bd439
--- /dev/null
+++ b/testing/tests/regression-suite/969-REPORT-bound.result
@@ -0,0 +1,199 @@
+
+
+
+ /caldav.php/user4/user2/33169d69-2969-4a96-a3e1-2e312b7614e6.ics
+
+
+ BEGIN:VCALENDAR
+PRODID:-//davical.org//NONSGML AWL Calendar//EN
+VERSION:2.0
+CALSCALE:GREGORIAN
+BEGIN:VEVENT
+CREATED:20081023T054958Z
+LAST-MODIFIED:20081023T055044Z
+DTSTAMP:20081023T054958Z
+UID:33169d69-2969-4a96-a3e1-2e312b7614e6
+SUMMARY:Daily Action Meeting
+RRULE:FREQ=DAILY;INTERVAL=1;BYDAY=MO,TU,WE,TH,FR
+X-MOZ-GENERATION:2
+DTSTART:20081020T110000Z
+DURATION:PT30M
+END:VEVENT
+BEGIN:VEVENT
+CREATED:20081023T054958Z
+LAST-MODIFIED:20081023T055044Z
+DTSTAMP:20081023T054958Z
+UID:33169d69-2969-4a96-a3e1-2e312b7614e6
+SUMMARY:Daily Action Meeting
+RRULE:FREQ=DAILY;INTERVAL=1;BYDAY=MO,TU,WE,TH,FR
+X-MOZ-GENERATION:2
+DTSTART:20081021T110000Z
+DURATION:PT30M
+END:VEVENT
+BEGIN:VEVENT
+CREATED:20081023T054958Z
+LAST-MODIFIED:20081023T055044Z
+DTSTAMP:20081023T054958Z
+UID:33169d69-2969-4a96-a3e1-2e312b7614e6
+SUMMARY:Daily Action Meeting
+RRULE:FREQ=DAILY;INTERVAL=1;BYDAY=MO,TU,WE,TH,FR
+X-MOZ-GENERATION:2
+DTSTART:20081022T110000Z
+DURATION:PT30M
+END:VEVENT
+BEGIN:VEVENT
+CREATED:20081023T054958Z
+LAST-MODIFIED:20081023T055044Z
+DTSTAMP:20081023T054958Z
+UID:33169d69-2969-4a96-a3e1-2e312b7614e6
+SUMMARY:Daily Action Meeting
+RRULE:FREQ=DAILY;INTERVAL=1;BYDAY=MO,TU,WE,TH,FR
+X-MOZ-GENERATION:2
+DTSTART:20081023T110000Z
+DURATION:PT30M
+END:VEVENT
+BEGIN:VEVENT
+CREATED:20081023T054958Z
+LAST-MODIFIED:20081023T055044Z
+DTSTAMP:20081023T054958Z
+UID:33169d69-2969-4a96-a3e1-2e312b7614e6
+SUMMARY:Daily Action Meeting
+RRULE:FREQ=DAILY;INTERVAL=1;BYDAY=MO,TU,WE,TH,FR
+X-MOZ-GENERATION:2
+DTSTART:20081024T110000Z
+DURATION:PT30M
+END:VEVENT
+BEGIN:VEVENT
+CREATED:20081023T054958Z
+LAST-MODIFIED:20081023T055044Z
+DTSTAMP:20081023T054958Z
+UID:33169d69-2969-4a96-a3e1-2e312b7614e6
+SUMMARY:Daily Action Meeting
+RRULE:FREQ=DAILY;INTERVAL=1;BYDAY=MO,TU,WE,TH,FR
+X-MOZ-GENERATION:2
+DTSTART:20081027T110000Z
+DURATION:PT30M
+END:VEVENT
+BEGIN:VEVENT
+CREATED:20081023T054958Z
+LAST-MODIFIED:20081023T055044Z
+DTSTAMP:20081023T054958Z
+UID:33169d69-2969-4a96-a3e1-2e312b7614e6
+SUMMARY:Daily Action Meeting
+RRULE:FREQ=DAILY;INTERVAL=1;BYDAY=MO,TU,WE,TH,FR
+X-MOZ-GENERATION:2
+DTSTART:20081028T110000Z
+DURATION:PT30M
+END:VEVENT
+BEGIN:VEVENT
+CREATED:20081023T054958Z
+LAST-MODIFIED:20081023T055044Z
+DTSTAMP:20081023T054958Z
+UID:33169d69-2969-4a96-a3e1-2e312b7614e6
+SUMMARY:Daily Action Meeting
+RRULE:FREQ=DAILY;INTERVAL=1;BYDAY=MO,TU,WE,TH,FR
+X-MOZ-GENERATION:2
+DTSTART:20081029T110000Z
+DURATION:PT30M
+END:VEVENT
+BEGIN:VEVENT
+CREATED:20081023T054958Z
+LAST-MODIFIED:20081023T055044Z
+DTSTAMP:20081023T054958Z
+UID:33169d69-2969-4a96-a3e1-2e312b7614e6
+SUMMARY:Daily Action Meeting
+RRULE:FREQ=DAILY;INTERVAL=1;BYDAY=MO,TU,WE,TH,FR
+X-MOZ-GENERATION:2
+DTSTART:20081030T110000Z
+DURATION:PT30M
+END:VEVENT
+BEGIN:VEVENT
+CREATED:20081023T054958Z
+LAST-MODIFIED:20081023T055044Z
+DTSTAMP:20081023T054958Z
+UID:33169d69-2969-4a96-a3e1-2e312b7614e6
+SUMMARY:Daily Action Meeting
+RRULE:FREQ=DAILY;INTERVAL=1;BYDAY=MO,TU,WE,TH,FR
+X-MOZ-GENERATION:2
+DTSTART:20081031T110000Z
+DURATION:PT30M
+END:VEVENT
+END:VCALENDAR
+
+
+ HTTP/1.1 200 OK
+
+
+
+ /caldav.php/user4/user2/047871e3-6b70-4178-9af8-0ceb50f7b092.ics
+
+
+ BEGIN:VCALENDAR
+PRODID:-//davical.org//NONSGML AWL Calendar//EN
+VERSION:2.0
+CALSCALE:GREGORIAN
+BEGIN:VEVENT
+CREATED:20081023T054934Z
+LAST-MODIFIED:20081023T055059Z
+DTSTAMP:20081023T054934Z
+UID:047871e3-6b70-4178-9af8-0ceb50f7b092
+SUMMARY:Weekly Project Meeting
+RRULE:FREQ=WEEKLY;INTERVAL=1
+X-MOZ-GENERATION:2
+DTSTART:20081020T090000Z
+DURATION:PT60M
+END:VEVENT
+BEGIN:VEVENT
+CREATED:20081023T054934Z
+LAST-MODIFIED:20081023T055059Z
+DTSTAMP:20081023T054934Z
+UID:047871e3-6b70-4178-9af8-0ceb50f7b092
+SUMMARY:Weekly Project Meeting
+RRULE:FREQ=WEEKLY;INTERVAL=1
+X-MOZ-GENERATION:2
+DTSTART:20081027T090000Z
+DURATION:PT60M
+END:VEVENT
+END:VCALENDAR
+
+
+ HTTP/1.1 200 OK
+
+
+
+ /caldav.php/user4/user2/9429a973-2b13-4b1a-be09-948d75425c45.ics
+
+
+ BEGIN:VCALENDAR
+PRODID:-//davical.org//NONSGML AWL Calendar//EN
+VERSION:2.0
+CALSCALE:GREGORIAN
+BEGIN:VEVENT
+CREATED:20081023T055115Z
+LAST-MODIFIED:20081023T055139Z
+DTSTAMP:20081023T055115Z
+UID:9429a973-2b13-4b1a-be09-948d75425c45
+SUMMARY:Weekly catch-up
+RRULE:FREQ=WEEKLY;INTERVAL=1
+X-MOZ-GENERATION:2
+DTSTART:20081024T140000Z
+DURATION:PT60M
+END:VEVENT
+BEGIN:VEVENT
+CREATED:20081023T055115Z
+LAST-MODIFIED:20081023T055139Z
+DTSTAMP:20081023T055115Z
+UID:9429a973-2b13-4b1a-be09-948d75425c45
+SUMMARY:Weekly catch-up
+RRULE:FREQ=WEEKLY;INTERVAL=1
+X-MOZ-GENERATION:2
+DTSTART:20081031T140000Z
+DURATION:PT60M
+END:VEVENT
+END:VCALENDAR
+
+
+ HTTP/1.1 200 OK
+
+
+
diff --git a/testing/tests/regression-suite/969-REPORT-bound.test b/testing/tests/regression-suite/969-REPORT-bound.test
new file mode 100644
index 00000000..b9af82de
--- /dev/null
+++ b/testing/tests/regression-suite/969-REPORT-bound.test
@@ -0,0 +1,29 @@
+#
+# Test REPORT access to a bound calendar using a ticket.
+#
+TYPE=REPORT
+URL=http://regression.host/caldav.php/user4/user2/
+AUTH=user4:user4
+
+HEADER=User-Agent: DAViCalTester/public
+HEADER=Content-Type: text/xml; charset="UTF-8"
+
+
+BEGINDATA
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ENDDATA
+