fix: SA: Split critical issues in its own file.

SA stands for Static Analysis.
This commit is contained in:
Pol Dellaiera
2021-11-16 13:55:55 +01:00
parent c68bda5c9b
commit 8ede116cf5
12 changed files with 333 additions and 380 deletions

View File

@@ -23,6 +23,7 @@ use Chill\MainBundle\Security\RoleProvider;
use Doctrine\ORM\EntityManagerInterface;
use Chill\MainBundle\Entity\GroupCenter;
use Chill\MainBundle\Entity\RoleScope;
use Symfony\Component\Security\Core\User\UserInterface;
/**
* Helper for authorizations.
@@ -145,19 +146,21 @@ class AuthorizationHelper implements AuthorizationHelperInterface
if ($this->scopeResolverDispatcher->isConcerned($entity)) {
$scope = $this->scopeResolverDispatcher->resolveScope($entity);
if (NULL === $scope) {
return true;
} elseif (is_iterable($scope)) {
foreach ($scope as $s) {
if ($s === $roleScope->getScope()) {
return true;
}
}
} else {
if ($scope === $roleScope->getScope()) {
return true;
}
}
if (NULL === $scope) {
return true;
}
if (is_iterable($scope)) {
foreach ($scope as $s) {
if ($s === $roleScope->getScope()) {
return true;
}
}
} else {
if ($scope === $roleScope->getScope()) {
return true;
}
}
} else {
return true;
}
@@ -176,14 +179,11 @@ class AuthorizationHelper implements AuthorizationHelperInterface
/**
* Get reachable Centers for the given user, role,
* and optionnaly Scope
* and optionally Scope
*
* @param User $user
* @param string|Role $role
* @param null|Scope $scope
* @return Center[]|array
*/
public function getReachableCenters(User $user, string $role, ?Scope $scope = null): array
public function getReachableCenters(UserInterface $user, string $role, ?Scope $scope = null): array
{
if ($role instanceof Role) {
$role = $role->getRole();
@@ -199,11 +199,11 @@ class AuthorizationHelper implements AuthorizationHelperInterface
if ($scope === null) {
$centers[] = $groupCenter->getCenter();
break 1;
} else {
if ($scope->getId() == $roleScope->getScope()->getId()){
$centers[] = $groupCenter->getCenter();
break 1;
}
}
if ($scope->getId() == $roleScope->getScope()->getId()){
$centers[] = $groupCenter->getCenter();
break 1;
}
}
}
@@ -242,12 +242,10 @@ class AuthorizationHelper implements AuthorizationHelperInterface
*
* @deprecated Use getReachableCircles
*
* @param User $user
* @param string role
* @param Center|Center[] $center
* @return Scope[]|array
*/
public function getReachableScopes(User $user, string $role, $center): array
public function getReachableScopes(UserInterface $user, string $role, $center): array
{
if ($role instanceof Role) {
$role = $role->getRole();
@@ -259,12 +257,11 @@ class AuthorizationHelper implements AuthorizationHelperInterface
/**
* Return all reachable circle for a given user, center and role
*
* @param User $user
* @param string|Role $role
* @param Center|Center[] $center
* @return Scope[]
*/
public function getReachableCircles(User $user, $role, $center)
public function getReachableCircles(UserInterface $user, $role, $center)
{
$scopes = [];

View File

@@ -4,29 +4,23 @@ namespace Chill\MainBundle\Security\Authorization;
use Chill\MainBundle\Entity\Center;
use Chill\MainBundle\Entity\Scope;
use Chill\MainBundle\Entity\User;
use Symfony\Component\Security\Core\Role\Role;
use Symfony\Component\Security\Core\User\UserInterface;
interface AuthorizationHelperInterface
{
/**
* Get reachable Centers for the given user, role,
* and optionnaly Scope
*
* @param User $user
* @param string|Role $role
* @param null|Scope $scope
* @return Center[]
*/
public function getReachableCenters(User $user, string $role, ?Scope $scope = null): array;
public function getReachableCenters(UserInterface $user, string $role, ?Scope $scope = null): array;
/**
* @param User $user
* @param string $role
* @param Center|Center[]|array $center
* @return array
*/
public function getReachableScopes(User $user, string $role, $center): array;
public function getReachableScopes(UserInterface $user, string $role, $center): array;
}