Skip to content

Commit

Permalink
Urgent fixes for not filtering the repository
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcel Kallen authored and Marcel Kallen committed Dec 1, 2021
1 parent 36aa624 commit 1467c08
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion src/Repository/Abstraction/AbstractTenantRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,38 @@
namespace Fluxter\SaasProviderBundle\Repository\Abstraction;

use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Fluxter\SaasProviderBundle\Model\TenantInterface;
use Fluxter\SaasProviderBundle\Service\TenantService;

abstract class AbstractTenantRepository extends ServiceEntityRepository
{
use TenantRepositoryTrait;
protected TenantService $clientService;

public function findAll()
{
return $this->createQueryBuilder('e')->getQuery()->getResult();
}

/** @required */
public function setTenantService(TenantService $clientService)
{
$this->clientService = $clientService;
}

public function createQueryBuilder($alias, $indexBy = null, ?TenantInterface $tenant = null)
{
if (null == $tenant) {
$tenant = $this->clientService->getTenant();
}

return parent::createQueryBuilder($alias, $indexBy)
->andWhere($alias . '.tenant = :saasTenantId')
->setParameter('saasTenantId', $tenant->getId());
}

// THIS IS ONLY FOR CONSOLE COMMANDS OR SOMETHING!
public function createGlobalQueryBuilder($alias, $indexBy = null)
{
return parent::createGlobalQueryBuilder($alias, $indexBy);
}
}

0 comments on commit 1467c08

Please sign in to comment.