public function testNobodyUserHomePageView()
 {
     $nobody = $this->logoutCurrentUserLoginNewUserAndGetByUsername('nobody');
     $content = $this->runControllerWithNoExceptionsAndGetContent('home/default/welcome');
     $this->assertContains('Welcome to Zurmo', $content);
     //When hideWelcomeView is on nobody should see HomeView
     $form = UserConfigurationFormAdapter::makeFormFromUserConfigurationByUser($nobody);
     $form->hideWelcomeView = true;
     UserConfigurationFormAdapter::setConfigurationFromFormForCurrentUser($form);
     $content = $this->runControllerWithNoExceptionsAndGetContent('home/default/welcome');
     $this->assertContains('HomeView', $content);
 }
 public function testSuperUserWelcomeActions()
 {
     $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     //test that the welcome screen appears
     $content = $this->runControllerWithNoExceptionsAndGetContent('home/default/welcome');
     $this->assertContains('Go to the dashboard', $content);
     //Change setting so user ignores welcome view.
     $form = UserConfigurationFormAdapter::makeFormFromUserConfigurationByUser($super);
     $form->hideWelcomeView = true;
     UserConfigurationFormAdapter::setConfigurationFromFormForCurrentUser($form);
     //Now the welcome screen should not appear
     $this->runControllerWithRedirectExceptionAndGetContent('home/default/welcome');
 }
Пример #3
0
 public function actionConfigurationEdit($id)
 {
     UserAccessUtil::resolveCanCurrentUserAccessAction(intval($id));
     $user = User::getById(intval($id));
     UserAccessUtil::resolveCanCurrentUserAccessRootUser($user);
     UserAccessUtil::resolveAccessingASystemUser($user);
     $title = Zurmo::t('ConfigurationModule', 'Configuration');
     $breadCrumbLinks = array(strval($user) => array('default/details', 'id' => $id), $title);
     $configurationForm = UserConfigurationFormAdapter::makeFormFromUserConfigurationByUser($user);
     $postVariableName = get_class($configurationForm);
     if (isset($_POST[$postVariableName])) {
         $configurationForm->setAttributes($_POST[$postVariableName]);
         if ($configurationForm->validate()) {
             if ($user->id != Yii::app()->user->userModel->id) {
                 UserConfigurationFormAdapter::setConfigurationFromForm($configurationForm, $user);
             } else {
                 UserConfigurationFormAdapter::setConfigurationFromFormForCurrentUser($configurationForm);
             }
             Yii::app()->user->setFlash('notification', Zurmo::t('UsersModule', 'User configuration saved successfully.'));
             $this->redirect(array($this->getId() . '/details', 'id' => $user->id));
         }
     }
     $titleBarAndEditView = new UserActionBarAndConfigurationEditView($this->getId(), $this->getModule()->getId(), $user, $configurationForm);
     $titleBarAndEditView->setCssClasses(array('AdministrativeArea'));
     $view = new UsersPageView($this->resolveZurmoDefaultOrAdminView($titleBarAndEditView, $breadCrumbLinks, 'UserBreadCrumbView'));
     echo $view->render();
 }
 public function testMakeFormAndSetConfigurationFromForm()
 {
     $billy = User::getByUsername('billy');
     $sally = User::getByUsername('sally');
     Yii::app()->pagination->setGlobalValueByType('listPageSize', 50);
     Yii::app()->pagination->setGlobalValueByType('subListPageSize', 51);
     Yii::app()->pagination->setGlobalValueByType('dashboardListPageSize', 52);
     //Confirm sally's configuration is the defaults.
     $form = UserConfigurationFormAdapter::makeFormFromUserConfigurationByUser($sally);
     $this->assertEquals(50, $form->listPageSize);
     $this->assertEquals(51, $form->subListPageSize);
     $this->assertEquals(52, $form->dashboardListPageSize);
     $this->assertEquals('blue', Yii::app()->themeManager->resolveAndGetThemeColorValue($sally));
     $this->assertEquals(null, Yii::app()->themeManager->resolveAndGetBackgroundTextureValue($sally));
     $this->assertFalse(UserConfigurationFormAdapter::resolveAndGetValue($sally, 'hideWelcomeView'));
     $this->assertFalse(UserConfigurationFormAdapter::resolveAndGetValue($sally, 'enableDesktopNotifications'));
     $this->assertNull(UserConfigurationFormAdapter::resolveAndGetValue($sally, 'defaultPermissionGroupSetting', false));
     $this->assertEquals(UserConfigurationFormAdapter::resolveAndGetDefaultPermissionSetting($sally), UserConfigurationForm::DEFAULT_PERMISSIONS_SETTING_EVERYONE);
     $this->assertFalse(UserConfigurationFormAdapter::resolveAndGetValue($sally, 'hideFromSelecting'));
     $this->assertFalse(UserConfigurationFormAdapter::resolveAndGetValue($sally, 'hideFromLeaderboard'));
     $sally->hideFromLeaderboard = true;
     $sally->hideFromSelecting = true;
     $this->assertTrue($sally->save());
     unset($sally);
     $sally = User::getByUsername('sally');
     $this->assertTrue((bool) $sally->hideFromLeaderboard);
     $this->assertTrue((bool) $sally->hideFromSelecting);
     //Confirm billy's configuration is the defaults.
     $form = UserConfigurationFormAdapter::makeFormFromUserConfigurationByUser($billy);
     $this->assertEquals(50, $form->listPageSize);
     $this->assertEquals(51, $form->subListPageSize);
     $this->assertEquals(52, $form->dashboardListPageSize);
     $this->assertEquals('blue', Yii::app()->themeManager->resolveAndGetThemeColorValue($billy));
     $this->assertEquals(null, Yii::app()->themeManager->resolveAndGetBackgroundTextureValue($billy));
     $this->assertFalse(UserConfigurationFormAdapter::resolveAndGetValue($billy, 'hideWelcomeView'));
     $this->assertFalse(UserConfigurationFormAdapter::resolveAndGetValue($billy, 'enableDesktopNotifications'));
     $this->assertNull(UserConfigurationFormAdapter::resolveAndGetValue($billy, 'defaultPermissionGroupSetting', false));
     $this->assertEquals(UserConfigurationFormAdapter::resolveAndGetDefaultPermissionSetting($billy), UserConfigurationForm::DEFAULT_PERMISSIONS_SETTING_EVERYONE);
     $this->assertFalse(UserConfigurationFormAdapter::resolveAndGetValue($sally, 'hideFromSelecting'));
     $this->assertFalse(UserConfigurationFormAdapter::resolveAndGetValue($sally, 'hideFromLeaderboard'));
     //Now change configuration for Billy.
     $form->listPageSize = 60;
     $form->subListPageSize = 61;
     $form->dashboardListPageSize = 62;
     $form->themeColor = 'lime';
     $form->backgroundTexture = 'paper';
     $form->hideWelcomeView = true;
     $form->enableDesktopNotifications = true;
     $form->defaultPermissionSetting = UserConfigurationForm::DEFAULT_PERMISSIONS_SETTING_OWNER_AND_USERS_IN_GROUP;
     $form->defaultPermissionGroupSetting = 6;
     $form->hideFromLeaderboard = true;
     $form->hideFromSelecting = true;
     UserConfigurationFormAdapter::setConfigurationFromForm($form, $billy);
     //Confirm billy's settings are changed correctly.
     $form = UserConfigurationFormAdapter::makeFormFromUserConfigurationByUser($billy);
     $this->assertEquals(60, $form->listPageSize);
     $this->assertEquals(61, $form->subListPageSize);
     $this->assertEquals(62, $form->dashboardListPageSize);
     $this->assertEquals('lime', Yii::app()->themeManager->resolveAndGetThemeColorValue($billy));
     $this->assertEquals('paper', Yii::app()->themeManager->resolveAndGetBackgroundTextureValue($billy));
     $this->assertTrue(UserConfigurationFormAdapter::resolveAndGetValue($billy, 'hideWelcomeView'));
     $this->assertTrue(UserConfigurationFormAdapter::resolveAndGetValue($billy, 'enableDesktopNotifications'));
     $this->assertFalse(UserConfigurationFormAdapter::resolveAndGetValue($sally, 'hideWelcomeView'));
     $this->assertFalse(UserConfigurationFormAdapter::resolveAndGetValue($sally, 'enableDesktopNotifications'));
     $this->assertEquals(UserConfigurationFormAdapter::resolveAndGetDefaultPermissionSetting($billy), UserConfigurationForm::DEFAULT_PERMISSIONS_SETTING_OWNER_AND_USERS_IN_GROUP);
     $this->assertEquals(UserConfigurationFormAdapter::resolveAndGetValue($billy, 'defaultPermissionGroupSetting', false), 6);
     $this->assertEquals(UserConfigurationFormAdapter::resolveAndGetDefaultPermissionSetting($sally), UserConfigurationForm::DEFAULT_PERMISSIONS_SETTING_EVERYONE);
     $this->assertNull(UserConfigurationFormAdapter::resolveAndGetValue($sally, 'defaultPermissionGroupSetting', false));
     $this->assertTrue((bool) $billy->hideFromLeaderboard);
     $this->assertTrue((bool) $billy->hideFromSelecting);
     //Now set configuration settings for sally and confirm they are correct.
     Yii::app()->user->userModel = $sally;
     UserConfigurationFormAdapter::setConfigurationFromFormForCurrentUser($form);
     $form = UserConfigurationFormAdapter::makeFormFromUserConfigurationByUser($sally);
     $this->assertEquals(60, $form->listPageSize);
     $this->assertEquals(61, $form->subListPageSize);
     $this->assertEquals(62, $form->dashboardListPageSize);
     $this->assertEquals('lime', Yii::app()->themeManager->resolveAndGetThemeColorValue($sally));
     $this->assertEquals('paper', Yii::app()->themeManager->resolveAndGetBackgroundTextureValue($sally));
     $this->assertTrue(UserConfigurationFormAdapter::resolveAndGetValue($sally, 'hideWelcomeView'));
     $this->assertTrue(UserConfigurationFormAdapter::resolveAndGetValue($sally, 'enableDesktopNotifications'));
     $this->assertEquals(UserConfigurationFormAdapter::resolveAndGetDefaultPermissionSetting($sally), UserConfigurationForm::DEFAULT_PERMISSIONS_SETTING_OWNER_AND_USERS_IN_GROUP);
     $this->assertEquals(UserConfigurationFormAdapter::resolveAndGetValue($sally, 'defaultPermissionGroupSetting', false), 6);
     $this->assertTrue((bool) $billy->hideFromLeaderboard);
     $this->assertTrue((bool) $billy->hideFromSelecting);
     //Now test that setting defaultPermissionSetting to owner makes the group settings null
     $form = UserConfigurationFormAdapter::makeFormFromUserConfigurationByUser($billy);
     $form->defaultPermissionSetting = UserConfigurationForm::DEFAULT_PERMISSIONS_SETTING_OWNER;
     $form->defaultPermissionGroupSetting = 4;
     UserConfigurationFormAdapter::setConfigurationFromForm($form, $billy);
     $form = UserConfigurationFormAdapter::makeFormFromUserConfigurationByUser($billy);
     $this->assertEquals(UserConfigurationFormAdapter::resolveAndGetDefaultPermissionSetting($billy), UserConfigurationForm::DEFAULT_PERMISSIONS_SETTING_OWNER);
     $this->assertNull(UserConfigurationFormAdapter::resolveAndGetValue($billy, 'defaultPermissionGroupSetting', false));
 }