From 06431170c894ab661ee97a790294a242e905e008 Mon Sep 17 00:00:00 2001 From: Andrew Ruthven Date: Fri, 26 Oct 2007 09:41:18 +1300 Subject: [PATCH 1/4] By default calendar items are PUBLIC. --- dba/patches/1.1.9.sql | 8 ++++---- inc/caldav-PUT-functions.php | 25 +++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/dba/patches/1.1.9.sql b/dba/patches/1.1.9.sql index 056cd100..e3d49113 100644 --- a/dba/patches/1.1.9.sql +++ b/dba/patches/1.1.9.sql @@ -1,13 +1,13 @@ --- Adding a primary key to the calendar_item table +-- Make sure that class is set to something, by default PUBLIC. +-- According to RFC2445, 4.8.1.3. BEGIN; SELECT check_db_revision(1,1,8); -ALTER TABLE calendar_item ADD PRIMARY KEY (user_no, dav_name ); +UPDATE calendar_item SET class = 'PUBLIC' WHERE class IS NULL; -SELECT new_db_revision(1,1,9, 'September' ); +SELECT new_db_revision(1,1,9, 'October' ); COMMIT; ROLLBACK; -VACUUM FULL ANALYZE; \ No newline at end of file diff --git a/inc/caldav-PUT-functions.php b/inc/caldav-PUT-functions.php index 7deee23b..7b2ae3d5 100644 --- a/inc/caldav-PUT-functions.php +++ b/inc/caldav-PUT-functions.php @@ -185,6 +185,16 @@ function import_collection( $ics_content, $user_no, $path, $caldav_context ) { $dtstamp = $last_modified; } + /* + * It seems that some calendar clients don't set a class... + * RFC2445, 4.8.1.3: + * Default is PUBLIC + */ + $class = $ic->Get("class"); + if ( !isset($class) || $class == '' ) { + $class = 'PUBLIC' + } + $sql .= <<Get('uid'), $dtstamp, $ic->Get('dtstart'), $ic->Get('summary'), $ic->Get('location'), - $ic->Get('class'), $ic->Get('transp'), $ic->Get('description'), $ic->Get('rrule'), $ic->Get('tz_id'), + $class, $ic->Get('transp'), $ic->Get('description'), $ic->Get('rrule'), $ic->Get('tz_id'), $last_modified, $ic->Get('url'), $ic->Get('priority'), $ic->Get('created'), $ic->Get('due'), $ic->Get('percent-complete') ); @@ -315,6 +325,17 @@ function putCalendarResource( &$request, $author, $caldav_context ) { $dtstamp = $last_modified; } + /* + * It seems that some calendar clients don't set a class... + * RFC2445, 4.8.1.3: + * Default is PUBLIC + */ + $class = $ic->Get("class"); + if ( !isset($class) || $class == '' ) { + $class = 'PUBLIC' + } + + if ( $put_action_type != 'INSERT' ) { $sql .= "DELETE FROM calendar_item WHERE user_no=$request->user_no AND dav_name=".qpg($request->path).";"; } @@ -327,7 +348,7 @@ EOSQL; $qry = new PgQuery( $sql, $request->user_no, $request->path, $etag, $ic->Get('UID'), $dtstamp, $ic->Get('DTSTART'), $ic->Get('SUMMARY'), $ic->Get('LOCATION'), - $ic->Get('CLASS'), $ic->Get('TRANSP'), $ic->Get('DESCRIPTION'), $ic->Get('RRULE'), $ic->Get('TZ_ID'), + $class, $ic->Get('TRANSP'), $ic->Get('DESCRIPTION'), $ic->Get('RRULE'), $ic->Get('TZ_ID'), $last_modified, $ic->Get('URL'), $ic->Get('PRIORITY'), $ic->Get('CREATED'), $ic->Get('DUE'), $ic->Get('PERCENT-COMPLETE'), $ic->Get('STATUS') ); From bbcd6a82acc9e7df8144917ecdc7ce61ca22b369 Mon Sep 17 00:00:00 2001 From: Andrew Ruthven Date: Fri, 26 Oct 2007 09:50:45 +1300 Subject: [PATCH 2/4] Bugger, fix up the DB patches. --- dba/patches/1.1.10.sql | 13 +++++++++++++ dba/patches/1.1.9.sql | 8 ++++---- 2 files changed, 17 insertions(+), 4 deletions(-) create mode 100644 dba/patches/1.1.10.sql diff --git a/dba/patches/1.1.10.sql b/dba/patches/1.1.10.sql new file mode 100644 index 00000000..0dcefe57 --- /dev/null +++ b/dba/patches/1.1.10.sql @@ -0,0 +1,13 @@ + +-- Make sure that class is set to something, by default PUBLIC. +-- According to RFC2445, 4.8.1.3. + +BEGIN; +SELECT check_db_revision(1,1,9); + +UPDATE calendar_item SET class = 'PUBLIC' WHERE class IS NULL; + +SELECT new_db_revision(1,1,10, 'October' ); +COMMIT; +ROLLBACK; + diff --git a/dba/patches/1.1.9.sql b/dba/patches/1.1.9.sql index e3d49113..056cd100 100644 --- a/dba/patches/1.1.9.sql +++ b/dba/patches/1.1.9.sql @@ -1,13 +1,13 @@ --- Make sure that class is set to something, by default PUBLIC. --- According to RFC2445, 4.8.1.3. +-- Adding a primary key to the calendar_item table BEGIN; SELECT check_db_revision(1,1,8); -UPDATE calendar_item SET class = 'PUBLIC' WHERE class IS NULL; +ALTER TABLE calendar_item ADD PRIMARY KEY (user_no, dav_name ); -SELECT new_db_revision(1,1,9, 'October' ); +SELECT new_db_revision(1,1,9, 'September' ); COMMIT; ROLLBACK; +VACUUM FULL ANALYZE; \ No newline at end of file From e0746e058eca9904cedfde8bc76d4e3379fdbbbf Mon Sep 17 00:00:00 2001 From: Andrew Ruthven Date: Fri, 26 Oct 2007 11:05:32 +1300 Subject: [PATCH 3/4] Allow forcing all events in a collection to a specified class. --- dba/patches/1.1.10.sql | 8 ++++++-- inc/caldav-PUT-functions.php | 37 ++++++++++++++++++++++++++++++++++-- 2 files changed, 41 insertions(+), 4 deletions(-) diff --git a/dba/patches/1.1.10.sql b/dba/patches/1.1.10.sql index 0dcefe57..d7cce76a 100644 --- a/dba/patches/1.1.10.sql +++ b/dba/patches/1.1.10.sql @@ -1,12 +1,16 @@ --- Make sure that class is set to something, by default PUBLIC. --- According to RFC2445, 4.8.1.3. +-- Sort out accessing calendar entries. BEGIN; SELECT check_db_revision(1,1,9); +-- Make sure that class is set to something, by default PUBLIC. +-- According to RFC2445, 4.8.1.3. UPDATE calendar_item SET class = 'PUBLIC' WHERE class IS NULL; +-- Allow forcing all events in a calendar to a specific class +ALTER TABLE collection ADD COLUMN force_class TEXT; + SELECT new_db_revision(1,1,10, 'October' ); COMMIT; ROLLBACK; diff --git a/inc/caldav-PUT-functions.php b/inc/caldav-PUT-functions.php index 7b2ae3d5..fbe4383c 100644 --- a/inc/caldav-PUT-functions.php +++ b/inc/caldav-PUT-functions.php @@ -83,6 +83,27 @@ function controlRequestContainer( $username, $user_no, $path, $caldav_context ) return $is_collection; } +/** +* Check if there is a class that new events should be forced to. +* @param string $user_no the user that owns the collection +* @param string $dav_name the collection to check +*/ +function find_forced_class( $user_no, $dav_name ) { + $sql = "SELECT force_class "; + $sql .= "FROM collection "; + $sql .= "WHERE user_no=? AND dav_name=?"); + + $qry = new PgQuery($sql); + + if( $qry->Exec($user_no, $dav_name) && $qry->rows == 1 ) { + $collection = $qry->Fetch(); + + if ( ( isset($collection->force_class) && $collection->force_class != '' ) { + return $collection->force_class; + } + } +} + /** * This function will import a whole calendar @@ -185,12 +206,18 @@ function import_collection( $ics_content, $user_no, $path, $caldav_context ) { $dtstamp = $last_modified; } + $class = $ic->Get("class"); + /* Check and see if we should over ride the class. */ + $force_class = find_forced_class($user_no, $path); + if ( isset($force_class) ) { + $class = $force_class; + } + /* * It seems that some calendar clients don't set a class... * RFC2445, 4.8.1.3: * Default is PUBLIC */ - $class = $ic->Get("class"); if ( !isset($class) || $class == '' ) { $class = 'PUBLIC' } @@ -325,12 +352,18 @@ function putCalendarResource( &$request, $author, $caldav_context ) { $dtstamp = $last_modified; } + $class = $ic->Get("class"); + /* Check and see if we should over ride the class. */ + $force_class = find_forced_class($user_no, $path); + if ( isset($force_class) ) { + $class = $force_class; + } + /* * It seems that some calendar clients don't set a class... * RFC2445, 4.8.1.3: * Default is PUBLIC */ - $class = $ic->Get("class"); if ( !isset($class) || $class == '' ) { $class = 'PUBLIC' } From e72559061228a57b18d17c15b1a7e2cfe6530680 Mon Sep 17 00:00:00 2001 From: Andrew Ruthven Date: Fri, 26 Oct 2007 11:35:19 +1300 Subject: [PATCH 4/4] Rewrite force events to public logic to be PUBLIC only, not general. --- dba/patches/1.1.10.sql | 6 ++++-- inc/caldav-PUT-functions.php | 24 +++++++++++++----------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/dba/patches/1.1.10.sql b/dba/patches/1.1.10.sql index d7cce76a..532a3bb0 100644 --- a/dba/patches/1.1.10.sql +++ b/dba/patches/1.1.10.sql @@ -8,8 +8,10 @@ SELECT check_db_revision(1,1,9); -- According to RFC2445, 4.8.1.3. UPDATE calendar_item SET class = 'PUBLIC' WHERE class IS NULL; --- Allow forcing all events in a calendar to a specific class -ALTER TABLE collection ADD COLUMN force_class TEXT; +-- Allow forcing all events in a calendar to be public +ALTER TABLE collection ADD COLUMN public_events_only BOOLEAN; +ALTER TABLE collection ALTER public_events_only SET NOT NULL; +ALTER TABLE collection ALTER public_events_only SET DEFAULT 'f'; SELECT new_db_revision(1,1,10, 'October' ); COMMIT; diff --git a/inc/caldav-PUT-functions.php b/inc/caldav-PUT-functions.php index fbe4383c..8bea00a2 100644 --- a/inc/caldav-PUT-functions.php +++ b/inc/caldav-PUT-functions.php @@ -84,12 +84,13 @@ function controlRequestContainer( $username, $user_no, $path, $caldav_context ) } /** -* Check if there is a class that new events should be forced to. +* Check if this collection sould force all events to be PUBLIC. * @param string $user_no the user that owns the collection * @param string $dav_name the collection to check +* @return boolean Return true if public events only are allowed. */ -function find_forced_class( $user_no, $dav_name ) { - $sql = "SELECT force_class "; +function public_events_only( $user_no, $dav_name ) { + $sql = "SELECT public_events_only "; $sql .= "FROM collection "; $sql .= "WHERE user_no=? AND dav_name=?"); @@ -98,10 +99,13 @@ function find_forced_class( $user_no, $dav_name ) { if( $qry->Exec($user_no, $dav_name) && $qry->rows == 1 ) { $collection = $qry->Fetch(); - if ( ( isset($collection->force_class) && $collection->force_class != '' ) { - return $collection->force_class; + if ($collection->public_events_only == 't') { + return true; } } + + // Something went wrong, must be false. + return false; } @@ -208,9 +212,8 @@ function import_collection( $ics_content, $user_no, $path, $caldav_context ) { $class = $ic->Get("class"); /* Check and see if we should over ride the class. */ - $force_class = find_forced_class($user_no, $path); - if ( isset($force_class) ) { - $class = $force_class; + if ( public_events_only($user_no, $path) ) { + $class = 'PUBLIC'; } /* @@ -354,9 +357,8 @@ function putCalendarResource( &$request, $author, $caldav_context ) { $class = $ic->Get("class"); /* Check and see if we should over ride the class. */ - $force_class = find_forced_class($user_no, $path); - if ( isset($force_class) ) { - $class = $force_class; + if ( public_events_only($user_no, $path) ) { + $class = 'PUBLIC'; } /*