summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksander Machniak <machniak@kolabsys.com>2012-12-05 10:52:40 (GMT)
committerAleksander Machniak <machniak@kolabsys.com>2012-12-05 10:52:40 (GMT)
commite33d2fb929467b1203a8b7046547ffa4e55cf8ed (patch)
treea6ac3d4970567273a128cf10cd2295d3b9a3958f
parentbf13c1f79cb57b7e30f8f7c9705e9cfccf51e8c9 (diff)
downloadroundcubemail-plugins-kolab-e33d2fb929467b1203a8b7046547ffa4e55cf8ed.tar.gz
Fix Invitations can not be accepted when calendars are shared with certain rights (#1406)
Conflicts: plugins/calendar/calendar.php plugins/calendar/drivers/kolab/kolab_driver.php
-rw-r--r--plugins/calendar/calendar.php56
-rw-r--r--plugins/calendar/drivers/calendar_driver.php12
-rw-r--r--plugins/calendar/drivers/database/database_driver.php49
-rw-r--r--plugins/calendar/drivers/kolab/kolab_driver.php61
4 files changed, 132 insertions, 46 deletions
diff --git a/plugins/calendar/calendar.php b/plugins/calendar/calendar.php
index 37a723e..c632376 100644
--- a/plugins/calendar/calendar.php
+++ b/plugins/calendar/calendar.php
@@ -246,6 +246,28 @@ class calendar extends rcube_plugin
return $this->ical;
}
+ /**
+ * Get properties of the calendar this user has specified as default
+ */
+ public function get_default_calendar($writeable = false)
+ {
+ $default_id = $this->rc->config->get('calendar_default_calendar');
+ $calendars = $this->driver->list_calendars(false, true);
+ $calendar = $calendars[$default_id] ?: null;
+ if (!$calendar || ($writeable && $calendar['readonly'])) {
+ foreach ($calendars as $cal) {
+ if ($cal['default']) {
+ $calendar = $cal;
+ break;
+ }
+ if (!$writeable || !$cal['readonly']) {
+ $first = $cal;
+ }
+ }
+ }
+
+ return $calendar ?: $first;
+ }
/**
* Render the main calendar view from skin template
@@ -397,9 +419,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));
- 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));
}
$p['blocks']['view']['options']['defaultcalendar'] = array(
'title' => html::label($field_id . 'value', Q($this->gettext('defaultcalendar'))),
@@ -689,7 +710,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)) {
@@ -700,7 +721,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'));
$numcals = 0;
foreach ($calendars as $calendar) {
@@ -911,7 +932,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;
@@ -1294,12 +1315,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;
@@ -2127,17 +2144,9 @@ class calendar extends rcube_plugin
// successfully parsed events?
if (!empty($events) && ($event = $events[$index])) {
// find writeable calendar to store event
- $cal_id = !empty($_REQUEST['_calendar']) ? get_input_value('_calendar', RCUBE_INPUT_POST) : $this->rc->config->get('calendar_default_calendar');
- $calendars = $this->driver->list_calendars();
- $calendar = $calendars[$cal_id] ? $calendars[$cal_id] : null;
- if (!$calendar || $calendar['readonly']) {
- foreach ($calendars as $cal) {
- if (!$cal['readonly']) {
- $calendar = $cal;
- break;
- }
- }
- }
+ $cal_id = !empty($_REQUEST['_calendar']) ? get_input_value('_calendar', RCUBE_INPUT_POST) : null;
+ $calendars = $this->driver->list_calendars(false, true);
+ $calendar = $calendars[$cal_id] ?: $this->get_default_calendar(true);
// update my attendee status according to submitted method
if (!empty($status)) {
@@ -2200,6 +2209,7 @@ class calendar extends rcube_plugin
// import the (newer) event
// TODO: compare SEQUENCE numbers instead of changed dates
else if ($event['changed'] >= $existing['changed']) {
+ $event['calendar'] = $existing['calendar'];
$success = $this->driver->edit_event($event);
}
else if (!empty($status)) {
diff --git a/plugins/calendar/drivers/calendar_driver.php b/plugins/calendar/drivers/calendar_driver.php
index 4b03a34..0bf9ea5 100644
--- a/plugins/calendar/drivers/calendar_driver.php
+++ b/plugins/calendar/drivers/calendar_driver.php
@@ -96,8 +96,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
@@ -212,9 +217,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.
diff --git a/plugins/calendar/drivers/database/database_driver.php b/plugins/calendar/drivers/database/database_driver.php
index 5f25c1a..28fb6ca 100644
--- a/plugins/calendar/drivers/database/database_driver.php
+++ b/plugins/calendar/drivers/database/database_driver.php
@@ -108,18 +108,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
*
@@ -667,23 +685,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);
diff --git a/plugins/calendar/drivers/kolab/kolab_driver.php b/plugins/calendar/drivers/kolab/kolab_driver.php
index 955fb23..067bb10 100644
--- a/plugins/calendar/drivers/kolab/kolab_driver.php
+++ b/plugins/calendar/drivers/kolab/kolab_driver.php
@@ -101,8 +101,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) {
@@ -112,10 +117,10 @@ 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 = $origname = $cal->get_name();
// find folder prefix to truncate (the same code as in kolab_addressbook plugin)
@@ -141,7 +146,6 @@ class kolab_driver extends calendar_driver
'class_name' => $cal->get_namespace(),
'active' => rcube_kolab::is_subscribed($cal->get_realname()),
);
- }
}
return $calendars;
@@ -149,6 +153,37 @@ class kolab_driver extends calendar_driver
/**
+ * 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 && !rcube_kolab::is_subscribed($cal->get_realname())) {
+ continue;
+ }
+ if ($personal && $cal->get_namespace() != 'personal') {
+ continue;
+ }
+ $calendars[$cal->id] = $cal;
+ }
+
+ return $calendars;
+ }
+
+ /**
* Create a new calendar assigned to the current user
*
* @param array Hash array with calendar properties
@@ -368,7 +403,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'];
@@ -377,16 +412,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;
}
}