From da7153e0325f8d1b3e37426cf8e5de6d497b0a71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kruli=C5=A1?= Date: Tue, 6 May 2025 13:13:01 +0200 Subject: [PATCH 1/2] Fixing recent exceptions in assignment-solutions presenter (a situation when no best solution exists). --- .../AssignmentSolutionsPresenter.php | 25 +++++++++++-------- recodex-api.spec | 4 +-- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/app/V1Module/presenters/AssignmentSolutionsPresenter.php b/app/V1Module/presenters/AssignmentSolutionsPresenter.php index c2007fc93..54113d0f4 100644 --- a/app/V1Module/presenters/AssignmentSolutionsPresenter.php +++ b/app/V1Module/presenters/AssignmentSolutionsPresenter.php @@ -390,12 +390,12 @@ public function actionSetBonusPoints(string $id) $changedSolutions[] = $this->assignmentSolutionViewFactory->getSolutionData($solution); if ($assignment) { $best = $this->assignmentSolutions->findBestSolution($assignment, $author); - if ($best->getId() !== $oldBest->getId()) { + if (!$best || !$oldBest || $best->getId() !== $oldBest->getId()) { // best solution has changed, we need to report this - if ($best->getId() !== $id) { + if ($best && $best->getId() !== $id) { $changedSolutions[] = $this->assignmentSolutionViewFactory->getSolutionData($best); } - if ($oldBest->getId() !== $id) { + if ($oldBest && $oldBest->getId() !== $id) { $changedSolutions[] = $this->assignmentSolutionViewFactory->getSolutionData($oldBest); } } @@ -498,7 +498,9 @@ public function actionSetFlag(string $id, string $flag) // finally flush all changed to the database $this->assignmentSolutions->flush(); - $this->assignmentSolutions->refresh($oldBestSolution); + if ($oldBestSolution) { + $this->assignmentSolutions->refresh($oldBestSolution); + } // send notification email $notificationMethod = $flag . 'FlagChanged'; @@ -512,7 +514,6 @@ public function actionSetFlag(string $id, string $flag) } // assemble response (all entities and stats that may have changed) - $assignmentId = $solution->getAssignment()->getId(); $groupOfSolution = $solution->getAssignment()->getGroup(); if ($groupOfSolution === null) { throw new NotFoundException("Group for assignment '$id' was not found"); @@ -528,12 +529,16 @@ public function actionSetFlag(string $id, string $flag) $solution->getAssignment(), $solution->getSolution()->getAuthor() ); - if ($oldBestSolution->getId() !== $bestSolution->getId()) { + if (!$oldBestSolution || !$bestSolution || $oldBestSolution->getId() !== $bestSolution->getId()) { // add old and current best solutions as well (since they have changed) - $resSolutions[$oldBestSolution->getId()] = - $this->assignmentSolutionViewFactory->getSolutionData($oldBestSolution); - $resSolutions[$bestSolution->getId()] = - $this->assignmentSolutionViewFactory->getSolutionData($bestSolution); + if ($oldBestSolution) { + $resSolutions[$oldBestSolution->getId()] = + $this->assignmentSolutionViewFactory->getSolutionData($oldBestSolution); + } + if ($bestSolution) { + $resSolutions[$bestSolution->getId()] = + $this->assignmentSolutionViewFactory->getSolutionData($bestSolution); + } } $this->sendSuccessResponse([ diff --git a/recodex-api.spec b/recodex-api.spec index 26a0bddc1..9c5cd7940 100644 --- a/recodex-api.spec +++ b/recodex-api.spec @@ -2,8 +2,8 @@ %define short_name api %define install_dir /opt/%{name} %define version 2.16.1 -%define unmangled_version 9f2e984f03086c228016bc7e420bfa23d8c7e8b9 -%define release 1 +%define unmangled_version 1e145d5253dacbe64a8ed1050883834b05a8deeb +%define release 2 Summary: ReCodEx core API component Name: %{name} From b6c0d2a3c467aeacd51e1ef076aacd64eef783c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kruli=C5=A1?= Date: Sun, 8 Jun 2025 17:46:45 +0200 Subject: [PATCH 2/2] Enabling locked IP addresses in user views for all eligible users. --- app/model/view/UserViewFactory.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/model/view/UserViewFactory.php b/app/model/view/UserViewFactory.php index c3ac97744..6dbe8bd05 100644 --- a/app/model/view/UserViewFactory.php +++ b/app/model/view/UserViewFactory.php @@ -86,7 +86,7 @@ private function getUserData(User $user, bool $canViewPrivate, bool $reallyShowE "isExternal" => $user->hasExternalAccounts(), "isAllowed" => $user->isAllowed(), "externalIds" => $this->getExternalIds($user, $reallyShowEverything), - "ipLock" => $user->isIpLocked(), + "ipLock" => $user->isIpLocked() ? $user->getIpLockRaw() : null, "groupLock" => $user->getGroupLock()?->getId(), "isGroupLockStrict" => $user->isGroupLockStrict(), ]; @@ -96,8 +96,6 @@ private function getUserData(User $user, bool $canViewPrivate, bool $reallyShowE $uiData = $user->getUiData(); $privateData["uiData"] = $uiData ? $uiData->getData() : null; $privateData["settings"] = $user->getSettings(); - // ipLock is replaced with actual IP address - $privateData["ipLock"] = $user->isIpLocked() ? $user->getIpLockRaw() : null; $privateData["ipLockExpiration"] = $user->isIpLocked() ? $user->getIpLockExpiration()?->getTimestamp() : null; $privateData["groupLockExpiration"] = $user->isGroupLocked()