mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 14:43:49 +00:00
Merge remote-tracking branch 'origin/master' into fix-phpstan-issues-202303
This commit is contained in:
@@ -18,6 +18,7 @@ function loadDynamicPicker(element) {
|
||||
isMultiple = parseInt(el.dataset.multiple) === 1,
|
||||
uniqId = el.dataset.uniqid,
|
||||
input = element.querySelector('[data-input-uniqid="'+ el.dataset.uniqid +'"]'),
|
||||
// the "picked" will always be an array, even if multiple is false
|
||||
picked = isMultiple ?
|
||||
JSON.parse(input.value) : (
|
||||
(input.value === '[]' || input.value === '') ?
|
||||
@@ -54,15 +55,11 @@ function loadDynamicPicker(element) {
|
||||
},
|
||||
computed: {
|
||||
notPickedSuggested() {
|
||||
if (this.multiple) {
|
||||
const pickedIds = new Set();
|
||||
for (const p of this.picked) {
|
||||
pickedIds.add(`${p.type}${p.id}`);
|
||||
}
|
||||
return this.suggested.filter(e => !pickedIds.has(`${e.type}${e.id}`))
|
||||
const pickedIds = new Set();
|
||||
for (const p of this.picked) {
|
||||
pickedIds.add(`${p.type}${p.id}`);
|
||||
}
|
||||
|
||||
return this.suggested.filter(e => e.type !== this.picked.type && e.id !== e.picked.id);
|
||||
return this.suggested.filter(e => !pickedIds.has(`${e.type}${e.id}`))
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
@@ -90,7 +87,11 @@ function loadDynamicPicker(element) {
|
||||
this.suggested.push(entity);
|
||||
}
|
||||
this.picked = this.picked.filter(e => !(e.type === entity.type && e.id === entity.id));
|
||||
input.value = JSON.stringify(this.picked);
|
||||
if (this.multiple) {
|
||||
input.value = JSON.stringify(this.picked);
|
||||
} else {
|
||||
input.value = "";
|
||||
}
|
||||
},
|
||||
}
|
||||
})
|
||||
|
@@ -66,6 +66,7 @@
|
||||
{{ form_row(transition_form.future_dest_users) }}
|
||||
|
||||
{{ form_row(transition_form.future_dest_emails) }}
|
||||
{{ form_errors(transition_form.future_dest_users) }}
|
||||
</div>
|
||||
|
||||
<p>{{ form_label(transition_form.comment) }}</p>
|
||||
|
@@ -30,7 +30,7 @@ class SearchApi
|
||||
|
||||
private PaginatorFactory $paginator;
|
||||
|
||||
private iterable $providers = [];
|
||||
private iterable $providers;
|
||||
|
||||
public function __construct(
|
||||
EntityManagerInterface $em,
|
||||
@@ -42,9 +42,6 @@ class SearchApi
|
||||
$this->paginator = $paginator;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Model/Result[]
|
||||
*/
|
||||
public function getResults(string $pattern, array $types, array $parameters): Collection
|
||||
{
|
||||
$queries = $this->findQueries($pattern, $types, $parameters);
|
||||
@@ -53,10 +50,10 @@ class SearchApi
|
||||
throw new SearchApiNoQueryException($pattern, $types, $parameters);
|
||||
}
|
||||
|
||||
$total = $this->countItems($queries, $types, $parameters);
|
||||
$total = $this->countItems($queries);
|
||||
$paginator = $this->paginator->create($total);
|
||||
|
||||
$rawResults = $this->fetchRawResult($queries, $types, $parameters, $paginator);
|
||||
$rawResults = $this->fetchRawResult($queries, $types, $paginator);
|
||||
|
||||
$this->prepareProviders($rawResults);
|
||||
$results = $this->buildResults($rawResults);
|
||||
@@ -64,7 +61,7 @@ class SearchApi
|
||||
return new Collection($results, $paginator);
|
||||
}
|
||||
|
||||
private function buildCountQuery(array $queries, $types, $parameters)
|
||||
private function buildCountQuery(array $queries): array
|
||||
{
|
||||
$query = 'SELECT SUM(c) AS count FROM ({union_unordered}) AS sq';
|
||||
$unions = [];
|
||||
@@ -88,7 +85,7 @@ class SearchApi
|
||||
$items = [];
|
||||
|
||||
foreach ($rawResults as $r) {
|
||||
foreach ($this->providers as $k => $p) {
|
||||
foreach ($this->providers as $p) {
|
||||
if ($p->supportsResult($r['key'], $r['metadata'])) {
|
||||
$items[] = (new SearchApiResult($r['pertinence']))
|
||||
->setResult(
|
||||
@@ -103,7 +100,7 @@ class SearchApi
|
||||
return $items;
|
||||
}
|
||||
|
||||
private function buildUnionQuery(array $queries, $types, $parameters, Paginator $paginator)
|
||||
private function buildUnionQuery(array $queries, Paginator $paginator): array
|
||||
{
|
||||
$query = '{unions} ORDER BY pertinence DESC LIMIT ? OFFSET ?';
|
||||
$unions = [];
|
||||
@@ -126,9 +123,9 @@ class SearchApi
|
||||
];
|
||||
}
|
||||
|
||||
private function countItems($providers, $types, $parameters): int
|
||||
private function countItems($providers): int
|
||||
{
|
||||
[$countQuery, $parameters] = $this->buildCountQuery($providers, $types, $parameters);
|
||||
[$countQuery, $parameters] = $this->buildCountQuery($providers);
|
||||
$rsmCount = new ResultSetMappingBuilder($this->em);
|
||||
$rsmCount->addScalarResult('count', 'count');
|
||||
$countNq = $this->em->createNativeQuery($countQuery, $rsmCount);
|
||||
@@ -137,9 +134,9 @@ class SearchApi
|
||||
return (int) $countNq->getSingleScalarResult();
|
||||
}
|
||||
|
||||
private function fetchRawResult($queries, $types, $parameters, Paginator $paginator): array
|
||||
private function fetchRawResult($queries, $types, Paginator $paginator): array
|
||||
{
|
||||
[$union, $parameters] = $this->buildUnionQuery($queries, $types, $parameters, $paginator);
|
||||
[$union, $parameters] = $this->buildUnionQuery($queries, $paginator);
|
||||
$rsm = new ResultSetMappingBuilder($this->em);
|
||||
$rsm->addScalarResult('key', 'key', Types::STRING)
|
||||
->addScalarResult('metadata', 'metadata', Types::JSON)
|
||||
@@ -172,7 +169,7 @@ class SearchApi
|
||||
);
|
||||
}
|
||||
|
||||
private function prepareProviders(array $rawResults)
|
||||
private function prepareProviders(array $rawResults): void
|
||||
{
|
||||
$metadatas = [];
|
||||
$providers = [];
|
||||
|
@@ -16,6 +16,18 @@ use function count;
|
||||
use function implode;
|
||||
use function strtr;
|
||||
|
||||
/**
|
||||
* This create a query optimized for searching for the api response.
|
||||
*
|
||||
* When build, this class generate a SQL string and a list of a parameters which is suitable for running
|
||||
* a native SQL query. This have usually the form of
|
||||
*
|
||||
* `SELECT '<key>' as key, <metadata> as metadata, <pertinence> as pertinence FROM <from clause> WHERE <where clause>`.
|
||||
*
|
||||
* The clause between `<>` are provided through the dedicated method in this class (@link{self::setSelectKey},
|
||||
* @link{self::setFromClause}), etc.).
|
||||
*
|
||||
*/
|
||||
class SearchApiQuery
|
||||
{
|
||||
private ?string $fromClause = null;
|
||||
|
@@ -16,7 +16,7 @@ use Chill\MainBundle\Entity\Scope;
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Chill\MainBundle\Repository\UserACLAwareRepositoryInterface;
|
||||
use Chill\MainBundle\Security\ParentRoleHelper;
|
||||
use Chill\MainBundle\Security\Resolver\CenterResolverDispatcherInterface;
|
||||
use Chill\MainBundle\Security\Resolver\CenterResolverManagerInterface;
|
||||
use Chill\MainBundle\Security\Resolver\ScopeResolverDispatcher;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\Security\Core\Role\Role;
|
||||
@@ -34,7 +34,7 @@ use function get_class;
|
||||
*/
|
||||
class AuthorizationHelper implements AuthorizationHelperInterface
|
||||
{
|
||||
private CenterResolverDispatcherInterface $centerResolverDispatcher;
|
||||
private CenterResolverManagerInterface $centerResolverManager;
|
||||
|
||||
private LoggerInterface $logger;
|
||||
|
||||
@@ -45,13 +45,13 @@ class AuthorizationHelper implements AuthorizationHelperInterface
|
||||
private UserACLAwareRepositoryInterface $userACLAwareRepository;
|
||||
|
||||
public function __construct(
|
||||
CenterResolverDispatcherInterface $centerResolverDispatcher,
|
||||
CenterResolverManagerInterface $centerResolverManager,
|
||||
LoggerInterface $logger,
|
||||
ScopeResolverDispatcher $scopeResolverDispatcher,
|
||||
UserACLAwareRepositoryInterface $userACLAwareRepository,
|
||||
ParentRoleHelper $parentRoleHelper
|
||||
) {
|
||||
$this->centerResolverDispatcher = $centerResolverDispatcher;
|
||||
$this->centerResolverManager = $centerResolverManager;
|
||||
$this->logger = $logger;
|
||||
$this->scopeResolverDispatcher = $scopeResolverDispatcher;
|
||||
$this->userACLAwareRepository = $userACLAwareRepository;
|
||||
@@ -63,7 +63,7 @@ class AuthorizationHelper implements AuthorizationHelperInterface
|
||||
*
|
||||
* @param User $user The user
|
||||
* @param array $centers a list of centers which are going to be filtered
|
||||
* @param Center|string $role
|
||||
* @param string $role
|
||||
*/
|
||||
public function filterReachableCenters(User $user, array $centers, $role): array
|
||||
{
|
||||
@@ -113,13 +113,14 @@ class AuthorizationHelper implements AuthorizationHelperInterface
|
||||
* Get reachable Centers for the given user, role,
|
||||
* and optionally Scope.
|
||||
*
|
||||
* @return array|Center[]
|
||||
* @return list<Center>
|
||||
*/
|
||||
public function getReachableCenters(UserInterface $user, string $role, ?Scope $scope = null): array
|
||||
{
|
||||
if ($role instanceof Role) {
|
||||
$role = $role->getRole();
|
||||
}
|
||||
/** @var array<string, Center> $centers */
|
||||
$centers = [];
|
||||
|
||||
foreach ($user->getGroupCenters() as $groupCenter) {
|
||||
@@ -129,13 +130,13 @@ class AuthorizationHelper implements AuthorizationHelperInterface
|
||||
//check that the role is in the reachable roles
|
||||
if ($this->isRoleReached($role, $roleScope->getRole())) {
|
||||
if (null === $scope) {
|
||||
$centers[] = $groupCenter->getCenter();
|
||||
$centers[spl_object_hash($groupCenter->getCenter())] = $groupCenter->getCenter();
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if ($scope->getId() === $roleScope->getScope()->getId()) {
|
||||
$centers[] = $groupCenter->getCenter();
|
||||
$centers[spl_object_hash($groupCenter->getCenter())] = $groupCenter->getCenter();
|
||||
|
||||
break;
|
||||
}
|
||||
@@ -143,7 +144,7 @@ class AuthorizationHelper implements AuthorizationHelperInterface
|
||||
}
|
||||
}
|
||||
|
||||
return $centers;
|
||||
return array_values($centers);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -194,7 +195,7 @@ class AuthorizationHelper implements AuthorizationHelperInterface
|
||||
*
|
||||
* @return array|Scope[]
|
||||
*/
|
||||
public function getReachableScopes(UserInterface $user, string $role, $center): array
|
||||
public function getReachableScopes(UserInterface $user, string $role, Center|array $center): array
|
||||
{
|
||||
if ($role instanceof Role) {
|
||||
$role = $role->getRole();
|
||||
@@ -252,27 +253,15 @@ class AuthorizationHelper implements AuthorizationHelperInterface
|
||||
*/
|
||||
public function userHasAccess(User $user, $entity, $attribute)
|
||||
{
|
||||
$center = $this->centerResolverDispatcher->resolveCenter($entity);
|
||||
$centers = $this->centerResolverManager->resolveCenters($entity);
|
||||
|
||||
if (is_iterable($center)) {
|
||||
foreach ($center as $c) {
|
||||
if ($this->userHasAccessForCenter($user, $c, $entity, $attribute)) {
|
||||
return true;
|
||||
}
|
||||
foreach ($centers as $c) {
|
||||
if ($this->userHasAccessForCenter($user, $c, $entity, $attribute)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($center instanceof Center) {
|
||||
return $this->userHasAccessForCenter($user, $center, $entity, $attribute);
|
||||
}
|
||||
|
||||
if (null === $center) {
|
||||
return false;
|
||||
}
|
||||
|
||||
throw new UnexpectedValueException('could not resolver a center');
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -21,12 +21,12 @@ interface AuthorizationHelperInterface
|
||||
* Get reachable Centers for the given user, role,
|
||||
* and optionnaly Scope.
|
||||
*
|
||||
* @return Center[]
|
||||
* @return list<Center>
|
||||
*/
|
||||
public function getReachableCenters(UserInterface $user, string $role, ?Scope $scope = null): array;
|
||||
|
||||
/**
|
||||
* @param array|Center|Center[] $center
|
||||
* @param Center|list<Center> $center
|
||||
*/
|
||||
public function getReachableScopes(UserInterface $user, string $role, $center): array;
|
||||
public function getReachableScopes(UserInterface $user, string $role, Center|array $center): array;
|
||||
}
|
||||
|
@@ -1,8 +1,8 @@
|
||||
"This program is free software: you can redistribute it and/or modify it under the terms of the <strong>GNU Affero General Public License</strong>": "Ce programme est un logiciel libre: vous pouvez le redistribuer et/ou le modifier selon les termes de la licence <strong>GNU Affero GPL</strong>"
|
||||
User manual: Manuel d'utilisation
|
||||
Search: Rechercher
|
||||
"Search persons, ...": "Recherche des personnes, ..."
|
||||
Person name: Nom / Prénom de la personne
|
||||
"Search persons, ...": "Recherche des usagers, ..."
|
||||
Person name: Nom / Prénom de l'usager
|
||||
Login: Connexion
|
||||
Logout: Se déconnecter
|
||||
Bad credentials.: Le mot de passe et le nom d'utilisateur ne correspondent pas.
|
||||
|
Reference in New Issue
Block a user