Skip to content

Commit

Permalink
Allow moderators to access surveys of their admin
Browse files Browse the repository at this point in the history
  • Loading branch information
Epd02 committed Feb 18, 2024
1 parent d85e30d commit 1c98a06
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
9 changes: 8 additions & 1 deletion application/Controller/AdminSurveyController.php
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,14 @@ private function setStudy($name) {

$study = SurveyStudy::loadByUserAndName($this->user, $name);
if (!$study->valid) {
formr_error(404, 'Not Found', 'Requested Survey does not exist or has been moved');
if($this->user->moderator_for==0){
formr_error(404, 'Not Found', 'Requested Survey does not exist or has been moved');
}

$study = SurveyStudy::loadByUserIdAndName($this->user->moderator_for, $name);
if(!$study->valid){
formr_error(404, 'Not Found', 'Requested Survey does not exist or has been moved');
}

This comment has been minimized.

Copy link
@till-20

till-20 Feb 18, 2024

gives moderator ability to access to the surveys by loading them with the id of the moderated admin instead of the own one

}

$google_id = $study->getGoogleFileId();
Expand Down
14 changes: 14 additions & 0 deletions application/Model/SurveyStudy.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,20 @@ public static function loadByUserAndName(User $user, $name) {
return new SurveyStudy(null, $options);
}

/**
*
* @param int $id
* @param string $name
* @return \SurveyStudy
*/
public static function loadByUserIDAndName(int $id, $name) {

This comment has been minimized.

Copy link
@till-20

till-20 Feb 18, 2024

supportive method to load a survey

$options = [
'name' => $name,
'user_id' => $id,
];
return new SurveyStudy(null, $options);
}

protected function load($id, $options) {
if (!$options || !is_array($options)) {
$options = [];
Expand Down

0 comments on commit 1c98a06

Please sign in to comment.