0011272: resource invitation: organizer receives no mail if he is no attendee
authorsstamer <s.stamer@metaways.de>
Wed, 19 Aug 2015 11:52:44 +0000 (13:52 +0200)
committerPhilipp Schüle <p.schuele@metaways.de>
Thu, 27 Aug 2015 12:28:15 +0000 (14:28 +0200)
- Send all notification level
- Consider the send level for additional recipients

https://forge.tine20.org/view.php?id=11272

Change-Id: If3ebc8893f6598f7748da005529524a6abe400bb
Reviewed-on: http://gerrit.tine20.com/customers/2136
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
Tested-by: Philipp Schüle <p.schuele@metaways.de>
tests/tine20/Calendar/Controller/EventNotificationsTests.php
tine20/Calendar/Controller/EventNotifications.php
tine20/Calendar/Controller/Resource.php

index cd07b16..f403620 100644 (file)
@@ -1327,7 +1327,7 @@ class Calendar_Controller_EventNotificationsTests extends Calendar_TestCase
     /**
      * Enable by a preference which sends mails to every user who got permissions to edit the resource
      */
-    public function testResourceNotificationForGrantedUsers()
+    public function testResourceNotificationForGrantedUsers($userIsAttendee = true)
     {
         // Enable feature, disabled by default!
         Calendar_Config::getInstance()->set(Calendar_Config::RESOURCE_MAIL_FOR_EDITORS, true);
@@ -1338,6 +1338,16 @@ class Calendar_Controller_EventNotificationsTests extends Calendar_TestCase
 
         $event = $this->_getEvent(/*now = */ true);
         $event->attendee->addRecord($this->_createAttender($persistentResource->getId(), Calendar_Model_Attender::USERTYPE_RESOURCE));
+
+        if (! $userIsAttendee) {
+            // remove organizer attendee
+            foreach ($event->attendee as $idx => $attender) {
+                if ($attender->user_id === $event->organizer) {
+                    $event->attendee->removeRecord($attender);
+                }
+            }
+        }
+
         $grants = Tinebase_Container::getInstance()->getGrantsOfContainer($resource->container_id);
 
         $newGrants = array(
@@ -1358,7 +1368,16 @@ class Calendar_Controller_EventNotificationsTests extends Calendar_TestCase
         Tinebase_Container::getInstance()->setGrants($resource->container_id, $grants);
 
         $this->assertContains('Meeting Room (Required, No response)', print_r($messages, true));
-        $this->assertEquals(4, count($messages), 'four mails should be send to current user (resource + attender + everybody whos allowed to edit this resource)');
-        $this->assertEquals(3, count($persistentEvent->attendee));
+
+        $this->assertEquals(4, count($messages), 'four mails should be send to current user (resource + attender + everybody who is allowed to edit this resource)');
+        $this->assertEquals(count($event->attendee), count($persistentEvent->attendee));
+    }
+
+    /**
+     * @see 0011272: ressource invitation: organizer receives no mail if he is no attendee
+     */
+    public function testResourceNotificationForNonAttendeeOrganizer()
+    {
+        $this->testResourceNotificationForGrantedUsers(/* $userIsAttendee = */ false);
     }
 }
index ddd6804..e265ea6 100644 (file)
                 $sendOnOwnActions = false;
             }
             
+            // Add additional recipients for ressources
+            $recipients = array($attendee);
+            if ($_attender->user_type == Calendar_Model_Attender::USERTYPE_RESOURCE
+                    && Calendar_Config::getInstance()->get(Calendar_Config::RESOURCE_MAIL_FOR_EDITORS)
+            ) {
+                // Consider all notification level (Ressource Users have a send level of 30)
+                $sendLevel = self::NOTIFICATION_LEVEL_ATTENDEE_STATUS_UPDATE;
+                $recipients = array_merge($recipients,
+                        Calendar_Controller_Resource::getInstance()->getNotificationRecipients(
+                                Calendar_Controller_Resource::getInstance()->get($_attender->user_id),
+                                $_notificationLevel
+                        )
+                );
+            }
+            
             // check if user wants this notification NOTE: organizer gets mails unless she set notificationlevel to NONE
             // NOTE prefUser is organzier for external notifications
             if (($attendeeAccountId == $_updater->getId() && ! $sendOnOwnActions) 
             if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " body: $messageBody");
 
             $sender = $_action == 'alarm' ? $prefUser : $_updater;
-
-            $recipients = array($attendee);
-            if ($_attender->user_type == Calendar_Model_Attender::USERTYPE_RESOURCE
-                && Calendar_Config::getInstance()->get(Calendar_Config::RESOURCE_MAIL_FOR_EDITORS)
-            ) {
-                $recipients = array_merge($recipients,
-                    Calendar_Controller_Resource::getInstance()->getNotificationRecipients(
-                        Calendar_Controller_Resource::getInstance()->get($_attender->user_id)
-                    )
-                );
-            }
+            
             Tinebase_Notification::getInstance()->send($sender, $recipients, $messageSubject, $messageBody, $calendarPart, $attachments);
         } catch (Exception $e) {
             Tinebase_Exception::log($e);
index b3937f6..2b317fc 100644 (file)
@@ -174,7 +174,7 @@ class Calendar_Controller_Resource extends Tinebase_Controller_Record_Abstract
      * @param  Calendar_Model_Resource $_lead
      * @return array          array of int|Addressbook_Model_Contact
      */
-    public function getNotificationRecipients(Calendar_Model_Resource $resource)
+    public function getNotificationRecipients(Calendar_Model_Resource $resource, $_notificationLevel)
     {
         $recipients = array();
 
@@ -195,7 +195,12 @@ class Calendar_Controller_Resource extends Tinebase_Controller_Record_Abstract
             foreach ($containerGrants as $grant) {
                 if ($grant['account_type'] == Tinebase_Acl_Rights::ACCOUNT_TYPE_USER && $grant[Tinebase_Model_Grants::GRANT_EDIT] == 1) {
                     try {
-                        $recipients[] = Addressbook_Controller_Contact::getInstance()->getContactByUserId($grant['account_id'], TRUE);
+                        $recipient = Addressbook_Controller_Contact::getInstance()->getContactByUserId($grant['account_id'], TRUE);
+                        $sendLevel = Tinebase_Core::getPreference('Calendar')->getValueForUser(Calendar_Preference::NOTIFICATION_LEVEL, $grant['account_id']);
+                        // only add recipients that want that kind of notification (consider the send Level)
+                        if ($sendLevel >= $_notificationLevel) {
+                            $recipients[] = $recipient;
+                        }
                     } catch (Addressbook_Exception_NotFound $aenf) {
                         if (Tinebase_Core::isLogLevel(Zend_Log::NOTICE)) Tinebase_Core::getLogger()->notice(__CLASS__ . '::' . __METHOD__ . '::' . __LINE__
                             . ' Do not send notification to non-existant user: ' . $aenf->getMessage());
@@ -203,7 +208,6 @@ class Calendar_Controller_Resource extends Tinebase_Controller_Record_Abstract
                 }
             }
         }
-
         return $recipients;
     }
 }