diff --git a/app/V1Module/presenters/AssignmentsPresenter.php b/app/V1Module/presenters/AssignmentsPresenter.php index a79e4b20..c3a15880 100644 --- a/app/V1Module/presenters/AssignmentsPresenter.php +++ b/app/V1Module/presenters/AssignmentsPresenter.php @@ -215,6 +215,8 @@ public function checkUpdateDetail(string $id) * description="Date from which this assignment will be visible to students") * @Param(type="post", name="canViewLimitRatios", validation="bool", * description="Can all users view ratio of theirs solution memory and time usages and assignment limits?") + * @Param(type="post", name="canViewMeasuredValues", validation="bool", + * description="Can all users view absolute memory and time values?") * @Param(type="post", name="canViewJudgeStdout", validation="bool", * description="Can all users view judge primary log (stdout) of theirs solution?") * @Param(type="post", name="canViewJudgeStderr", validation="bool", @@ -347,6 +349,10 @@ public function actionUpdateDetail(string $id) $assignment->setAllowSecondDeadline($allowSecondDeadline); $assignment->setMaxPointsDeadlineInterpolation($maxPointsDeadlineInterpolation); $assignment->setCanViewLimitRatios(filter_var($req->getPost("canViewLimitRatios"), FILTER_VALIDATE_BOOLEAN)); + $assignment->setCanViewMeasuredValues(filter_var( + $req->getPost("canViewMeasuredValues"), + FILTER_VALIDATE_BOOLEAN + )); $assignment->setCanViewJudgeStdout(filter_var($req->getPost("canViewJudgeStdout"), FILTER_VALIDATE_BOOLEAN)); $assignment->setCanViewJudgeStderr(filter_var($req->getPost("canViewJudgeStderr"), FILTER_VALIDATE_BOOLEAN)); $assignment->setIsBonus(filter_var($req->getPost("isBonus"), FILTER_VALIDATE_BOOLEAN)); diff --git a/app/V1Module/security/Policies/AssignmentSolutionPermissionPolicy.php b/app/V1Module/security/Policies/AssignmentSolutionPermissionPolicy.php index b6182ef2..e2637311 100644 --- a/app/V1Module/security/Policies/AssignmentSolutionPermissionPolicy.php +++ b/app/V1Module/security/Policies/AssignmentSolutionPermissionPolicy.php @@ -75,6 +75,11 @@ public function areEvaluationDetailsPublic(Identity $identity, AssignmentSolutio return $solution->getAssignment() && $solution->getAssignment()->getCanViewLimitRatios(); } + public function areMeasuredValuesPublic(Identity $identity, AssignmentSolution $solution) + { + return $solution->getAssignment() && $solution->getAssignment()->getCanViewMeasuredValues(); + } + public function areJudgeStdoutsPublic(Identity $identity, AssignmentSolution $solution) { return $solution->getAssignment() && $solution->getAssignment()->getCanViewJudgeStdout(); diff --git a/app/config/permissions.neon b/app/config/permissions.neon index ff836165..9d4e3cfe 100644 --- a/app/config/permissions.neon +++ b/app/config/permissions.neon @@ -586,6 +586,17 @@ permissions: - assignmentSolution.isAuthor - assignmentSolution.userIsNotLockedElsewhereStrictly + - allow: true + role: student + resource: assignmentSolution + actions: + - viewEvaluationValues + conditions: + - assignmentSolution.areEvaluationDetailsPublic + - assignmentSolution.areMeasuredValuesPublic + - assignmentSolution.isAuthor + - assignmentSolution.userIsNotLockedElsewhereStrictly + - allow: true role: supervisor-student resource: assignmentSolution diff --git a/app/model/entity/Assignment.php b/app/model/entity/Assignment.php index 6a717290..ae6dd1bd 100644 --- a/app/model/entity/Assignment.php +++ b/app/model/entity/Assignment.php @@ -34,6 +34,7 @@ private function __construct( DateTime $secondDeadline = null, int $maxPointsBeforeSecondDeadline = 0, bool $canViewLimitRatios = false, + bool $canViewMeasuredValues = false, bool $isBonus = false, $pointsPercentualThreshold = 0, ?DateTime $visibleFrom = null, @@ -62,6 +63,7 @@ private function __construct( $this->localizedTexts = new ArrayCollection($exercise->getLocalizedTexts()->toArray()); $this->localizedAssignments = new ArrayCollection(); $this->canViewLimitRatios = $canViewLimitRatios; + $this->canViewMeasuredValues = $canViewMeasuredValues; $this->canViewJudgeStdout = $canViewJudgeStdout; $this->canViewJudgeStderr = $canViewJudgeStderr; $this->mergeJudgeLogs = $exercise->getMergeJudgeLogs(); @@ -254,23 +256,31 @@ public function hasAssignedPoints(): bool /** * @ORM\Column(type="boolean") + * Whether a student can see the relative consumed time and memory (for each test). */ - protected $canViewLimitRatios; + protected $canViewLimitRatios = false; /** * @ORM\Column(type="boolean") + * Whether a student can see the absolute values of consumed time and memory (for each test). + * This only applies if $canViewLimitRatios is true. */ - protected $canViewJudgeStdout; + protected $canViewMeasuredValues = false; /** * @ORM\Column(type="boolean") */ - protected $canViewJudgeStderr; + protected $canViewJudgeStdout = false; /** * @ORM\Column(type="boolean") */ - protected $mergeJudgeLogs; + protected $canViewJudgeStderr = false; + + /** + * @ORM\Column(type="boolean") + */ + protected $mergeJudgeLogs = false; /** * @ORM\Column(type="boolean") @@ -578,6 +588,16 @@ public function setCanViewLimitRatios(bool $canViewLimitRatios): void $this->canViewLimitRatios = $canViewLimitRatios; } + public function getCanViewMeasuredValues(): bool + { + return $this->canViewMeasuredValues; + } + + public function setCanViewMeasuredValues(bool $canViewMeasuredValues): void + { + $this->canViewMeasuredValues = $canViewMeasuredValues; + } + public function getFirstDeadline(): DateTime { return $this->firstDeadline; diff --git a/app/model/view/AssignmentViewFactory.php b/app/model/view/AssignmentViewFactory.php index 4ad79b45..a63923ac 100644 --- a/app/model/view/AssignmentViewFactory.php +++ b/app/model/view/AssignmentViewFactory.php @@ -62,6 +62,7 @@ function (LocalizedExercise $text) use ($assignment) { "runtimeEnvironmentIds" => $assignment->getAllRuntimeEnvironmentsIds(), "disabledRuntimeEnvironmentIds" => $assignment->getDisabledRuntimeEnvironmentsIds(), "canViewLimitRatios" => $assignment->getCanViewLimitRatios(), + "canViewMeasuredValues" => $assignment->getCanViewMeasuredValues(), "canViewJudgeStdout" => $assignment->getCanViewJudgeStdout(), "canViewJudgeStderr" => $assignment->getCanViewJudgeStderr(), "mergeJudgeLogs" => $assignment->getMergeJudgeLogs(), diff --git a/tests/Presenters/AssignmentsPresenter.phpt b/tests/Presenters/AssignmentsPresenter.phpt index 7d0a11fd..a8a00529 100644 --- a/tests/Presenters/AssignmentsPresenter.phpt +++ b/tests/Presenters/AssignmentsPresenter.phpt @@ -153,6 +153,7 @@ class TestAssignmentsPresenter extends Tester\TestCase $submissionsCountLimit = 32; $allowSecondDeadline = true; $canViewLimitRatios = false; + $canViewMeasuredValues = false; $canViewJudgeStdout = true; $canViewJudgeStderr = false; $secondDeadline = (new DateTime())->getTimestamp() + 10; @@ -177,6 +178,7 @@ class TestAssignmentsPresenter extends Tester\TestCase 'allowSecondDeadline' => $allowSecondDeadline, 'maxPointsDeadlineInterpolation' => false, 'canViewLimitRatios' => $canViewLimitRatios, + 'canViewMeasuredValues' => $canViewMeasuredValues, 'canViewJudgeStdout' => $canViewJudgeStdout, 'canViewJudgeStderr' => $canViewJudgeStderr, 'secondDeadline' => $secondDeadline, @@ -203,6 +205,7 @@ class TestAssignmentsPresenter extends Tester\TestCase Assert::equal($submissionsCountLimit, $updatedAssignment["submissionsCountLimit"]); Assert::equal($allowSecondDeadline, $updatedAssignment["allowSecondDeadline"]); Assert::equal($canViewLimitRatios, $updatedAssignment["canViewLimitRatios"]); + Assert::equal($canViewMeasuredValues, $updatedAssignment["canViewMeasuredValues"]); Assert::equal($canViewJudgeStdout, $updatedAssignment["canViewJudgeStdout"]); Assert::equal($canViewJudgeStderr, $updatedAssignment["canViewJudgeStderr"]); Assert::equal($secondDeadline, $updatedAssignment["secondDeadline"]); @@ -256,6 +259,7 @@ class TestAssignmentsPresenter extends Tester\TestCase 'allowSecondDeadline' => false, 'maxPointsDeadlineInterpolation' => true, 'canViewLimitRatios' => false, + 'canViewMeasuredValues' => false, 'canViewJudgeStdout' => false, 'canViewJudgeStderr' => false, 'isBonus' => false, @@ -308,6 +312,7 @@ class TestAssignmentsPresenter extends Tester\TestCase $submissionsCountLimit = 32; $allowSecondDeadline = true; $canViewLimitRatios = false; + $canViewMeasuredValues = false; $canViewJudgeStdout = true; $canViewJudgeStderr = false; $secondDeadline = (new DateTime())->getTimestamp() + 1000; @@ -333,6 +338,7 @@ class TestAssignmentsPresenter extends Tester\TestCase 'allowSecondDeadline' => $allowSecondDeadline, 'maxPointsDeadlineInterpolation' => false, 'canViewLimitRatios' => $canViewLimitRatios, + 'canViewMeasuredValues' => $canViewMeasuredValues, 'canViewJudgeStdout' => $canViewJudgeStdout, 'canViewJudgeStderr' => $canViewJudgeStderr, 'secondDeadline' => $secondDeadline, @@ -359,6 +365,7 @@ class TestAssignmentsPresenter extends Tester\TestCase Assert::equal($submissionsCountLimit, $updatedAssignment["submissionsCountLimit"]); Assert::equal($allowSecondDeadline, $updatedAssignment["allowSecondDeadline"]); Assert::equal($canViewLimitRatios, $updatedAssignment["canViewLimitRatios"]); + Assert::equal($canViewMeasuredValues, $updatedAssignment["canViewMeasuredValues"]); Assert::equal($canViewJudgeStdout, $updatedAssignment["canViewJudgeStdout"]); Assert::equal($canViewJudgeStderr, $updatedAssignment["canViewJudgeStderr"]); Assert::equal($secondDeadline, $updatedAssignment["secondDeadline"]); @@ -402,6 +409,7 @@ class TestAssignmentsPresenter extends Tester\TestCase 'allowSecondDeadline' => true, 'maxPointsDeadlineInterpolation' => true, 'canViewLimitRatios' => false, + 'canViewMeasuredValues' => false, 'canViewJudgeStdout' => false, 'canViewJudgeStderr' => false, 'secondDeadline' => (new DateTime())->getTimestamp() + 10, @@ -448,6 +456,7 @@ class TestAssignmentsPresenter extends Tester\TestCase 'allowSecondDeadline' => true, 'maxPointsDeadlineInterpolation' => false, 'canViewLimitRatios' => false, + 'canViewMeasuredValues' => false, 'canViewJudgeStdout' => false, 'canViewJudgeStderr' => false, 'secondDeadline' => (new DateTime())->getTimestamp() + 10, @@ -467,6 +476,55 @@ class TestAssignmentsPresenter extends Tester\TestCase Assert::true(in_array($disabledEnv->getId(), $updatedAssignment["runtimeEnvironmentIds"])); } + public function testSetVisibilityFlags() + { + PresenterTestHelper::loginDefaultAdmin($this->container); + + $assignments = $this->assignments->findAll(); + /** @var Assignment $assignment */ + $assignment = array_pop($assignments); + + $payload = PresenterTestHelper::performPresenterRequest( + $this->presenter, + 'V1:Assignments', + 'POST', + ['action' => 'updateDetail', 'id' => $assignment->getId()], + [ + 'isPublic' => true, + 'version' => 1, + 'localizedTexts' => [ + ["locale" => "locA", "text" => "descA", "name" => "nameA"] + ], + 'firstDeadline' => (new DateTime())->getTimestamp(), + 'maxPointsBeforeFirstDeadline' => 123, + 'submissionsCountLimit' => 32, + 'allowSecondDeadline' => true, + 'maxPointsDeadlineInterpolation' => false, + 'canViewLimitRatios' => true, + 'canViewMeasuredValues' => true, + 'canViewJudgeStdout' => true, + 'canViewJudgeStderr' => true, + 'secondDeadline' => (new DateTime())->getTimestamp() + 10, + 'maxPointsBeforeSecondDeadline' => 543, + 'isBonus' => true, + 'pointsPercentualThreshold' => 90.0, + 'solutionFilesLimit' => null, + 'solutionSizeLimit' => null, + 'isExam' => false, + ] + ); + + Assert::true($payload["canViewLimitRatios"]); + Assert::true($payload["canViewMeasuredValues"]); + Assert::true($payload["canViewJudgeStdout"]); + Assert::true($payload["canViewJudgeStderr"]); + $this->presenter->assignments->refresh($assignment); + Assert::true($assignment->getCanViewLimitRatios()); + Assert::true($assignment->getCanViewMeasuredValues()); + Assert::true($assignment->getCanViewJudgeStdout()); + Assert::true($assignment->getCanViewJudgeStderr()); + } + public function testSetExamFlag() { PresenterTestHelper::loginDefaultAdmin($this->container); @@ -492,6 +550,7 @@ class TestAssignmentsPresenter extends Tester\TestCase 'allowSecondDeadline' => true, 'maxPointsDeadlineInterpolation' => false, 'canViewLimitRatios' => false, + 'canViewMeasuredValues' => false, 'canViewJudgeStdout' => false, 'canViewJudgeStderr' => false, 'secondDeadline' => (new DateTime())->getTimestamp() + 10, @@ -538,6 +597,7 @@ class TestAssignmentsPresenter extends Tester\TestCase 'allowSecondDeadline' => true, 'maxPointsDeadlineInterpolation' => false, 'canViewLimitRatios' => false, + 'canViewMeasuredValues' => false, 'canViewJudgeStdout' => false, 'canViewJudgeStderr' => false, 'secondDeadline' => (new DateTime())->getTimestamp() + 10,