-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5377bb6
commit 7eb2355
Showing
35 changed files
with
1,123 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DoctrineMigrations; | ||
|
||
use Doctrine\DBAL\Schema\Schema; | ||
use Doctrine\Migrations\AbstractMigration; | ||
|
||
/** | ||
* Auto-generated Migration: Please modify to your needs! | ||
*/ | ||
final class Version20230506160659 extends AbstractMigration | ||
{ | ||
public function getDescription(): string | ||
{ | ||
return ''; | ||
} | ||
|
||
public function up(Schema $schema): void | ||
{ | ||
// this up() migration is auto-generated, please modify it to your needs | ||
$this->addSql( | ||
'CREATE TABLE webhook_repository (webhook_id INT NOT NULL, repository_id INT NOT NULL, INDEX IDX_57821885C9BA60B (webhook_id), ' . | ||
'INDEX IDX_578218850C9D4F7 (repository_id), ' . | ||
'PRIMARY KEY(webhook_id, repository_id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB' | ||
); | ||
$this->addSql( | ||
'ALTER TABLE webhook_repository ADD CONSTRAINT FK_57821885C9BA60B FOREIGN KEY (webhook_id) REFERENCES webhook (id) ON DELETE CASCADE' | ||
); | ||
$this->addSql( | ||
'ALTER TABLE webhook_repository ' . | ||
'ADD CONSTRAINT FK_578218850C9D4F7 FOREIGN KEY (repository_id) REFERENCES repository (id) ON DELETE CASCADE' | ||
); | ||
$this->addSql('ALTER TABLE webhook DROP FOREIGN KEY FK_8A74175650C9D4F7'); | ||
$this->addSql('DROP INDEX IDX_8A74175650C9D4F7 ON webhook'); | ||
$this->addSql('INSERT INTO webhook_repository SELECT `id` AS webhook_id, repository_id FROM webhook'); | ||
$this->addSql('ALTER TABLE webhook DROP repository_id'); | ||
} | ||
|
||
public function down(Schema $schema): void | ||
{ | ||
// this down() migration is auto-generated, please modify it to your needs | ||
$this->addSql('ALTER TABLE webhook_repository DROP FOREIGN KEY FK_57821885C9BA60B'); | ||
$this->addSql('ALTER TABLE webhook_repository DROP FOREIGN KEY FK_578218850C9D4F7'); | ||
$this->addSql('DROP TABLE webhook_repository'); | ||
$this->addSql('ALTER TABLE webhook ADD repository_id INT DEFAULT NULL'); | ||
$this->addSql( | ||
'ALTER TABLE webhook ' . | ||
'ADD CONSTRAINT FK_8A74175650C9D4F7 FOREIGN KEY (repository_id) REFERENCES repository (id) ON UPDATE NO ACTION ON DELETE NO ACTION' | ||
); | ||
$this->addSql('CREATE INDEX IDX_8A74175650C9D4F7 ON webhook (repository_id)'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DoctrineMigrations; | ||
|
||
use Doctrine\DBAL\Schema\Schema; | ||
use Doctrine\Migrations\AbstractMigration; | ||
|
||
/** | ||
* Auto-generated Migration: Please modify to your needs! | ||
*/ | ||
final class Version20230506201821 extends AbstractMigration | ||
{ | ||
public function getDescription(): string | ||
{ | ||
return ''; | ||
} | ||
|
||
public function up(Schema $schema): void | ||
{ | ||
// this up() migration is auto-generated, please modify it to your needs | ||
$this->addSql('CREATE INDEX create_timestamp_idx ON webhook_activity (create_timestamp)'); | ||
} | ||
|
||
public function down(Schema $schema): void | ||
{ | ||
// this down() migration is auto-generated, please modify it to your needs | ||
$this->addSql('DROP INDEX create_timestamp_idx ON webhook_activity'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace DR\Review\Command\Webhook; | ||
|
||
use DR\Review\Repository\Webhook\WebhookActivityRepository; | ||
use Symfony\Component\Console\Attribute\AsCommand; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
#[AsCommand('webhook:cleanup', "Clean up all the webhook activity from 2 weeks and older.")] | ||
class WebhookCleanUpCommand extends Command | ||
{ | ||
public function __construct(private readonly WebhookActivityRepository $activityRepository) | ||
{ | ||
parent::__construct(); | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output): int | ||
{ | ||
$removed = $this->activityRepository->cleanUp(strtotime("-2 weeks")); | ||
|
||
$output->writeln("Removed " . $removed . " webhook activities"); | ||
|
||
return self::SUCCESS; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace DR\Review\Controller\App\Admin; | ||
|
||
use DR\Review\Controller\AbstractController; | ||
use DR\Review\Entity\Webhook\Webhook; | ||
use DR\Review\Repository\Webhook\WebhookRepository; | ||
use DR\Review\Security\Role\Roles; | ||
use DR\Review\ViewModel\App\Admin\EditWebhookViewModel; | ||
use Symfony\Bridge\Doctrine\Attribute\MapEntity; | ||
use Symfony\Component\HttpFoundation\RedirectResponse; | ||
use Symfony\Component\Routing\Annotation\Route; | ||
use Symfony\Component\Security\Http\Attribute\IsGranted; | ||
|
||
class DeleteWebhookController extends AbstractController | ||
{ | ||
public function __construct(private WebhookRepository $webhookRepository) | ||
{ | ||
} | ||
|
||
/** | ||
* @return array<string, EditWebhookViewModel>|RedirectResponse | ||
*/ | ||
#[Route('/app/admin/webhook/{id<\d+>}', self::class, methods: ['DELETE'])] | ||
#[IsGranted(Roles::ROLE_ADMIN)] | ||
public function __invoke(#[MapEntity] Webhook $webhook): array|RedirectResponse | ||
{ | ||
$this->webhookRepository->remove($webhook, true); | ||
|
||
$this->addFlash('success', 'webhook.successful.removed'); | ||
|
||
return $this->refererRedirect(WebhooksController::class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace DR\Review\Controller\App\Admin; | ||
|
||
use DR\Review\Controller\AbstractController; | ||
use DR\Review\Entity\Webhook\Webhook; | ||
use DR\Review\Form\Webhook\EditWebhookFormType; | ||
use DR\Review\Repository\Webhook\WebhookRepository; | ||
use DR\Review\Security\Role\Roles; | ||
use DR\Review\ViewModel\App\Admin\EditWebhookViewModel; | ||
use Symfony\Bridge\Doctrine\Attribute\MapEntity; | ||
use Symfony\Bridge\Twig\Attribute\Template; | ||
use Symfony\Component\HttpFoundation\RedirectResponse; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; | ||
use Symfony\Component\Routing\Annotation\Route; | ||
use Symfony\Component\Security\Http\Attribute\IsGranted; | ||
|
||
class WebhookController extends AbstractController | ||
{ | ||
public function __construct(private WebhookRepository $webhookRepository) | ||
{ | ||
} | ||
|
||
/** | ||
* @return array<string, EditWebhookViewModel>|RedirectResponse | ||
*/ | ||
#[Route('/app/admin/webhook/{id<\d+>?}', self::class, methods: ['GET', 'POST'])] | ||
#[Template('app/admin/edit_webhook.html.twig')] | ||
#[IsGranted(Roles::ROLE_ADMIN)] | ||
public function __invoke(Request $request, #[MapEntity] ?Webhook $webhook): array|RedirectResponse | ||
{ | ||
if ($webhook === null && $request->attributes->get('id') !== null) { | ||
throw new NotFoundHttpException('Webhook not found'); | ||
} | ||
|
||
$webhook ??= (new Webhook())->setEnabled(true)->setRetries(3)->setVerifySsl(true); | ||
|
||
$form = $this->createForm(EditWebhookFormType::class, ['webhook' => $webhook]); | ||
$form->handleRequest($request); | ||
if ($form->isSubmitted() === false || $form->isValid() === false) { | ||
return ['editWebhookModel' => new EditWebhookViewModel($webhook, $form->createView())]; | ||
} | ||
|
||
$this->webhookRepository->save($webhook, true); | ||
|
||
$this->addFlash('success', 'webhook.successful.saved'); | ||
|
||
return $this->redirectToRoute(WebhooksController::class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace DR\Review\Controller\App\Admin; | ||
|
||
use DR\Review\Controller\AbstractController; | ||
use DR\Review\Security\Role\Roles; | ||
use DR\Review\ViewModel\App\Admin\WebhooksViewModel; | ||
use DR\Review\ViewModelProvider\WebhooksViewModelProvider; | ||
use Symfony\Bridge\Twig\Attribute\Template; | ||
use Symfony\Component\Routing\Annotation\Route; | ||
use Symfony\Component\Security\Http\Attribute\IsGranted; | ||
|
||
class WebhooksController extends AbstractController | ||
{ | ||
public function __construct(private readonly WebhooksViewModelProvider $viewModelProvider) | ||
{ | ||
} | ||
|
||
/** | ||
* @return array<string, WebhooksViewModel> | ||
*/ | ||
#[Route('/app/admin/webhooks', self::class, methods: 'GET')] | ||
#[Template('app/admin/webhooks.html.twig')] | ||
#[IsGranted(Roles::ROLE_ADMIN)] | ||
public function __invoke(): array | ||
{ | ||
return ['webhooksViewModel' => $this->viewModelProvider->getWebhooksViewModel()]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace DR\Review\Form\Webhook; | ||
|
||
use DR\Review\Controller\App\Admin\WebhookController; | ||
use DR\Review\Entity\Webhook\Webhook; | ||
use Symfony\Component\Form\AbstractType; | ||
use Symfony\Component\Form\Extension\Core\Type\SubmitType; | ||
use Symfony\Component\Form\FormBuilderInterface; | ||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface; | ||
|
||
class EditWebhookFormType extends AbstractType | ||
{ | ||
public function __construct(private UrlGeneratorInterface $urlGenerator) | ||
{ | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function buildForm(FormBuilderInterface $builder, array $options): void | ||
{ | ||
/** @var array{webhook: Webhook|null} $data */ | ||
$data = $options['data']; | ||
|
||
$builder->setAction($this->urlGenerator->generate(WebhookController::class, ['id' => $data['webhook']?->getId()])); | ||
$builder->setMethod('POST'); | ||
$builder->add('webhook', WebhookType::class, ['label' => false]); | ||
$builder->add('save', SubmitType::class, ['label' => 'save']); | ||
} | ||
} |
Oops, something went wrong.