Skip to content

Commit

Permalink
Dev: Don't allow survey id to be 0 when copying survey
Browse files Browse the repository at this point in the history
Dev: Superadmin permission entity id is 0, so it will be
Dev: removed when permission are copied.
  • Loading branch information
olleharstedt committed Jul 28, 2016
1 parent 8b84d55 commit 81bf249
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
10 changes: 5 additions & 5 deletions application/helpers/admin/import_helper.php
Expand Up @@ -1543,13 +1543,13 @@ function XMLImportSurvey($sFullFilePath,$sXMLdata=NULL,$sNewSurveyName=NULL,$iDe
* This function returns a new random sid if the existing one is taken,
* otherwise it returns the old one.
*
* @param mixed $iOldSID
* @param mixed $iDesiredSurveyId
*/
function GetNewSurveyID($iOldSID)
function GetNewSurveyID($iDesiredSurveyId)
{
Yii::app()->loadHelper('database');
$aSurvey=Survey::model()->findByPk($iOldSID);
if(!empty($aSurvey))
$aSurvey=Survey::model()->findByPk($iDesiredSurveyId);
if(!empty($aSurvey) || $iDesiredSurveyId == 0)
{
// Get new random ids until one is found that is not used
do
Expand All @@ -1563,7 +1563,7 @@ function GetNewSurveyID($iOldSID)
}
else
{
return $iOldSID;
return $iDesiredSurveyId;
}
}

Expand Down
5 changes: 5 additions & 0 deletions application/models/Permission.php
Expand Up @@ -440,6 +440,11 @@ public function setGlobalPermission($iNewUID,$sPermType,array $aPermissions=arra

public function giveAllSurveyPermissions($iUserID, $iSurveyID)
{
if ($iSurveyID == 0)
{
throw new InvalidArgumentException('Survey ID cannot be 0 (collides with superadmin permission entity id)');
}

$aPermissions=$this->getSurveyBasePermissions();
$aPermissionsToSet=array();
foreach ($aPermissions as $sPermissionName=>$aPermissionDetails)
Expand Down

0 comments on commit 81bf249

Please sign in to comment.