Skip to content
This repository was archived by the owner on Oct 15, 2025. It is now read-only.

Commit 9441b7f

Browse files
committed
feat: Email Delivery Event, admin and preview page
1 parent 82f76ce commit 9441b7f

15 files changed

+404
-180
lines changed

migrations/Version20241202060920.php

Lines changed: 0 additions & 61 deletions
This file was deleted.
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace DoctrineMigrations;
6+
7+
use Doctrine\DBAL\Schema\Schema;
8+
use Doctrine\Migrations\AbstractMigration;
9+
10+
/**
11+
* Auto-generated Migration: Please modify to your needs!
12+
*/
13+
final class Version20241204160558 extends AbstractMigration
14+
{
15+
public function getDescription(): string
16+
{
17+
return 'Email and Email Delivery Event';
18+
}
19+
20+
public function up(Schema $schema): void
21+
{
22+
// this up() migration is auto-generated, please modify it to your needs
23+
$this->addSql(<<<'SQL'
24+
CREATE SEQUENCE email_id_seq INCREMENT BY 1 MINVALUE 1 START 1
25+
SQL);
26+
$this->addSql(<<<'SQL'
27+
CREATE TABLE email (
28+
id INT NOT NULL,
29+
subject VARCHAR(4096) NOT NULL,
30+
content TEXT NOT NULL,
31+
kind VARCHAR(255) NOT NULL,
32+
PRIMARY KEY(id)
33+
)
34+
SQL);
35+
$this->addSql(<<<'SQL'
36+
CREATE TABLE email_delivery_event (
37+
id UUID NOT NULL,
38+
to_user_id INT DEFAULT NULL,
39+
email_id INT NOT NULL,
40+
created_at TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL,
41+
to_address VARCHAR(512) NOT NULL,
42+
PRIMARY KEY(id)
43+
)
44+
SQL);
45+
$this->addSql(<<<'SQL'
46+
CREATE INDEX IDX_F35AF0FC29F6EE60 ON email_delivery_event (to_user_id)
47+
SQL);
48+
$this->addSql(<<<'SQL'
49+
CREATE INDEX IDX_F35AF0FCA832C1C9 ON email_delivery_event (email_id)
50+
SQL);
51+
$this->addSql(<<<'SQL'
52+
COMMENT ON COLUMN email_delivery_event.id IS '(DC2Type:ulid)'
53+
SQL);
54+
$this->addSql(<<<'SQL'
55+
COMMENT ON COLUMN email_delivery_event.created_at IS '(DC2Type:datetime_immutable)'
56+
SQL);
57+
$this->addSql(<<<'SQL'
58+
ALTER TABLE
59+
email_delivery_event
60+
ADD
61+
CONSTRAINT FK_F35AF0FC29F6EE60 FOREIGN KEY (to_user_id) REFERENCES "user" (id) NOT DEFERRABLE INITIALLY IMMEDIATE
62+
SQL);
63+
$this->addSql(<<<'SQL'
64+
ALTER TABLE
65+
email_delivery_event
66+
ADD
67+
CONSTRAINT FK_F35AF0FCA832C1C9 FOREIGN KEY (email_id) REFERENCES email (id) NOT DEFERRABLE INITIALLY IMMEDIATE
68+
SQL);
69+
}
70+
71+
public function down(Schema $schema): void
72+
{
73+
// this down() migration is auto-generated, please modify it to your needs
74+
$this->addSql(<<<'SQL'
75+
DROP SEQUENCE email_id_seq CASCADE
76+
SQL);
77+
$this->addSql(<<<'SQL'
78+
ALTER TABLE email_delivery_event DROP CONSTRAINT FK_F35AF0FC29F6EE60
79+
SQL);
80+
$this->addSql(<<<'SQL'
81+
ALTER TABLE email_delivery_event DROP CONSTRAINT FK_F35AF0FCA832C1C9
82+
SQL);
83+
$this->addSql(<<<'SQL'
84+
DROP TABLE email
85+
SQL);
86+
$this->addSql(<<<'SQL'
87+
DROP TABLE email_delivery_event
88+
SQL);
89+
}
90+
}

src/Controller/Admin/DashboardController.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
use App\Entity\Announcement;
88
use App\Entity\Comment;
99
use App\Entity\CommentLikeEvent;
10-
use App\Entity\EmailEvent;
10+
use App\Entity\Email;
11+
use App\Entity\EmailDeliveryEvent;
1112
use App\Entity\Feedback;
1213
use App\Entity\Group;
1314
use App\Entity\HintOpenEvent;
@@ -64,12 +65,15 @@ public function configureMenuItems(): iterable
6465
yield MenuItem::linkToCrud('Comment', 'fa fa-comment', Comment::class);
6566
yield MenuItem::linkToCrud('CommentLikeEvent', 'fa fa-thumbs-up', CommentLikeEvent::class);
6667

68+
yield MenuItem::section('Mails');
69+
yield MenuItem::linkToCrud('Email', 'fa fa-envelope', Email::class);
70+
yield MenuItem::linkToCrud('EmailDeliveryEvent', 'fa fa-paper-plane', EmailDeliveryEvent::class);
71+
6772
yield MenuItem::section('Events');
6873
yield MenuItem::linkToCrud('SolutionEvent', 'fa fa-check', SolutionEvent::class);
6974
yield MenuItem::linkToCrud('SolutionVideoEvent', 'fa fa-video', SolutionVideoEvent::class);
7075
yield MenuItem::linkToCrud('HintOpenEvent', 'fa fa-lightbulb', HintOpenEvent::class);
7176
yield MenuItem::linkToCrud('LoginEvent', 'fa fa-right-to-bracket', LoginEvent::class);
72-
yield MenuItem::linkToCrud('EmailEvent', 'fa fa-envelope', EmailEvent::class);
7377

7478
yield MenuItem::section('Feedback');
7579
yield MenuItem::linkToCrud('Feedback', 'fa fa-comments', Feedback::class);
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Controller\Admin;
6+
7+
use App\Entity\Email;
8+
use App\Entity\EmailKind;
9+
use EasyCorp\Bundle\EasyAdminBundle\Config\Filters;
10+
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractCrudController;
11+
use EasyCorp\Bundle\EasyAdminBundle\Field\ChoiceField;
12+
use EasyCorp\Bundle\EasyAdminBundle\Field\IdField;
13+
use EasyCorp\Bundle\EasyAdminBundle\Field\TextEditorField;
14+
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
15+
use EasyCorp\Bundle\EasyAdminBundle\Filter\ChoiceFilter;
16+
17+
class EmailCrudController extends AbstractCrudController
18+
{
19+
public static function getEntityFqcn(): string
20+
{
21+
return Email::class;
22+
}
23+
24+
public function configureFields(string $pageName): iterable
25+
{
26+
return [
27+
IdField::new('id')->hideOnForm(),
28+
TextField::new('subject'),
29+
TextEditorField::new('content'),
30+
ChoiceField::new('kind'),
31+
];
32+
}
33+
34+
public function configureFilters(Filters $filters): Filters
35+
{
36+
return $filters->add(ChoiceFilter::new('kind')->setTranslatableChoices([
37+
'email-kind.transactional' => EmailKind::Transactional,
38+
'email-kind.marketing' => EmailKind::Marketing,
39+
]));
40+
}
41+
}

src/Controller/Admin/EmailEventCrudController.php renamed to src/Controller/Admin/EmailDeliveryEventCrudController.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace App\Controller\Admin;
66

7-
use App\Entity\EmailEvent;
7+
use App\Entity\EmailDeliveryEvent;
88
use EasyCorp\Bundle\EasyAdminBundle\Config\Action;
99
use EasyCorp\Bundle\EasyAdminBundle\Config\Actions;
1010
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
@@ -13,14 +13,13 @@
1313
use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
1414
use EasyCorp\Bundle\EasyAdminBundle\Field\DateTimeField;
1515
use EasyCorp\Bundle\EasyAdminBundle\Field\IdField;
16-
use EasyCorp\Bundle\EasyAdminBundle\Field\TextEditorField;
1716
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
1817

19-
class EmailEventCrudController extends AbstractCrudController
18+
class EmailDeliveryEventCrudController extends AbstractCrudController
2019
{
2120
public static function getEntityFqcn(): string
2221
{
23-
return EmailEvent::class;
22+
return EmailDeliveryEvent::class;
2423
}
2524

2625
public function configureFields(string $pageName): iterable
@@ -29,8 +28,7 @@ public function configureFields(string $pageName): iterable
2928
IdField::new('id')->hideOnIndex()->setDisabled(),
3029
AssociationField::new('toUser'),
3130
TextField::new('toAddress')->hideOnIndex(),
32-
TextField::new('subject'),
33-
TextEditorField::new('content'),
31+
AssociationField::new('email'),
3432
DateTimeField::new('createdAt', 'Created at')->setDisabled(),
3533
];
3634
}
@@ -45,13 +43,13 @@ public function configureFilters(Filters $filters): Filters
4543
public function configureActions(Actions $actions): Actions
4644
{
4745
$previewAction = Action::new('preview', 'Preview', 'fa fa-eye')
48-
->linkToUrl(fn (EmailEvent $entity) => $this->generateUrl(
46+
->linkToUrl(fn (EmailDeliveryEvent $entity) => $this->generateUrl(
4947
'app_email_preview',
5048
['id' => $entity->getId()]
5149
));
5250

5351
return $actions
54-
->disable(Action::DELETE, Action::EDIT, Action::NEW)
52+
// ->disable(Action::DELETE, Action::EDIT, Action::NEW)
5553
->add(Crud::PAGE_INDEX, Action::DETAIL)
5654
->add(Crud::PAGE_INDEX, $previewAction)
5755
->add(Crud::PAGE_DETAIL, $previewAction);

src/Controller/EmailController.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace App\Controller;
66

7-
use App\Entity\EmailEvent;
7+
use App\Entity\EmailDeliveryEvent;
88
use App\Entity\User;
99
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
1010
use Symfony\Component\HttpFoundation\Response;
@@ -14,16 +14,16 @@
1414
class EmailController extends AbstractController
1515
{
1616
#[Route('/email/{id}', name: 'app_email_preview')]
17-
public function details(#[CurrentUser] User $user, EmailEvent $emailEvent): Response
17+
public function details(#[CurrentUser] User $user, EmailDeliveryEvent $emailDeliveryEvent): Response
1818
{
1919
// if this email is not owned by the current user and the user is not an admin,
2020
// we deny the access.
21-
if ($emailEvent->getToUser() !== $user && !$this->isGranted('ROLE_ADMIN')) {
21+
if ($emailDeliveryEvent->getToUser() !== $user && !$this->isGranted('ROLE_ADMIN')) {
2222
throw $this->createAccessDeniedException('You are not authorized to access this email.');
2323
}
2424

2525
return $this->render('email/preview.html.twig', [
26-
'email' => $emailEvent,
26+
'emailDeliveryEvent' => $emailDeliveryEvent,
2727
]);
2828
}
2929
}

0 commit comments

Comments
 (0)