Skip to content

Commit

Permalink
Fixed issue: Database exception when trying to add the same user twic…
Browse files Browse the repository at this point in the history
…e in survey permissions
  • Loading branch information
c-schmitz committed Oct 6, 2020
1 parent de658f2 commit 7cb3e8b
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions application/controllers/admin/surveypermission.php
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,14 @@ function adduser($surveyid)

if ($postuserid > 0) {

$isrresult = Permission::model()->insertSomeRecords(array('entity_id' => $surveyid, 'entity'=>'survey', 'uid' => $postuserid, 'permission' => 'survey', 'read_p' => 1));
try {
$isrresult = Permission::model()->insertSomeRecords(array('entity_id' => $surveyid, 'entity'=>'survey', 'uid' => $postuserid, 'permission' => 'survey', 'read_p' => 1));
} catch(CDbException $e) {
// This database error happens usually if user already exists
$isrresult=false;
}



if ($isrresult) {

Expand All @@ -380,14 +387,14 @@ function adduser($surveyid)
$addsummary .= "<div class=\"jumbotron message-box message-box-error\">\n";
$addsummary .= "<h2>".gT("Add user")."</h2>\n";
$addsummary .= "<p class='lead'>".gT("Failed to add user.")."</p>\n"
. "<p>".gT("Username already exists.")."</p>";
. "<p>".gT("User already has permissions for this survey.")."</p>";
$addsummary .= "<p><input class='btn btn-default' type=\"submit\" onclick=\"window.open('".$this->getController()->createUrl('admin/surveypermission/sa/view/surveyid/'.$surveyid)."', '_top')\" value=\"".gT("Continue")."\"/></p>\n";
}
} else {
$addsummary .= "<div class=\"jumbotron message-box message-box-error\">\n";
$addsummary .= "<h2>".gT("Add user")."</h2>\n";
$addsummary .= "<p class='lead'>".gT("Failed to add user.")."</p>\n"
. "<p>".gT("No Username selected.")."</p>\n";
. "<p>".gT("No username selected.")."</p>\n";
$addsummary .= "<p><input class='btn btn-default' type=\"submit\" onclick=\"window.open('".$this->getController()->createUrl('admin/surveypermission/sa/view/surveyid/'.$surveyid)."', '_top')\" value=\"".gT("Continue")."\"/></p>\n";
}
} else {
Expand Down

0 comments on commit 7cb3e8b

Please sign in to comment.