Recognize which Attendee Changed
authorsstamer <s.stamer@metaways.de>
Mon, 23 Nov 2015 15:51:08 +0000 (16:51 +0100)
committerPhilipp Schüle <p.schuele@metaways.de>
Mon, 21 Dec 2015 11:06:35 +0000 (12:06 +0100)
- Only Send Ressource notification if it was the ressource

Change-Id: I6c98e00745bfd3f1634fb59141361ac33a507186
Reviewed-on: http://gerrit.tine20.com/customers/2451
Tested-by: Jenkins CI (http://ci.tine20.com/)
Reviewed-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 bcb26da..fe8a90e 100644 (file)
@@ -1338,7 +1338,7 @@ class Calendar_Controller_EventNotificationsTests extends Calendar_TestCase
     {
         // create resource with email address of unittest user
         $resource = $this->_getResource();
-        $resource->email = Tinebase_Core::getUser()->accountEmailAddress;
+        $resource->email = $this->_GetPersonasContacts('pwulf')->email;
         $resource->suppress_notification = $suppress_notification;
         $persistentResource = Calendar_Controller_Resource::getInstance()->create($resource);
         
@@ -1354,7 +1354,7 @@ class Calendar_Controller_EventNotificationsTests extends Calendar_TestCase
         $messages = self::getMessages();
 
         if ($suppress_notification) {
-            $this->assertEquals(1, count($messages), 'one mails should be send to current user (only attender)');
+            $this->assertEquals(2, count($messages), 'two mails should be send to attender (invite) + resource');
         } else {
             $this->assertEquals(2, count($messages), 'two mails should be send to current user (resource + attender)');
         }
@@ -1363,13 +1363,14 @@ 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($userIsAttendee = true)
+    public function testResourceNotificationForGrantedUsers($userIsAttendee = true, $suppress_notification = false)
     {
         // Enable feature, disabled by default!
         Calendar_Config::getInstance()->set(Calendar_Config::RESOURCE_MAIL_FOR_EDITORS, true);
 
         $resource = $this->_getResource();
         $resource->email = Tinebase_Core::getUser()->accountEmailAddress;
+        $resource->suppress_notification = $suppress_notification;
         $persistentResource = Calendar_Controller_Resource::getInstance()->create($resource);
 
         $event = $this->_getEvent(/*now = */ true);
@@ -1406,8 +1407,12 @@ class Calendar_Controller_EventNotificationsTests extends Calendar_TestCase
         $this->assertContains('Resource "' . $persistentResource->name . '" was booked', print_r($messages, true));
         $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 who is allowed to edit this resource)');
-        $this->assertEquals(count($event->attendee), count($persistentEvent->attendee));
+        if ($suppress_notification) {
+            $this->assertEquals(2, count($messages), 'two mails should be send to current user (resource + attender)');
+        } else {
+            $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));
+        }
     }
 
     /**
@@ -1425,7 +1430,8 @@ class Calendar_Controller_EventNotificationsTests extends Calendar_TestCase
      */
     public function testResourceNotificationMuteForEditors()
     {
-        $this->testResourceNotification(/* $suppress_notification = */ false);
+        $this->testResourceNotification(/* $suppress_notification = */ true);
+        $this->testResourceNotificationForGrantedUsers(/* $userIsAttendee = */ false, /* $suppress_notification = */ true);
     }
     
     /**
index 9333540..6f3a1ae 100644 (file)
 
             $recipients = array($attendee);
 
-            $this->_handleResourceEditors($_attender, $_notificationLevel, $recipients, $_action, $sendLevel);
+            $this->_handleResourceEditors($_attender, $_notificationLevel, $recipients, $_action, $sendLevel, $_updates);
 
             // check if user wants this notification NOTE: organizer gets mails unless she set notificationlevel to NONE
             // NOTE prefUser is organizer for external notifications
       * @param $sendLevel
       * @return bool
       */
-     protected function _handleResourceEditors($attender, $_notificationLevel, &$recipients, &$action, &$sendLevel)
+     protected function _handleResourceEditors($attender, $_notificationLevel, &$recipients, &$action, &$sendLevel, $_updates)
      {
          // Add additional recipients for resources
          if ($attender->user_type !== Calendar_Model_Attender::USERTYPE_RESOURCE
              return true;
          }
          
+         // Set custom startus booked
+         if ($action == 'created') {
+             $action = 'booked';
+         }
+         
          $resource = Calendar_Controller_Resource::getInstance()->get($attender->user_id);
          if ($resource->suppress_notification) {
              if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__
                      . " Do not send Notifications for this resource: ". $resource->name);
+             // $recipients will still contain the resource itself
              return true;
          }
-
-         if ($action == 'created') {
-             $action = 'booked';
+         
+         // The resource has no account there for the organizer preference (sendLevel) is used. We don't want that
+         $sendLevel = self::NOTIFICATION_LEVEL_EVENT_RESCHEDULE;
+         //handle attendee status change
+         if(! empty($_updates['attendee']) && ! empty($_updates['attendee']['toUpdate'])) {
+             foreach ($_updates['attendee']['toUpdate'] as $updatedAttendee) {
+                 if ($updatedAttendee->user_type == Calendar_Model_Attender::USERTYPE_RESOURCE && $resource->getId() == $updatedAttendee->user_id) {
+                     $sendLevel = self::NOTIFICATION_LEVEL_ATTENDEE_STATUS_UPDATE;
+                 }
+             }
          }
-
-         // Consider all notification level (Resource Users have a send level of 30)
-         $sendLevel = self::NOTIFICATION_LEVEL_ATTENDEE_STATUS_UPDATE;
+         
+         /*
+         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__
+                 . " Attender: ". $attender);
+         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__
+                 . " Action: ". $action);
+         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__
+                 . " Notification Level: ". $_notificationLevel);
+         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__
+                 . " Send Level: ". $sendLevel);
+         */
+         
          $recipients = array_merge($recipients,
              Calendar_Controller_Resource::getInstance()->getNotificationRecipients(
-                 Calendar_Controller_Resource::getInstance()->get($attender->user_id),
-                 $_notificationLevel
+                 Calendar_Controller_Resource::getInstance()->get($attender->user_id)
              )
          );
      }
                 if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " unknown action '$_action'");
                 break;
         }
-        
+        if ($attender->user_type === Calendar_Model_Attender::USERTYPE_RESOURCE) {
+            $messageSubject = '[' . $translate->_('Resource Management') . '] ' . $messageSubject;
+        }
         return $messageSubject;
     }
     
index 2b317fc..10722e5 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, $_notificationLevel)
+    public function getNotificationRecipients(Calendar_Model_Resource $resource)
     {
         $recipients = array();
 
@@ -196,11 +196,7 @@ class Calendar_Controller_Resource extends Tinebase_Controller_Record_Abstract
                 if ($grant['account_type'] == Tinebase_Acl_Rights::ACCOUNT_TYPE_USER && $grant[Tinebase_Model_Grants::GRANT_EDIT] == 1) {
                     try {
                         $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());