Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix https://mantis.ilias.de/view.php?id=32824 #4636

Merged
merged 3 commits into from
Jun 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 33 additions & 28 deletions Modules/Test/classes/class.ilAssQuestionPageCommandForwarder.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,56 +35,61 @@ public function setTestObj($testObj)

public function forward()
{
global $DIC; /* @var ILIAS\DI\Container $DIC */
global $DIC;
$ctrl = $DIC->ctrl();
$lng = $DIC->language();
$ui = $DIC->ui()->mainTemplate();

$q_gui = assQuestionGUI::_getQuestionGUI("", $_GET["q_id"]);
$q_gui->setRenderPurpose(assQuestionGUI::RENDER_PURPOSE_PREVIEW);
$q_gui->setQuestionTabs();
$q_gui->outAdditionalOutput();
$q_gui->object->setObjId($this->getTestObj()->getId());
$question = &$q_gui->object;


if ($ctrl->getCmd() === 'edit' && $question->isInActiveTest()) {
ilUtil::sendFailure($lng->txt("question_is_part_of_running_test"), true);
$ctrl->redirectByClass('ilAssQuestionPreviewGUI', ilAssQuestionPreviewGUI::CMD_SHOW);
}

require_once "./Modules/TestQuestionPool/classes/class.ilAssQuestionPageGUI.php";
//echo $_REQUEST['prev_qid'];
if ($_REQUEST['prev_qid']) {
$DIC->ctrl()->setParameter($this, 'prev_qid', $_REQUEST['prev_qid']);
$ctrl->setParameter($this, 'prev_qid', $_REQUEST['prev_qid']);
}

//global $___test_express_mode;
//$___test_express_mode = true;
$_GET['calling_test'] = $this->getTestObj()->getRefId();
include_once("./Services/Style/Content/classes/class.ilObjStyleSheet.php");
$DIC->ui()->mainTemplate()->setCurrentBlock("ContentStyle");
$DIC->ui()->mainTemplate()->setVariable(
$ui->setCurrentBlock("ContentStyle");
$ui->setVariable(
"LOCATION_CONTENT_STYLESHEET",
ilObjStyleSheet::getContentStylePath(0)
);
$DIC->ui()->mainTemplate()->parseCurrentBlock();
$ui->parseCurrentBlock();

// syntax style
$DIC->ui()->mainTemplate()->setCurrentBlock("SyntaxStyle");
$DIC->ui()->mainTemplate()->setVariable(
$ui->setCurrentBlock("SyntaxStyle");
$ui->setVariable(
"LOCATION_SYNTAX_STYLESHEET",
ilObjStyleSheet::getSyntaxStylePath()
);
$DIC->ui()->mainTemplate()->parseCurrentBlock();
require_once "./Modules/TestQuestionPool/classes/class.assQuestionGUI.php";
$q_gui = assQuestionGUI::_getQuestionGUI("", $_GET["q_id"]);
$q_gui->setRenderPurpose(assQuestionGUI::RENDER_PURPOSE_PREVIEW);
$q_gui->setQuestionTabs();
$q_gui->outAdditionalOutput();
$q_gui->object->setObjId($this->getTestObj()->getId());
$question = &$q_gui->object;
$DIC->ctrl()->saveParameter($this, "q_id");
$DIC->language()->loadLanguageModule("content");
$DIC->ctrl()->setReturnByClass("ilAssQuestionPageGUI", "view");
$DIC->ctrl()->setReturnByClass("ilObjTestGUI", "questions");
$ui->parseCurrentBlock();
$ctrl->saveParameter($this, "q_id");
$lng->loadLanguageModule("content");
$ctrl->setReturnByClass("ilAssQuestionPageGUI", "view");
$ctrl->setReturnByClass("ilObjTestGUI", "questions");
$page_gui = new ilAssQuestionPageGUI($_GET["q_id"]);
$page_gui->setEditPreview(true);
if (strlen($DIC->ctrl()->getCmd()) == 0) {
$DIC->ctrl()->setCmdClass(get_class($page_gui));
$DIC->ctrl()->setCmd("preview");
if (strlen($ctrl->getCmd()) == 0) {
$ctrl->setCmdClass(get_class($page_gui));
$ctrl->setCmd("preview");
}
$page_gui->setQuestionHTML(array($q_gui->object->getId() => $q_gui->getPreview(true)));
$page_gui->setTemplateTargetVar("ADM_CONTENT");
$page_gui->setOutputMode($this->getTestObj()->evalTotalPersons() == 0 ? "edit" : 'preview');
$page_gui->setHeader($question->getTitle());
$page_gui->setPresentationTitle($question->getTitle() . ' [' . $DIC->language()->txt('question_id_short') . ': ' . $question->getId() . ']');

$html = $DIC->ctrl()->forwardCommand($page_gui);
$DIC->ui()->mainTemplate()->setContent($html);
$html = $ctrl->forwardCommand($page_gui);
$ui->setContent($html);
}
}
43 changes: 36 additions & 7 deletions Modules/Test/classes/class.ilObjTestGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -665,8 +665,8 @@ public function executeCommand()
break;

case 'ilassquestionpreviewgui':
if ((!$ilAccess->checkAccess("read", "", $_GET["ref_id"]))) {
$ilias->raiseError($this->lng->txt("permission_denied"), $ilias->error_obj->MESSAGE);
if (!$ilAccess->checkAccess('write', '', $this->object->getRefId())) {
$this->redirectAfterMissingWrite();
}
$this->prepareOutput();

Expand All @@ -689,6 +689,9 @@ public function executeCommand()
if ((!$ilAccess->checkAccess("read", "", $_GET["ref_id"]))) {
$ilias->raiseError($this->lng->txt("permission_denied"), $ilias->error_obj->MESSAGE);
}
if ($cmd === 'edit' && !$ilAccess->checkAccess('write', '', $this->object->getRefId())) {
$this->redirectAfterMissingWrite();
}
$_GET['q_id'] = $this->fetchAuthoringQuestionIdParameter();
$this->prepareOutput();
require_once 'Modules/Test/classes/class.ilAssQuestionPageCommandForwarder.php';
Expand Down Expand Up @@ -748,8 +751,8 @@ public function executeCommand()
break;

case 'ilassquestionhintsgui':
if ((!$ilAccess->checkAccess("read", "", $_GET["ref_id"]))) {
$ilias->raiseError($this->lng->txt("permission_denied"), $ilias->error_obj->MESSAGE);
if (!$ilAccess->checkAccess('write', '', $this->object->getRefId())) {
$this->redirectAfterMissingWrite();
}
$this->prepareSubGuiOutput();

Expand All @@ -761,6 +764,11 @@ public function executeCommand()
$questionGUI = assQuestionGUI::_getQuestionGUI('', $this->fetchAuthoringQuestionIdParameter());
$questionGUI->object->setObjId($this->object->getId());
$questionGUI->setQuestionTabs();

if ($questionGUI->object->isInActiveTest()) {
ilUtil::sendFailure($this->lng->txt("question_is_part_of_running_test"), true);
$this->ctrl->redirectByClass('ilAssQuestionPreviewGUI', ilAssQuestionPreviewGUI::CMD_SHOW);
}

// forward to ilAssQuestionHintsGUI
require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionHintsGUI.php';
Expand All @@ -775,8 +783,8 @@ public function executeCommand()
break;

case 'ilassquestionfeedbackeditinggui':
if ((!$ilAccess->checkAccess("read", "", $_GET["ref_id"]))) {
$ilias->raiseError($this->lng->txt("permission_denied"), $ilias->error_obj->MESSAGE);
if (!$ilAccess->checkAccess('write', '', $this->object->getRefId())) {
$this->redirectAfterMissingWrite();
}
$this->prepareSubGuiOutput();

Expand All @@ -788,6 +796,11 @@ public function executeCommand()
$questionGUI = assQuestionGUI::_getQuestionGUI('', $this->fetchAuthoringQuestionIdParameter());
$questionGUI->object->setObjId($this->object->getId());
$questionGUI->setQuestionTabs();

if ($questionGUI->object->isInActiveTest()) {
ilUtil::sendFailure($this->lng->txt("question_is_part_of_running_test"), true);
$this->ctrl->redirectByClass('ilAssQuestionPreviewGUI', ilAssQuestionPreviewGUI::CMD_SHOW);
}

// forward to ilAssQuestionFeedbackGUI
require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionFeedbackEditingGUI.php';
Expand Down Expand Up @@ -828,6 +841,9 @@ public function executeCommand()
if ((!$ilAccess->checkAccess("read", "", $_GET["ref_id"]))) {
$ilias->raiseError($this->lng->txt("permission_denied"), $ilias->error_obj->MESSAGE);
}
if (in_array($cmd, ['editQuestion', 'save', 'suggestedsolution']) && !$ilAccess->checkAccess('write', '', $this->object->getRefId())) {
$this->redirectAfterMissingWrite();
}
// elba hack for storing question id for inserting new question after
if ($_REQUEST['prev_qid']) {
global $___prev_question_id;
Expand All @@ -850,6 +866,11 @@ public function executeCommand()

$questionGui->setEditContext(assQuestionGUI::EDIT_CONTEXT_AUTHORING);
$questionGui->object->setObjId($this->object->getId());

if (in_array($cmd, ['editQuestion', 'save', 'suggestedsolution']) && $questionGui->object->isInActiveTest()) {
ilUtil::sendFailure($this->lng->txt("question_is_part_of_running_test"), true);
$this->ctrl->redirectByClass('ilAssQuestionPreviewGUI', ilAssQuestionPreviewGUI::CMD_SHOW);
}

$questionGuiClass = get_class($questionGui);
$this->ctrl->setParameterByClass($questionGuiClass, 'prev_qid', $_REQUEST['prev_qid']);
Expand Down Expand Up @@ -882,6 +903,14 @@ public function executeCommand()
}
}

protected function redirectAfterMissingWrite()
{
ilUtil::sendFailure($this->lng->txt("no_permission"), true);
$target_class = get_class($this->object) . "GUI";
$this->ctrl->setParameterByClass($target_class, 'ref_id', $this->ref_id);
$this->ctrl->redirectByClass($target_class);
}

protected function trackTestObjectReadEvent()
{
/* @var ILIAS\DI\Container $DIC */ global $DIC;
Expand Down Expand Up @@ -972,7 +1001,7 @@ private function testResultsGatewayObject()
$gui = new ilParticipantsTestResultsGUI();
$gui->setTestObj($this->object);

$factory = new ilTestQuestionSetConfigFactory($this->tree,$DIC->database(),$ilPluginAdmin, $this->object);
$factory = new ilTestQuestionSetConfigFactory($this->tree, $DIC->database(), $ilPluginAdmin, $this->object);
$gui->setQuestionSetConfig($factory->getQuestionSetConfig());
$gui->setObjectiveParent(new ilTestObjectiveOrientedContainer());
$gui->setTestAccess($this->getTestAccess());
Expand Down
16 changes: 0 additions & 16 deletions Modules/TestQuestionPool/classes/class.assQuestion.php
Original file line number Diff line number Diff line change
Expand Up @@ -5504,20 +5504,4 @@ public function isInActiveTest() : bool
$res = $this->db->query($query);
return $res->numRows() > 0;
}

public function getParentTestRefId() : ?int
{
$query = 'SELECT ref_id FROM object_reference ' . PHP_EOL
. 'JOIN tst_tests ON tst_tests.obj_fi = object_reference.obj_id' . PHP_EOL
. 'JOIN tst_test_question ON tst_test_question.test_fi = tst_tests.test_id ' . PHP_EOL
. 'JOIN qpl_questions ON qpl_questions.question_id = tst_test_question.question_fi ' . PHP_EOL
. 'WHERE qpl_questions.obj_fi = ' . $this->db->quote($this->getObjId(), 'integer');

$res = $this->db->query($query);
$row = $this->db->fetchAssoc($res);
if ($res->numRows() > 0) {
return (int) $row['ref_id'];
}
return null;
}
}
15 changes: 0 additions & 15 deletions Modules/TestQuestionPool/classes/class.assQuestionGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,24 +226,9 @@ public function executeCommand()
{
global $DIC;
$DIC['ilHelp']->setScreenIdComponent('qpl');
$access = $DIC['ilAccess'];

$cmd = $this->ctrl->getCmd("editQuestion");

if (in_array($cmd, ['editQuestion', 'save'])) {
$parent_test_ref_id = $this->object->getParentTestRefId();
if ($parent_test_ref_id &&
!$access->checkAccess("write", "", $parent_test_ref_id)
) {
ilUtil::sendFailure($this->lng->txt("no_permission"), true);
$this->ctrl->redirectByClass('ilAssQuestionPreviewGUI', ilAssQuestionPreviewGUI::CMD_SHOW);
}
if ($this->object->isInActiveTest()) {
ilUtil::sendFailure($this->lng->txt("question_is_part_of_running_test"), true);
$this->ctrl->redirectByClass('ilAssQuestionPreviewGUI', ilAssQuestionPreviewGUI::CMD_SHOW);
}
}

$next_class = $this->ctrl->getNextClass($this);

switch ($next_class) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,18 +127,6 @@ public function executeCommand()

$this->setContentStyle();

$parent_test_ref_id = $this->questionOBJ->getParentTestRefId();
if ($parent_test_ref_id &&
!$this->access->checkAccess("write", "", $parent_test_ref_id)
) {
ilUtil::sendFailure($this->lng->txt("no_permission"), true);
$this->ctrl->redirectByClass('ilAssQuestionPreviewGUI', ilAssQuestionPreviewGUI::CMD_SHOW);
}
if ($this->questionOBJ->isInActiveTest()) {
ilUtil::sendFailure($this->lng->txt("question_is_part_of_running_test"), true);
$this->ctrl->redirectByClass('ilAssQuestionPreviewGUI', ilAssQuestionPreviewGUI::CMD_SHOW);
}

switch ($nextClass) {
case 'ilassspecfeedbackpagegui':
case 'ilassgenfeedbackpagegui':
Expand Down
Loading