helper function
This commit is contained in:
parent
4aadaa351a
commit
f1b953d005
|
|
@ -3,10 +3,16 @@
|
|||
namespace App\Service;
|
||||
|
||||
|
||||
use App\Entity\Organizations;
|
||||
use App\Entity\Roles;
|
||||
use App\Entity\User;
|
||||
use App\Entity\UsersOrganizations;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
class UserService
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
public function __construct(private readonly EntityManagerInterface $entityManager)
|
||||
{
|
||||
// Constructor logic if needed
|
||||
}
|
||||
|
|
@ -26,4 +32,31 @@ class UserService
|
|||
|
||||
return $randomPassword;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the user is an admin in the given organization.
|
||||
*
|
||||
* @param int $userId
|
||||
* @param int $organizationId
|
||||
* @return bool
|
||||
*/
|
||||
public function isUserAdminInOrganization(int $userId, int $organizationId): bool
|
||||
{
|
||||
$user = $this->entityManager->getRepository(User::class)->find($userId);
|
||||
if (!$user) {
|
||||
return false;
|
||||
}
|
||||
$organization = $this->entityManager->getRepository(Organizations::class)->find($organizationId);
|
||||
if (!$organization) {
|
||||
return false;
|
||||
}
|
||||
$roleAdmin = $this->entityManager->getRepository(Roles::class)->findBy(['name'=> 'ADMIN']);
|
||||
|
||||
// Check if the user is an admin in the organization
|
||||
return empty($this->entityManager->getRepository(UsersOrganizations::class)->findBy([
|
||||
'userId' => $userId,
|
||||
'organizationId' => $organizationId,
|
||||
'roleId' => $roleAdmin[0]->getId()]));
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue