diff --git a/lib/AppInfo/Application20.php b/lib/AppInfo/Application20.php index 9dd4f0eb0..bdac9cb85 100644 --- a/lib/AppInfo/Application20.php +++ b/lib/AppInfo/Application20.php @@ -45,6 +45,8 @@ use OCA\Deck\Service\FullTextSearchService; use OCA\Deck\Service\PermissionService; use OCA\Deck\Sharing\DeckShareProvider; use OCA\Deck\Sharing\Listener; +use OCA\Deck\Listeners\RegisterChecksListener; +use OCA\Deck\Listeners\RegisterEntityListener; use OCP\AppFramework\App; use OCP\AppFramework\Bootstrap\IBootContext; use OCP\AppFramework\Bootstrap\IBootstrap; @@ -66,6 +68,8 @@ use OCP\IUserManager; use OCP\Notification\IManager as NotificationManager; use OCP\Share\IManager; use OCP\Util; +use OCP\WorkflowEngine\Events\RegisterChecksEvent; +use OCP\WorkflowEngine\Events\RegisterEntitiesEvent; use Psr\Container\ContainerInterface; class Application20 extends App implements IBootstrap { @@ -127,6 +131,9 @@ class Application20 extends App implements IBootstrap { $context->registerDashboardWidget(DeckWidget::class); $context->registerEventListener(BeforeTemplateRenderedEvent::class, BeforeTemplateRenderedListener::class); + + $context->registerEventListener(RegisterEntitiesEvent::class, RegisterEntityListener::class); + //$context->registerEventListener(RegisterChecksEvent::class, RegisterChecksListener::class); } public function registerNotifications(NotificationManager $notificationManager): void { diff --git a/lib/Event/CardCreatedEvent.php b/lib/Event/CardCreatedEvent.php new file mode 100644 index 000000000..bcb915889 --- /dev/null +++ b/lib/Event/CardCreatedEvent.php @@ -0,0 +1,43 @@ + + * + * @author Julius Härtl + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +declare(strict_types=1); + + +namespace OCA\Deck\Event; + +use OCA\Deck\Db\Card; + +class CardCreatedEvent extends \OCP\EventDispatcher\Event { + + /** @var Card */ + private $card; + + public function __construct(Card $card) { + $this->card = $card; + } + + public function getCard(): Card { + return $this->card; + } +} diff --git a/lib/Flow/CardEntity.php b/lib/Flow/CardEntity.php new file mode 100644 index 000000000..f2e01325e --- /dev/null +++ b/lib/Flow/CardEntity.php @@ -0,0 +1,107 @@ + + * + * @author Julius Härtl + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +declare(strict_types=1); + + +namespace OCA\Deck\Flow; + +use OCA\Deck\Event\CardCreatedEvent; +use OCP\EventDispatcher\Event; +use OCP\IL10N; +use OCP\IURLGenerator; +use OCP\WorkflowEngine\EntityContext\IDisplayName; +use OCP\WorkflowEngine\EntityContext\IDisplayText; +use OCP\WorkflowEngine\EntityContext\IUrl; +use OCP\WorkflowEngine\IEntity; +use OCP\WorkflowEngine\IRuleMatcher; + +class CardEntity implements IEntity, IDisplayText, IDisplayName, IUrl { + + /** + * @var IL10N + */ + private $l10n; + /** + * @var IURLGenerator + */ + private $urlGenerator; + + private $card; + + public function __construct(IL10N $l, IURLGenerator $urlGenerator) { + $this->l10n = $l; + $this->urlGenerator = $urlGenerator; + } + /** + * @inheritDoc + */ + public function getName(): string { + return $this->l10n->t('Deck card'); + } + + /** + * @inheritDoc + */ + public function getIcon(): string { + return $this->urlGenerator->imagePath('deck', 'deck-dark.svg'); + } + + /** + * @inheritDoc + */ + public function getEvents(): array { + return [new CardEntityCreatedEvent($this->l10n)]; + } + + /** + * @inheritDoc + */ + public function prepareRuleMatcher(IRuleMatcher $ruleMatcher, string $eventName, Event $event): void { + if(!$event instanceof CardCreatedEvent) { + return; + } + /** @var CardCreatedEvent $event */ + $ruleMatcher->setEntitySubject($this, $event->getCard()); + $this->card = $event->getCard(); + } + + /** + * @inheritDoc + */ + public function isLegitimatedForUserId(string $userId): bool { + return true; + } + + public function getDisplayName(): string { + return $this->card->getTitle(); + } + + public function getDisplayText(int $verbosity = 0): string { + return $this->card->getTitle() . PHP_EOL . $this->card->getDescription(); + } + + public function getUrl(): string { + return $this->urlGenerator->linkToRouteAbsolute('deck.page.index') . '#' . '/board/1/card/' . $this->card->getId(); + } +} diff --git a/lib/Flow/CardEntityCreatedEvent.php b/lib/Flow/CardEntityCreatedEvent.php new file mode 100644 index 000000000..78c2b61d8 --- /dev/null +++ b/lib/Flow/CardEntityCreatedEvent.php @@ -0,0 +1,48 @@ + + * + * @author Julius Härtl + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +declare(strict_types=1); + + +namespace OCA\Deck\Flow; + +use OCA\Deck\Event\CardCreatedEvent; +use OCP\IL10N; +use OCP\WorkflowEngine\IEntityEvent; + +class CardEntityCreatedEvent implements IEntityEvent { + + /** @var IL10N */ + private $l10n; + + public function __construct(IL10N $l10n) { + $this->l10n = $l10n; + } + public function getDisplayName(): string { + return $this->l10n->t('Card created'); + } + + public function getEventName(): string { + return CardCreatedEvent::class; + } +} diff --git a/lib/Listeners/RegisterChecksListener.php b/lib/Listeners/RegisterChecksListener.php new file mode 100644 index 000000000..75c6b4191 --- /dev/null +++ b/lib/Listeners/RegisterChecksListener.php @@ -0,0 +1,51 @@ + + * + * @author Arthur Schiwon + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +namespace OCA\Deck\Listeners; + +use OCA\FlowWebhooks\AppInfo\Application; +use OCA\FlowWebhooks\Flow\ParameterCheck; +use OCP\EventDispatcher\Event; +use OCP\EventDispatcher\IEventListener; +use OCP\Util; +use OCP\WorkflowEngine\Events\RegisterChecksEvent; + +class RegisterChecksListener implements IEventListener { + + /** @var ParameterCheck */ + private $parameterCheck; + + public function __construct(ParameterCheck $parameterCheck) { + $this->parameterCheck = $parameterCheck; + } + + public function handle(Event $event): void { + if (!($event instanceof RegisterChecksEvent)) { + return; + } + $event->registerCheck($this->parameterCheck); + + Util::addScript(Application::APP_ID, Application::APP_ID); + } +} diff --git a/lib/Listeners/RegisterEntityListener.php b/lib/Listeners/RegisterEntityListener.php new file mode 100644 index 000000000..559eb8d72 --- /dev/null +++ b/lib/Listeners/RegisterEntityListener.php @@ -0,0 +1,47 @@ + + * + * @author Arthur Schiwon + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +namespace OCA\Deck\Listeners; + +use OCA\Deck\Flow\CardEntity; +use OCP\EventDispatcher\Event; +use OCP\EventDispatcher\IEventListener; +use OCP\WorkflowEngine\Events\RegisterEntitiesEvent; + +class RegisterEntityListener implements IEventListener { + + /** @var CardEntity */ + private $cardEntity; + + public function __construct(CardEntity $cardEntity) { + $this->cardEntity = $cardEntity; + } + + public function handle(Event $event): void { + if(!$event instanceof RegisterEntitiesEvent) { + return; + } + $event->registerEntity($this->cardEntity); + } +} diff --git a/lib/Service/CardService.php b/lib/Service/CardService.php index e0961151a..3f44d94e8 100644 --- a/lib/Service/CardService.php +++ b/lib/Service/CardService.php @@ -35,6 +35,7 @@ use OCA\Deck\Db\CardMapper; use OCA\Deck\Db\Acl; use OCA\Deck\Db\ChangeHelper; use OCA\Deck\Db\StackMapper; +use OCA\Deck\Event\CardCreatedEvent; use OCA\Deck\Event\FTSEvent; use OCA\Deck\Notification\NotificationHelper; use OCA\Deck\Db\BoardMapper; @@ -224,7 +225,8 @@ class CardService { $card = $this->cardMapper->insert($card); $this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_CARD, $card, ActivityManager::SUBJECT_CARD_CREATE); $this->changeHelper->cardChanged($card->getId(), false); - + $this->eventDispatcher->dispatchTyped(new CardCreatedEvent($card)); + $this->eventDispatcher->dispatch( '\OCA\Deck\Card::onCreate', new FTSEvent(