/**
  * Creates a model for getModel(). Called only for each new $action.
  *
  * The parameters allow you to easily adapt the model to the current action. The $detailed
  * parameter was added, because the most common use of action is a split between detailed
  * and summarized actions.
  *
  * @param boolean $detailed True when the current action is not in $summarizedActions.
  * @param string $action The current action.
  * @return \MUtil_Model_ModelAbstract
  */
 protected function createModel($detailed, $action)
 {
     // Make sure the user is loaded
     $user = $this->getSelectedUser();
     if ($user) {
         if (!($this->currentUser->hasPrivilege('pr.staff.see.all') || $this->currentUser->isAllowedOrganization($user->getBaseOrganizationId()))) {
             throw new \Gems_Exception($this->_('No access to page'), 403, null, sprintf($this->_('You have no right to access users from the organization %s.'), $user->getBaseOrganization()->getName()));
         }
     }
     return parent::createModel($detailed, $action);
 }
 /**
  * Creates a model for getModel(). Called only for each new $action.
  *
  * The parameters allow you to easily adapt the model to the current action. The $detailed
  * parameter was added, because the most common use of action is a split between detailed
  * and summarized actions.
  *
  * @param boolean $detailed True when the current action is not in $summarizedActions.
  * @param string $action The current action.
  * @return \MUtil_Model_ModelAbstract
  */
 public function createModel($detailed, $action)
 {
     $defaultOrgId = null;
     if ($detailed) {
         // Make sure the user is loaded
         $user = $this->getSelectedUser();
         if ($user) {
             if (!($this->currentUser->hasPrivilege('pr.staff.see.all') || $this->currentUser->isAllowedOrganization($user->getBaseOrganizationId()))) {
                 throw new \Gems_Exception($this->_('No access to page'), 403, null, sprintf($this->_('You have no right to access users from the organization %s.'), $user->getBaseOrganization()->getName()));
             }
             switch ($action) {
                 case 'create':
                 case 'show':
                 case 'mail':
                     break;
                 default:
                     if (!$user->hasAllowedRole()) {
                         throw new \Gems_Exception($this->_('No access to page'), 403, null, sprintf($this->_('As %s user you have no right to access users with the role %s.'), $this->currentUser->getRole(), $user->getRole()));
                     }
             }
             $defaultOrgId = $user->getBaseOrganizationId();
         }
     }
     // \MUtil_Model::$verbose = true;
     $model = $this->loader->getModels()->getStaffModel(!('deactivate' === $action || 'reactivate' === $action));
     $model->applySettings($detailed, $action, $defaultOrgId);
     return $model;
 }