diff --git a/CHANGELOG.md b/CHANGELOG.md index 8bbfd3481..81cb8ba0a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,24 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com), and this project adheres to [Semantic Versioning](https://semver.org). +## [4.4.4] - 2025-02-19 +### Added +* *Nothing* + +### Changed +* *Nothing* + +### Deprecated +* *Nothing* + +### Removed +* *Nothing* + +### Fixed +* [#2366](https://github.com/shlinkio/shlink/issues/2366) Fix error "Cannot use 'SCRIPT' with redis-cluster" thrown when creating a lock while using a redis cluster. +* [#2368](https://github.com/shlinkio/shlink/issues/2368) Fix error when listing non-orphan visits using API key with `AUTHORED_SHORT_URLS` role. + + ## [4.4.3] - 2025-02-15 ### Added * *Nothing* diff --git a/composer.json b/composer.json index 8d4848e4f..d23ec7cf1 100644 --- a/composer.json +++ b/composer.json @@ -56,7 +56,7 @@ "spiral/roadrunner-jobs": "^4.6", "symfony/console": "^7.2", "symfony/filesystem": "^7.2", - "symfony/lock": "7.2.0", + "symfony/lock": "7.1.6", "symfony/process": "^7.2", "symfony/string": "^7.2" }, diff --git a/module/Core/src/Visit/Repository/VisitRepository.php b/module/Core/src/Visit/Repository/VisitRepository.php index 9c4668c1a..bfba51784 100644 --- a/module/Core/src/Visit/Repository/VisitRepository.php +++ b/module/Core/src/Visit/Repository/VisitRepository.php @@ -21,6 +21,7 @@ use Shlinkio\Shlink\Core\Visit\Spec\CountOfNonOrphanVisits; use Shlinkio\Shlink\Core\Visit\Spec\CountOfOrphanVisits; use Shlinkio\Shlink\Rest\ApiKey\Role; +use Shlinkio\Shlink\Rest\Entity\ApiKey; use const PHP_INT_MAX; @@ -177,7 +178,12 @@ public function findNonOrphanVisits(VisitsListFiltering $filtering): array $qb = $this->createAllVisitsQueryBuilder($filtering); $qb->andWhere($qb->expr()->isNotNull('v.shortUrl')); - $this->applySpecification($qb, $filtering->apiKey?->inlinedSpec()); + $apiKey = $filtering->apiKey; + if (ApiKey::isShortUrlRestricted($apiKey)) { + $qb->join('v.shortUrl', 's'); + } + + $this->applySpecification($qb, $apiKey?->inlinedSpec(), 'v'); return $this->resolveVisitsWithNativeQuery($qb, $filtering->limit, $filtering->offset); } diff --git a/module/Core/test-db/Visit/Repository/VisitRepositoryTest.php b/module/Core/test-db/Visit/Repository/VisitRepositoryTest.php index 29227b8bd..fe53629fd 100644 --- a/module/Core/test-db/Visit/Repository/VisitRepositoryTest.php +++ b/module/Core/test-db/Visit/Repository/VisitRepositoryTest.php @@ -470,22 +470,18 @@ public function countOrphanVisitsReturnsExpectedResult(): void #[Test] public function findNonOrphanVisitsReturnsExpectedResult(): void { - $shortUrl = ShortUrl::create(ShortUrlCreation::fromRawData(['longUrl' => 'https://1'])); - $this->getEntityManager()->persist($shortUrl); - $this->createVisitsForShortUrl($shortUrl, 7); + $authoredApiKey = ApiKey::fromMeta(ApiKeyMeta::withRoles(RoleDefinition::forAuthoredShortUrls())); + $this->getEntityManager()->persist($authoredApiKey); - $shortUrl2 = ShortUrl::create(ShortUrlCreation::fromRawData(['longUrl' => 'https://2'])); - $this->getEntityManager()->persist($shortUrl2); - $this->createVisitsForShortUrl($shortUrl2, 4); - - $shortUrl3 = ShortUrl::create(ShortUrlCreation::fromRawData(['longUrl' => 'https://3'])); - $this->getEntityManager()->persist($shortUrl3); - $this->createVisitsForShortUrl($shortUrl3, 10); + $this->createShortUrlsAndVisits(withDomain: false, visitsAmount: 7); + $this->createShortUrlsAndVisits(withDomain: false, apiKey: $authoredApiKey, visitsAmount: 4); + $this->createShortUrlsAndVisits(withDomain: false, visitsAmount: 10); $this->getEntityManager()->flush(); self::assertCount(21, $this->repo->findNonOrphanVisits(new VisitsListFiltering())); self::assertCount(21, $this->repo->findNonOrphanVisits(new VisitsListFiltering(DateRange::allTime()))); + self::assertCount(4, $this->repo->findNonOrphanVisits(new VisitsListFiltering(apiKey: $authoredApiKey))); self::assertCount(7, $this->repo->findNonOrphanVisits(new VisitsListFiltering(DateRange::since( Chronos::parse('2016-01-05')->endOfDay(), )))); @@ -503,11 +499,11 @@ public function findNonOrphanVisitsReturnsExpectedResult(): void self::assertCount(3, $this->repo->findNonOrphanVisits(new VisitsListFiltering(DateRange::between( Chronos::parse('2016-01-03')->startOfDay(), Chronos::parse('2016-01-08')->endOfDay(), - ), false, null, 10, 10))); - self::assertCount(15, $this->repo->findNonOrphanVisits(new VisitsListFiltering(null, true))); - self::assertCount(10, $this->repo->findNonOrphanVisits(new VisitsListFiltering(null, false, null, 10))); - self::assertCount(1, $this->repo->findNonOrphanVisits(new VisitsListFiltering(null, false, null, 10, 20))); - self::assertCount(5, $this->repo->findNonOrphanVisits(new VisitsListFiltering(null, false, null, 5, 5))); + ), limit: 10, offset: 10))); + self::assertCount(15, $this->repo->findNonOrphanVisits(new VisitsListFiltering(excludeBots: true))); + self::assertCount(10, $this->repo->findNonOrphanVisits(new VisitsListFiltering(limit: 10))); + self::assertCount(1, $this->repo->findNonOrphanVisits(new VisitsListFiltering(limit: 10, offset: 20))); + self::assertCount(5, $this->repo->findNonOrphanVisits(new VisitsListFiltering(limit: 5, offset: 5))); } #[Test] @@ -535,6 +531,7 @@ private function createShortUrlsAndVisits( bool|string $withDomain = true, array $tags = [], ApiKey|null $apiKey = null, + int $visitsAmount = 6, ): array { $shortUrl = ShortUrl::create(ShortUrlCreation::fromRawData([ ShortUrlInputFilter::LONG_URL => 'https://longUrl', @@ -545,7 +542,7 @@ private function createShortUrlsAndVisits( $shortCode = $shortUrl->getShortCode(); $this->getEntityManager()->persist($shortUrl); - $this->createVisitsForShortUrl($shortUrl); + $this->createVisitsForShortUrl($shortUrl, $visitsAmount); if ($withDomain !== false) { $shortUrlWithDomain = ShortUrl::create(ShortUrlCreation::fromRawData([