/** * @depends testCreateStateValues */ public function testGetSetConvertToAccountSetting() { $this->assertEquals(2, LeadsModule::getConvertToAccountSetting()); $this->assertEquals(2, LeadsModule::CONVERT_ACCOUNT_NOT_REQUIRED); $metadata = LeadsModule::getMetadata(); $metadata['global']['convertToAccountSetting'] = LeadsModule::CONVERT_ACCOUNT_REQUIRED; LeadsModule::setMetadata($metadata); $this->assertEquals(3, LeadsModule::getConvertToAccountSetting()); }
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(); } }
/** * @depends testUserHasNoAccessToAccountsAndTriesToConvertWhenAccountIsOptional */ public function testUserCanAccessAccountsButCannotCreateAccountShowConvertAction() { $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super'); $belina = User::getByUserName('belina'); $lead = LeadTestHelper::createLeadbyNameForOwner('BelinaLead1', $belina); $belina->setRight('AccountsModule', AccountsModule::RIGHT_ACCESS_ACCOUNTS, Right::ALLOW); $this->assertTrue($belina->save()); $belina = $this->logoutCurrentUserLoginNewUserAndGetByUsername('belina'); $convertToAccountSetting = LeadsModule::getConvertToAccountSetting(); $this->assertEquals(Right::DENY, $belina->getEffectiveRight('AccountsModule', AccountsModule::RIGHT_CREATE_ACCOUNTS)); //The convert view should load up normally, except the option to create an account will not be pressent. //This tests that the view does in fact come up. $this->setGetArray(array('id' => $lead->id)); $this->runControllerWithNoExceptionsAndGetContent('leads/default/convert'); }
public function actionConvertFinal($id) { assert('!empty($id)'); $accountPostData = LeadsUtil::getFromSession(LeadsUtil::LEAD_CONVERSION_ACCOUNT_DATA_SESSION_KEY); if (empty($accountPostData)) { $urlParams = array('/leads/' . $this->getId() . '/convert', 'id' => $id); $this->redirect($urlParams); } $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(); $convertToOpportunitySetting = LeadsModule::getConvertToOpportunitySetting(); $opportunity = new Opportunity(); ControllerSecurityUtil::resolveAccessCanCurrentUserWriteModel($contact); $userCanAccessContacts = RightsUtil::canUserAccessModule('ContactsModule', Yii::app()->user->userModel); $userCanAccessAccounts = RightsUtil::canUserAccessModule('AccountsModule', Yii::app()->user->userModel); $userCanAccessOpportunities = RightsUtil::canUserAccessModule('OpportunitiesModule', Yii::app()->user->userModel); $userCanCreateOpportunity = RightsUtil::doesUserHaveAllowByRightName('OpportunitiesModule', OpportunitiesModule::RIGHT_CREATE_OPPORTUNITIES, Yii::app()->user->userModel); LeadsControllerSecurityUtil::resolveCanUserProperlyConvertLead($userCanAccessContacts, $userCanAccessAccounts, $convertToAccountSetting); LeadsControllerSecurityUtil::resolveCanUserProperlyConvertLeadFinalStep($userCanAccessContacts, $userCanAccessOpportunities, $convertToOpportunitySetting); if (isset($_POST['Opportunity'])) { $controllerUtil = static::getZurmoControllerUtil(); $savedSuccessfully = false; $modelToStringValue = null; $postData = $_POST['Opportunity']; $opportunity = $controllerUtil->saveModelFromPost($postData, $opportunity, $savedSuccessfully, $modelToStringValue, false); if ($savedSuccessfully) { $explicitReadWriteModelPermissions = ExplicitReadWriteModelPermissionsUtil::makeBySecurableItem($contact); ExplicitReadWriteModelPermissionsUtil::resolveExplicitReadWriteModelPermissions($opportunity, $explicitReadWriteModelPermissions); $account = LeadsUtil::createAccountForLeadConversionFromAccountPostData($accountPostData, $contact, $controllerUtil); $opportunity->account = $account; if (!$opportunity->save()) { throw new NotSupportedException(); } LeadsUtil::removeFromSession(LeadsUtil::LEAD_CONVERSION_ACCOUNT_DATA_SESSION_KEY); $this->actionSaveConvertedContact($contact, $account, $opportunity); } } elseif (isset($_POST['OpportunitySkip']) || $convertToOpportunitySetting == LeadsModule::CONVERT_NO_OPPORTUNITY || $convertToOpportunitySetting == LeadsModule::CONVERT_OPPORTUNITY_NOT_REQUIRED && !$userCanAccessOpportunities) { $controllerUtil = static::getZurmoControllerUtil(); $account = LeadsUtil::createAccountForLeadConversionFromAccountPostData($accountPostData, $contact, $controllerUtil); LeadsUtil::removeFromSession(LeadsUtil::LEAD_CONVERSION_ACCOUNT_DATA_SESSION_KEY); $this->actionSaveConvertedContact($contact, $account, null); } $progressBarAndStepsView = new LeadConversionStepsAndProgressBarForWizardView(1); $convertView = new LeadConvertOpportunityView($this->getId(), $this->getModule()->getId(), $contact->id, strval($contact), $opportunity, $convertToOpportunitySetting, $userCanCreateOpportunity); $view = new LeadsPageView(ZurmoDefaultViewUtil::makeTwoStandardViewsForCurrentUser($this, $progressBarAndStepsView, $convertView)); echo $view->render(); }
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(); }