Skip to content

Commit

Permalink
Dev: set public to public function
Browse files Browse the repository at this point in the history
Dev: move getUserId to protected
Dev: throw error if we came to getUserId with console
  • Loading branch information
Shnoulle committed Jan 21, 2016
1 parent e90dcc7 commit 59180f6
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions application/models/Permission.php
Expand Up @@ -438,7 +438,7 @@ public function setGlobalPermission($iNewUID,$sPermType,array $aPermissions=arra
$this->insertSomeRecords($aPerm);
}

function giveAllSurveyPermissions($iUserID, $iSurveyID)
public function giveAllSurveyPermissions($iUserID, $iSurveyID)
{
$aPermissions=$this->getSurveyBasePermissions();
$aPermissionsToSet=array();
Expand All @@ -456,21 +456,21 @@ function giveAllSurveyPermissions($iUserID, $iSurveyID)
$this->setPermissions($iUserID, $iSurveyID, 'survey', $aPermissionsToSet);
}

function insertRecords($data)
public function insertRecords($data)
{
foreach ($item as $data)
$this->insertSomeRecords($item);
}

function insertSomeRecords($data)
public function insertSomeRecords($data)
{
$permission = new self;
foreach ($data as $k => $v)
$permission->$k = $v;
return $permission->save();
}

function getUserDetails($surveyid)
public function getUserDetails($surveyid)
{
$sQuery = "SELECT p.entity_id, p.uid, u.users_name, u.full_name FROM {{permissions}} AS p INNER JOIN {{users}} AS u ON p.uid = u.uid
WHERE p.entity_id = :surveyid AND u.uid != :userid and p.entity='survey'
Expand All @@ -480,7 +480,7 @@ function getUserDetails($surveyid)
return Yii::app()->db->createCommand($sQuery)->bindParam(":userid", $iUserID, PDO::PARAM_INT)->bindParam("surveyid", $surveyid, PDO::PARAM_INT)->query()->readAll(); //Checked
}

function copySurveyPermissions($iSurveyIDSource,$iSurveyIDTarget)
public function copySurveyPermissions($iSurveyIDSource,$iSurveyIDTarget)
{
$aRows=self::model()->findAll("entity_id=:sid AND entity='survey'", array(':sid'=>$iSurveyIDSource));
foreach ($aRows as $aRow)
Expand Down Expand Up @@ -509,7 +509,7 @@ function copySurveyPermissions($iSurveyIDSource,$iSurveyIDTarget)
* @param $iUserID integer User ID - if not given the one of the current user is used
* @return bool True if user has the permission
*/
function hasPermission($iEntityID, $sEntityName, $sPermission, $sCRUD='read', $iUserID=null)
public function hasPermission($iEntityID, $sEntityName, $sPermission, $sCRUD='read', $iUserID=null)
{
if(is_null($iUserID) && Yii::app() instanceof CConsoleApplication)
return true;
Expand All @@ -530,7 +530,7 @@ function hasPermission($iEntityID, $sEntityName, $sPermission, $sCRUD='read', $i
if (!in_array($sCRUD,array('create','read','update','delete','import','export'))) return false;
$sCRUD=$sCRUD.'_p';

$iUserID=self::getUserId($iUserID);
$iUserID=$this->getUserId($iUserID);
if(!$iUserID)
return false;

Expand Down Expand Up @@ -575,7 +575,7 @@ function hasPermission($iEntityID, $sEntityName, $sPermission, $sCRUD='read', $i
* @param $iUserID integer User ID - if not given the one of the current user is used
* @return bool True if user has the permission
*/
function hasGlobalPermission($sPermission, $sCRUD='read', $iUserID=null)
public function hasGlobalPermission($sPermission, $sCRUD='read', $iUserID=null)
{
return $this->hasPermission(0, 'global', $sPermission, $sCRUD, $iUserID);
}
Expand All @@ -589,14 +589,14 @@ function hasGlobalPermission($sPermission, $sCRUD='read', $iUserID=null)
* @param $iUserID integer User ID - if not given the one of the current user is used
* @return bool True if user has the permission
*/
function hasSurveyPermission($iSurveyID, $sPermission, $sCRUD='read', $iUserID=null)
public function hasSurveyPermission($iSurveyID, $sPermission, $sCRUD='read', $iUserID=null)
{
$oSurvey=Survey::Model()->findByPk($iSurveyID);
if (!$oSurvey)
return false;
if(is_null($iUserID) && Yii::app() instanceof CConsoleApplication)
return true;
$iUserID=self::getUserId($iUserID);
$iUserID=$this->getUserId($iUserID);
// If you own a survey you have access to the whole survey
if ($iUserID==$oSurvey->owner_id)
return true;
Expand All @@ -612,7 +612,7 @@ function hasSurveyPermission($iSurveyID, $sPermission, $sCRUD='read', $iUserID=n
* @param $iUserID integer User ID - if not given the one of the current user is used
* @return bool True if user has the permission
*/
function hasTemplatePermission($sTemplateName, $sCRUD='read', $iUserID=null)
public function hasTemplatePermission($sTemplateName, $sCRUD='read', $iUserID=null)
{
return $this->hasPermission(0, 'global', 'templates', $sCRUD, $iUserID) || $this->hasPermission(0, 'template', $sTemplateName, $sCRUD, $iUserID);
}
Expand All @@ -633,8 +633,10 @@ private static function comparePermissionTitle($aApermission,$aBpermission)
* @param iUserID optionnal user id
* @return integer user id
*/
private static function getUserId($iUserID=null)
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())
$iUserID = Yii::app()->session['loginID'];
Expand Down

0 comments on commit 59180f6

Please sign in to comment.