* CalDAV/Lightning: fixed under some conditions infinit poping up alarms and user not able to add alarms

- Lightning pops up alarm, until Sequence/etag get updated: if user has no edit rights on an other users calendar, etag never got updated, now we update it
- fixed user was not able to add alarms via CalDAV, if he had no edit rights for event (was always possible in web UI)
- alarms from other users calendars are not included any more, as they make no sense but a lot of trouble
- fixed wrong condition on adding alarms, causing some alarms no being saved
This commit is contained in:
Ralf Becker 2011-03-05 10:21:32 +00:00
parent 738966ca68
commit 3bb9e89bcf
8 changed files with 73 additions and 42 deletions

View File

@ -276,9 +276,10 @@ class addressbook_groupdav extends groupdav_handler
* *
* @param array &$options * @param array &$options
* @param int $id * @param int $id
* @param int $user=null account_id
* @return mixed boolean true on success, false on failure or string with http status (eg. '404 Not Found') * @return mixed boolean true on success, false on failure or string with http status (eg. '404 Not Found')
*/ */
function get(&$options,$id) function get(&$options,$id,$user=null)
{ {
if (!is_array($contact = $this->_common_get_put_delete('GET',$options,$id))) if (!is_array($contact = $this->_common_get_put_delete('GET',$options,$id)))
{ {

View File

@ -220,7 +220,7 @@ error_log(__METHOD__."($path,,".array2string($start).") filter=".array2string($f
//error_log(__FILE__ . __METHOD__ . "Calendar Data : $calendar_data"); //error_log(__FILE__ . __METHOD__ . "Calendar Data : $calendar_data");
if ($calendar_data) if ($calendar_data)
{ {
$content = $this->iCal($event); $content = $this->iCal($event,$filter['users']);
$props[] = HTTP_WebDAV_Server::mkprop('getcontentlength',bytes($content)); $props[] = HTTP_WebDAV_Server::mkprop('getcontentlength',bytes($content));
$props[] = HTTP_WebDAV_Server::mkprop(groupdav::CALDAV,'calendar-data',$content); $props[] = HTTP_WebDAV_Server::mkprop(groupdav::CALDAV,'calendar-data',$content);
} }
@ -382,15 +382,16 @@ error_log(__METHOD__."($path,,".array2string($start).") filter=".array2string($f
* *
* @param array &$options * @param array &$options
* @param int $id * @param int $id
* @param int $user=null account_id
* @return mixed boolean true on success, false on failure or string with http status (eg. '404 Not Found') * @return mixed boolean true on success, false on failure or string with http status (eg. '404 Not Found')
*/ */
function get(&$options,$id) function get(&$options,$id,$user=null)
{ {
if (!is_array($event = $this->_common_get_put_delete('GET',$options,$id))) if (!is_array($event = $this->_common_get_put_delete('GET',$options,$id)))
{ {
return $event; return $event;
} }
$options['data'] = $this->iCal($event); $options['data'] = $this->iCal($event,$user);
$options['mimetype'] = 'text/calendar; charset=utf-8'; $options['mimetype'] = 'text/calendar; charset=utf-8';
header('Content-Encoding: identity'); header('Content-Encoding: identity');
header('ETag: '.$this->get_etag($event)); header('ETag: '.$this->get_etag($event));
@ -403,13 +404,23 @@ error_log(__METHOD__."($path,,".array2string($start).") filter=".array2string($f
* Taking into account virtual an real exceptions for recuring events * Taking into account virtual an real exceptions for recuring events
* *
* @param array $event * @param array $event
* @param int $user=null account_id of calendar to display
* @return string * @return string
*/ */
private function iCal(array $event) private function iCal(array $event,$user=null)
{ {
static $handler = null; static $handler = null;
if (is_null($handler)) $handler = $this->_get_handler(); if (is_null($handler)) $handler = $this->_get_handler();
if (!$user) $user = $GLOBALS['egw_info']['user']['account_id'];
// only return alarms in own calendar, not other users calendars
if ($user != $GLOBALS['egw_info']['user']['account_id'])
{
//error_log(__METHOD__.'('.array2string($event).", $user) clearing alarms");
$event['alarm'] = array();
}
$events = array($event); $events = array($event);
// for recuring events we have to add the exceptions // for recuring events we have to add the exceptions
@ -551,8 +562,18 @@ error_log(__METHOD__."($path,,".array2string($start).") filter=".array2string($f
} }
else else
{ {
// let lightning think the event is added $retval = '204 No Content';
$retval = '201 Created';
// lightning will pop up the alarm, as long as the Sequence (etag) does NOT change
// --> update the etag alone, if user has no edit rights
if ($this->agent == 'lightning' && !$this->check_access(EGW_ACL_EDIT, $oldEvent) &&
isset($oldEvent['participants'][$GLOBALS['egw_info']['user']['account_id']]))
{
// just update etag in database
$GLOBALS['egw']->db->update($this->bo->so->cal_table,'cal_etag=cal_etag+1',array(
'cal_id' => $eventId,
),__LINE__,__FILE__,'calendar');
}
} }
} }
else else

View File

@ -1423,6 +1423,12 @@ class calendar_ical extends calendar_boupdate
$alarm['owner'] = $this->user; $alarm['owner'] = $this->user;
$alarm['all'] = false; $alarm['all'] = false;
// if no edit rights, allow participants to set alarms directly (like status)
if ($event_info['stored_event'] && !$event_info['acl_edit'])
{
$this->save_alarm($event_info['stored_event']['id'], $alarm);
}
if (is_array($event_info['stored_event']) if (is_array($event_info['stored_event'])
&& count($event_info['stored_event']['alarm']) > 0) && count($event_info['stored_event']['alarm']) > 0)
{ {

View File

@ -1090,11 +1090,11 @@ ORDER BY cal_user_type, cal_usre_id
$alarm['time'] = $event['cal_start'] - $alarm['offset']; $alarm['time'] = $event['cal_start'] - $alarm['offset'];
} }
$start = (int)time() + $alarm['offset']; if ($alarm['time'] < time())
if ($alarm['time'] < $start)
{ {
//pgoerzen: don't add an alarm in the past //pgoerzen: don't add an alarm in the past
if ($event['recur_type'] == MCAL_RECUR_NONE) continue; if ($event['recur_type'] == MCAL_RECUR_NONE) continue;
$start = (int)time() + $alarm['offset'];
$event['start'] = $event['cal_start']; $event['start'] = $event['cal_start'];
$event['end'] = $event['cal_end']; $event['end'] = $event['cal_end'];
$event['tzid'] = $event['cal_tzid']; $event['tzid'] = $event['cal_tzid'];

View File

@ -331,9 +331,10 @@ class infolog_groupdav extends groupdav_handler
* *
* @param array &$options * @param array &$options
* @param int $id * @param int $id
* @param int $user=null account_id
* @return mixed boolean true on success, false on failure or string with http status (eg. '404 Not Found') * @return mixed boolean true on success, false on failure or string with http status (eg. '404 Not Found')
*/ */
function get(&$options,$id) function get(&$options,$id,$user=null)
{ {
if (!is_array($task = $this->_common_get_put_delete('GET',$options,$id))) if (!is_array($task = $this->_common_get_put_delete('GET',$options,$id)))
{ {

View File

@ -548,7 +548,7 @@ class groupdav extends HTTP_WebDAV_Server
} }
if (($handler = self::app_handler($app))) if (($handler = self::app_handler($app)))
{ {
return $handler->get($options,$id); return $handler->get($options,$id,$user);
} }
error_log(__METHOD__."(".array2string($options).") 501 Not Implemented"); error_log(__METHOD__."(".array2string($options).") 501 Not Implemented");
return '501 Not Implemented'; return '501 Not Implemented';

View File

@ -135,9 +135,10 @@ abstract class groupdav_handler
* *
* @param array &$options * @param array &$options
* @param int $id * @param int $id
* @param int $user=null account_id
* @return mixed boolean true on success, false on failure or string with http status (eg. '404 Not Found') * @return mixed boolean true on success, false on failure or string with http status (eg. '404 Not Found')
*/ */
abstract function get(&$options,$id); abstract function get(&$options,$id,$user=null);
/** /**
* Handle get request for an applications entry * Handle get request for an applications entry

View File

@ -440,9 +440,10 @@ class groupdav_principals extends groupdav_handler
* *
* @param array &$options * @param array &$options
* @param int $id * @param int $id
* @param int $user=null account_id
* @return mixed boolean true on success, false on failure or string with http status (eg. '404 Not Found') * @return mixed boolean true on success, false on failure or string with http status (eg. '404 Not Found')
*/ */
function get(&$options,$id) function get(&$options,$id,$user=null)
{ {
if (!is_array($account = $this->_common_get_put_delete('GET',$options,$id))) if (!is_array($account = $this->_common_get_put_delete('GET',$options,$id)))
{ {