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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [#68](https://github.com/itk-dev/devops_itksites/pull/68)
6667: Update advisories on Detailed site display

- [#68](https://github.com/itk-dev/devops_itksites/pull/68)
6667: Show sites affected on advisories.

## [1.9.2] - 2026-04-07

- [#67](https://github.com/itk-dev/devops_itksites/pull/67)
Expand Down
22 changes: 22 additions & 0 deletions src/Admin/Field/AffectedSitesField.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace App\Admin\Field;

use EasyCorp\Bundle\EasyAdminBundle\Contracts\Field\FieldInterface;
use EasyCorp\Bundle\EasyAdminBundle\Field\FieldTrait;
use Symfony\Contracts\Translation\TranslatableInterface;

class AffectedSitesField implements FieldInterface
{
use FieldTrait;

public static function new(string $propertyName, TranslatableInterface|string|bool|null $label = null): self
{
return new self()
->setProperty($propertyName)
->setLabel($label)
->setTemplatePath('EasyAdminBundle/Fields/affected_sites.html.twig');
}
}
2 changes: 2 additions & 0 deletions src/Controller/Admin/AdvisoryCrudController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\Controller\Admin;

use App\Admin\Field\AffectedSitesField;
use App\Admin\Field\SourcesField;
use App\Admin\Field\TextMonospaceField;
use App\Entity\Advisory;
Expand Down Expand Up @@ -58,6 +59,7 @@ public function configureFields(string $pageName): iterable
yield DateField::new('reportedAt')->setColumns(6)->onlyOnIndex();
yield DateTimeField::new('reportedAt')->setColumns(6)->onlyOnDetail();
yield SourcesField::new('sourceLinks')->setColumns(6)->onlyOnDetail();
yield AffectedSitesField::new('sites')->setLabel('Affected Sites');
}

#[\Override]
Expand Down
17 changes: 17 additions & 0 deletions src/Entity/Advisory.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,23 @@ public function removePackageVersion(PackageVersion $packageVersion): self
return $this;
}

/**
* @return Collection<int, Site>
*/
public function getSites(): Collection
{
$sites = [];
foreach ($this->packageVersions as $packageVersion) {
foreach ($packageVersion->getInstallations() as $installation) {
foreach ($installation->getSites() as $site) {
$sites[$site->getId()->toRfc4122()] = $site;
}
}
}

return new ArrayCollection(array_values($sites));
Comment on lines +198 to +207
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$sites = [];
foreach ($this->packageVersions as $packageVersion) {
foreach ($packageVersion->getInstallations() as $installation) {
foreach ($installation->getSites() as $site) {
$sites[$site->getId()->toRfc4122()] = $site;
}
}
}
return new ArrayCollection(array_values($sites));
$sites = new ArrayCollection();
foreach ($this->packageVersions as $packageVersion) {
foreach ($packageVersion->getInstallations() as $installation) {
foreach ($installation->getSites() as $site) {
if (!$sites->contains($site)) {
$sites->add($site);
}
}
}
}
return $sites;

}

public function getPackage(): ?Package
{
return $this->package;
Expand Down
33 changes: 33 additions & 0 deletions templates/EasyAdminBundle/Fields/affected_sites.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{# @var ea \EasyCorp\Bundle\EasyAdminBundle\Context\AdminContext #}
{# @var field \EasyCorp\Bundle\EasyAdminBundle\Dto\FieldDto #}
{# @var entity \EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDto #}
{% set sites = entity.instance.sites %}
{% if ea().crud.currentAction == 'detail' %}
{% if sites|length > 0 %}
<table class="table table-sm table-borderless">
<thead>
<tr>
<th>Domain</th>
<th>Server</th>
</tr>
</thead>
<tbody>
{% for site in sites %}
{% set url = ea_url()
.unsetAll()
.setController('App\\Controller\\Admin\\SiteCrudController')
.setAction('detail')
.setEntityId(site.id) %}
<tr>
<td><a href="{{ url }}">{{ site.primaryDomain }}</a></td>
<td>{{ site.server }}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% else %}
<span class="text-muted">None</span>
{% endif %}
{% else %}
<span class="badge badge-info">{{ sites|length }}</span>
{% endif %}
Loading