Fix handling of kolab_freebusy_server=false (and other empty values)

- Cleanup code
- Hide availability features in the Resources tab
This commit is contained in:
Aleksander Machniak 2023-06-23 14:38:10 +02:00
parent 5863bcc947
commit 83d5c9f7f5
6 changed files with 88 additions and 68 deletions

View file

@ -342,6 +342,7 @@ class calendar extends rcube_plugin
$this->rc->output->set_env('timezone', $this->timezone->getName());
$this->rc->output->set_env('calendar_driver', $this->rc->config->get('calendar_driver'), false);
$this->rc->output->set_env('calendar_resources', (bool)$this->rc->config->get('calendar_resources_driver'));
$this->rc->output->set_env('calendar_resources_freebusy', !empty($this->rc->config->get('kolab_freebusy_server')));
$this->rc->output->set_env('identities-selector', $this->ui->identity_select([
'id' => 'edit-identities-list',
'aria-label' => $this->gettext('roleorganizer'),

View file

@ -924,13 +924,19 @@ function rcube_calendar_ui(settings)
$('#edit-tab-attachments')[(calendar.attachments?'show':'hide')]();
$('#eventedit:not([data-notabs])').tabs('option', 'active', 0); // Larry
// show/hide tabs according to calendar's feature support and activate first tab (Ellastic)
// show/hide tabs according to calendar's feature support and activate first tab (Elastic)
$('li > a[href="#event-panel-attendees"]').parent()[(calendar.attendees?'show':'hide')]();
$('li > a[href="#event-panel-resources"]').parent()[(rcmail.env.calendar_resources?'show':'hide')]();
$('li > a[href="#event-panel-attachments"]').parent()[(calendar.attachments?'show':'hide')]();
if ($('#eventedit').data('notabs'))
$('#eventedit li.nav-item:first-child a').tab('show');
if (!rcmail.env.calendar_resources_freebusy) {
// With no freebusy setup, some features needs to be hidden
// TODO: Show "Find resources" dialog, but with Availability tab hidden
$('#event-panel-resources').find('#edit-resource-find,#edit-attendees-legend,td.availability,th.availability').hide();
}
// hack: set task to 'calendar' to make all dialog actions work correctly
var comm_path_before = rcmail.env.comm_path;
rcmail.env.comm_path = comm_path_before.replace(/_task=[a-z]+/, '_task=calendar');
@ -3381,6 +3387,7 @@ function rcube_calendar_ui(settings)
me.calendars[this.id].url = this.url;
sources.push(this.id);
});
id += '@'+sources.join(',');
// ignore if query didn't change

View file

@ -2016,6 +2016,12 @@ class kolab_driver extends calendar_driver
return false;
}
$url = $this->storage->get_freebusy_url($email);
if (empty($url)) {
return false;
}
// map vcalendar fbtypes to internal values
$fbtypemap = [
'FREE' => calendar::FREEBUSY_FREE,
@ -2031,7 +2037,7 @@ class kolab_driver extends calendar_driver
'follow_redirects' => true,
];
$request = libkolab::http_request($this->storage->get_freebusy_url($email), 'GET', $request_config);
$request = libkolab::http_request($url, 'GET', $request_config);
$response = $request->send();
// authentication required

View file

@ -279,11 +279,12 @@ class kolab_storage
{
$rcmail = rcube::get_instance();
$url = 'https://' . $_SESSION['imap_host'] . '/freebusy';
$url = $rcmail->config->get('kolab_freebusy_server', $url);
if ($url = $rcmail->config->get('kolab_freebusy_server')) {
$url = rcube_utils::resolve_url($url);
$url = unslashify($url);
}
return unslashify($url);
return $url;
}
/**
@ -293,10 +294,16 @@ class kolab_storage
* @param object DateTime Start of the query range (optional)
* @param object DateTime End of the query range (optional)
*
* @return string Fully qualified URL to query free/busy data
* @return ?string Fully qualified URL to query free/busy data
*/
public static function get_freebusy_url($email, $start = null, $end = null)
{
$url = self::get_freebusy_server();
if (empty($url)) {
return null;
}
$query = '';
$param = array();
$utc = new \DateTimeZone('UTC');
@ -317,8 +324,6 @@ class kolab_storage
$query = '?' . http_build_query($param);
}
$url = self::get_freebusy_server();
if (strpos($url, '%u')) {
// Expected configured full URL, just replace the %u variable
// Note: Cyrus v3 Free-Busy service does not use .ifb extension

View file

@ -149,7 +149,7 @@ class kolab_storage_dav
* @param object DateTime Start of the query range (optional)
* @param object DateTime End of the query range (optional)
*
* @return string Fully qualified URL to query free/busy data
* @return ?string Fully qualified URL to query free/busy data
*/
public static function get_freebusy_url($email, $start = null, $end = null)
{

View file

@ -1099,13 +1099,14 @@ class kolab_storage_folder extends kolab_storage_folder_api
{
$owner = $this->get_owner();
$result = false;
$url = kolab_storage::get_freebusy_server();
switch ($this->type) {
case 'event':
if ($this->get_namespace() == 'personal') {
if ($url && $this->get_namespace() == 'personal') {
$result = $this->trigger_url(
sprintf('%s/trigger/%s/%s.pfb',
kolab_storage::get_freebusy_server(),
$url,
urlencode($owner),
urlencode($this->imap->mod_folder($this->name))
),
@ -1119,7 +1120,7 @@ class kolab_storage_folder extends kolab_storage_folder_api
return true;
}
if ($result && is_object($result) && is_a($result, 'PEAR_Error')) {
if ($result instanceof PEAR_Error) {
return PEAR::raiseError(
sprintf("Failed triggering folder %s. Error was: %s", $this->name, $result->getMessage())
);