public function testResolveContactStateAdapterByModulesUserHasAccessTo() { $super = User::getByUsername('super'); Yii::app()->user->userModel = $super; $bobby = User::getByUsername('bobby'); $this->assertEquals(Right::DENY, $bobby->getEffectiveRight('ContactsModule', ContactsModule::RIGHT_ACCESS_CONTACTS)); $this->assertEquals(Right::DENY, $bobby->getEffectiveRight('LeadsModule', LeadsModule::RIGHT_ACCESS_LEADS)); //test Contact model where has no access to either the leads or contacts module. $adapterName = ContactsUtil::resolveContactStateAdapterByModulesUserHasAccessTo('ContactsModule', 'LeadsModule', $bobby); $this->assertFalse($adapterName); //test Contact model where user has access to only the leads module $bobby->setRight('LeadsModule', LeadsModule::RIGHT_ACCESS_LEADS); $this->assertTrue($bobby->save()); $adapterName = ContactsUtil::resolveContactStateAdapterByModulesUserHasAccessTo('ContactsModule', 'LeadsModule', $bobby); $this->assertEquals('LeadsStateMetadataAdapter', $adapterName); //test Contact model where user has access to only the contacts module $bobby->removeRight('LeadsModule', LeadsModule::RIGHT_ACCESS_LEADS); $bobby->setRight('ContactsModule', ContactsModule::RIGHT_ACCESS_CONTACTS); $this->assertTrue($bobby->save()); $adapterName = ContactsUtil::resolveContactStateAdapterByModulesUserHasAccessTo('ContactsModule', 'LeadsModule', $bobby); $this->assertEquals('ContactsStateMetadataAdapter', $adapterName); //test Contact model where user has access to both the contacts and leads module. $bobby->setRight('LeadsModule', LeadsModule::RIGHT_ACCESS_LEADS); $this->assertTrue($bobby->save()); $adapterName = ContactsUtil::resolveContactStateAdapterByModulesUserHasAccessTo('ContactsModule', 'LeadsModule', $bobby); $this->assertNull($adapterName); }
/** * @param User $user * @return null | string */ public static function resolveStateAdapterUserHasAccessTo(User $user) { assert('$user->id > 0'); return ContactsUtil::resolveContactStateAdapterByModulesUserHasAccessTo('LeadsModule', 'ContactsModule', $user); }
public function actionModalListAllContacts() { $modalListLinkProvider = new SelectFromRelatedEditModalListLinkProvider($_GET['modalTransferInformation']['sourceIdFieldId'], $_GET['modalTransferInformation']['sourceNameFieldId'], $_GET['modalTransferInformation']['modalId']); $adapterName = ContactsUtil::resolveContactStateAdapterByModulesUserHasAccessTo('LeadsModule', 'ContactsModule', Yii::app()->user->userModel); if ($adapterName === false) { $messageView = new AccessFailureView(); $view = new AccessFailurePageView($messageView); echo $view->render(); Yii::app()->end(0, false); } echo ModalSearchListControllerUtil::setAjaxModeAndRenderModalSearchList($this, $modalListLinkProvider, $adapterName); }