Skip to content
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
35 changes: 20 additions & 15 deletions src/Controller/Admin/AnswerCrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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]
Expand Down
3 changes: 2 additions & 1 deletion templates/easy_admin_overrides/answers_show.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@
<td></td>
<td>
<a href="{{ ea_url({
system: entity.instance.id,
report: 'App\\Entity\\Report' == get_class(entity.instance) ? entity.instance.id : null,
system: 'App\\Entity\\System' == get_class(entity.instance) ? entity.instance.id : null,
question: question.id,
referer,
})
Expand Down
Loading