Skip to content

Commit cad11c3

Browse files
Exercise: Allow access to hotspot question images in quizzes - refs BT#22633
1 parent 2efc080 commit cad11c3

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

src/CoreBundle/Security/Authorization/Voter/ResourceNodeVoter.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
use Chamilo\CoreBundle\Settings\SettingsManager;
1515
use Chamilo\CourseBundle\Entity\CDocument;
1616
use Chamilo\CourseBundle\Entity\CGroup;
17+
use Chamilo\CourseBundle\Entity\CQuizQuestion;
18+
use Chamilo\CourseBundle\Entity\CQuizRelQuestion;
1719
use Chamilo\CourseBundle\Entity\CStudentPublicationRelDocument;
1820
use ChamiloSession;
1921
use Doctrine\ORM\EntityManagerInterface;
@@ -124,7 +126,27 @@ protected function voteOnAttribute(string $attribute, $subject, TokenInterface $
124126
return true;
125127
}
126128

127-
// no break
129+
// Exception: allow access to hotspot question images if student can view the quiz
130+
$questionRepo = $this->entityManager->getRepository(CQuizQuestion::class);
131+
$question = $questionRepo->findOneBy(['resourceNode' => $resourceNode]);
132+
if ($question) {
133+
// Check if it's a Hotspot-type question
134+
if (\in_array($question->getType(), [6, 7, 8], true)) { // HOT_SPOT, HOT_SPOT_ORDER, HOT_SPOT_DELINEATION
135+
$rel = $this->entityManager
136+
->getRepository(CQuizRelQuestion::class)
137+
->findOneBy(['question' => $question]);
138+
139+
if ($rel && $rel->getQuiz()) {
140+
$quiz = $rel->getQuiz();
141+
// Allow if the user has VIEW rights on the quiz
142+
if ($this->security->isGranted('VIEW', $quiz)) {
143+
return true;
144+
}
145+
}
146+
}
147+
}
148+
149+
// no break
128150
case self::EDIT:
129151
break;
130152
}

0 commit comments

Comments
 (0)