Fix: authorization helper won't send a list of center if an admin is authenticated

This commit is contained in:
Julien Fastré 2023-04-24 15:50:27 +02:00
parent 0c5a06c678
commit 9918cf2d58
Signed by: julienfastre
GPG Key ID: BDE2190974723FCB
3 changed files with 17 additions and 36 deletions

View File

@ -2631,11 +2631,6 @@ parameters:
count: 2 count: 2
path: src/Bundle/ChillMainBundle/Security/Authorization/AuthorizationHelper.php path: src/Bundle/ChillMainBundle/Security/Authorization/AuthorizationHelper.php
-
message: "#^Call to method getRoleScopes\\(\\) on an unknown class Chill\\\\MainBundle\\\\Entity\\\\PermissionGroup\\.$#"
count: 1
path: src/Bundle/ChillMainBundle/Security/Authorization/AuthorizationHelper.php
- -
message: "#^Empty array passed to foreach\\.$#" message: "#^Empty array passed to foreach\\.$#"
count: 1 count: 1

View File

@ -31,7 +31,7 @@ class GroupCenter
* ) * )
* @ORM\Cache(usage="NONSTRICT_READ_WRITE") * @ORM\Cache(usage="NONSTRICT_READ_WRITE")
*/ */
private $center; private ?Center $center = null;
/** /**
* @var int * @var int
@ -40,83 +40,64 @@ class GroupCenter
* @ORM\Column(name="id", type="integer") * @ORM\Column(name="id", type="integer")
* @ORM\GeneratedValue(strategy="AUTO") * @ORM\GeneratedValue(strategy="AUTO")
*/ */
private $id; private ?int $id = null;
/** /**
* @var PermissionsGroup
*
* @ORM\ManyToOne( * @ORM\ManyToOne(
* targetEntity="Chill\MainBundle\Entity\PermissionsGroup", * targetEntity="Chill\MainBundle\Entity\PermissionsGroup",
* inversedBy="groupCenters") * inversedBy="groupCenters")
* @ORM\Cache(usage="NONSTRICT_READ_WRITE") * @ORM\Cache(usage="NONSTRICT_READ_WRITE")
*/ */
private $permissionsGroup; private ?PermissionsGroup $permissionsGroup = null;
/** /**
* @var Collection
*
* @ORM\ManyToMany( * @ORM\ManyToMany(
* targetEntity="Chill\MainBundle\Entity\User", * targetEntity="Chill\MainBundle\Entity\User",
* mappedBy="groupCenters" * mappedBy="groupCenters"
* ) * )
* @var Collection<User::class>
*/ */
private $users; private Collection $users;
/** /**
* GroupCenter constructor. * GroupCenter constructor.
*/ */
public function __construct() public function __construct()
{ {
$this->permissionsGroup = new ArrayCollection();
$this->users = new ArrayCollection(); $this->users = new ArrayCollection();
} }
/** public function getCenter(): ?Center
* @return Center
*/
public function getCenter()
{ {
return $this->center; return $this->center;
} }
/** public function getId(): ?int
* @return int
*/
public function getId()
{ {
return $this->id; return $this->id;
} }
/** public function getPermissionsGroup(): ?PermissionsGroup
* @return PermissionGroup
*/
public function getPermissionsGroup()
{ {
return $this->permissionsGroup; return $this->permissionsGroup;
} }
/** /**
* @return ArrayCollection|Collection * @return Collection<User::class>
*/ */
public function getUsers() public function getUsers(): Collection
{ {
return $this->users; return $this->users;
} }
/** public function setCenter(Center $center): self
* @return \Chill\MainBundle\Entity\GroupCenter
*/
public function setCenter(Center $center)
{ {
$this->center = $center; $this->center = $center;
return $this; return $this;
} }
/** public function setPermissionsGroup(PermissionsGroup $permissionsGroup): self
* @return \Chill\MainBundle\Entity\GroupCenter
*/
public function setPermissionsGroup(PermissionsGroup $permissionsGroup)
{ {
$this->permissionsGroup = $permissionsGroup; $this->permissionsGroup = $permissionsGroup;

View File

@ -120,6 +120,11 @@ class AuthorizationHelper implements AuthorizationHelperInterface
if ($role instanceof Role) { if ($role instanceof Role) {
$role = $role->getRole(); $role = $role->getRole();
} }
if (!$user instanceof User) {
return [];
}
/** @var array<string, Center> $centers */ /** @var array<string, Center> $centers */
$centers = []; $centers = [];