Fix Invitations can not be accepted when calendars are shared with certain rights (#1406)

This commit is contained in:
Aleksander Machniak 2012-12-04 20:10:04 +01:00
parent cda4c47325
commit f0ef421c00
4 changed files with 122 additions and 50 deletions

View file

@ -234,7 +234,7 @@ class calendar extends rcube_plugin
public function get_default_calendar($writeable = false)
{
$default_id = $this->rc->config->get('calendar_default_calendar');
$calendars = $this->driver->list_calendars();
$calendars = $this->driver->list_calendars(false, true);
$calendar = $calendars[$default_id] ?: null;
if (!$calendar || ($writeable && $calendar['readonly'])) {
foreach ($calendars as $cal) {
@ -402,9 +402,8 @@ class calendar extends rcube_plugin
// default calendar selection
$field_id = 'rcmfd_default_calendar';
$select_cal = new html_select(array('name' => '_default_calendar', 'id' => $field_id, 'is_escaped' => true));
foreach ((array)$this->driver->list_calendars() as $id => $prop) {
if (!$prop['readonly'])
$select_cal->add($prop['name'], strval($id));
foreach ((array)$this->driver->list_calendars(false, true) as $id => $prop) {
$select_cal->add($prop['name'], strval($id));
if ($prop['default'])
$default_calendar = $id;
}
@ -705,7 +704,7 @@ class calendar extends rcube_plugin
$status = $event['fallback'];
$html = html::div('rsvp-status', $status != 'CANCELLED' ? $this->gettext('acceptinvitation') : '');
$this->load_driver();
if ($existing = $this->driver->get_event($event, true)) {
if ($existing = $this->driver->get_event($event, true, false, true)) {
$emails = $this->get_user_emails();
foreach ($existing['attendees'] as $i => $attendee) {
if ($attendee['email'] && in_array($attendee['email'], $emails)) {
@ -716,7 +715,7 @@ class calendar extends rcube_plugin
}
else {
// get a list of writeable calendars
$calendars = $this->driver->list_calendars();
$calendars = $this->driver->list_calendars(false, true);
$calendar_select = new html_select(array('name' => 'calendar', 'id' => 'calendar-saveto', 'is_escaped' => true));
$numcals = 0;
foreach ($calendars as $calendar) {
@ -949,7 +948,7 @@ class calendar extends rcube_plugin
if (!$start) $start = mktime(0, 0, 0, 1, date('n'), date('Y')-1);
if (!$end) $end = mktime(0, 0, 0, 31, 12, date('Y')+10);
$calid = $calname = get_input_value('source', RCUBE_INPUT_GET);
$calendars = $this->driver->list_calendars();
$calendars = $this->driver->list_calendars(true);
if ($calendars[$calid]) {
$calname = $calendars[$calid]['name'] ? $calendars[$calid]['name'] : $calid;
@ -1163,12 +1162,8 @@ class calendar extends rcube_plugin
{
$num = $_REQUEST['_num'] ? intval($_REQUEST['_num']) : 100;
$cats = array_keys($this->driver->list_categories());
$cals = array();
foreach ($this->driver->list_calendars() as $cid => $cal) {
if ($cal['active'])
$cals[$cid] = $cal;
}
$cals = $this->driver->list_calendars(true);
while ($count++ < $num) {
$start = round((time() + rand(-2600, 2600) * 1000) / 300) * 300;
$duration = round(rand(30, 360) / 30) * 30 * 60;
@ -1789,7 +1784,7 @@ class calendar extends rcube_plugin
if (!empty($events) && ($event = $events[$index])) {
// find writeable calendar to store event
$cal_id = !empty($_REQUEST['_calendar']) ? get_input_value('_calendar', RCUBE_INPUT_POST) : null;
$calendars = $this->driver->list_calendars();
$calendars = $this->driver->list_calendars(false, true);
$calendar = $calendars[$cal_id] ?: $this->get_default_calendar(true);
// update my attendee status according to submitted method
@ -1852,6 +1847,7 @@ class calendar extends rcube_plugin
// import the (newer) event
else if ($event['sequence'] >= $existing['sequence'] || $event['changed'] >= $existing['changed']) {
$event['id'] = $existing['id'];
$event['calendar'] = $existing['calendar'];
$success = $this->driver->edit_event($event);
}
else if (!empty($status)) {

View file

@ -92,8 +92,13 @@ abstract class calendar_driver
/**
* Get a list of available calendars from this source
*
* @param bool $active Return only active calendars
* @param bool $personal Return only personal calendars
*
* @return array List of calendars
*/
abstract function list_calendars();
abstract function list_calendars($active = false, $personal = false);
/**
* Create a new calendar assigned to the current user
@ -208,9 +213,12 @@ abstract class calendar_driver
* id: Event identifier
* calendar: Calendar identifier (optional)
* @param boolean If true, only writeable calendars shall be searched
* @param boolean If true, only active calendars shall be searched
* @param boolean If true, only personal calendars shall be searched
*
* @return array Event object as hash array
*/
abstract function get_event($event, $writeable = null);
abstract function get_event($event, $writeable = false, $active = false, $personal = false);
/**
* Get events from source.

View file

@ -103,18 +103,36 @@ class database_driver extends calendar_driver
/**
* Get a list of available calendars from this source
*
* @param bool $active Return only active calendars
* @param bool $personal Return only personal calendars
*
* @return array List of calendars
*/
public function list_calendars()
public function list_calendars($active = false, $personal = false)
{
// attempt to create a default calendar for this user
if (empty($this->calendars)) {
if ($this->create_calendar(array('name' => 'Default', 'color' => 'cc0000')))
$this->_read_calendars();
}
return $this->calendars;
$calendars = $this->calendars;
// filter active calendars
if ($active) {
foreach ($calendars as $idx => $cal) {
if (!$cal['active']) {
unset($calendars[$idx]);
}
}
}
// 'personal' is unsupported in this driver
return $calendars;
}
/**
* Create a new calendar assigned to the current user
*
@ -651,23 +669,38 @@ class database_driver extends calendar_driver
/**
* Return data of a specific event
* @param mixed Hash array with event properties or event UID
* @param boolean Only search in writeable calendars (currently ignored)
* @param boolean Only search in writeable calendars (ignored)
* @param boolean Only search in active calendars
* @param boolean Only search in personal calendars (ignored)
* @return array Hash array with event properties
*/
public function get_event($event, $writeable = null)
public function get_event($event, $writeable = false, $active = false, $personal = false)
{
$id = is_array($event) ? ($event['id'] ? $event['id'] : $event['uid']) : $event;
$col = is_array($event) && is_numeric($id) ? 'event_id' : 'uid';
if ($this->cache[$id])
return $this->cache[$id];
if ($active) {
$calendars = $this->calendars;
foreach ($calendars as $idx => $cal) {
if (!$cal['active']) {
unset($calendars[$idx]);
}
}
$cals = join(',', $calendars);
}
else {
$cals = $this->calendar_ids;
}
$result = $this->rc->db->query(sprintf(
"SELECT e.*, COUNT(a.attachment_id) AS _attachments FROM " . $this->db_events . " AS e
LEFT JOIN " . $this->db_attachments . " AS a ON (a.event_id = e.event_id OR a.event_id = e.recurrence_id)
WHERE e.calendar_id IN (%s)
AND e.$col=?",
$this->calendar_ids
$cals
),
$id);

View file

@ -96,8 +96,13 @@ class kolab_driver extends calendar_driver
/**
* Get a list of available calendars from this source
*
* @param bool $active Return only active calendars
* @param bool $personal Return only personal calendars
*
* @return array List of calendars
*/
public function list_calendars()
public function list_calendars($active = false, $personal = false)
{
// attempt to create a default calendar for this user
if (!$this->has_writeable) {
@ -107,30 +112,60 @@ class kolab_driver extends calendar_driver
}
}
$calendars = $names = array();
$calendars = $this->filter_calendars(false, $active, $personal);
$names = array();
foreach ($this->calendars as $id => $cal) {
if ($cal->ready) {
$name = kolab_storage::folder_displayname($cal->get_name(), $names);
foreach ($calendars as $id => $cal) {
$name = kolab_storage::folder_displayname($cal->get_name(), $names);
$calendars[$cal->id] = array(
'id' => $cal->id,
'name' => $name,
'editname' => $cal->get_foldername(),
'color' => $cal->get_color(),
'readonly' => $cal->readonly,
'showalarms' => $cal->alarms,
'class_name' => $cal->get_namespace(),
'default' => $cal->storage->default,
'active' => $cal->storage->is_subscribed(kolab_storage::SERVERSIDE_SUBSCRIPTION),
);
}
$calendars[$id] = array(
'id' => $cal->id,
'name' => $name,
'editname' => $cal->get_foldername(),
'color' => $cal->get_color(),
'readonly' => $cal->readonly,
'showalarms' => $cal->alarms,
'class_name' => $cal->get_namespace(),
'default' => $cal->storage->default,
'active' => $cal->storage->is_subscribed(),
);
}
return $calendars;
}
/**
* Get list of calendars according to specified filters
*
* @param bool $writable Return only writeable calendars
* @param bool $active Return only active calendars
* @param bool $personal Return only personal calendars
*
* @return array List of calendars
*/
protected function filter_calendars($writable = false, $active = false, $personal = false)
{
$calendars = array();
foreach ($this->calendars as $cal) {
if (!$cal->ready) {
continue;
}
if ($writeable && $cal->readonly) {
continue;
}
if ($active && !$cal->storage->is_subscribed()) {
continue;
}
if ($personal && $cal->get_namespace() != 'personal') {
continue;
}
$calendars[$cal->id] = $cal;
}
return $calendars;
}
/**
* Create a new calendar assigned to the current user
*
@ -252,7 +287,7 @@ class kolab_driver extends calendar_driver
* @see calendar_driver::get_event()
* @return array Hash array with event properties, false if not found
*/
public function get_event($event, $writeable = null)
public function get_event($event, $writeable = false, $active = false, $personal = false)
{
if (is_array($event)) {
$id = $event['id'] ? $event['id'] : $event['uid'];
@ -261,16 +296,16 @@ class kolab_driver extends calendar_driver
else {
$id = $event;
}
if ($cal && ($storage = $this->calendars[$cal])) {
return $storage->get_event($id);
if ($cal) {
if ($storage = $this->calendars[$cal]) {
return $storage->get_event($id);
}
}
// iterate over all calendar folders and search for the event ID
else if (!$cal) {
foreach ($this->calendars as $storage) {
if ($writeable && $storage->readonly)
continue;
if ($result = $storage->get_event($id)) {
else {
foreach ($this->filter_calendars($writeable, $active, $personal) as $calendar) {
if ($result = $calendar->get_event($id)) {
return $result;
}
}