fix for $c->hide_TODO processing and user-agent extension

new option: if set to PHP regex string then hide_TODO is enabled if the client
user-agent string matches the regex for example:
    $c->hide_TODO='#^iOS.*dataaccessd.*#';
will hide all todos from non-owner/non-admin users for iOS devices
This commit is contained in:
Ján Máté 2013-09-20 23:18:55 +12:00 committed by Andrew Ruthven
parent 26275a5fab
commit 183a8c4083
4 changed files with 13 additions and 7 deletions

View File

@ -185,12 +185,17 @@ function get_collection_contents( $depth, $collection, $parent_path = null ) {
if ( $collection->HavePrivilegeTo('DAV::read', false) ) {
dbg_error_log('PROPFIND','Getting collection items: Depth %d, Path: %s', $depth, $bound_from );
$privacy_clause = ' ';
$todo_clause = ' ';
$time_limit_clause = ' ';
if ( $collection->IsCalendar() ) {
if ( ! $collection->HavePrivilegeTo('all', false) ) {
$privacy_clause = " AND (calendar_item.class != 'PRIVATE' OR calendar_item.class IS NULL) ";
}
if ( isset($c->hide_TODO) && ($c->hide_TODO === true || (is_string($c->hide_TODO) && preg_match($c->hide_TODO, $_SERVER['HTTP_USER_AGENT']))) && ! $collection->HavePrivilegeTo('all') ) {
$todo_clause = " AND caldav_data.caldav_type NOT IN ('VTODO') ";
}
if ( isset($c->hide_older_than) && intval($c->hide_older_than > 0) ) {
$time_limit_clause = " AND (CASE WHEN caldav_data.caldav_type<>'VEVENT' OR calendar_item.dtstart IS NULL THEN true ELSE calendar_item.dtstart > (now() - interval '".intval($c->hide_older_than)." days') END) ";
}
@ -202,7 +207,7 @@ function get_collection_contents( $depth, $collection, $parent_path = null ) {
$sql .= 'summary AS dav_displayname ';
$sql .= 'FROM caldav_data LEFT JOIN calendar_item USING( dav_id, user_no, dav_name, collection_id) ';
$sql .= 'LEFT JOIN collection USING(collection_id,user_no) LEFT JOIN principal USING(user_no) ';
$sql .= 'WHERE collection.dav_name = :collection_dav_name '.$time_limit_clause.' '.$privacy_clause;
$sql .= 'WHERE collection.dav_name = :collection_dav_name '.$time_limit_clause.' '.$todo_clause.' '.$privacy_clause;
if ( isset($c->strict_result_ordering) && $c->strict_result_ordering ) $sql .= " ORDER BY caldav_data.dav_id";
$qry = new AwlQuery( $sql, array( ':collection_dav_name' => $bound_from) );
if( $qry->Exec('PROPFIND',__LINE__,__FILE__) && $qry->rows() > 0 ) {

View File

@ -334,7 +334,7 @@ if ( $target_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 && ! $target_collection->HavePrivilegeTo('DAV::write-content') ) {
if ( isset($c->hide_TODO) && ($c->hide_TODO === true || (is_string($c->hide_TODO) && preg_match($c->hide_TODO, $_SERVER['HTTP_USER_AGENT']))) && ! $target_collection->HavePrivilegeTo('all') ) {
$where .= " AND caldav_data.caldav_type NOT IN ('VTODO') ";
}

View File

@ -88,9 +88,6 @@ if ( $mode == 'caldav' ) {
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 && ! $collection->HavePrivilegeTo('all') ) {
$where .= " AND caldav_data.caldav_type NOT IN ('VTODO') ";
}
}
$sql = 'SELECT calendar_item.*, addressbook_resource.*, caldav_data.* FROM caldav_data
LEFT JOIN calendar_item USING(dav_id, user_no, dav_name, collection_id)

View File

@ -84,13 +84,17 @@ else {
if ( isset($c->hide_older_than) && intval($c->hide_older_than) > 0 )
$hide_older = " AND (CASE WHEN caldav_data.caldav_type<>'VEVENT' OR calendar_item.dtstart IS NULL THEN true ELSE calendar_item.dtstart > (now() - interval '".intval($c->hide_older_than)." days') END)";
$hide_todo = '';
if ( isset($c->hide_TODO) && ($c->hide_TODO === true || (is_string($c->hide_TODO) && preg_match($c->hide_TODO, $_SERVER['HTTP_USER_AGENT']))) && ! $collection->HavePrivilegeTo('all') )
$hide_todo = " AND caldav_data.caldav_type NOT IN ('VTODO') ";
if ( $sync_token == 0 ) {
$sql = <<<EOSQL
SELECT collection.*, calendar_item.*, caldav_data.*, addressbook_resource.*, 201 AS sync_status FROM collection
LEFT JOIN caldav_data USING (collection_id)
LEFT JOIN calendar_item USING (dav_id)
LEFT JOIN addressbook_resource USING (dav_id)
WHERE collection.collection_id = :collection_id $hide_older
WHERE collection.collection_id = :collection_id $hide_older $hide_todo
ORDER BY collection.collection_id, caldav_data.dav_id
EOSQL;
unset($params[':sync_token']);
@ -102,7 +106,7 @@ EOSQL;
LEFT JOIN caldav_data USING (collection_id,dav_id)
LEFT JOIN calendar_item USING (collection_id,dav_id)
LEFT JOIN addressbook_resource USING (dav_id)
WHERE collection.collection_id = :collection_id $hide_older
WHERE collection.collection_id = :collection_id $hide_older $hide_todo
AND sync_time >= (SELECT modification_time FROM sync_tokens WHERE sync_token = :sync_token)
EOSQL;
if ( isset($c->strict_result_ordering) && $c->strict_result_ordering ) {