Skip to content

Commit d9e0c76

Browse files
Add display classes for maintainer added/removed records
1 parent 6b7b102 commit d9e0c76

File tree

5 files changed

+104
-0
lines changed

5 files changed

+104
-0
lines changed

src/Audit/Display/AuditLogDisplayFactory.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,18 @@ public function build(iterable $auditRecords): array
3434
public function buildSingle(AuditRecord $record): AuditLogDisplayInterface
3535
{
3636
return match ($record->type) {
37+
AuditRecordType::MaintainerAdded => new MaintainerAddedDisplay(
38+
$record->datetime,
39+
$record->attributes['name'],
40+
$this->buildActor($record->attributes['maintainer']),
41+
$this->buildActor($record->attributes['actor']),
42+
),
43+
AuditRecordType::MaintainerRemoved => new MaintainerRemovedDisplay(
44+
$record->datetime,
45+
$record->attributes['name'],
46+
$this->buildActor($record->attributes['maintainer']),
47+
$this->buildActor($record->attributes['actor']),
48+
),
3749
AuditRecordType::PackageCreated => new PackageCreatedDisplay(
3850
$record->datetime,
3951
$record->attributes['name'],
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php declare(strict_types=1);
2+
3+
/*
4+
* This file is part of Packagist.
5+
*
6+
* (c) Jordi Boggiano <[email protected]>
7+
* Nils Adermann <[email protected]>
8+
*
9+
* For the full copyright and license information, please view the LICENSE
10+
* file that was distributed with this source code.
11+
*/
12+
13+
namespace App\Audit\Display;
14+
15+
use App\Audit\AuditRecordType;
16+
17+
readonly class MaintainerAddedDisplay extends AbstractAuditLogDisplay
18+
{
19+
public function __construct(
20+
\DateTimeImmutable $datetime,
21+
public string $packageName,
22+
public ActorDisplay $maintainer,
23+
ActorDisplay $actor,
24+
) {
25+
parent::__construct($datetime, $actor);
26+
}
27+
28+
public function getType(): AuditRecordType
29+
{
30+
return AuditRecordType::MaintainerAdded;
31+
}
32+
33+
public function getTemplateName(): string
34+
{
35+
return 'audit_log/display/maintainer_added.html.twig';
36+
}
37+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php declare(strict_types=1);
2+
3+
/*
4+
* This file is part of Packagist.
5+
*
6+
* (c) Jordi Boggiano <[email protected]>
7+
* Nils Adermann <[email protected]>
8+
*
9+
* For the full copyright and license information, please view the LICENSE
10+
* file that was distributed with this source code.
11+
*/
12+
13+
namespace App\Audit\Display;
14+
15+
use App\Audit\AuditRecordType;
16+
17+
readonly class MaintainerRemovedDisplay extends AbstractAuditLogDisplay
18+
{
19+
public function __construct(
20+
\DateTimeImmutable $datetime,
21+
public string $packageName,
22+
public ActorDisplay $maintainer,
23+
ActorDisplay $actor,
24+
) {
25+
parent::__construct($datetime, $actor);
26+
}
27+
28+
public function getType(): AuditRecordType
29+
{
30+
return AuditRecordType::MaintainerRemoved;
31+
}
32+
33+
public function getTemplateName(): string
34+
{
35+
return 'audit_log/display/maintainer_removed.html.twig';
36+
}
37+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<strong>
2+
{%- if display.packageName is existing_package -%}
3+
<a href="{{ path('view_package', { 'name': display.packageName }) }}">{{ display.packageName }}</a>
4+
{%- else -%}
5+
{{ display.packageName }}
6+
{%- endif -%}
7+
</strong><br>
8+
Maintainer: {{ display.maintainer.username }}<br>
9+
Added by: {{ display.actor.username }}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<strong>
2+
{%- if display.packageName is existing_package -%}
3+
<a href="{{ path('view_package', { 'name': display.packageName }) }}">{{ display.packageName }}</a>
4+
{%- else -%}
5+
{{ display.packageName }}
6+
{%- endif -%}
7+
</strong><br>
8+
Maintainer: {{ display.maintainer.username }}<br>
9+
Removed by: {{ display.actor.username }}

0 commit comments

Comments
 (0)