From ca2409e081e24466f3b96d7e954199a2ed35a72c Mon Sep 17 00:00:00 2001 From: JodliDev Date: Mon, 25 Apr 2022 10:03:39 +0200 Subject: [PATCH] See https://git.kolab.org/rRPK3613a3d39999d67e46716658718c468bc23480e7 --- calendar.php | 31 +++++++++++++++++++++++--- calendar_ui.js | 12 +++++++++- drivers/ldap/resources_driver_ldap.php | 9 ++++---- localization/en_US.inc | 4 ++++ 4 files changed, 48 insertions(+), 8 deletions(-) diff --git a/calendar.php b/calendar.php index b757fa2..a6002e3 100644 --- a/calendar.php +++ b/calendar.php @@ -1251,23 +1251,31 @@ $("#rcmfd_new_category").keypress(function(event) { $noreply = intval($noreply) || $status == 'needs-action' || $itip_sending === 0; $reload = $event['calendar'] != $ev['calendar'] || !empty($event['recurrence']) ? 2 : 1; $emails = $this->get_user_emails(); + $ownedResourceEmails = $this->owned_resources_emails(); $organizer = null; + $resourceConfirmation = false; foreach ($event['attendees'] as $i => $attendee) { if ($attendee['role'] == 'ORGANIZER') { $organizer = $attendee; } - else if (!empty($attendee['email']) && in_array(strtolower($attendee['email']), $emails)) { + else if (!empty($attendee['email']) && in_array_nocase($attendee['email'], $emails)) { $reply_sender = $attendee['email']; } + else if (!empty($attendee['cutype']) && $attendee['cutype'] == 'RESOURCE' && !empty($attendee['email']) && in_array_nocase($attendee['email'], $ownedResourceEmails)) { + $resourceConfirmation = true; + // Note on behalf of which resource this update is going to be sent out + $event['_resource'] = $attendee['email']; + } } if (!$noreply) { $itip = $this->load_itip(); $itip->set_sender_email($reply_sender); $event['thisandfuture'] = $event['_savemode'] == 'future'; + $bodytextprefix = $resourceConfirmation ? 'itipmailbodyresource' : 'itipmailbody'; - if ($organizer && $itip->send_itip_message($event, 'REPLY', $organizer, 'itipsubject' . $status, 'itipmailbody' . $status)) { + if ($organizer && $itip->send_itip_message($event, 'REPLY', $organizer, 'itipsubject' . $status, $bodytextprefix . $status)) { $mailto = !empty($organizer['name']) ? $organizer['name'] : $organizer['email']; $msg = $this->gettext(['name' => 'sentresponseto', 'vars' => ['mailto' => $mailto]]); @@ -2018,10 +2026,12 @@ $("#rcmfd_new_category").keypress(function(event) { } $identity['emails'][] = $this->rc->user->get_username(); + $identity['ownedResources'] = $this->owned_resources_emails(); $settings['identity'] = [ 'name' => $identity['name'], 'email' => strtolower($identity['email']), - 'emails' => ';' . strtolower(join(';', $identity['emails'])) + 'emails' => ';' . strtolower(join(';', $identity['emails'])), + 'ownedResources' => ';' . strtolower(join(';', $identity['ownedResources'])) ]; } @@ -2879,6 +2889,21 @@ $("#rcmfd_new_category").keypress(function(event) { exit; } + /** + * List email addressed of owned resources + */ + private function owned_resources_emails() + { + $results = []; + if ($directory = $this->resources_directory()) { + foreach ($directory->load_resources($_SESSION['kolab_dn'], 5000, 'owner') as $rec) { + $results[] = $rec['email']; + } + } + return $results; + } + + /**** Event invitation plugin hooks ****/ /** diff --git a/calendar_ui.js b/calendar_ui.js index c6848cc..f65ab58 100644 --- a/calendar_ui.js +++ b/calendar_ui.js @@ -459,7 +459,7 @@ function rcube_calendar_ui(settings) for (var j=0; j < num_attendees; j++) { data = event.attendees[j]; if (data.email) { - if (data.role != 'ORGANIZER' && settings.identity.emails.indexOf(';'+data.email) >= 0) { + if (data.role != 'ORGANIZER' && is_this_me(data.email)) { mystatus = (data.status || 'UNKNOWN').toLowerCase(); if (data.status == 'NEEDS-ACTION' || data.status == 'TENTATIVE' || data.rsvp) rsvp = mystatus; @@ -2379,6 +2379,14 @@ function rcube_calendar_ui(settings) add_attendee($.extend({ role:'REQ-PARTICIPANT', status:'NEEDS-ACTION', cutype:'RESOURCE' }, resource)); } + var is_this_me = function(email) + { + if (settings.identity.emails.indexOf(';'+email) >= 0 || settings.identity.ownedResources.indexOf(';'+email) >= 0) { + return true; + } + return false; + }; + // when the user accepts or declines an event invitation var event_rsvp = function(response, delegate, replymode, event) { @@ -2414,6 +2422,8 @@ function rcube_calendar_ui(settings) for (var data, i=0; i < me.selected_event.attendees.length; i++) { data = me.selected_event.attendees[i]; if (settings.identity.emails.indexOf(';'+String(data.email).toLowerCase()) >= 0) { + //FIXME this can only work if there is a single resource per invitation + if (is_this_me(String(data.email).toLowerCase())) { data.status = response.toUpperCase(); data.rsvp = 0; // unset RSVP flag diff --git a/drivers/ldap/resources_driver_ldap.php b/drivers/ldap/resources_driver_ldap.php index 0be4126..3719b70 100644 --- a/drivers/ldap/resources_driver_ldap.php +++ b/drivers/ldap/resources_driver_ldap.php @@ -41,12 +41,13 @@ class resources_driver_ldap extends resources_driver /** * Fetch resource objects to be displayed for booking * - * @param string $query Search query (optional) - * @param int $num Max size of the result + * @param string $query Search query (optional) + * @param int $num Max size of the result + * @param string $searchField Field to search with query * * @return array List of resource records available for booking */ - public function load_resources($query = null, $num = 5000) + public function load_resources($query = null, $num = 5000, $searchField = '*') { if (!($ldap = $this->connect())) { return []; @@ -56,7 +57,7 @@ class resources_driver_ldap extends resources_driver $ldap->set_pagesize($num); if (isset($query)) { - $results = $ldap->search('*', $query, 0, true, true); + $results = $ldap->search($searchField, $query, 0, true, true); } else { $results = $ldap->list_records(); diff --git a/localization/en_US.inc b/localization/en_US.inc index 8626d9f..40fe9b5 100644 --- a/localization/en_US.inc +++ b/localization/en_US.inc @@ -213,6 +213,10 @@ $labels['itipmailbodycancel'] = "\$sender has rejected your participation in the $labels['itipmailbodydelegated'] = "\$sender has delegated the participation in the following event:\n\n*\$title*\n\nWhen: \$date"; $labels['itipmailbodydelegatedto'] = "\$sender has delegated the participation in the following event to you:\n\n*\$title*\n\nWhen: \$date"; +$labels['itipmailbodyresourceaccepted'] = "\$sender has accepted the following resource booking:\n\n*\$title*\n\nWhen: \$date\n\nInvitees: \$attendees"; +$labels['itipmailbodyresourcetentative'] = "\$sender has tentatively accepted the following resource booking:\n\n*\$title*\n\nWhen: \$date\n\nInvitees: \$attendees"; +$labels['itipmailbodyresourcedeclined'] = "\$sender has declined the the following resource booking:\n\n*\$title*\n\nWhen: \$date\n\nInvitees: \$attendees"; + $labels['itipdeclineevent'] = 'Do you want to decline your invitation to this event?'; $labels['declinedeleteconfirm'] = 'Do you also want to delete this declined event from your calendar?'; $labels['itipcomment'] = 'Invitation/notification comment';