Skip to content

Commit

Permalink
Dev: use directly Yii::app()->session in getUserId : no need reset la…
Browse files Browse the repository at this point in the history
…nguage

Dev: Throw Exception for CConsoleApplication only if userid is null
  • Loading branch information
Shnoulle committed Mar 2, 2016
1 parent 0a6682e commit 9cf4b0d
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions application/models/Permission.php
Expand Up @@ -544,13 +544,9 @@ public function hasPermission($iEntityID, $sEntityName, $sPermission, $sCRUD='re
$sCRUD=$sCRUD.'_p';

/* Always return false for guests */
if(is_null($iUserID))
if(!$this->getUserId($iUserID))
{
$iUserID=$this->getUserId($iUserID);
if(!$iUserID)
{
return false;
}
return false;
}

/* Always return true if you are the owner : this can be done in core plugin ? */
Expand Down Expand Up @@ -659,12 +655,14 @@ private static function comparePermissionTitle($aApermission,$aBpermission)
*/
protected function getUserId($iUserID=null)
{
if(Yii::app() instanceof CConsoleApplication)
throw new Exception('Permission must not be tested with console application.');
$sOldLanguage=App()->language;// Call of Yii::app()->user reset App()->language to default. Quick fix for #09695
if (is_null($iUserID) && !Yii::app()->user->getIsGuest())
if (is_null($iUserID))
{
if(Yii::app() instanceof CConsoleApplication)
{
throw new Exception('Permission must not be tested with console application.');
}
$iUserID = Yii::app()->session['loginID'];
App()->setLanguage($sOldLanguage);
}
return $iUserID;
}

Expand Down

0 comments on commit 9cf4b0d

Please sign in to comment.