diff --git a/CHANGELOG.md b/CHANGELOG.md index 99310dc..5b46911 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +### Fixed + +- Fixed resolving of cookie suggestions that were not already created by crawler. + ## 0.11.0 - 2023-10-24 ### Added diff --git a/src/Web/AdminModule/CookieModule/Presenter/FoundCookiesPresenter.php b/src/Web/AdminModule/CookieModule/Presenter/FoundCookiesPresenter.php index d24cee4..332ce22 100644 --- a/src/Web/AdminModule/CookieModule/Presenter/FoundCookiesPresenter.php +++ b/src/Web/AdminModule/CookieModule/Presenter/FoundCookiesPresenter.php @@ -22,6 +22,7 @@ use App\Domain\CookieSuggestion\Command\DoNotIgnoreCookieSuggestionCommand; use App\Domain\CookieSuggestion\Command\IgnoreCookieSuggestionPermanentlyCommand; use App\Domain\CookieSuggestion\Command\IgnoreCookieSuggestionUntilNextOccurrenceCommand; +use App\Domain\CookieSuggestion\ValueObject\CookieSuggestionId; use App\Domain\Project\Command\AddCookieProvidersToProjectCommand; use App\Domain\Project\ValueObject\ProjectId; use App\ReadModel\Cookie\CookieView; @@ -453,8 +454,12 @@ private function resolveIgnore( bool $uiActionsAllowed, bool $virtualSuggestion, ): bool { - if ($virtualSuggestion && !$this->createCookieSuggestionFromVirtualId($cookieSuggestionId, $uiActionsAllowed)) { - return false; + if ($virtualSuggestion) { + $cookieSuggestionId = $this->createVirtualCookieSuggestion($cookieSuggestionId, $uiActionsAllowed); + + if (null === $cookieSuggestionId) { + return false; + } } try { @@ -667,11 +672,11 @@ private function resolveCookieForm( /** * @throws AbortException */ - private function createCookieSuggestionFromVirtualId( - string $virtualId, + private function createVirtualCookieSuggestion( + string $cookieId, bool $uiActionsAllowed, - ): bool { - $cookieView = $this->queryBus->dispatch(GetCookieByIdQuery::create($virtualId)); + ): ?string { + $cookieView = $this->queryBus->dispatch(GetCookieByIdQuery::create($cookieId)); if (!$cookieView instanceof CookieView) { if ($uiActionsAllowed) { @@ -680,19 +685,21 @@ private function createCookieSuggestionFromVirtualId( $this->redirectIfNotAjax(); } - return false; + return null; } try { + $cookieSuggestionId = CookieSuggestionId::new()->toString(); + $this->commandBus->dispatch(CreateCookieSuggestionCommand::create( $this->projectView->id->toString(), $cookieView->name->value(), $cookieView->domain->value() ?: $this->projectView->domain->value(), [], - $virtualId, + $cookieSuggestionId, )); - return true; + return $cookieSuggestionId; } catch (Throwable $e) { if (!$e instanceof DomainException) { $this->logger->error((string) $e); @@ -704,7 +711,7 @@ private function createCookieSuggestionFromVirtualId( $this->redirectIfNotAjax(); } - return false; + return null; } } }