Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed resolving of cookie suggestions #63

Merged
merged 2 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
Expand All @@ -704,7 +711,7 @@ private function createCookieSuggestionFromVirtualId(
$this->redirectIfNotAjax();
}

return false;
return null;
}
}
}