Skip to content

Commit

Permalink
Replace all direct access to GET and POST in Test component with acco…
Browse files Browse the repository at this point in the history
…rding DataRequestCollector calls
  • Loading branch information
matheuszych committed Sep 10, 2024
1 parent 0cbb7f3 commit a3bcf0c
Show file tree
Hide file tree
Showing 17 changed files with 224 additions and 122 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

declare(strict_types=1);

use ILIAS\Test\RequestDataCollector;

/**
* @author Björn Heyser <[email protected]>
* @version $Id$
Expand All @@ -26,15 +28,14 @@
*/
class ilTestSettingsChangeConfirmationGUI extends ilConfirmationGUI
{
protected ilObjTest $testOBJ;
private ?string $oldQuestionSetType;
private ?string $newQuestionSetType;
private ?bool $questionLossInfoEnabled;

public function __construct(ilObjTest $testOBJ)
{
$this->testOBJ = $testOBJ;

public function __construct(
private readonly RequestDataCollector $testrequest,
protected readonly ilObjTest $testOBJ
) {
parent::__construct();
}

Expand Down Expand Up @@ -93,15 +94,18 @@ public function build(): void

public function populateParametersFromPost(): void
{
foreach ($_POST as $key => $value) {
if (strcmp($key, "cmd") != 0) {
foreach ($this->testrequest->getPostKeys() as $key) {
if ($key !== 'cmd') {
$value = $this->testrequest->getArrayOfStringsOrStringFromPost($key);

if (is_array($value)) {
foreach ($value as $k => $v) {
$this->addHiddenItem("{$key}[{$k}]", $v);
}
} else {
$this->addHiddenItem($key, $value);
continue;
}

$this->addHiddenItem($key, $value);
}
}
}
Expand Down
15 changes: 9 additions & 6 deletions components/ILIAS/Test/classes/class.ilObjTestGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,7 @@ public function executeCommand(): void
$this->component_repository,
$this->getTestObject(),
$this->questionrepository,
$this->testrequest,
$this->ref_id
);
$this->ctrl->forwardCommand($gui);
Expand Down Expand Up @@ -2199,7 +2200,8 @@ public function exportLegacyLogsObject(): void
*/
public function participantsActionObject(): void
{
$command = $this->testrequest->strVal('command');
$command = $this->testrequest->getStringFromPost('command', '');

if ($command === '') {
$method = $command . 'Object';
if (method_exists($this, $method)) {
Expand Down Expand Up @@ -2385,10 +2387,11 @@ public function confirmedApplyDefaultsObject()
/**
* Applies the selected test defaults
*/
public function applyDefaultsObject($confirmed = false)
public function applyDefaultsObject($confirmed = false): void
{
$defaults = $this->testrequest->getArrayOfStringsFromPost('chb_defaults');
if ($defaults !== null && $defaults !== []) {
$defaults = $this->testrequest->getArrayOfIntsFromPost('chb_defaults');

if ($defaults !== []) {
$this->tpl->setOnScreenMessage('info', $this->lng->txt('tst_defaults_apply_select_one'));

$this->defaultsObject();
Expand Down Expand Up @@ -2429,7 +2432,7 @@ public function applyDefaultsObject($confirmed = false)

default:

$confirmation = new ilTestSettingsChangeConfirmationGUI($this->getTestObject());
$confirmation = new ilTestSettingsChangeConfirmationGUI($this->testrequest, $this->getTestObject());

$confirmation->setFormAction($this->ctrl->getFormAction($this));
$confirmation->setCancel($this->lng->txt('cancel'), 'defaults');
Expand Down Expand Up @@ -2471,7 +2474,7 @@ public function applyDefaultsObject($confirmed = false)
*/
public function addDefaultsObject()
{
$name = $this->testrequest->strVal('name');
$name = $this->testrequest->getStringFromPost('name');
if ($name !== '') {
$this->getTestObject()->addDefaults($name);
} else {
Expand Down
9 changes: 6 additions & 3 deletions components/ILIAS/Test/classes/class.ilTestDashboardGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@

declare(strict_types=1);

use ILIAS\Test\RequestDataCollector;
use ILIAS\UI\Factory as UIFactory;
use ILIAS\UI\Renderer as UIRenderer;

use ILIAS\Test\RequestDataCollector;

/**
* Class ilTestDashboardGUI
*
Expand Down Expand Up @@ -107,6 +106,9 @@ public function setObjectiveParent(ilTestObjectiveOrientedContainer $objective_p
$this->objective_parent = $objective_parent;
}

/**
* @throws ilCtrlException
*/
public function executeCommand(): void
{
if (!$this->getTestAccess()->checkManageParticipantsAccess()) {
Expand Down Expand Up @@ -149,7 +151,8 @@ public function executeCommand(): void
$this->lng,
$this->db,
$this->main_tpl,
new ilTestParticipantAccessFilterFactory($this->access)
new ilTestParticipantAccessFilterFactory($this->access),
$this->testrequest
);
$this->ctrl->forwardCommand($gui);
break;
Expand Down
32 changes: 11 additions & 21 deletions components/ILIAS/Test/classes/class.ilTestEvaluationGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -1535,12 +1535,12 @@ public function confirmDeletePass()
$this->tpl->setContent($this->ctrl->getHTML($confirm));
}

public function cancelDeletePass()
public function cancelDeletePass(): void
{
$this->redirectToPassDeletionContext($_POST['context']);
$this->redirectToPassDeletionContext($this->testrequest->getStringFromPost('context'));
}

private function redirectToPassDeletionContext($context)
private function redirectToPassDeletionContext($context): void
{
switch ($context) {
case ilTestPassDeletionConfirmationGUI::CONTEXT_PASS_OVERVIEW:
Expand All @@ -1554,36 +1554,26 @@ private function redirectToPassDeletionContext($context)
}
}

public function performDeletePass()
/**
* @throws ilCtrlException|ilTestException
*/
public function performDeletePass(): void
{
if (isset($_POST['context']) && strlen($_POST['context'])) {
$context = $_POST['context'];
} else {
$context = ilTestPassDeletionConfirmationGUI::CONTEXT_PASS_OVERVIEW;
}
$context = $this->testrequest->getStringFromPost('context', ilTestPassDeletionConfirmationGUI::CONTEXT_PASS_OVERVIEW);
$active_fi = $this->testrequest->getIntFromPost('active_id', null);
$pass = $this->testrequest->getIntFromPost('pass', null);

if (!$this->object->isPassDeletionAllowed()) {
$this->redirectToPassDeletionContext($context);
}

$ilDB = $this->db;

$active_fi = null;
$pass = null;

if (isset($_POST['active_id']) && (int) $_POST['active_id']) {
$active_fi = $_POST['active_id'];
}

if (isset($_POST['pass']) && is_numeric($_POST['pass'])) {
$pass = $_POST['pass'];
}

if (is_null($active_fi) || is_null($pass)) {
$this->ctrl->redirect($this, 'outUserResultsOverview');
}

if ($pass == $this->object->_getResultPass($active_fi)) {
if ($pass === $this->object::_getResultPass($active_fi)) {
$this->ctrl->redirect($this, 'outUserResultsOverview');
}

Expand Down
46 changes: 32 additions & 14 deletions components/ILIAS/Test/classes/class.ilTestParticipantsGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@

declare(strict_types=1);

use ILIAS\Test\RequestDataCollector;
use ILIAS\UI\Factory as UIFactory;
use ILIAS\UI\Renderer as UIRenderer;

use ILIAS\Test\RequestDataCollector;

/**
* Class ilTestParticipantsGUI
*
Expand Down Expand Up @@ -141,26 +140,30 @@ public function executeCommand(): void
}
}

/**
* @throws ilCtrlException
*/
public function addParticipants($user_ids = []): ?bool
{
$filter_closure = $this->participant_access_filter->getManageParticipantsUserFilter($this->getTestObj()->getRefId());
$filtered_user_ids = $filter_closure($user_ids);

$countusers = 0;
$count_users = 0;
foreach ($filtered_user_ids as $user_id) {
$client_ip = $_POST["client_ip"][$countusers] ?? '';
$client_ip = $this->testrequest->getArrayOfStringsFromPost('client_ip')[$count_users] ?? '';

$this->getTestObj()->inviteUser($user_id, $client_ip);
$countusers++;
$count_users++;
}

$message = "";
if ($countusers) {
$message = $this->lng->txt("tst_invited_selected_users");
$message = '';
if ($count_users) {
$message = $this->lng->txt('tst_invited_selected_users');
}
if (strlen($message)) {
if ($message !== '') {
$this->main_tpl->setOnScreenMessage('info', $message, true);
} else {
$this->main_tpl->setOnScreenMessage('info', $this->lng->txt("tst_invited_nobody"), true);
$this->main_tpl->setOnScreenMessage('info', $this->lng->txt('tst_invited_nobody'), true);
return false;
}

Expand Down Expand Up @@ -319,33 +322,48 @@ protected function addFinishAllPassesButton(ilToolbarGUI $toolbar): void
$toolbar->addComponent($finish_all_user_passes_btn);
}

/**
* @throws ilCtrlException
*/
protected function saveClientIpCmd(): void
{
$filter_closure = $this->participant_access_filter->getManageParticipantsUserFilter($this->getTestObj()->getRefId());
$selected_users = $filter_closure($this->testrequest->raw('chbUser') ?? []);

if ($selected_users === []) {
$this->main_tpl->setOnScreenMessage('info', $this->lng->txt("select_one_user"), true);
$this->main_tpl->setOnScreenMessage('info', $this->lng->txt('select_one_user'), true);
}

foreach ($selected_users as $user_id) {
$this->getTestObj()->setClientIP($user_id, $_POST["clientip_" . $user_id]);
$client_ip = $this->testrequest->getStringFromPost('clientip_' . $user_id);

if ($client_ip === '') {
continue;
}

$this->getTestObj()->setClientIP($user_id, $client_ip);
}

$this->ctrl->redirect($this, self::CMD_SHOW);
}

/**
* @throws ilCtrlException
*/
protected function removeParticipantsCmd(): void
{
$filter_closure = $this->participant_access_filter->getManageParticipantsUserFilter($this->getTestObj()->getRefId());
$a_user_ids = $filter_closure((array) $_POST["chbUser"]);

$chb_user = $this->testrequest->getArrayOfIntsFromPost('chbUser');

$a_user_ids = $filter_closure($chb_user);

if (is_array($a_user_ids)) {
foreach ($a_user_ids as $user_id) {
$this->getTestObj()->disinviteUser($user_id);
}
} else {
$this->main_tpl->setOnScreenMessage('info', $this->lng->txt("select_one_user"), true);
$this->main_tpl->setOnScreenMessage('info', $this->lng->txt('select_one_user'), true);
}

$this->ctrl->redirect($this, self::CMD_SHOW);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

declare(strict_types=1);

use ILIAS\Test\RequestDataCollector;

/**
* Class ilTestParticipantsTimeExtensionGUI
*
Expand All @@ -41,7 +43,8 @@ public function __construct(
private illanguage $lng,
private ilDBInterface $db,
private ilGlobalTemplateInterface $main_tpl,
private ilTestParticipantAccessFilterFactory $participant_access_filter
private ilTestParticipantAccessFilterFactory $participant_access_filter,
private RequestDataCollector $testrequest
) {
}

Expand Down Expand Up @@ -193,8 +196,16 @@ protected function buildTimingForm(): ilPropertyFormGUI
$extratime->setSize(5);
$form->addItem($extratime);

if (is_array($_POST) && isset($_POST['cmd']['timing']) && $_POST['cmd']['timing'] != '') {
$form->setValuesByArray($_POST);
$cmd = $this->testrequest->getArrayOfStringsFromPost('cmd');

if (isset($cmd['timing']) && $cmd['timing'] !== '') {
$values = [];

foreach ($this->testrequest->getPostKeys() as $key) {
$values[$key] = $this->testrequest->getArrayOfStringsOrStringFromPost($key);
}

$form->setValuesByArray($values);
}

$form->addCommandButton(self::CMD_SET_TIMING, $this->lng->txt("save"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,12 @@ private function showPasswordFormCmd(): void
);
}

/**
* @throws ilCtrlException
*/
private function saveEnteredPasswordCmd(): void
{
$this->password_checker->setUserEnteredPassword($_POST["password"]);
$this->password_checker->setUserEnteredPassword($this->testrequest->getStringFromPost('password'));

if (!$this->password_checker->isUserEnteredPasswordCorrect()) {
$this->password_checker->logWrongEnteredPassword();
Expand Down
Loading

0 comments on commit a3bcf0c

Please sign in to comment.