Skip to content

Commit

Permalink
Fixing minor issues
Browse files Browse the repository at this point in the history
- status code 400 with related message is returned from `/api/crawler/receive-result` endpoint if the project not foud
- changed some icons
- panels with cookie suggestion types are collapsed by default
- changed translation of "private provider" to "project provider"
  • Loading branch information
tg666 committed Oct 23, 2023
1 parent 880fe08 commit e37252b
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 19 deletions.
1 change: 1 addition & 0 deletions config/packages/contributte.monolog.neon
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ services:
type: Sentry\Client
factory: Sentry\ClientBuilder::create([
dsn: ::env(SENTRY_DSN)
max_request_body_size: always
])::getClient()

sentry_hub:
Expand Down
22 changes: 15 additions & 7 deletions src/Api/Crawler/ReceiveResultController.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,21 @@ public function receiveResult(ApiRequest $request, ApiResponse $response): ApiRe
}
}

$this->cookieSuggestionsStore->storeCrawledCookies(
$scenarioResponseBody->name,
$scenarioResponseBody->flags['projectId'],
$acceptedCategories,
$scenarioResponseBody->finishedAt ?? new DateTimeImmutable('now'),
$scenarioResponseBody->results->cookies,
);
try {
$this->cookieSuggestionsStore->storeCrawledCookies(
$scenarioResponseBody->name,
$scenarioResponseBody->flags['projectId'],
$acceptedCategories,
$scenarioResponseBody->finishedAt ?? new DateTimeImmutable('now'),
$scenarioResponseBody->results->cookies,
);
} catch (Throwable $e) {
$error = new ClientErrorException('Unable to process received crawler result: ' . $e->getMessage(), ApiResponse::S400_BAD_REQUEST, $e);

$this->logger->error((string) $error);

throw $error;
}

return $response->withStatus(ApiResponse::S200_OK)
->writeJsonBody([
Expand Down
11 changes: 11 additions & 0 deletions src/Application/CookieSuggestion/CookieSuggestionsStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@
use App\ReadModel\CookieSuggestion\CookieSuggestionForResolving;
use App\ReadModel\CookieSuggestion\FindCookieSuggestionsForResolvingQuery;
use App\ReadModel\CookieSuggestion\GetCookieSuggestionByProjectIdAndNameAndDomainQuery;
use App\ReadModel\Project\GetProjectByIdQuery;
use Closure;
use DateTimeImmutable;
use DateTimeInterface;
use DateTimeZone;
use Exception;
use InvalidArgumentException;
use Psr\Log\LoggerInterface;
use SixtyEightPublishers\ArchitectureBundle\Bus\CommandBusInterface;
use SixtyEightPublishers\ArchitectureBundle\Bus\QueryBusInterface;
Expand All @@ -64,6 +66,15 @@ public function __construct(
*/
public function storeCrawledCookies(string $scenarioName, string $projectId, array $acceptedCategories, DateTimeImmutable $finishedAt, array $cookies): void
{
$projectView = $this->queryBus->dispatch(GetProjectByIdQuery::create($projectId));

if (null === $projectView) {
throw new InvalidArgumentException(sprintf(
'The project with ID %s not found.',
$projectId,
));
}

$cookiesData = null;
$getCookiesData = function () use (&$cookiesData, $projectId): array {
if (null !== $cookiesData) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function __invoke(FindCookieDataForSuggestionQuery $query): array
->from('cookie', 'c')
->join('c', 'category', 'cat', 'c.category_id = cat.id AND cat.deleted_at IS NULL')
->join('c', 'cookie_provider', 'cp', 'c.cookie_provider_id = cp.id AND cp.deleted_at IS NULL')
->leftJoin('c', 'project', 'p', 'p.id = :projectId AND p.deleted_at IS NULL')
->join('c', 'project', 'p', 'p.id = :projectId AND p.deleted_at IS NULL')
->leftJoin('cp', 'project_has_cookie_provider', 'p_has_cp', 'p_has_cp.cookie_provider_id = cp.id AND p_has_cp.project_id = p.id')
->where('c.deleted_at IS NULL')
->andWhere('cp.private = false OR cp.id = p.cookie_provider_id')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

{block #heading_actions}
<a n:if="$user->isAllowed(App\Application\Acl\CrawlerScenariosResource::class, App\Application\Acl\CrawlerScenariosResource::READ)" n:href='":Admin:Crawler:Scenarios:?scenarioList-grid-filter[project]={$projectView->id->toString()}"' data-spinner-for="self" class="spinner-white inline-flex items-center px-4 py-2 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-blue-600 hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500">
{svg common/queue-list.svg, class: 'h-4 w-4 mr-2'}
{_running_scenarios}
</a>
<a n:if="$user->isAllowed(App\Application\Acl\FoundCookiesProjectsResource::class, App\Application\Acl\FoundCookiesProjectsResource::READ)" n:href="FoundCookiesProjects:" data-spinner-for="self" class="spinner-white inline-flex items-center px-4 py-2 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-indigo-600 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500">
Expand Down Expand Up @@ -55,7 +54,7 @@
</span>
</div>

<div x-bind="collapsePanel" n:attr="'x-cloak' => 0 >= (count($missingCookieSuggestions) + count($unassociatedCookieSuggestions))">
<div x-bind="collapsePanel" x-cloak>
<div n:snippet="new-cookies-panel" class="p-4 pb-6 border-b border-gray-200 divide-y divide-gray-150">
{foreach $missingCookieSuggestions as $suggestion}
<div>
Expand Down Expand Up @@ -90,7 +89,7 @@
</span>
</div>

<div x-bind="collapsePanel" n:attr="'x-cloak' => 0 >= count($problematicCookieSuggestions)">
<div x-bind="collapsePanel" x-cloak>
<div n:snippet="problematic-cookies-panel" class="p-4 pb-6 border-b border-gray-200 divide-y divide-gray-150">
{foreach $problematicCookieSuggestions as $suggestion}
{include #problematic-cookie-suggestion, suggestion: $suggestion}
Expand Down Expand Up @@ -119,7 +118,7 @@
</span>
</div>

<div x-bind="collapsePanel" n:attr="'x-cloak' => 0 >= count($unproblematicCookieSuggestions)">
<div x-bind="collapsePanel" x-cloak>
<div n:snippet="unproblematic-cookies-panel" class="p-4 pb-6 border-b border-gray-200 divide-y divide-gray-150">
{foreach $unproblematicCookieSuggestions as $suggestion}
{include #unproblematic-cookie-suggestion, suggestion: $suggestion}
Expand Down Expand Up @@ -148,7 +147,7 @@
</span>
</div>

<div x-bind="collapsePanel" n:attr="'x-cloak' => 0 >= count($ignoredCookieSuggestions)">
<div x-bind="collapsePanel" x-cloak>
<div n:snippet="ignored-cookies-panel" class="p-4 pb-6 divide-y divide-gray-150">
{foreach $ignoredCookieSuggestions as $suggestion}
{var $originalSuggestion = $suggestion->getOriginalSuggestion()}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
{/block}

{block #footer}
<a n:if="null !== $scenarioResponse && isset($scenarioResponse->getBody()->flags['projectId']) && $user->isAllowed(App\Application\Acl\FoundCookiesResource::class, App\Application\Acl\FoundCookiesResource::READ)" href="{plink :Admin:Cookie:FoundCookies: id => $scenarioResponse->getBody()->flags['projectId']}" data-spinner-for="self" class="spinner-white mt-3 sm:ml-3 w-full inline-flex justify-center rounded-md border border-transparent shadow-sm px-4 py-2 bg-blue-600 text-base font-medium text-white hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500 sm:mt-0 sm:w-auto sm:text-sm sm:mr-2">
<a n:if="null !== $scenarioResponse && isset($scenarioResponse->getBody()->flags['projectId']) && $user->isAllowed(App\Application\Acl\FoundCookiesResource::class, App\Application\Acl\FoundCookiesResource::READ)" href="{plink :Admin:Cookie:FoundCookies: id => $scenarioResponse->getBody()->flags['projectId']}" data-spinner-for="self" class="spinner-white mt-3 sm:ml-3 w-full inline-flex items-center justify-center rounded-md border border-transparent shadow-sm px-4 py-2 bg-blue-600 text-base font-medium text-white hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500 sm:mt-0 sm:w-auto sm:text-sm sm:mr-2">
{svg common/queue-list.svg, class: 'h-4 w-4 mr-2'}
{_manage_suggestions}
</a>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,6 @@
{define col-duration}
{App\Application\Helper\DurationFormatter::formatDiff(
$item->createdAt->setTimezone(App\Application\Localization\ApplicationDateTimeZone::get()),
($item->finishedAt ?? new \DateTimeImmutable('now'))->setTimezone(App\Application\Localization\ApplicationDateTimeZone::get())
($item->finishedAt ?? new \DateTimeImmutable('now', new DateTimeZone('UTC')))->setTimezone(App\Application\Localization\ApplicationDateTimeZone::get())
)}
{/define}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
use App\ReadModel\CookieSuggestion\CookieSuggestionForResolving;
use App\ReadModel\CookieSuggestion\FindCookieSuggestionsForResolvingQuery;
use App\ReadModel\CookieSuggestion\GetCookieSuggestionByProjectIdAndNameAndDomainQuery;
use App\ReadModel\Project\GetProjectByIdQuery;
use App\ReadModel\Project\ProjectView;
use Closure;
use DateTimeImmutable;
use DateTimeInterface;
Expand All @@ -43,6 +45,7 @@
use Mockery;
use SixtyEightPublishers\ArchitectureBundle\Bus\CommandBusInterface;
use SixtyEightPublishers\ArchitectureBundle\Bus\QueryBusInterface;
use SixtyEightPublishers\ArchitectureBundle\ReadModel\View\ArrayViewData;
use SixtyEightPublishers\CrawlerClient\Controller\Scenario\ValueObject\Cookie as CrawlerClientCookie;
use Tester\Assert;
use Tester\TestCase;
Expand All @@ -63,6 +66,10 @@ public function testCrawledCookieStoring(): void
$finishedAtString = $finishedAt->format(DateTimeInterface::ATOM);
$store = $this->createStore(
[
[
GetProjectByIdQuery::create($projectId),
ProjectView::fromData(new ArrayViewData([])),
],
[
FindCookieDataForSuggestionQuery::create($projectId),
[
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: Název
code: Kód
active: Aktivní
private: Privátní
private_description: 'Privátní poskytovatel je "hlavní" poskytovatel vázaný na daný projekt.'
private: Projektový
private_description: 'Projektový poskytovatel je "hlavní" poskytovatel vázaný na daný projekt.'
type: Typ
link: Odkaz
number_of_cookies: Cookies
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: Name
code: Code
active: Active
private: Private
private_description: 'A private provider is the "main" provider associated with the project.'
private: Project provider
private_description: 'A project provider is the "main" provider associated with the project.'
type: Type
link: Link
number_of_cookies: Cookies
Expand Down

0 comments on commit e37252b

Please sign in to comment.