0010822: contact relation is not saved correctly
authorPhilipp Schüle <p.schuele@metaways.de>
Tue, 10 Feb 2015 13:51:04 +0000 (14:51 +0100)
committerPhilipp Schüle <p.schuele@metaways.de>
Tue, 10 Feb 2015 16:37:37 +0000 (17:37 +0100)
* RESPONSIBLE relation type needs to be upper case
- fixed in js client default data for new leads
- adds update script for current relations types
* fixes lead notification mails for new leads
* adds a helper function for setting container grants to TestCase
* some more minor improvements

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

Change-Id: Ic46b21518db985a8d86a0042fe4b6b44dd047537
Reviewed-on: http://gerrit.tine20.com/customers/1637
Tested-by: Jenkins CI (http://ci.tine20.com/)
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
13 files changed:
tests/tine20/Calendar/Controller/EventGrantsTests.php
tests/tine20/Crm/JsonTest.php
tests/tine20/Crm/NotificationsTests.php
tests/tine20/TestCase.php
tine20/Crm/Controller/Lead.php
tine20/Crm/Frontend/Json.php
tine20/Crm/Setup/Update/Release8.php
tine20/Crm/Setup/setup.xml
tine20/Crm/js/Contact.js
tine20/Crm/js/LeadEditDialog.js
tine20/Crm/js/Model.js
tine20/Tinebase/Controller/Record/Abstract.php
tine20/Tinebase/Relation/Backend/Sql.php

index 0bb4061..7bc3bfa 100644 (file)
@@ -341,7 +341,7 @@ class Calendar_Controller_EventGrantsTests extends Calendar_TestCase
      */
     public function testFreeBusyViaAttendee()
     {
-        // whipe grants from jmcblack
+        // wipe grants from jmcblack
         Tinebase_Container::getInstance()->setGrants($this->_getPersonasDefaultCals('jmcblack'), new Tinebase_Record_RecordSet('Tinebase_Model_Grants', array(array(
             'account_id'    => $this->_getPersona('jmcblack')->getId(),
             'account_type'  => 'user',
index 5de66b2..6bbb3a1 100644 (file)
@@ -99,7 +99,6 @@ class Crm_JsonTest extends Crm_AbstractTest
             Tinebase_Container::getInstance()->getDefaultContainer('Crm')->getId(),
             $registry['defaults']['container_id']['id']
         );
-        //print_r($registry);
     }
     
     /**
index 679c767..306e562 100644 (file)
@@ -42,7 +42,7 @@ class Crm_NotificationsTests extends Crm_AbstractTest
     }
     
     /**
-     * testInvitation
+     * testNotification
      */
     public function testNotification()
     {
@@ -64,5 +64,34 @@ class Crm_NotificationsTests extends Crm_AbstractTest
         $this->assertEquals(1, count($messages));
         $bodyText = $messages[0]->getBodyText()->getContent();
         $this->assertContains(' Lars Kneschke (Metaways', $bodyText);
-    }    
+    }
+
+    /**
+     * testNotificationToResponsible
+     */
+    public function testNotificationToResponsible()
+    {
+        self::flushMailer();
+        
+        $lead = $this->_getLead();
+        
+        // give sclever access to lead container
+        $this->_setPersonaGrantsForTestContainer($lead['container_id'], 'sclever');
+        
+        $lead->relations = array(new Tinebase_Model_Relation(array(
+            'type'                   => 'RESPONSIBLE',
+            'related_record'         => Addressbook_Controller_Contact::getInstance()->getContactByUserId(Tinebase_Core::getUser()->getId()),
+            'own_model'              => 'Crm_Model_Lead',
+            'own_backend'            => 'Sql',
+            'own_degree'             => Tinebase_Model_Relation::DEGREE_SIBLING,
+            'related_model'          => 'Addressbook_Model_Contact',
+            'related_backend'        => Tasks_Backend_Factory::SQL,
+        ), TRUE));
+        $savedLead = $this->_leadController->create($lead);
+        
+        $messages = self::getMessages();
+        $this->assertEquals(1, count($messages));
+        $bodyText = $messages[0]->getBodyText()->getContent();
+        $this->assertContains('**PHPUnit **', $bodyText);
+    }
 }
index 77060b5..0b2bbb0 100644 (file)
@@ -358,4 +358,34 @@ abstract class TestCase extends PHPUnit_Framework_TestCase
         $tempFile = $tempFileBackend->createTempFile(dirname(__FILE__) . '/Filemanager/files/test.txt');
         return $tempFile;
     }
+    
+    /**
+     * set grants for a persona
+     * 
+     * @param integer $containerId
+     * @param string $persona
+     * @param string $adminGrant
+     */
+    protected function _setPersonaGrantsForTestContainer($containerId, $persona, $adminGrant = false)
+    {
+        $grants = new Tinebase_Record_RecordSet('Tinebase_Model_Grants', array(array(
+            'account_id'    => $this->_personas[$persona]->getId(),
+            'account_type'  => 'user',
+            Tinebase_Model_Grants::GRANT_READ     => true,
+            Tinebase_Model_Grants::GRANT_ADD      => true,
+            Tinebase_Model_Grants::GRANT_EDIT     => true,
+            Tinebase_Model_Grants::GRANT_DELETE   => true,
+            Tinebase_Model_Grants::GRANT_ADMIN    => $adminGrant,
+        ), array(
+            'account_id'    => Tinebase_Core::getUser()->getId(),
+            'account_type'  => 'user',
+            Tinebase_Model_Grants::GRANT_READ     => true,
+            Tinebase_Model_Grants::GRANT_ADD      => true,
+            Tinebase_Model_Grants::GRANT_EDIT     => true,
+            Tinebase_Model_Grants::GRANT_DELETE   => true,
+            Tinebase_Model_Grants::GRANT_ADMIN    => true,
+        )));
+        
+        Tinebase_Container::getInstance()->setGrants($containerId, $grants, TRUE);
+    }
 }
index 2c58065..c0ffeab 100644 (file)
@@ -8,7 +8,7 @@
  * @subpackage  Controller
  * @license     http://www.gnu.org/licenses/agpl.html AGPL Version 3
  * @author      Philipp Schüle <p.schuele@metaways.de>
- * @copyright   Copyright (c) 2007-2011 Metaways Infosystems GmbH (http://www.metaways.de)
+ * @copyright   Copyright (c) 2007-2015 Metaways Infosystems GmbH (http://www.metaways.de)
  *
  */
 
@@ -250,9 +250,10 @@ class Crm_Controller_Lead extends Tinebase_Controller_Record_Abstract
     {
         $recipients = array();
         
-        $relations = Tinebase_Relations::getInstance()->getRelations('Crm_Model_Lead', 'Sql', $_lead->getId(), true);
-        
-        foreach ($relations as $relation) {
+        if (! $_lead->relations instanceof Tinebase_Record_RecordSet) {
+            $_lead->relations = Tinebase_Relations::getInstance()->getRelations('Crm_Model_Lead', 'Sql', $_lead->getId(), true);
+        }
+        foreach ($_lead->relations as $relation) {
             if ($relation->related_model == 'Addressbook_Model_Contact' && $relation->type == 'RESPONSIBLE') {
                 $recipients[] = $relation->related_record;
             }
index df31532..25bea75 100644 (file)
@@ -5,7 +5,7 @@
  * @subpackage  Frontend
  * @license     http://www.gnu.org/licenses/agpl.html AGPL Version 3
  * @author      Philipp Schüle <p.schuele@metaways.de>
- * @copyright   Copyright (c) 2007-2012 Metaways Infosystems GmbH (http://www.metaways.de)
+ * @copyright   Copyright (c) 2007-2015 Metaways Infosystems GmbH (http://www.metaways.de)
  *
  */
 
@@ -24,7 +24,7 @@ class Crm_Frontend_Json extends Tinebase_Frontend_Json_Abstract
      * @var Crm_Controller_Lead
      */
     protected $_controller = NULL;
-        
+    
     protected $_relatableModels = array('Crm_Model_Lead');
     
     /**
@@ -56,7 +56,7 @@ class Crm_Frontend_Json extends Tinebase_Frontend_Json_Abstract
         $result['totalleadtypes'] = $result['totalcount']['leadtypes'];
         
         $result['totalcount'] = $result['totalcount']['totalcount'];
-                
+        
         return $result;
     }
     
index 431e055..4ba8a04 100644 (file)
@@ -5,7 +5,7 @@
  * @package     Crm
  * @subpackage  Setup
  * @license     http://www.gnu.org/licenses/agpl.html AGPL3
- * @copyright   Copyright (c) 2014 Metaways Infosystems GmbH (http://www.metaways.de)
+ * @copyright   Copyright (c) 2014-2015 Metaways Infosystems GmbH (http://www.metaways.de)
  * @author      Alexander Stintzing <a.stintzing@metaways.de>
  */
 class Crm_Setup_Update_Release8 extends Setup_Update_Abstract
@@ -28,4 +28,19 @@ class Crm_Setup_Update_Release8 extends Setup_Update_Abstract
         
         $this->setApplicationVersion('Crm', '8.1');
     }
+
+    /**
+     * update to 8.2
+     * 
+     * convert relation type 'responsible' to uppercase
+     * 
+     * @see 0010822: contact relation is not saved correctly when new lead is created
+     */
+    public function update_1()
+    {
+        $where = array('type = ?' => 'responsible');
+        $this->_db->update(SQL_TABLE_PREFIX . 'relations', array('type' => 'RESPONSIBLE'), $where);
+        
+        $this->setApplicationVersion('Crm', '8.2');
+    }
 }
index 08a95a0..3c5342b 100644 (file)
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="utf-8"?>
 <application>
     <name>Crm</name>
-    <version>8.1</version>
+    <version>8.2</version>
     <order>20</order>
     <depends>
         <application>Admin</application>
index 2057108..53a2c93 100644 (file)
@@ -52,7 +52,7 @@ Tine.Crm.Contact.Combo = Ext.extend(Tine.Addressbook.SearchCombo, {
             
         this.collapse();
         this.clearValue();
-    }    
+    }
 });
 
 /**
index cfc3cfb..55e60ee 100644 (file)
@@ -186,7 +186,7 @@ Tine.Crm.LeadEditDialog = Ext.extend(Tine.widgets.dialog.EditDialog, {
             delete relations[i]['related_record']['relation'];
             newLinkObject.relation = relations[i];
             newLinkObject.relation_type = relations[i]['type'].toLowerCase();
-    
+            
             if ((newLinkObject.relation_type === 'responsible' 
               || newLinkObject.relation_type === 'customer' 
               || newLinkObject.relation_type === 'partner')) {
@@ -200,7 +200,7 @@ Tine.Crm.LeadEditDialog = Ext.extend(Tine.widgets.dialog.EditDialog, {
                 products.push(newLinkObject);
             }
         }
-
+        
         return {
             contacts: contacts,
             tasks: tasks,
index ec147f0..c203266 100644 (file)
@@ -85,7 +85,7 @@ Tine.Crm.Model.Lead.getDefaultData = function() {
         probability: 0,
         turnover: 0,
         relations: [{
-            type: 'responsible',
+            type: 'RESPONSIBLE',
             related_record: Tine.Tinebase.registry.get('userContact')
         }]
     };
index 22113f1..d64b87d 100644 (file)
@@ -591,23 +591,22 @@ abstract class Tinebase_Controller_Record_Abstract
             $this->_inspectAfterCreate($createdRecord, $_record);
             $this->_setRelatedData($createdRecord, $_record, TRUE);
             $this->_setNotes($createdRecord, $_record);
-
+            
             if ($this->sendNotifications()) {
                 $this->doSendNotifications($createdRecord, Tinebase_Core::getUser(), 'created');
             }
             
             $this->_increaseContainerContentSequence($createdRecord, Tinebase_Model_ContainerContent::ACTION_CREATE);
-
+            
             Tinebase_TransactionManager::getInstance()->commitTransaction($transactionId);
-
         } catch (Exception $e) {
             $this->_handleRecordCreateOrUpdateException($e);
         }
-
+        
         if ($this->_clearCustomFieldsCache) {
             Tinebase_Core::getCache()->clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG, array('customfields'));
         }
-
+        
         return $this->get($createdRecord);
     }
     
index 1b55640..592010e 100644 (file)
@@ -219,7 +219,7 @@ class Tinebase_Relation_Backend_Sql extends Tinebase_Backend_Sql_Abstract
         foreach ($this->_dbTable->fetchAll($where) as $relation) {
             $relations->addRecord($this->_rawDataToRecord($relation->toArray(), true));
         }
-           return $relations;
+        return $relations;
     }
     
     /**