mirror of
https://github.com/shlinkio/shlink.git
synced 2025-02-25 18:45:27 -06:00
Ensured domains not used in short URLs but with redirects configured are returned in domains list
This commit is contained in:
@@ -18,8 +18,13 @@ class DomainRepository extends EntitySpecificationRepository implements DomainRe
|
|||||||
public function findDomainsWithout(?string $excludedAuthority, ?ApiKey $apiKey = null): array
|
public function findDomainsWithout(?string $excludedAuthority, ?ApiKey $apiKey = null): array
|
||||||
{
|
{
|
||||||
$qb = $this->createQueryBuilder('d');
|
$qb = $this->createQueryBuilder('d');
|
||||||
$qb->join(ShortUrl::class, 's', Join::WITH, 's.domain = d')
|
$qb->leftJoin(ShortUrl::class, 's', Join::WITH, 's.domain = d')
|
||||||
->orderBy('d.authority', 'ASC');
|
->orderBy('d.authority', 'ASC')
|
||||||
|
->groupBy('d')
|
||||||
|
->having($qb->expr()->gt('COUNT(s.id)', '0'))
|
||||||
|
->orHaving($qb->expr()->isNotNull('d.baseUrlRedirect'))
|
||||||
|
->orHaving($qb->expr()->isNotNull('d.regular404Redirect'))
|
||||||
|
->orHaving($qb->expr()->isNotNull('d.invalidShortUrlRedirect'));
|
||||||
|
|
||||||
if ($excludedAuthority !== null) {
|
if ($excludedAuthority !== null) {
|
||||||
$qb->where($qb->expr()->neq('d.authority', ':excludedAuthority'))
|
$qb->where($qb->expr()->neq('d.authority', ':excludedAuthority'))
|
||||||
|
@@ -6,6 +6,7 @@ namespace ShlinkioTest\Shlink\Core\Domain\Repository;
|
|||||||
|
|
||||||
use Doctrine\Common\Collections\ArrayCollection;
|
use Doctrine\Common\Collections\ArrayCollection;
|
||||||
use Doctrine\Common\Collections\Collection;
|
use Doctrine\Common\Collections\Collection;
|
||||||
|
use Shlinkio\Shlink\Core\Config\NotFoundRedirects;
|
||||||
use Shlinkio\Shlink\Core\Domain\Repository\DomainRepository;
|
use Shlinkio\Shlink\Core\Domain\Repository\DomainRepository;
|
||||||
use Shlinkio\Shlink\Core\Entity\Domain;
|
use Shlinkio\Shlink\Core\Entity\Domain;
|
||||||
use Shlinkio\Shlink\Core\Entity\ShortUrl;
|
use Shlinkio\Shlink\Core\Entity\ShortUrl;
|
||||||
@@ -43,12 +44,32 @@ class DomainRepositoryTest extends DatabaseTestCase
|
|||||||
$detachedDomain = Domain::withAuthority('detached.com');
|
$detachedDomain = Domain::withAuthority('detached.com');
|
||||||
$this->getEntityManager()->persist($detachedDomain);
|
$this->getEntityManager()->persist($detachedDomain);
|
||||||
|
|
||||||
|
$detachedWithRedirects = Domain::withAuthority('detached-with-redirects.com');
|
||||||
|
$detachedWithRedirects->configureNotFoundRedirects(new NotFoundRedirects('foo.com', 'bar.com'));
|
||||||
|
$this->getEntityManager()->persist($detachedWithRedirects);
|
||||||
|
|
||||||
$this->getEntityManager()->flush();
|
$this->getEntityManager()->flush();
|
||||||
|
|
||||||
self::assertEquals([$barDomain, $bazDomain, $fooDomain], $this->repo->findDomainsWithout(null));
|
self::assertEquals(
|
||||||
self::assertEquals([$barDomain, $bazDomain], $this->repo->findDomainsWithout('foo.com'));
|
[$barDomain, $bazDomain, $detachedWithRedirects, $fooDomain],
|
||||||
self::assertEquals([$bazDomain, $fooDomain], $this->repo->findDomainsWithout('bar.com'));
|
$this->repo->findDomainsWithout(null),
|
||||||
self::assertEquals([$barDomain, $fooDomain], $this->repo->findDomainsWithout('baz.com'));
|
);
|
||||||
|
self::assertEquals(
|
||||||
|
[$barDomain, $bazDomain, $detachedWithRedirects],
|
||||||
|
$this->repo->findDomainsWithout('foo.com'),
|
||||||
|
);
|
||||||
|
self::assertEquals(
|
||||||
|
[$bazDomain, $detachedWithRedirects, $fooDomain],
|
||||||
|
$this->repo->findDomainsWithout('bar.com'),
|
||||||
|
);
|
||||||
|
self::assertEquals(
|
||||||
|
[$barDomain, $detachedWithRedirects, $fooDomain],
|
||||||
|
$this->repo->findDomainsWithout('baz.com'),
|
||||||
|
);
|
||||||
|
self::assertEquals(
|
||||||
|
[$barDomain, $bazDomain, $fooDomain],
|
||||||
|
$this->repo->findDomainsWithout('detached-with-redirects.com'),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @test */
|
/** @test */
|
||||||
@@ -71,6 +92,13 @@ class DomainRepositoryTest extends DatabaseTestCase
|
|||||||
$this->getEntityManager()->persist($bazDomain);
|
$this->getEntityManager()->persist($bazDomain);
|
||||||
$this->getEntityManager()->persist($this->createShortUrl($bazDomain, $authorApiKey));
|
$this->getEntityManager()->persist($this->createShortUrl($bazDomain, $authorApiKey));
|
||||||
|
|
||||||
|
// $detachedDomain = Domain::withAuthority('detached.com');
|
||||||
|
// $this->getEntityManager()->persist($detachedDomain);
|
||||||
|
//
|
||||||
|
// $detachedWithRedirects = Domain::withAuthority('detached-with-redirects.com');
|
||||||
|
// $detachedWithRedirects->configureNotFoundRedirects(new NotFoundRedirects('foo.com', 'bar.com'));
|
||||||
|
// $this->getEntityManager()->persist($detachedWithRedirects);
|
||||||
|
|
||||||
$this->getEntityManager()->flush();
|
$this->getEntityManager()->flush();
|
||||||
|
|
||||||
$authorAndDomainApiKey->registerRole(RoleDefinition::forDomain($fooDomain));
|
$authorAndDomainApiKey->registerRole(RoleDefinition::forDomain($fooDomain));
|
||||||
@@ -79,12 +107,21 @@ class DomainRepositoryTest extends DatabaseTestCase
|
|||||||
$this->getEntityManager()->persist($fooDomainApiKey);
|
$this->getEntityManager()->persist($fooDomainApiKey);
|
||||||
|
|
||||||
$barDomainApiKey = ApiKey::fromMeta(ApiKeyMeta::withRoles(RoleDefinition::forDomain($barDomain)));
|
$barDomainApiKey = ApiKey::fromMeta(ApiKeyMeta::withRoles(RoleDefinition::forDomain($barDomain)));
|
||||||
$this->getEntityManager()->persist($fooDomainApiKey);
|
$this->getEntityManager()->persist($barDomainApiKey);
|
||||||
|
|
||||||
|
// $detachedWithRedirectsApiKey = ApiKey::fromMeta(
|
||||||
|
// ApiKeyMeta::withRoles(RoleDefinition::forDomain($detachedWithRedirects)),
|
||||||
|
// );
|
||||||
|
// $this->getEntityManager()->persist($detachedWithRedirectsApiKey);
|
||||||
|
|
||||||
$this->getEntityManager()->flush();
|
$this->getEntityManager()->flush();
|
||||||
|
|
||||||
self::assertEquals([$fooDomain], $this->repo->findDomainsWithout(null, $fooDomainApiKey));
|
self::assertEquals([$fooDomain], $this->repo->findDomainsWithout(null, $fooDomainApiKey));
|
||||||
self::assertEquals([$barDomain], $this->repo->findDomainsWithout(null, $barDomainApiKey));
|
self::assertEquals([$barDomain], $this->repo->findDomainsWithout(null, $barDomainApiKey));
|
||||||
|
// self::assertEquals(
|
||||||
|
// [$detachedWithRedirects],
|
||||||
|
// $this->repo->findDomainsWithout(null, $detachedWithRedirectsApiKey),
|
||||||
|
// );
|
||||||
self::assertEquals([$bazDomain, $fooDomain], $this->repo->findDomainsWithout(null, $authorApiKey));
|
self::assertEquals([$bazDomain, $fooDomain], $this->repo->findDomainsWithout(null, $authorApiKey));
|
||||||
self::assertEquals([], $this->repo->findDomainsWithout(null, $authorAndDomainApiKey));
|
self::assertEquals([], $this->repo->findDomainsWithout(null, $authorAndDomainApiKey));
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user