Skip to content
This repository has been archived by the owner on Dec 27, 2023. It is now read-only.

Commit

Permalink
feature(Calendar): config for skip external notifications
Browse files Browse the repository at this point in the history
Change-Id: Ie4f6d1118b0bc3a8a96611865b2947fa9b11bc88
Reviewed-on: http://gerrit.tine20.com/customers/19219
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
Tested-by: Jenkins CI (http://ci.tine20.com/) <tine20-jenkins@metaways.de>
  • Loading branch information
pschuele committed Mar 15, 2021
1 parent f65acfd commit 6af126d
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 29 deletions.
18 changes: 18 additions & 0 deletions tests/tine20/Calendar/Controller/EventNotificationsTests.php
Expand Up @@ -381,6 +381,24 @@ public function testNotificationToNonAccounts()
$this->_assertMail('pwulf', 'declined');
}

public function testSkipNotificationToNonAccounts()
{
$persistentEvent = $this->_createEventWithExternal();

// add alarm
$persistentEvent->summary = 'Update Event';

$origConf = Calendar_Config::getInstance()->get(Calendar_Config::DISABLE_EXTERNAL_NOTIFICATIONS);
Calendar_Config::getInstance()->set(Calendar_Config::DISABLE_EXTERNAL_NOTIFICATIONS,true);

self::flushMailer();
$this->_eventController->update($persistentEvent);

$this->_assertMail('externer@example.org');

Calendar_Config::getInstance()->set(Calendar_Config::DISABLE_EXTERNAL_NOTIFICATIONS,$origConf);
}

/**
* @param bool $externalOrganizer
* @return Calendar_Model_Event
Expand Down
34 changes: 34 additions & 0 deletions tine20/Addressbook/Controller/Contact.php
Expand Up @@ -576,6 +576,40 @@ public function getSyncBackends()
return $this->_syncBackends;
}

/**
* @param $mails
* @return array
* @throws Tinebase_Exception_InvalidArgument
*/
public function doMailsBelongToAccount($mails) {
$contactFilter = new Addressbook_Model_ContactFilter([
[
'field' => 'type',
'operator' => 'equals',
'value' => Addressbook_Model_Contact::CONTACTTYPE_USER
],
[
'condition' => 'OR',
'filters' => [
[
'field' => 'email',
'operator' => 'in',
'value' => $mails
],
[
'field' => 'email_home',
'operator' => 'in',
'value' => $mails
]
]
]
]);

$contacts = Addressbook_Controller_Contact::getInstance()->search($contactFilter);
$usermails = array_filter(array_merge($contacts->email, $contacts->email_home));
return array_diff($mails, $usermails);
}

/**
* delete one record
* - don't delete if it belongs to an user account
Expand Down
18 changes: 18 additions & 0 deletions tine20/Calendar/Config.php
Expand Up @@ -140,6 +140,13 @@ class Calendar_Config extends Tinebase_Config_Abstract
* @var string
*/
const DISABLE_EXTERNAL_IMIP = 'disableExternalImip';

/**
* DISABLE_EXTERNAL_IMIP_NOTIFICATION
*
* @var string
*/
const DISABLE_EXTERNAL_NOTIFICATIONS = 'disableExternalNotifications';

/**
* SKIP_DOUBLE_EVENTS
Expand Down Expand Up @@ -516,6 +523,17 @@ class Calendar_Config extends Tinebase_Config_Abstract
'setBySetupModule' => true,
'default' => false,
),
self::DISABLE_EXTERNAL_NOTIFICATIONS => array(
//_('Disable notification for external organizers')
'label' => 'Disable notification for external organizers',
//_('Disable notification for external organizers')
'description' => 'Disable notification for external organizers',
'type' => Tinebase_Config_Abstract::TYPE_BOOL,
'clientRegistryInclude' => false,
'setByAdminModule' => true,
'setBySetupModule' => true,
'default' => false,
),
self::SKIP_DOUBLE_EVENTS => array(
//_('(CalDAV) Skip double events from personal or shared calendar')
'label' => '(CalDAV) Skip double events from personal or shared calendar',
Expand Down
11 changes: 10 additions & 1 deletion tine20/Calendar/Controller/EventNotifications.php
Expand Up @@ -346,10 +346,19 @@ public function sendNotificationToAttender(Calendar_Model_Attender $_attender, $
}
if (!$attendee instanceof Tinebase_Record_Interface) {
if (Tinebase_Core::isLogLevel(Zend_Log::WARN)) Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__
. " Skip notification for unknown attende: " . print_r($attendee, true) . ' attender: ' . print_r($_attender, true));
. " Skip notification for unknown attendee: " . print_r($attendee, true) . ' attender: ' . print_r($_attender, true));
return;
}

if (Calendar_Config::getInstance()->get(Calendar_Config::DISABLE_EXTERNAL_NOTIFICATIONS)) {
if ($attendee->account_id === null) {
if (Tinebase_Core::isLogLevel(Zend_Log::WARN)) Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__
. " Skip notification for external attendee: " . print_r($attendee, true) . ' attender: ' . print_r($_attender, true));
return;
}
}


list($prefUser, $locale, $timezone, $translate, $sendLevel, $sendOnOwnActions, $sendAlarms) = self::getNotificationPreferences($_attender, $_event);
$attendeeAccountId = $_attender->getUserAccountId();

Expand Down
3 changes: 3 additions & 0 deletions tine20/Calendar/translations/de.po
Expand Up @@ -2626,3 +2626,6 @@ msgstr "Farbe nach Ressource"

msgid "Color"
msgstr "Farbe"

msgid "Disable notification for external attendeers"
msgstr "Deaktiviere Benachrichtigung für externe Teilnehmer"
30 changes: 2 additions & 28 deletions tine20/Felamimail/Frontend/Json.php
Expand Up @@ -717,34 +717,8 @@ public function getRegistryData()
*/
public function doMailsBelongToAccount($mails)
{
$contactFilter = new Addressbook_Model_ContactFilter([
[
'field' => 'type',
'operator' => 'equals',
'value' => Addressbook_Model_Contact::CONTACTTYPE_USER
],
[
'condition' => 'OR',
'filters' => [
[
'field' => 'email',
'operator' => 'in',
'value' => $mails
],
[
'field' => 'email_home',
'operator' => 'in',
'value' => $mails
]
]
]
]);

$contacts = Addressbook_Controller_Contact::getInstance()->search($contactFilter);

$usermails = array_filter(array_merge($contacts->email, $contacts->email_home));

return array_diff($mails, $usermails);
$mails = Addressbook_Controller_Contact::getInstance()->doMailsBelongToAccount($mails);
return $mails;
}

/**
Expand Down

0 comments on commit 6af126d

Please sign in to comment.