コード例 #1
0
 /**
  * @return string content
  * @param EmailMessage object $emailMessage
  * @param User object $user
  */
 public static function renderEmailMessageToMatchContent(EmailMessage $emailMessage, $user)
 {
     $userCanAccessContacts = RightsUtil::canUserAccessModule('ContactsModule', $user);
     $userCanAccessLeads = RightsUtil::canUserAccessModule('LeadsModule', $user);
     $userCanCreateContact = RightsUtil::doesUserHaveAllowByRightName('ContactsModule', ContactsModule::getCreateRight(), $user);
     $userCanCreateLead = RightsUtil::doesUserHaveAllowByRightName('LeadsModule', LeadsModule::getCreateRight(), $user);
     if ($userCanAccessLeads && $userCanAccessContacts) {
         $selectForm = new AnyContactSelectForm();
     } elseif (!$userCanAccessLeads && $userCanAccessContacts) {
         $selectForm = new ContactSelectForm();
     } else {
         $selectForm = new LeadSelectForm();
     }
     if ($userCanCreateContact && $userCanCreateLead) {
         $gridSize = 3;
     } elseif ($userCanCreateContact || $userCanCreateLead) {
         $gridSize = 2;
     } else {
         $gridSize = 1;
     }
     $contact = new Contact();
     self::resolveEmailAddressAndNameToContact($emailMessage, $contact);
     $view = new ArchivedEmailMatchingView('default', 'emailMessages', $emailMessage, $contact, $selectForm, $userCanAccessLeads, $userCanAccessContacts, $userCanCreateContact, $userCanCreateLead, $gridSize);
     return $view->render();
 }
コード例 #2
0
 public function __construct($controllerId, $moduleId)
 {
     parent::__construct(2, 1);
     $moduleDisplayName = LeadsModule::getModuleLabelByTypeAndLanguage('Plural');
     $this->setView(new ActionBarForDesignerModuleView($controllerId, $moduleId, Yii::app()->getModule('leads'), 'DesignerFieldsLink'), 0, 0);
     $this->setView(new AttributesRedirectToContactsView($controllerId, $moduleId), 1, 0);
 }
コード例 #3
0
ファイル: LeadElement.php プロジェクト: youprofit/Zurmo
 protected function renderLabel()
 {
     $label = LeadsModule::getModuleLabelByTypeAndLanguage('Singular');
     if ($this->form === null) {
         return $this->getFormattedAttributeLabel();
     }
     $id = $this->getIdForHiddenField();
     return $this->form->labelEx($this->model, $this->attribute, array('for' => $id, 'label' => $label));
 }
コード例 #4
0
 /**
  * Given a post data array, map the lead to account attributes
  * but only if the post data does not contain a set attribute.
  * This method is used when a posted form has an empty value on
  * an input field.  We do not want to set the mapped field since
  * the use of setAttributes will pick up the correct information
  * from the posted data.  This will allow form validation to work
  * properly in the case where a mapped field is cleared to blank
  * in the input field and submitted. Such an event should trigger
  * a form validation error.
  * @see LeadsUtil::attributesToAccount
  * @param $contact Contact model
  * @param $account Account model
  * @param $postData array of posted form data
  * @return Account, with mapped attributes from Contact
  */
 public static function attributesToAccountWithNoPostData(Contact $contact, Account $account, array $postData)
 {
     assert('is_array($postData)');
     assert('!empty($contact->id)');
     $metadata = LeadsModule::getMetadata();
     $map = $metadata['global']['convertToAccountAttributesMapping'];
     foreach ($map as $contactAttributeName => $accountAttributeName) {
         if (!isset($postData[$accountAttributeName])) {
             $account->{$accountAttributeName} = $contact->{$contactAttributeName};
         }
     }
     return $account;
 }
コード例 #5
0
 protected function getDefaultRoute()
 {
     if (!empty($this->modelId)) {
         $convertToAccountSetting = LeadsModule::getConvertToAccountSetting();
         $userCanAccessAccounts = RightsUtil::canUserAccessModule('AccountsModule', Yii::app()->user->userModel);
         if ($convertToAccountSetting == LeadsModule::CONVERT_NO_ACCOUNT || $convertToAccountSetting == LeadsModule::CONVERT_ACCOUNT_NOT_REQUIRED && !$userCanAccessAccounts) {
             return Yii::app()->createUrl($this->moduleId . '/' . $this->controllerId . '/details/', array('id' => $this->modelId));
         } else {
             return Yii::app()->createUrl($this->moduleId . '/' . $this->controllerId . '/convert/', array('id' => $this->modelId));
         }
     } else {
         throw new NotSupportedException();
     }
 }
コード例 #6
0
 /**
  * Get the display label used to describe the import rules.
  * @return string
  */
 public static function getDisplayLabel()
 {
     return LeadsModule::getModuleLabelByTypeAndLanguage('Plural');
 }
コード例 #7
0
 public function actionMassSubscribeProgress()
 {
     $this->triggerMassAction('Contact', static::getSearchFormClassName(), 'LeadsPageView', LeadsModule::getModuleLabelByTypeAndLanguage('Plural'), 'LeadsSearchView', 'LeadsStateMetadataAdapter', false);
 }
コード例 #8
0
 /**
  * @depends testListLead
  */
 public function testUnprivilegedUserViewUpdateDeleteLead()
 {
     Yii::app()->user->userModel = User::getByUsername('super');
     $notAllowedUser = UserTestHelper::createBasicUser('Steven');
     $notAllowedUser->setRight('UsersModule', UsersModule::RIGHT_LOGIN_VIA_WEB_API);
     $saved = $notAllowedUser->save();
     $authenticationData = $this->login('steven', 'steven');
     $headers = array('Accept: application/json', 'ZURMO_SESSION_ID: ' . $authenticationData['sessionId'], 'ZURMO_TOKEN: ' . $authenticationData['token'], 'ZURMO_API_REQUEST_TYPE: REST');
     $everyoneGroup = Group::getByName(Group::EVERYONE_GROUP_NAME);
     $this->assertTrue($everyoneGroup->save());
     $leads = Contact::getByName('Michael Smith');
     $this->assertEquals(1, count($leads));
     $data['department'] = "Support";
     // Test with unprivileged user to view, edit and delete account.
     $authenticationData = $this->login('steven', 'steven');
     $headers = array('Accept: application/json', 'ZURMO_SESSION_ID: ' . $authenticationData['sessionId'], 'ZURMO_TOKEN: ' . $authenticationData['token'], 'ZURMO_API_REQUEST_TYPE: REST');
     $response = ApiRestTestHelper::createApiCall($this->serverUrl . '/test.php/leads/contact/api/read/' . $leads[0]->id, 'GET', $headers);
     $response = json_decode($response, true);
     $this->assertEquals(ApiResponse::STATUS_FAILURE, $response['status']);
     $this->assertEquals('You do not have rights to perform this action.', $response['message']);
     $response = ApiRestTestHelper::createApiCall($this->serverUrl . '/test.php/leads/contact/api/update/' . $leads[0]->id, 'PUT', $headers, array('data' => $data));
     $response = json_decode($response, true);
     $this->assertEquals(ApiResponse::STATUS_FAILURE, $response['status']);
     $this->assertEquals('You do not have rights to perform this action.', $response['message']);
     $response = ApiRestTestHelper::createApiCall($this->serverUrl . '/test.php/leads/contact/api/delete/' . $leads[0]->id, 'DELETE', $headers);
     $response = json_decode($response, true);
     $this->assertEquals(ApiResponse::STATUS_FAILURE, $response['status']);
     $this->assertEquals('You do not have rights to perform this action.', $response['message']);
     //now check if user have rights, but no permissions.
     $notAllowedUser->setRight('LeadsModule', LeadsModule::getAccessRight());
     $notAllowedUser->setRight('LeadsModule', LeadsModule::getCreateRight());
     $notAllowedUser->setRight('LeadsModule', LeadsModule::getDeleteRight());
     $saved = $notAllowedUser->save();
     $this->assertTrue($saved);
     $response = ApiRestTestHelper::createApiCall($this->serverUrl . '/test.php/leads/contact/api/read/' . $leads[0]->id, 'GET', $headers);
     $response = json_decode($response, true);
     $this->assertEquals(ApiResponse::STATUS_FAILURE, $response['status']);
     $this->assertEquals('You do not have permissions for this action.', $response['message']);
     $response = ApiRestTestHelper::createApiCall($this->serverUrl . '/test.php/leads/contact/api/update/' . $leads[0]->id, 'PUT', $headers, array('data' => $data));
     $response = json_decode($response, true);
     $this->assertEquals(ApiResponse::STATUS_FAILURE, $response['status']);
     $this->assertEquals('You do not have permissions for this action.', $response['message']);
     $response = ApiRestTestHelper::createApiCall($this->serverUrl . '/test.php/leads/contact/api/delete/' . $leads[0]->id, 'DELETE', $headers);
     $response = json_decode($response, true);
     $this->assertEquals(ApiResponse::STATUS_FAILURE, $response['status']);
     $this->assertEquals('You do not have permissions for this action.', $response['message']);
     // Update unprivileged user permissions
     $authenticationData = $this->login();
     $headers = array('Accept: application/json', 'ZURMO_SESSION_ID: ' . $authenticationData['sessionId'], 'ZURMO_TOKEN: ' . $authenticationData['token'], 'ZURMO_API_REQUEST_TYPE: REST');
     unset($data);
     $data['explicitReadWriteModelPermissions'] = array('type' => ExplicitReadWriteModelPermissionsUtil::MIXED_TYPE_EVERYONE_GROUP);
     $response = ApiRestTestHelper::createApiCall($this->serverUrl . '/test.php/leads/contact/api/update/' . $leads[0]->id, 'PUT', $headers, array('data' => $data));
     $response = json_decode($response, true);
     $this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']);
     $authenticationData = $this->login('steven', 'steven');
     $headers = array('Accept: application/json', 'ZURMO_SESSION_ID: ' . $authenticationData['sessionId'], 'ZURMO_TOKEN: ' . $authenticationData['token'], 'ZURMO_API_REQUEST_TYPE: REST');
     $response = ApiRestTestHelper::createApiCall($this->serverUrl . '/test.php/leads/contact/api/read/' . $leads[0]->id, 'GET', $headers);
     $response = json_decode($response, true);
     $this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']);
     unset($data);
     $data['department'] = "Support";
     $response = ApiRestTestHelper::createApiCall($this->serverUrl . '/test.php/leads/contact/api/update/' . $leads[0]->id, 'PUT', $headers, array('data' => $data));
     $response = json_decode($response, true);
     $this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']);
     $this->assertEquals('Support', $response['data']['department']);
     $response = ApiRestTestHelper::createApiCall($this->serverUrl . '/test.php/leads/contact/api/delete/' . $leads[0]->id, 'DELETE', $headers);
     $response = json_decode($response, true);
     $this->assertEquals(ApiResponse::STATUS_FAILURE, $response['status']);
     $this->assertEquals('You do not have permissions for this action.', $response['message']);
     // Test with privileged user
     $authenticationData = $this->login();
     $headers = array('Accept: application/json', 'ZURMO_SESSION_ID: ' . $authenticationData['sessionId'], 'ZURMO_TOKEN: ' . $authenticationData['token'], 'ZURMO_API_REQUEST_TYPE: REST');
     //Test Delete
     $response = ApiRestTestHelper::createApiCall($this->serverUrl . '/test.php/leads/contact/api/delete/' . $leads[0]->id, 'DELETE', $headers);
     $response = json_decode($response, true);
     $this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']);
     $response = ApiRestTestHelper::createApiCall($this->serverUrl . '/test.php/leads/contact/api/read/' . $leads[0]->id, 'GET', $headers);
     $response = json_decode($response, true);
     $this->assertEquals(ApiResponse::STATUS_FAILURE, $response['status']);
 }
コード例 #9
0
 public function actionConvert($id)
 {
     assert('!empty($id)');
     $contact = Contact::getById(intval($id));
     if (!LeadsUtil::isStateALead($contact->state)) {
         $urlParams = array('/contacts/' . $this->getId() . '/details', 'id' => $contact->id);
         $this->redirect($urlParams);
     }
     $convertToAccountSetting = LeadsModule::getConvertToAccountSetting();
     $selectAccountForm = new AccountSelectForm();
     $account = new Account();
     ControllerSecurityUtil::resolveAccessCanCurrentUserWriteModel($contact);
     $userCanAccessContacts = RightsUtil::canUserAccessModule('ContactsModule', Yii::app()->user->userModel);
     $userCanAccessAccounts = RightsUtil::canUserAccessModule('AccountsModule', Yii::app()->user->userModel);
     $userCanCreateAccount = RightsUtil::doesUserHaveAllowByRightName('AccountsModule', AccountsModule::RIGHT_CREATE_ACCOUNTS, Yii::app()->user->userModel);
     LeadsControllerSecurityUtil::resolveCanUserProperlyConvertLead($userCanAccessContacts, $userCanAccessAccounts, $convertToAccountSetting);
     if (isset($_POST['AccountSelectForm'])) {
         $selectAccountForm->setAttributes($_POST['AccountSelectForm']);
         if ($selectAccountForm->validate()) {
             $account = Account::getById(intval($selectAccountForm->accountId));
             $this->actionSaveConvertedContact($contact, $account);
         }
     } elseif (isset($_POST['Account'])) {
         $account = LeadsUtil::attributesToAccountWithNoPostData($contact, $account, $_POST['Account']);
         $account->setAttributes($_POST['Account']);
         if ($account->save()) {
             $explicitReadWriteModelPermissions = ExplicitReadWriteModelPermissionsUtil::makeBySecurableItem($contact);
             ExplicitReadWriteModelPermissionsUtil::resolveExplicitReadWriteModelPermissions($account, $explicitReadWriteModelPermissions);
             if (!$account->save()) {
                 throw new NotSupportedException();
             }
             $this->actionSaveConvertedContact($contact, $account);
         }
     } elseif (isset($_POST['AccountSkip']) || $convertToAccountSetting == LeadsModule::CONVERT_NO_ACCOUNT || $convertToAccountSetting == LeadsModule::CONVERT_ACCOUNT_NOT_REQUIRED && !$userCanAccessAccounts) {
         $this->actionSaveConvertedContact($contact);
     } else {
         $account = LeadsUtil::attributesToAccount($contact, $account);
     }
     $convertView = new LeadConvertView($this->getId(), $this->getModule()->getId(), $contact->id, strval($contact), $selectAccountForm, $account, $convertToAccountSetting, $userCanCreateAccount);
     $view = new LeadsPageView(ZurmoDefaultViewUtil::makeStandardViewForCurrentUser($this, $convertView));
     echo $view->render();
 }
 public function testSuperUserLeadDefaultControllerActions()
 {
     $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     //Default Controller actions requiring some sort of parameter via POST or GET
     //Load Lead Modules Menu.
     $this->setGetArray(array('moduleClassName' => 'LeadsModule'));
     $this->runControllerWithNoExceptionsAndGetContent('designer/default/modulesMenu');
     //Load AttributesList for Leads module.
     $this->setGetArray(array('moduleClassName' => 'LeadsModule'));
     $this->runControllerWithNoExceptionsAndGetContent('designer/default/attributesList');
     //Load ModuleLayoutsList for Lead module.
     $this->setGetArray(array('moduleClassName' => 'LeadsModule'));
     $this->runControllerWithNoExceptionsAndGetContent('designer/default/moduleLayoutsList');
     //Load ModuleEdit view for each applicable module.
     $this->setGetArray(array('moduleClassName' => 'LeadsModule'));
     $this->runControllerWithNoExceptionsAndGetContent('designer/default/moduleEdit');
     //Now validate save with failed validation.
     $this->setGetArray(array('moduleClassName' => 'LeadsModule'));
     $this->setPostArray(array('ajax' => 'edit-form', 'LeadsModuleForm' => $this->createModuleEditBadValidationPostData()));
     $content = $this->runControllerWithExitExceptionAndGetContent('designer/default/moduleEdit');
     $this->assertTrue(strlen($content) > 50);
     //approximate, but should definetely be larger than 50.
     //Now validate save with successful validation.
     $this->setGetArray(array('moduleClassName' => 'LeadsModule'));
     $this->setPostArray(array('ajax' => 'edit-form', 'LeadsModuleForm' => $this->createModuleEditGoodValidationPostData('lea new name')));
     $content = $this->runControllerWithExitExceptionAndGetContent('designer/default/moduleEdit');
     $this->assertEquals('[]', $content);
     //Now save successfully.
     $this->setGetArray(array('moduleClassName' => 'LeadsModule'));
     $this->setPostArray(array('save' => 'Save', 'LeadsModuleForm' => $this->createModuleEditGoodValidationPostData('lea new name')));
     $this->runControllerWithRedirectExceptionAndGetContent('designer/default/moduleEdit');
     //Now confirm everything did in fact save correctly.
     $this->assertEquals('Lea New Name', LeadsModule::getModuleLabelByTypeAndLanguage('Singular'));
     $this->assertEquals('Lea New Names', LeadsModule::getModuleLabelByTypeAndLanguage('Plural'));
     $this->assertEquals('lea new name', LeadsModule::getModuleLabelByTypeAndLanguage('SingularLowerCase'));
     $this->assertEquals('lea new names', LeadsModule::getModuleLabelByTypeAndLanguage('PluralLowerCase'));
     //Load LayoutEdit for each applicable module and applicable layout
     $this->resetPostArray();
     $this->setGetArray(array('moduleClassName' => 'LeadsModule', 'viewClassName' => 'LeadEditAndDetailsView'));
     $this->runControllerWithNoExceptionsAndGetContent('designer/default/LayoutEdit');
     $this->setGetArray(array('moduleClassName' => 'LeadsModule', 'viewClassName' => 'LeadsListView'));
     $this->runControllerWithNoExceptionsAndGetContent('designer/default/LayoutEdit');
     $this->setGetArray(array('moduleClassName' => 'LeadsModule', 'viewClassName' => 'LeadsMassEditView'));
     $this->runControllerWithNoExceptionsAndGetContent('designer/default/LayoutEdit');
     $this->setGetArray(array('moduleClassName' => 'LeadsModule', 'viewClassName' => 'LeadsModalListView'));
     $this->runControllerWithNoExceptionsAndGetContent('designer/default/LayoutEdit');
     $this->setGetArray(array('moduleClassName' => 'LeadsModule', 'viewClassName' => 'LeadsModalSearchView'));
     $this->runControllerWithNoExceptionsAndGetContent('designer/default/LayoutEdit');
     $this->setGetArray(array('moduleClassName' => 'LeadsModule', 'viewClassName' => 'LeadsSearchView'));
     $this->runControllerWithNoExceptionsAndGetContent('designer/default/LayoutEdit');
 }
コード例 #11
0
 /**
  * Override since the ContactsModule controls module permissions for both leads and contacts.
  */
 public static function getSecurableModuleDisplayName()
 {
     $label = static::getModuleLabelByTypeAndLanguage('Plural') . ' & ' . LeadsModule::getModuleLabelByTypeAndLanguage('Plural');
     return $label;
 }
コード例 #12
0
 public static function getConvertToOpportunitySetting()
 {
     $metadata = LeadsModule::getMetadata();
     if (isset($metadata['global']['convertToOpportunitySetting'])) {
         return (int) $metadata['global']['convertToOpportunitySetting'];
     } else {
         return (int) LeadsModule::CONVERT_OPPORTUNITY_NOT_REQUIRED;
     }
 }
コード例 #13
0
 /**
  * @depends testUserCanAccessAccountsButCannotCreateAccountShowConvertAction
  */
 public function testLeadConversionMisconfigurationScenarios()
 {
     $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     $bubby = UserTestHelper::createBasicUser('bubby');
     $lead = LeadTestHelper::createLeadbyNameForOwner('BelinaLead1', $bubby);
     $bubby->setRight('LeadsModule', LeadsModule::RIGHT_CONVERT_LEADS, Right::ALLOW);
     $bubby->setRight('LeadsModule', LeadsModule::RIGHT_ACCESS_LEADS, Right::ALLOW);
     $this->assertTrue($bubby->save());
     //Scenario #1 - User does not have access to contacts
     $this->assertEquals(Right::DENY, $bubby->getEffectiveRight('ContactsModule', ContactsModule::RIGHT_ACCESS_CONTACTS));
     $bubby = $this->logoutCurrentUserLoginNewUserAndGetByUsername('bubby');
     //View will not show up properly.
     $this->setGetArray(array('id' => $lead->id));
     $content = $this->runControllerWithExitExceptionAndGetContent('leads/default/convert');
     $this->assertContains('Conversion requires access to the contacts module which you do not have. Please contact your administrator.', $content);
     //Scenario #2 - User cannot access accounts and an account is required for conversion
     $bubby->setRight('ContactsModule', ContactsModule::RIGHT_CREATE_CONTACTS, Right::ALLOW);
     $bubby->setRight('ContactsModule', ContactsModule::RIGHT_ACCESS_CONTACTS, Right::ALLOW);
     $this->assertTrue($bubby->save());
     $metadata = LeadsModule::getMetadata();
     $metadata['global']['convertToAccountSetting'] = LeadsModule::CONVERT_ACCOUNT_REQUIRED;
     LeadsModule::setMetadata($metadata);
     //At this point because the account is required, the view will not come up properly.
     $this->setGetArray(array('id' => $lead->id));
     $content = $this->runControllerWithExitExceptionAndGetContent('leads/default/convert');
     $this->assertContains('Conversion is set to require an account.  Currently you do not have access to the accounts module.', $content);
     //Scenario #3 - User cannot access opportunities and an opportunity is required for conversion
     $metadata = LeadsModule::getMetadata();
     $metadata['global']['convertToAccountSetting'] = LeadsModule::CONVERT_ACCOUNT_NOT_REQUIRED;
     $metadata['global']['convertToOpportunitySetting'] = LeadsModule::CONVERT_OPPORTUNITY_REQUIRED;
     LeadsModule::setMetadata($metadata);
     //At this point because the opportunity is required, the view will not come up properly.
     $this->setGetArray(array('id' => $lead->id));
     $this->runControllerWithRedirectExceptionAndGetContent('leads/default/convert');
     $this->setGetArray(array('id' => $lead->id));
     $content = $this->runControllerWithExitExceptionAndGetContent('leads/default/convertFinal');
     $this->assertContains('Conversion is set to require an opportunity.  Currently you do not have access to the opportunities module.', $content);
 }
コード例 #14
0
ファイル: LeadTest.php プロジェクト: maruthisivaprasad/zurmo
 public function testGetModelClassNames()
 {
     $modelClassNames = LeadsModule::getModelClassNames();
     $this->assertEquals(0, count($modelClassNames));
 }
コード例 #15
0
 public static function getConvertToAccountSetting()
 {
     $metadata = LeadsModule::getMetadata();
     return $metadata['global']['convertToAccountSetting'];
 }
コード例 #16
0
 protected function resolveConfirmAlertInHtmlOptions($htmlOptions)
 {
     $htmlOptions['confirm'] = Zurmo::t('Core', 'Are you sure you want to delete this {modelLabel}?', array('{modelLabel}' => LeadsModule::getModuleLabelByTypeAndLanguage('SingularLowerCase')));
     return $htmlOptions;
 }
 public function testRegularUserAllDefaultControllerActions()
 {
     $marketingList = MarketingListTestHelper::createMarketingListByName('MarketingListName 01', 'MarketingListDescription 01');
     $this->runControllerShouldResultInAccessFailureAndGetContent('marketingLists/default');
     $this->runControllerShouldResultInAccessFailureAndGetContent('marketingLists/default/index');
     $this->runControllerShouldResultInAccessFailureAndGetContent('marketingLists/default/list');
     $this->runControllerShouldResultInAccessFailureAndGetContent('marketingLists/default/create');
     $this->setGetArray(array('id' => $marketingList->id));
     $this->runControllerShouldResultInAccessFailureAndGetContent('marketingLists/default/edit');
     $this->runControllerShouldResultInAccessFailureAndGetContent('marketingLists/default/details');
     $this->runControllerShouldResultInAccessFailureAndGetContent('marketingLists/default/getInfoToCopyToCampaign');
     $this->setGetArray(array('term' => 'inexistant'));
     $this->runControllerShouldResultInAccessFailureAndGetContent('marketingLists/default/autoComplete');
     $this->setGetArray(array('modalTransferInformation' => array('sourceIdFieldId' => 'Campaign_marketingList_id', 'sourceNameFieldId' => 'Campaign_marketingList_name', 'modalId' => 'modalContainer-edit-form')));
     $this->runControllerShouldResultInAccessFailureAndGetContent('marketingLists/default/modalList');
     $this->resetGetArray();
     $this->user->setRight('MarketingListsModule', MarketingListsModule::getAccessRight());
     $this->assertTrue($this->user->save());
     $this->runControllerWithNoExceptionsAndGetContent('marketingLists/default');
     $this->runControllerWithNoExceptionsAndGetContent('marketingLists/default/index');
     $this->runControllerWithNoExceptionsAndGetContent('marketingLists/default/list');
     $this->setGetArray(array('term' => 'inexistant'));
     $this->runControllerWithNoExceptionsAndGetContent('marketingLists/default/autoComplete');
     $this->setGetArray(array('id' => $marketingList->id));
     $this->runControllerWithNoExceptionsAndGetContent('marketingLists/default/getInfoToCopyToCampaign');
     $this->setGetArray(array('modalTransferInformation' => array('sourceIdFieldId' => 'Campaign_marketingList_id', 'sourceNameFieldId' => 'Campaign_marketingList_name', 'modalId' => 'modalContainer-edit-form')));
     $this->runControllerWithNoExceptionsAndGetContent('marketingLists/default/modalList');
     $this->setGetArray(array('id' => $marketingList->id));
     $content = $this->runControllerWithNoExceptionsAndGetContent('marketingLists/default/details');
     $this->assertContains('<p>To manage Marketing Lists you must have access to either contacts' . ' or leads. Contact the CRM administrator about this issue.</p>', $content);
     $this->resetGetArray();
     $this->user->setRight('MarketingListsModule', MarketingListsModule::getCreateRight());
     $this->assertTrue($this->user->save());
     $content = $this->runControllerWithNoExceptionsAndGetContent('marketingLists/default/create');
     $this->assertContains('<p>To manage Marketing Lists you must have access to either contacts' . ' or leads. Contact the CRM administrator about this issue.</p>', $content);
     $this->user->setRight('ContactsModule', ContactsModule::getAccessRight());
     $this->user->setRight('LeadsModule', LeadsModule::getAccessRight());
     $this->assertTrue($this->user->save());
     $this->setGetArray(array('id' => $marketingList->id));
     $content = $this->runControllerWithNoExceptionsAndGetContent('marketingLists/default/details');
     $this->assertNotContains('<p>To manage Marketing Lists you must have access to either contacts' . ' or leads. Contact the CRM administrator about this issue.</p>', $content);
     $this->resetGetArray();
     $this->user->setRight('MarketingListsModule', MarketingListsModule::getCreateRight());
     $this->assertTrue($this->user->save());
     $content = $this->runControllerWithNoExceptionsAndGetContent('marketingLists/default/create');
     $this->assertNotContains('<p>To manage Marketing Lists you must have access to either contacts' . ' or leads. Contact the CRM administrator about this issue.</p>', $content);
     $this->setGetArray(array('id' => $marketingList->id));
     $this->runControllerWithNoExceptionsAndGetContent('marketingLists/default/edit');
     $this->user->setRight('MarketingListsModule', MarketingListsModule::getDeleteRight());
     $this->assertTrue($this->user->save());
     $this->runControllerWithRedirectExceptionAndGetUrl('marketingLists/default/delete');
     $this->setGetArray(array('id' => static::$listOwnedBySuper->id));
     $this->runControllerShouldResultInAccessFailureAndGetContent('marketingLists/default/edit');
     $this->runControllerShouldResultInAccessFailureAndGetContent('marketingLists/default/details');
     $this->runControllerShouldResultInAccessFailureAndGetContent('marketingLists/default/delete');
 }
コード例 #18
0
 /**
  * Test if all newly created items was pulled from read permission tables via API.
  * Please note that here we do not test if data are inserted in read permission tables correctly, that is
  * part of read permission subscription tests
  * @throws NotFoundException
  * @throws NotImplementedException
  * @throws NotSupportedException
  */
 public function testGetCreatedLeads()
 {
     $timestamp = time();
     sleep(1);
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     $lisa = UserTestHelper::createBasicUser('Lisa');
     $lisa->setRight('UsersModule', UsersModule::RIGHT_LOGIN_VIA_WEB_API);
     $lisa->setRight('LeadsModule', LeadsModule::getAccessRight());
     $this->assertTrue($lisa->save());
     $this->deleteAllModelsAndRecordsFromReadPermissionTable('Contact');
     $job = new ReadPermissionSubscriptionUpdateJob();
     ReadPermissionsOptimizationUtil::rebuild();
     $lead1 = LeadTestHelper::createLeadbyNameForOwner('Mike', $super);
     sleep(1);
     $lead2 = LeadTestHelper::createLeadbyNameForOwner('Jake', $super);
     sleep(1);
     $lead3 = LeadTestHelper::createLeadbyNameForOwner('Joe', $super);
     sleep(1);
     $lead1->primaryEmail->emailAddress = '*****@*****.**';
     $lead1->companyName = "IBM";
     $this->assertTrue($lead1->save());
     $lead2->primaryEmail->emailAddress = '*****@*****.**';
     $this->assertTrue($lead2->save());
     $lead3->primaryEmail->emailAddress = '*****@*****.**';
     $this->assertTrue($lead3->save());
     $this->assertTrue($job->run());
     $authenticationData = $this->login();
     $headers = array('Accept: application/json', 'ZURMO_SESSION_ID: ' . $authenticationData['sessionId'], 'ZURMO_TOKEN: ' . $authenticationData['token'], 'ZURMO_API_REQUEST_TYPE: REST');
     $data = array('sinceTimestamp' => $timestamp, 'pagination' => array('pageSize' => 2, 'page' => 1));
     $response = $this->createApiCallWithRelativeUrl('getCreatedItems/', 'POST', $headers, array('data' => $data));
     $response = json_decode($response, true);
     $this->assertEquals(3, $response['data']['totalCount']);
     $this->assertEquals(2, $response['data']['pageSize']);
     $this->assertEquals(1, $response['data']['currentPage']);
     $this->assertEquals($lead1->id, $response['data']['items'][0]['id']);
     $this->assertEquals($super->id, $response['data']['items'][0]['owner']['id']);
     $this->assertEquals($lead1->firstName, $response['data']['items'][0]['firstName']);
     $this->assertEquals($lead1->lastName, $response['data']['items'][0]['lastName']);
     $this->assertEquals($lead1->companyName, $response['data']['items'][0]['companyName']);
     $this->assertEquals($lead1->primaryEmail->emailAddress, $response['data']['items'][0]['primaryEmail']['emailAddress']);
     $this->assertEquals($lead2->id, $response['data']['items'][1]['id']);
     $this->assertEquals($super->id, $response['data']['items'][1]['owner']['id']);
     $this->assertEquals($lead2->firstName, $response['data']['items'][1]['firstName']);
     $this->assertEquals($lead2->lastName, $response['data']['items'][1]['lastName']);
     $this->assertEquals($lead2->primaryEmail->emailAddress, $response['data']['items'][1]['primaryEmail']['emailAddress']);
     $data = array('sinceTimestamp' => 0, 'pagination' => array('pageSize' => 2, 'page' => 2));
     $response = $this->createApiCallWithRelativeUrl('getCreatedItems/', 'POST', $headers, array('data' => $data));
     $response = json_decode($response, true);
     $this->assertEquals(3, $response['data']['totalCount']);
     $this->assertEquals(2, $response['data']['pageSize']);
     $this->assertEquals(2, $response['data']['currentPage']);
     $this->assertEquals($lead3->id, $response['data']['items'][0]['id']);
     $this->assertEquals($super->id, $response['data']['items'][0]['owner']['id']);
     $this->assertEquals($lead3->firstName, $response['data']['items'][0]['firstName']);
     $this->assertEquals($lead3->lastName, $response['data']['items'][0]['lastName']);
     $this->assertEquals($lead3->primaryEmail->emailAddress, $response['data']['items'][0]['primaryEmail']['emailAddress']);
     // Change owner of $contact1, it should appear in Lisa's created contacts
     $lead1->owner = $lisa;
     $this->assertTrue($lead1->save());
     sleep(1);
     $this->assertTrue($job->run());
     $data = array('sinceTimestamp' => $timestamp, 'pagination' => array('pageSize' => 2, 'page' => 1));
     $response = $this->createApiCallWithRelativeUrl('getCreatedItems/', 'POST', $headers, array('data' => $data));
     $response = json_decode($response, true);
     $this->assertEquals(2, $response['data']['totalCount']);
     $this->assertEquals(2, $response['data']['pageSize']);
     $this->assertEquals(1, $response['data']['currentPage']);
     $this->assertEquals($lead2->id, $response['data']['items'][0]['id']);
     $this->assertEquals($super->id, $response['data']['items'][0]['owner']['id']);
     $this->assertEquals($lead2->firstName, $response['data']['items'][0]['firstName']);
     $this->assertEquals($lead2->lastName, $response['data']['items'][0]['lastName']);
     $this->assertEquals($lead2->companyName, $response['data']['items'][0]['companyName']);
     $this->assertEquals($lead2->primaryEmail->emailAddress, $response['data']['items'][0]['primaryEmail']['emailAddress']);
     $this->assertEquals($lead3->id, $response['data']['items'][1]['id']);
     $this->assertEquals($super->id, $response['data']['items'][1]['owner']['id']);
     $this->assertEquals($lead3->firstName, $response['data']['items'][1]['firstName']);
     $this->assertEquals($lead3->lastName, $response['data']['items'][1]['lastName']);
     $this->assertEquals($lead3->primaryEmail->emailAddress, $response['data']['items'][1]['primaryEmail']['emailAddress']);
     $authenticationData = $this->login('lisa', 'lisa');
     $headers = array('Accept: application/json', 'ZURMO_SESSION_ID: ' . $authenticationData['sessionId'], 'ZURMO_TOKEN: ' . $authenticationData['token'], 'ZURMO_API_REQUEST_TYPE: REST');
     $data = array('sinceTimestamp' => $timestamp, 'pagination' => array('pageSize' => 2, 'page' => 1));
     $response = $this->createApiCallWithRelativeUrl('getCreatedItems/', 'POST', $headers, array('data' => $data));
     $response = json_decode($response, true);
     $this->assertEquals(1, $response['data']['totalCount']);
     $this->assertEquals(2, $response['data']['pageSize']);
     $this->assertEquals(1, $response['data']['currentPage']);
     $this->assertEquals($lead1->id, $response['data']['items'][0]['id']);
     $this->assertEquals($lisa->id, $response['data']['items'][0]['owner']['id']);
     $this->assertEquals($lead1->firstName, $response['data']['items'][0]['firstName']);
     $this->assertEquals($lead1->lastName, $response['data']['items'][0]['lastName']);
     $this->assertEquals($lead1->companyName, $response['data']['items'][0]['companyName']);
     $this->assertEquals($lead1->primaryEmail->emailAddress, $response['data']['items'][0]['primaryEmail']['emailAddress']);
 }