Skip to content

Commit

Permalink
Merge pull request #2371 from shlinkio/develop
Browse files Browse the repository at this point in the history
Release 4.4.4
  • Loading branch information
acelaya authored Feb 19, 2025
2 parents bee9f2a + af2d676 commit 104b1e7
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 18 deletions.
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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*
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
8 changes: 7 additions & 1 deletion module/Core/src/Visit/Repository/VisitRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}
Expand Down
29 changes: 13 additions & 16 deletions module/Core/test-db/Visit/Repository/VisitRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
))));
Expand All @@ -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]
Expand Down Expand Up @@ -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',
Expand All @@ -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([
Expand Down

0 comments on commit 104b1e7

Please # to comment.