0010046: config for disabling external imip
authorPhilipp Schüle <p.schuele@metaways.de>
Wed, 9 Jul 2014 15:30:18 +0000 (17:30 +0200)
committerPhilipp Schüle <p.schuele@metaways.de>
Mon, 28 Jul 2014 15:50:31 +0000 (17:50 +0200)
if config DISABLE_EXTERNAL_IMIP is set:
* disable external iMIP in iMIP frontend
* sending iMIP to external attendee is disabled, too

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

Change-Id: I397c1ecce509bde1f311c936b9ebd0fb95868caf
Reviewed-on: http://gerrit.tine20.com/customers/839
Tested-by: Jenkins CI (http://ci.tine20.com/)
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
tests/tine20/Calendar/Frontend/iMIPTest.php
tests/tine20/TestCase.php
tine20/Calendar/Config.php
tine20/Calendar/Controller/EventNotifications.php
tine20/Calendar/Frontend/iMIP.php
tine20/Felamimail/Frontend/Json.php

index fb248c0..4b45d94 100644 (file)
@@ -4,19 +4,14 @@
  * 
  * @package     Calendar
  * @license     http://www.gnu.org/licenses/agpl.html
- * @copyright   Copyright (c) 2011-2012 Metaways Infosystems GmbH (http://www.metaways.de)
+ * @copyright   Copyright (c) 2011-2014 Metaways Infosystems GmbH (http://www.metaways.de)
  * @author      Philipp Schüle <p.schuele@metaways.de>
  */
 
 /**
- * Test helper
- */
-require_once dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR . 'TestHelper.php';
-
-/**
  * Test class for Calendar_Frontend_iMIP
  */
-class Calendar_Frontend_iMIPTest extends PHPUnit_Framework_TestCase
+class Calendar_Frontend_iMIPTest extends TestCase
 {
     /**
      * event ids that should be deleted in tearDown
@@ -251,14 +246,7 @@ class Calendar_Frontend_iMIPTest extends PHPUnit_Framework_TestCase
      */
     public function testExternalInvitationRequestProcess()
     {
-        $this->_checkIMAPConfig();
-        
-        $testConfig = Zend_Registry::get('testConfig');
-        $email = ($testConfig->email) ? $testConfig->email : Tinebase_Core::getUser()->accountEmailAddress;
-        
-        // handle message with fmail (add to cache)
-        $message = $this->_emailTestClass->messageTestHelper('calendar_request.eml', NULL, NULL, array('unittest@tine20.org', $email));
-        $complete = Felamimail_Controller_Message::getInstance()->getCompleteMessage($message);
+        $complete = $this->_addImipMessageToEmailCache();
         
         $iMIP = $complete->preparedParts->getFirstRecord()->preparedData;
         
@@ -273,7 +261,7 @@ class Calendar_Frontend_iMIPTest extends PHPUnit_Framework_TestCase
         
         // assert attendee
         $this->assertEquals(1, count($iMIP->event->attendee), 'all attendee but curruser must be whiped');
-        $this->assertEquals($email, $iMIP->event->attendee->getFirstRecord()->user_id->email, 'wrong attendee mail');
+        $this->assertEquals($this->_getEmailAddress(), $iMIP->event->attendee->getFirstRecord()->user_id->email, 'wrong attendee mail');
         $this->assertEquals(Tinebase_Core::getUser()->getId(), $iMIP->event->attendee->getFirstRecord()->user_id->account_id, 'wrong attendee');
         $this->assertEquals(Calendar_Model_Attender::STATUS_ACCEPTED, $iMIP->event->attendee->getFirstRecord()->status);
         
@@ -285,6 +273,33 @@ class Calendar_Frontend_iMIPTest extends PHPUnit_Framework_TestCase
     }
     
     /**
+     * adds new imip message to Felamimail cache
+     * 
+     * @return Felamimail_Model_Message
+     */
+    protected function _addImipMessageToEmailCache()
+    {
+        $this->_checkIMAPConfig();
+        
+        // handle message with fmail (add to cache)
+        $message = $this->_emailTestClass->messageTestHelper('calendar_request.eml', NULL, NULL, array('unittest@tine20.org', $this->_getEmailAddress()));
+        return Felamimail_Controller_Message::getInstance()->getCompleteMessage($message);
+    }
+    
+    /**
+     * testDisabledExternalImip
+     */
+    public function testDisabledExternalImip()
+    {
+        Calendar_Config::getInstance()->set(Calendar_Config::DISABLE_EXTERNAL_IMIP, true);
+        $complete = $this->_addImipMessageToEmailCache();
+        $fmailJson = new Felamimail_Frontend_Json();
+        $jsonMessage = $fmailJson->getMessage($complete->getId());
+        Calendar_Config::getInstance()->set(Calendar_Config::DISABLE_EXTERNAL_IMIP, false);
+        $this->assertEmpty($jsonMessage['preparedParts']);
+    }
+    
+    /**
      * check IMAP config and marks test as skipped if no IMAP backend is configured
      */
     protected function _checkIMAPConfig()
@@ -375,8 +390,6 @@ class Calendar_Frontend_iMIPTest extends PHPUnit_Framework_TestCase
         } catch (Exception $e) {
             $this->fail('autoProcess throwed Exception');
         }
-        
-        
     }
     */
     
@@ -459,18 +472,23 @@ class Calendar_Frontend_iMIPTest extends PHPUnit_Framework_TestCase
         $this->_iMIPFrontend->autoProcess($iMIP);
     }
 
-//     /**
-//      * testInvitationCancel
-//      * 
-//      * @todo implement
-//      */
-//     public function testInvitationCancel()
-//     {
-        
-//     }
+    /**
+     * testInvitationCancel
+     * 
+      * @todo implement
+      */
+     public function testInvitationCancel()
+     {
+        $this->markTestIncomplete('implement me');
+     }
     
-//     public function testOrganizerSendBy()
-//     {
-        
-//     }
+    /**
+      * testInvitationCancel
+      * 
+      * @todo implement
+      */
+     public function testOrganizerSendBy()
+     {
+         $this->markTestIncomplete('implement me');
+     }
 }
index f0f89fa..1ef5edf 100644 (file)
@@ -192,7 +192,18 @@ abstract class TestCase extends PHPUnit_Framework_TestCase
         $testconfig = Zend_Registry::get('testConfig');
         return ($testconfig && isset($testconfig->maildomain)) ? $testconfig->maildomain : 'tine20.org';
     }
-
+    
+    /**
+     * get test user email address
+     * 
+     * @return test user email address
+     */
+    protected function _getEmailAddress()
+    {
+        $testConfig = Zend_Registry::get('testConfig');
+        return ($testConfig->email) ? $testConfig->email : Tinebase_Core::getUser()->accountEmailAddress;
+    }
+    
     /**
      * lazy init of uit
      * 
index f357404..5677332 100644 (file)
@@ -4,7 +4,7 @@
  * @subpackage  Config
  * @license     http://www.gnu.org/licenses/agpl.html AGPL Version 3
  * @author      Cornelius Weiss <c.weiss@metaways.de>
- * @copyright   Copyright (c) 2011-2013 Metaways Infosystems GmbH (http://www.metaways.de)
+ * @copyright   Copyright (c) 2011-2014 Metaways Infosystems GmbH (http://www.metaways.de)
  */
 
 /**
@@ -65,6 +65,13 @@ class Calendar_Config extends Tinebase_Config_Abstract
     const MAX_JSON_DEFAULT_FILTER_PERIOD_UNTIL = 'maxjsondefaultfilterperioduntil';
     
     /**
+     * DISABLE_EXTERNAL_IMIP
+     *
+     * @var string
+     */
+    const DISABLE_EXTERNAL_IMIP = 'disableExternalImip';
+    
+    /**
      * (non-PHPdoc)
      * @see tine20/Tinebase/Config/Definition::$_properties
      */
@@ -143,6 +150,17 @@ class Calendar_Config extends Tinebase_Config_Abstract
             'setBySetupModule'      => TRUE,
             'default'               => 1,
         ),
+        self::DISABLE_EXTERNAL_IMIP => array(
+        //_('Disable iMIP for external organizers')
+            'label'                 => 'Disable iMIP for external organizers',
+        //_('Disable iMIP for external organizers')
+            'description'           => 'Disable iMIP for external organizers',
+            'type'                  => Tinebase_Config_Abstract::TYPE_BOOL,
+            'clientRegistryInclude' => false,
+            'setByAdminModule'      => false,
+            'setBySetupModule'      => true,
+            'default'               => false,
+        ),
     );
     
     /**
index fd39a26..c6c2449 100644 (file)
             $sendOnOwnActions = Tinebase_Core::getPreference('Calendar')->getValueForUser(Calendar_Preference::SEND_NOTIFICATION_OF_OWN_ACTIONS, $prefUserId);
             
             // external (non account) notification
-            if (!$attendeeAccountId) {
+            if (! $attendeeAccountId) {
                 // external organizer needs status updates
                 $sendLevel = is_object($organizer) && $_attender->getEmail() == $organizer->getPreferedEmailAddress() ? 40 : 30;
                 $sendOnOwnActions = false;
             $method = NULL;
             $messageSubject = $this->_getSubject($_event, $_notificationLevel, $_action, $_updates, $timezone, $locale, $translate, $method);
             
+            // we don't send iMIP parts to external attendee if config is active
+            if (Calendar_Config::getInstance()->get(Calendar_Config::DISABLE_EXTERNAL_IMIP) && ! $attendeeAccountId) {
+                if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__
+                    . " External iMIP is disabled.");
+                $method = NULL;
+            }
+            
             $view = new Zend_View();
             $view->setScriptPath(dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'views');
             
index 9d2ed74..6b6b152 100644 (file)
@@ -57,12 +57,13 @@ class Calendar_Frontend_iMIP
     /**
      * prepares iMIP component for client
      *  
-     * @param  Calendar_Model_iMIP $_iMIP
+     * @param Calendar_Model_iMIP $_iMIP
+     * @param boolean $_throwException
      * @return Calendar_Model_iMIP
      */
-    public function prepareComponent($_iMIP)
+    public function prepareComponent($_iMIP, $_throwException = false)
     {
-        $this->_checkPreconditions($_iMIP);
+        $this->_checkPreconditions($_iMIP, $_throwException);
         
         Calendar_Convert_Event_Json::resolveRelatedData($_iMIP->event);
         Tinebase_Model_Container::resolveContainerOfRecord($_iMIP->event);
@@ -182,6 +183,9 @@ class Calendar_Frontend_iMIP
      */
     protected function _checkRequestPreconditions($_iMIP)
     {
+        if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__
+            . ' Checking REQUEST preconditions of iMIP ...');
+        
         $result  = $this->_assertOwnAttender($_iMIP, TRUE, FALSE);
         $result &= $this->_assertOrganizer($_iMIP, TRUE, TRUE);
         
@@ -259,7 +263,7 @@ class Calendar_Frontend_iMIP
     * 
     * @todo this needs to be splitted into assertExternalOrganizer / assertInternalOrganizer
     */
-    protected function _assertOrganizer($_iMIP, $_assertExistence, $_assertOriginator, $_assertAccount = FALSE)
+    protected function _assertOrganizer($_iMIP, $_assertExistence, $_assertOriginator, $_assertAccount = false)
     {
         $result = TRUE;
         
@@ -281,12 +285,15 @@ class Calendar_Frontend_iMIP
         }
         */
         
-        /*
-        if ($_assertAccount && (! $organizer || ! $organizer->account_id)) {
+        if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__
+            . ' Organizer: ' . ($organizer ? print_r($organizer->toArray(), true) : 'not found'));
+        
+        // config setting overwrites method param
+        $assertAccount = Calendar_Config::getInstance()->get(Calendar_Config::DISABLE_EXTERNAL_IMIP, $_assertAccount);
+        if ($assertAccount && (! $organizer || ! $organizer->account_id)) {
             $_iMIP->addFailedPrecondition(Calendar_Model_iMIP::PRECONDITION_ORGANIZER, "processing {$_iMIP->method} without organizer user account is not possible");
             $result = FALSE;
         }
-        */
         
         return $result;
     }
@@ -398,7 +405,8 @@ class Calendar_Frontend_iMIP
             $result = FALSE;
         }
         
-        if (! $this->_assertOrganizer($_iMIP, TRUE, FALSE, TRUE)) {
+        // TODO fix organizer account asserting
+        if (! $this->_assertOrganizer($_iMIP, TRUE, FALSE/*, $_assertAccount = TRUE */)) {
             $result = FALSE;
         }
         
index 93f2c30..5e87bc0 100644 (file)
@@ -341,7 +341,7 @@ class Felamimail_Frontend_Json extends Tinebase_Frontend_Json_Abstract
                     if ($preparedPart->preparedData instanceof Calendar_Model_iMIP) {
                         try {
                             $iMIPFrontend = new Calendar_Frontend_iMIP();
-                            $iMIPFrontend->prepareComponent($preparedPart->preparedData);
+                            $iMIPFrontend->prepareComponent($preparedPart->preparedData, /* $_throwException = */ true);
                         } catch (Exception $e) {
                             Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . ' Could not prepare calendar iMIP component: ' . $e->getMessage());
                             if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' ' . $e->getTraceAsString());