Fix Invitations can not be accepted when calendars are shared with certain rights (#1406)
This commit is contained in:
parent
cda4c47325
commit
f0ef421c00
4 changed files with 122 additions and 50 deletions
|
@ -234,7 +234,7 @@ class calendar extends rcube_plugin
|
||||||
public function get_default_calendar($writeable = false)
|
public function get_default_calendar($writeable = false)
|
||||||
{
|
{
|
||||||
$default_id = $this->rc->config->get('calendar_default_calendar');
|
$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;
|
$calendar = $calendars[$default_id] ?: null;
|
||||||
if (!$calendar || ($writeable && $calendar['readonly'])) {
|
if (!$calendar || ($writeable && $calendar['readonly'])) {
|
||||||
foreach ($calendars as $cal) {
|
foreach ($calendars as $cal) {
|
||||||
|
@ -402,9 +402,8 @@ class calendar extends rcube_plugin
|
||||||
// default calendar selection
|
// default calendar selection
|
||||||
$field_id = 'rcmfd_default_calendar';
|
$field_id = 'rcmfd_default_calendar';
|
||||||
$select_cal = new html_select(array('name' => '_default_calendar', 'id' => $field_id, 'is_escaped' => true));
|
$select_cal = new html_select(array('name' => '_default_calendar', 'id' => $field_id, 'is_escaped' => true));
|
||||||
foreach ((array)$this->driver->list_calendars() as $id => $prop) {
|
foreach ((array)$this->driver->list_calendars(false, true) as $id => $prop) {
|
||||||
if (!$prop['readonly'])
|
$select_cal->add($prop['name'], strval($id));
|
||||||
$select_cal->add($prop['name'], strval($id));
|
|
||||||
if ($prop['default'])
|
if ($prop['default'])
|
||||||
$default_calendar = $id;
|
$default_calendar = $id;
|
||||||
}
|
}
|
||||||
|
@ -705,7 +704,7 @@ class calendar extends rcube_plugin
|
||||||
$status = $event['fallback'];
|
$status = $event['fallback'];
|
||||||
$html = html::div('rsvp-status', $status != 'CANCELLED' ? $this->gettext('acceptinvitation') : '');
|
$html = html::div('rsvp-status', $status != 'CANCELLED' ? $this->gettext('acceptinvitation') : '');
|
||||||
$this->load_driver();
|
$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();
|
$emails = $this->get_user_emails();
|
||||||
foreach ($existing['attendees'] as $i => $attendee) {
|
foreach ($existing['attendees'] as $i => $attendee) {
|
||||||
if ($attendee['email'] && in_array($attendee['email'], $emails)) {
|
if ($attendee['email'] && in_array($attendee['email'], $emails)) {
|
||||||
|
@ -716,7 +715,7 @@ class calendar extends rcube_plugin
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// get a list of writeable calendars
|
// 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));
|
$calendar_select = new html_select(array('name' => 'calendar', 'id' => 'calendar-saveto', 'is_escaped' => true));
|
||||||
$numcals = 0;
|
$numcals = 0;
|
||||||
foreach ($calendars as $calendar) {
|
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 (!$start) $start = mktime(0, 0, 0, 1, date('n'), date('Y')-1);
|
||||||
if (!$end) $end = mktime(0, 0, 0, 31, 12, date('Y')+10);
|
if (!$end) $end = mktime(0, 0, 0, 31, 12, date('Y')+10);
|
||||||
$calid = $calname = get_input_value('source', RCUBE_INPUT_GET);
|
$calid = $calname = get_input_value('source', RCUBE_INPUT_GET);
|
||||||
$calendars = $this->driver->list_calendars();
|
$calendars = $this->driver->list_calendars(true);
|
||||||
|
|
||||||
if ($calendars[$calid]) {
|
if ($calendars[$calid]) {
|
||||||
$calname = $calendars[$calid]['name'] ? $calendars[$calid]['name'] : $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;
|
$num = $_REQUEST['_num'] ? intval($_REQUEST['_num']) : 100;
|
||||||
$cats = array_keys($this->driver->list_categories());
|
$cats = array_keys($this->driver->list_categories());
|
||||||
$cals = array();
|
$cals = $this->driver->list_calendars(true);
|
||||||
foreach ($this->driver->list_calendars() as $cid => $cal) {
|
|
||||||
if ($cal['active'])
|
|
||||||
$cals[$cid] = $cal;
|
|
||||||
}
|
|
||||||
|
|
||||||
while ($count++ < $num) {
|
while ($count++ < $num) {
|
||||||
$start = round((time() + rand(-2600, 2600) * 1000) / 300) * 300;
|
$start = round((time() + rand(-2600, 2600) * 1000) / 300) * 300;
|
||||||
$duration = round(rand(30, 360) / 30) * 30 * 60;
|
$duration = round(rand(30, 360) / 30) * 30 * 60;
|
||||||
|
@ -1789,7 +1784,7 @@ class calendar extends rcube_plugin
|
||||||
if (!empty($events) && ($event = $events[$index])) {
|
if (!empty($events) && ($event = $events[$index])) {
|
||||||
// find writeable calendar to store event
|
// find writeable calendar to store event
|
||||||
$cal_id = !empty($_REQUEST['_calendar']) ? get_input_value('_calendar', RCUBE_INPUT_POST) : null;
|
$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);
|
$calendar = $calendars[$cal_id] ?: $this->get_default_calendar(true);
|
||||||
|
|
||||||
// update my attendee status according to submitted method
|
// update my attendee status according to submitted method
|
||||||
|
@ -1852,6 +1847,7 @@ class calendar extends rcube_plugin
|
||||||
// import the (newer) event
|
// import the (newer) event
|
||||||
else if ($event['sequence'] >= $existing['sequence'] || $event['changed'] >= $existing['changed']) {
|
else if ($event['sequence'] >= $existing['sequence'] || $event['changed'] >= $existing['changed']) {
|
||||||
$event['id'] = $existing['id'];
|
$event['id'] = $existing['id'];
|
||||||
|
$event['calendar'] = $existing['calendar'];
|
||||||
$success = $this->driver->edit_event($event);
|
$success = $this->driver->edit_event($event);
|
||||||
}
|
}
|
||||||
else if (!empty($status)) {
|
else if (!empty($status)) {
|
||||||
|
|
|
@ -92,8 +92,13 @@ abstract class calendar_driver
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a list of available calendars from this source
|
* 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
|
* Create a new calendar assigned to the current user
|
||||||
|
@ -208,9 +213,12 @@ abstract class calendar_driver
|
||||||
* id: Event identifier
|
* id: Event identifier
|
||||||
* calendar: Calendar identifier (optional)
|
* calendar: Calendar identifier (optional)
|
||||||
* @param boolean If true, only writeable calendars shall be searched
|
* @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
|
* @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.
|
* Get events from source.
|
||||||
|
|
|
@ -103,18 +103,36 @@ class database_driver extends calendar_driver
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a list of available calendars from this source
|
* 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
|
// attempt to create a default calendar for this user
|
||||||
if (empty($this->calendars)) {
|
if (empty($this->calendars)) {
|
||||||
if ($this->create_calendar(array('name' => 'Default', 'color' => 'cc0000')))
|
if ($this->create_calendar(array('name' => 'Default', 'color' => 'cc0000')))
|
||||||
$this->_read_calendars();
|
$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
|
* 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
|
* Return data of a specific event
|
||||||
* @param mixed Hash array with event properties or event UID
|
* @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
|
* @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;
|
$id = is_array($event) ? ($event['id'] ? $event['id'] : $event['uid']) : $event;
|
||||||
$col = is_array($event) && is_numeric($id) ? 'event_id' : 'uid';
|
$col = is_array($event) && is_numeric($id) ? 'event_id' : 'uid';
|
||||||
|
|
||||||
if ($this->cache[$id])
|
if ($this->cache[$id])
|
||||||
return $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(
|
$result = $this->rc->db->query(sprintf(
|
||||||
"SELECT e.*, COUNT(a.attachment_id) AS _attachments FROM " . $this->db_events . " AS e
|
"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)
|
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)
|
WHERE e.calendar_id IN (%s)
|
||||||
AND e.$col=?",
|
AND e.$col=?",
|
||||||
$this->calendar_ids
|
$cals
|
||||||
),
|
),
|
||||||
$id);
|
$id);
|
||||||
|
|
||||||
|
|
|
@ -96,8 +96,13 @@ class kolab_driver extends calendar_driver
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a list of available calendars from this source
|
* 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
|
// attempt to create a default calendar for this user
|
||||||
if (!$this->has_writeable) {
|
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) {
|
foreach ($calendars as $id => $cal) {
|
||||||
if ($cal->ready) {
|
$name = kolab_storage::folder_displayname($cal->get_name(), $names);
|
||||||
$name = kolab_storage::folder_displayname($cal->get_name(), $names);
|
|
||||||
|
|
||||||
$calendars[$cal->id] = array(
|
$calendars[$id] = array(
|
||||||
'id' => $cal->id,
|
'id' => $cal->id,
|
||||||
'name' => $name,
|
'name' => $name,
|
||||||
'editname' => $cal->get_foldername(),
|
'editname' => $cal->get_foldername(),
|
||||||
'color' => $cal->get_color(),
|
'color' => $cal->get_color(),
|
||||||
'readonly' => $cal->readonly,
|
'readonly' => $cal->readonly,
|
||||||
'showalarms' => $cal->alarms,
|
'showalarms' => $cal->alarms,
|
||||||
'class_name' => $cal->get_namespace(),
|
'class_name' => $cal->get_namespace(),
|
||||||
'default' => $cal->storage->default,
|
'default' => $cal->storage->default,
|
||||||
'active' => $cal->storage->is_subscribed(kolab_storage::SERVERSIDE_SUBSCRIPTION),
|
'active' => $cal->storage->is_subscribed(),
|
||||||
);
|
);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $calendars;
|
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
|
* Create a new calendar assigned to the current user
|
||||||
*
|
*
|
||||||
|
@ -252,7 +287,7 @@ class kolab_driver extends calendar_driver
|
||||||
* @see calendar_driver::get_event()
|
* @see calendar_driver::get_event()
|
||||||
* @return array Hash array with event properties, false if not found
|
* @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)) {
|
if (is_array($event)) {
|
||||||
$id = $event['id'] ? $event['id'] : $event['uid'];
|
$id = $event['id'] ? $event['id'] : $event['uid'];
|
||||||
|
@ -261,16 +296,16 @@ class kolab_driver extends calendar_driver
|
||||||
else {
|
else {
|
||||||
$id = $event;
|
$id = $event;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($cal && ($storage = $this->calendars[$cal])) {
|
if ($cal) {
|
||||||
return $storage->get_event($id);
|
if ($storage = $this->calendars[$cal]) {
|
||||||
|
return $storage->get_event($id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// iterate over all calendar folders and search for the event ID
|
// iterate over all calendar folders and search for the event ID
|
||||||
else if (!$cal) {
|
else {
|
||||||
foreach ($this->calendars as $storage) {
|
foreach ($this->filter_calendars($writeable, $active, $personal) as $calendar) {
|
||||||
if ($writeable && $storage->readonly)
|
if ($result = $calendar->get_event($id)) {
|
||||||
continue;
|
|
||||||
if ($result = $storage->get_event($id)) {
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue