diff --git a/CHANGELOG.md b/CHANGELOG.md index 0769603..8194ef4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,11 @@ See [keep a changelog] for information about writing changes to this log. ## [Unreleased] +## [3.0.1] - 2025-06-23 + +* [PR-34](https://github.com/itk-dev/sysstatus/pull/34) + 4767: Fixed handling of context for new questions + ## [3.0.0] - 2025-06-13 * [PR-33](https://github.com/itk-dev/sysstatus/pull/33) @@ -158,5 +163,6 @@ See [keep a changelog] for information about writing changes to this log. [keep a changelog]: https://keepachangelog.com/en/1.1.0/ [Unreleased]: https://github.com/itk-dev/sysstatus/compare/main...develop +[3.0.1]: https://github.com/itk-dev/sysstatus/releases/tag/3.0.1 [3.0.0]: https://github.com/itk-dev/sysstatus/releases/tag/3.0.0 [2.1.0]: https://github.com/itk-dev/sysstatus/releases/tag/2.1.0 diff --git a/src/Controller/Admin/AnswerCrudController.php b/src/Controller/Admin/AnswerCrudController.php index a6f62ff..dc54bb4 100644 --- a/src/Controller/Admin/AnswerCrudController.php +++ b/src/Controller/Admin/AnswerCrudController.php @@ -4,6 +4,7 @@ use App\Entity\Answer; use App\Entity\Question; +use App\Entity\Report; use App\Entity\System; use Doctrine\ORM\EntityManagerInterface; use EasyCorp\Bundle\EasyAdminBundle\Config\Action; @@ -59,24 +60,28 @@ protected function getRedirectResponseAfterSave(AdminContext $context, string $a #[\Override] public function createEntity(string $entityFqcn): Answer { - /** @var Answer $entity */ - $entity = parent::createEntity($entityFqcn); - - // Set system and question on new answers. + // Set question and report OR system on new answers. $params = $this->getContext()->getRequest()->query->all(); - if (isset($params['system'], $params['question'])) { - $system = $this->entityManager->getRepository(System::class)->find($params['system']); - $question = $this->entityManager->getRepository(Question::class)->find($params['question']); - if ($system && $question) { - $entity - ->setSystem($system) - ->setQuestion($question); - } else { - throw new BadRequestHttpException(); - } + // Question is required. + $question = isset($params['question']) ? $this->entityManager->getRepository(Question::class)->find($params['question']) : null; + if (null === $question) { + throw new BadRequestHttpException('Missing or invalid question'); } + // One of report or system is required. + $report = isset($params['report']) ? $this->entityManager->getRepository(Report::class)->find($params['report']) : null; + $system = isset($params['system']) ? $this->entityManager->getRepository(System::class)->find($params['system']) : null; + + if (null === $report && null === $system) { + throw new BadRequestHttpException('Either report or system must be set'); + } + + /** @var Answer $entity */ + $entity = parent::createEntity($entityFqcn); - return $entity; + return $entity + ->setQuestion($question) + ->setReport($report) + ->setSystem($system); } #[\Override] diff --git a/templates/easy_admin_overrides/answers_show.html.twig b/templates/easy_admin_overrides/answers_show.html.twig index 552b5d6..5b4236c 100644 --- a/templates/easy_admin_overrides/answers_show.html.twig +++ b/templates/easy_admin_overrides/answers_show.html.twig @@ -50,7 +50,8 @@