public function testResolveUserStatus()
 {
     $user = UserTestHelper::createBasicUser('statusCheck2');
     $this->assertTrue(Right::NONE == $user->getExplicitActualRight('UsersModule', UsersModule::RIGHT_LOGIN_VIA_WEB));
     $this->assertTrue(Right::NONE == $user->getExplicitActualRight('UsersModule', UsersModule::RIGHT_LOGIN_VIA_MOBILE));
     $this->assertTrue(Right::NONE == $user->getExplicitActualRight('UsersModule', UsersModule::RIGHT_LOGIN_VIA_WEB_API));
     //Set the user to inactive.
     $userStatus = new UserStatus();
     $userStatus->setInactive();
     UserStatusUtil::resolveUserStatus($user, $userStatus);
     $userId = $user->id;
     $user = User::getById($userId);
     $this->assertEquals(UserStatusUtil::INACTIVE, UserStatusUtil::getSelectedValueByUser($user));
     $this->assertTrue(Right::DENY == $user->getExplicitActualRight('UsersModule', UsersModule::RIGHT_LOGIN_VIA_WEB));
     $this->assertTrue(Right::DENY == $user->getExplicitActualRight('UsersModule', UsersModule::RIGHT_LOGIN_VIA_MOBILE));
     $this->assertTrue(Right::DENY == $user->getExplicitActualRight('UsersModule', UsersModule::RIGHT_LOGIN_VIA_WEB_API));
     //Now set the user back to active.
     $userStatus->setActive();
     UserStatusUtil::resolveUserStatus($user, $userStatus);
     $userId = $user->id;
     $user = User::getById($userId);
     $this->assertEquals(UserStatusUtil::ACTIVE, UserStatusUtil::getSelectedValueByUser($user));
     $this->assertTrue(Right::NONE == $user->getExplicitActualRight('UsersModule', UsersModule::RIGHT_LOGIN_VIA_WEB));
     $this->assertTrue(Right::NONE == $user->getExplicitActualRight('UsersModule', UsersModule::RIGHT_LOGIN_VIA_MOBILE));
     $this->assertTrue(Right::NONE == $user->getExplicitActualRight('UsersModule', UsersModule::RIGHT_LOGIN_VIA_WEB_API));
 }
 public static function processAfterSaveAction(RedBeanModel $model, $attributeValueData)
 {
     assert('$model instanceof User');
     assert('is_array($attributeValueData) && count($attributeValueData) == 1');
     assert('isset($attributeValueData["status"]) && ($attributeValueData["status"] == UserStatusUtil::ACTIVE ||
                 $attributeValueData["status"] == UserStatusUtil::INACTIVE)');
     $userStatus = new UserStatus();
     if ($attributeValueData['status'] == UserStatusUtil::INACTIVE) {
         $userStatus->setInactive();
     }
     UserStatusUtil::resolveUserStatus($model, $userStatus);
 }
 /**
  * Override to handle UserStatus processing.
  * @see ZurmoBaseController::attemptToSaveModelFromPost()
  */
 protected function attemptToSaveModelFromPost($model, $redirectUrlParams = null, $redirect = true, $returnOnValidate = false)
 {
     assert('$model instanceof User || $model instanceof UserPasswordForm || $model instanceof UserAvatarForm');
     assert('$redirectUrlParams == null || is_array($redirectUrlParams) || is_string($redirectUrlParams)');
     $postVariableName = get_class($model);
     if (isset($_POST[$postVariableName])) {
         $postData = $_POST[$postVariableName];
         if (isset($_POST[$postVariableName]['userStatus'])) {
             $userStatus = UserStatusUtil::makeByPostData($_POST[$postVariableName]);
             $sanitizedPostdata = UserStatusUtil::removeIfExistsFromPostData($postData);
         } else {
             $userStatus = null;
             $sanitizedPostdata = $postData;
         }
         $savedSucessfully = false;
         $modelToStringValue = null;
         $oldUsername = $model->username;
         $controllerUtil = new ZurmoControllerUtil();
         $model = $controllerUtil->saveModelFromPost($sanitizedPostdata, $model, $savedSucessfully, $modelToStringValue);
         if ($savedSucessfully) {
             if ($userStatus != null) {
                 if ($model instanceof UserPasswordForm || $model instanceof UserAvatarForm) {
                     UserStatusUtil::resolveUserStatus($model->getModel(), $userStatus);
                 } else {
                     UserStatusUtil::resolveUserStatus($model, $userStatus);
                 }
             }
             if ($model->id == Yii::app()->user->userModel->id && $model->username != $oldUsername) {
                 //If the logged in user changes their username, a logout must occur to properly to properly
                 //restart the session.
                 Yii::app()->getSession()->destroy();
                 $this->redirect(Yii::app()->homeUrl);
             }
             $this->actionAfterSuccessfulModelSave($model, $modelToStringValue, $redirectUrlParams);
         }
     }
     return $model;
 }