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 issue477_autosave_comment_parcours
This commit is contained in:
@@ -256,6 +256,13 @@ class ChillMainExtension extends Extension implements
|
||||
'channels' => ['chill'],
|
||||
]);
|
||||
|
||||
$container->prependExtensionConfig('security', [
|
||||
'access_decision_manager' => [
|
||||
'strategy' => 'unanimous',
|
||||
'allow_if_all_abstain' => false,
|
||||
],
|
||||
]);
|
||||
|
||||
//add crud api
|
||||
$this->prependCruds($container);
|
||||
}
|
||||
|
@@ -192,7 +192,7 @@ class EntityWorkflowStep
|
||||
* You should **not** rely on this method to get all users which are able to
|
||||
* apply a transition on this step. Use @see{EntityWorkflowStep::getAllDestUser} instead.
|
||||
*/
|
||||
public function getDestUser(): collection
|
||||
public function getDestUser(): Collection
|
||||
{
|
||||
return $this->destUser;
|
||||
}
|
||||
|
@@ -16,9 +16,7 @@ use libphonenumber\PhoneNumberUtil;
|
||||
use Misd\PhoneNumberBundle\Form\Type\PhoneNumberType;
|
||||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\OptionsResolver\Options;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
use function array_key_exists;
|
||||
|
||||
class ChillPhoneNumberType extends AbstractType
|
||||
{
|
||||
@@ -37,21 +35,7 @@ class ChillPhoneNumberType extends AbstractType
|
||||
$resolver
|
||||
->setDefault('default_region', $this->defaultCarrierCode)
|
||||
->setDefault('format', PhoneNumberFormat::NATIONAL)
|
||||
->setDefault('type', \libphonenumber\PhoneNumberType::FIXED_LINE_OR_MOBILE)
|
||||
->setNormalizer('attr', function (Options $options, $value) {
|
||||
if (array_key_exists('placeholder', $value)) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
$examplePhoneNumber = $this->phoneNumberUtil->getExampleNumberForType($this->defaultCarrierCode, $options['type']);
|
||||
|
||||
return array_merge(
|
||||
$value,
|
||||
[
|
||||
'placeholder' => PhoneNumberUtil::getInstance()->format($examplePhoneNumber, $options['format']),
|
||||
]
|
||||
);
|
||||
});
|
||||
->setDefault('type', \libphonenumber\PhoneNumberType::FIXED_LINE_OR_MOBILE);
|
||||
}
|
||||
|
||||
public function getParent()
|
||||
|
@@ -27,7 +27,7 @@ interface PhoneNumberHelperInterface
|
||||
/**
|
||||
* Get type (mobile, landline, ...) for phone number.
|
||||
*/
|
||||
public function getType(string $phonenumber): string;
|
||||
public function getType(PhoneNumber $phonenumber): string;
|
||||
|
||||
/**
|
||||
* Return true if the validation is configured and available.
|
||||
|
@@ -17,6 +17,7 @@ use GuzzleHttp\Exception\ConnectException;
|
||||
use GuzzleHttp\Exception\ServerException;
|
||||
use libphonenumber\NumberParseException;
|
||||
use libphonenumber\PhoneNumber;
|
||||
use libphonenumber\PhoneNumberType;
|
||||
use libphonenumber\PhoneNumberUtil;
|
||||
use Psr\Cache\CacheItemPoolInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
@@ -86,9 +87,19 @@ final class PhonenumberHelper implements PhoneNumberHelperInterface
|
||||
/**
|
||||
* Get type (mobile, landline, ...) for phone number.
|
||||
*/
|
||||
public function getType(string $phonenumber): string
|
||||
public function getType(PhoneNumber $phonenumber): string
|
||||
{
|
||||
return $this->performTwilioLookup($phonenumber) ?? 'unknown';
|
||||
switch ($this->phoneNumberUtil->getNumberType($phonenumber)) {
|
||||
case PhoneNumberType::MOBILE:
|
||||
return 'mobile';
|
||||
|
||||
case PhoneNumberType::FIXED_LINE:
|
||||
case PhoneNumberType::VOIP:
|
||||
return 'landline';
|
||||
|
||||
default:
|
||||
return 'landline';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -55,6 +55,30 @@ class EntityWorkflowRepository implements ObjectRepository
|
||||
return (int) $qb->getQuery()->getSingleScalarResult();
|
||||
}
|
||||
|
||||
public function countRelatedWorkflows(array $relateds): int
|
||||
{
|
||||
$qb = $this->repository->createQueryBuilder('w');
|
||||
|
||||
$orX = $qb->expr()->orX();
|
||||
$i = 0;
|
||||
|
||||
foreach ($relateds as $related) {
|
||||
$orX->add(
|
||||
$qb->expr()->andX(
|
||||
$qb->expr()->eq('w.relatedEntityClass', ':entity_class_' . $i),
|
||||
$qb->expr()->eq('w.relatedEntityId', ':entity_id_' . $i)
|
||||
)
|
||||
);
|
||||
$qb
|
||||
->setParameter('entity_class_' . $i, $related['entityClass'])
|
||||
->setParameter('entity_id_' . $i, $related['entityId']);
|
||||
++$i;
|
||||
}
|
||||
$qb->where($orX);
|
||||
|
||||
return $qb->select('COUNT(w)')->getQuery()->getSingleScalarResult();
|
||||
}
|
||||
|
||||
public function find($id): ?EntityWorkflow
|
||||
{
|
||||
return $this->repository->find($id);
|
||||
|
@@ -25,7 +25,7 @@ $chill-theme-buttons: (
|
||||
"notify": $chill-blue,
|
||||
"search": $gray-300,
|
||||
"unlink": $chill-red,
|
||||
"tpchild": $chill-pink,
|
||||
"tpchild": $chill-green,
|
||||
);
|
||||
|
||||
@each $button, $color in $chill-theme-buttons {
|
||||
|
@@ -9,6 +9,12 @@
|
||||
<span class="item-key">{{ 'Le'|trans ~ ' : ' }}</span>
|
||||
<b>{{ step.previous.transitionAt|format_datetime('short', 'short') }}</b>
|
||||
</li>
|
||||
<li>
|
||||
<span class="item-key">{{ 'workflow.For'|trans ~ ' : ' }}</span>
|
||||
<b>
|
||||
{% for d in step.destUser %}{{ d|chill_entity_render_string }}{% if not loop.last %}, {% endif %}{% endfor %}
|
||||
</b>
|
||||
</li>
|
||||
{% else %}
|
||||
<li>
|
||||
<span class="item-key">{{ 'workflow.Created by'|trans ~ ' : ' }}</span>
|
||||
|
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\MainBundle\Security\Authorization;
|
||||
|
||||
use Chill\MainBundle\Repository\Workflow\EntityWorkflowRepository;
|
||||
use Chill\MainBundle\Workflow\EntityWorkflowHandlerInterface;
|
||||
use RuntimeException;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
|
||||
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
|
||||
use function in_array;
|
||||
use function is_object;
|
||||
|
||||
class WorkflowEntityDeletionVoter extends Voter
|
||||
{
|
||||
private EntityWorkflowRepository $entityWorkflowRepository;
|
||||
|
||||
/**
|
||||
* @var iterable|EntityWorkflowHandlerInterface[]
|
||||
*/
|
||||
private iterable $handlers;
|
||||
|
||||
public function __construct($handlers, EntityWorkflowRepository $entityWorkflowRepository)
|
||||
{
|
||||
$this->handlers = $handlers;
|
||||
$this->entityWorkflowRepository = $entityWorkflowRepository;
|
||||
}
|
||||
|
||||
protected function supports($attribute, $subject)
|
||||
{
|
||||
if (!is_object($subject)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($this->handlers as $handler) {
|
||||
if ($handler->isObjectSupported($subject)
|
||||
&& in_array($attribute, $handler->getDeletionRoles($subject), true)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
protected function voteOnAttribute($attribute, $subject, TokenInterface $token)
|
||||
{
|
||||
foreach ($this->handlers as $handler) {
|
||||
if ($handler->isObjectSupported($subject)) {
|
||||
return 0 === $this->entityWorkflowRepository->countRelatedWorkflows(
|
||||
$handler->getRelatedObjects($subject)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
throw new RuntimeException('no handlers found');
|
||||
}
|
||||
}
|
@@ -113,6 +113,7 @@ class AddressNormalizer implements ContextAwareNormalizerInterface, NormalizerAw
|
||||
[
|
||||
'postcode' => $helper->normalize(self::NULL_POSTCODE_COUNTRY, $format, $context),
|
||||
'country' => $helper->normalize(self::NULL_POSTCODE_COUNTRY, $format, $context),
|
||||
'lines' => [],
|
||||
]
|
||||
);
|
||||
}
|
||||
|
@@ -40,6 +40,10 @@ class PhonenumberNormalizer implements NormalizerInterface, DenormalizerInterfac
|
||||
*/
|
||||
public function denormalize($data, $type, $format = null, array $context = [])
|
||||
{
|
||||
if ('' === trim($data)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
return $this->phoneNumberUtil->parse($data, $this->defaultCarrierCode);
|
||||
} catch (NumberParseException $e) {
|
||||
|
@@ -15,12 +15,19 @@ use Chill\MainBundle\Entity\Workflow\EntityWorkflow;
|
||||
|
||||
interface EntityWorkflowHandlerInterface
|
||||
{
|
||||
/**
|
||||
* @return array|string[]
|
||||
*/
|
||||
public function getDeletionRoles(): array;
|
||||
|
||||
public function getEntityData(EntityWorkflow $entityWorkflow, array $options = []): array;
|
||||
|
||||
public function getEntityTitle(EntityWorkflow $entityWorkflow, array $options = []): string;
|
||||
|
||||
public function getRelatedEntity(EntityWorkflow $entityWorkflow): ?object;
|
||||
|
||||
public function getRelatedObjects(object $object): array;
|
||||
|
||||
/**
|
||||
* Return a string representing the role required for seeing the workflow.
|
||||
*
|
||||
@@ -33,6 +40,8 @@ interface EntityWorkflowHandlerInterface
|
||||
|
||||
public function getTemplateData(EntityWorkflow $entityWorkflow, array $options = []): array;
|
||||
|
||||
public function isObjectSupported(object $object): bool;
|
||||
|
||||
public function supports(EntityWorkflow $entityWorkflow, array $options = []): bool;
|
||||
|
||||
public function supportsFreeze(EntityWorkflow $entityWorkflow, array $options = []): bool;
|
||||
|
@@ -75,3 +75,9 @@ services:
|
||||
$locker: '@Chill\MainBundle\Security\PasswordRecover\PasswordRecoverLocker'
|
||||
tags:
|
||||
- { name: security.voter }
|
||||
|
||||
Chill\MainBundle\Security\Authorization\WorkflowEntityDeletionVoter:
|
||||
autoconfigure: true
|
||||
autowire: true
|
||||
arguments:
|
||||
$handlers: !tagged_iterator chill_main.workflow_handler
|
||||
|
@@ -413,6 +413,7 @@ workflow:
|
||||
Previous workflow without reaction help: Liste des workflows où vous avez été cité comme pouvant réagir à une étape, mais où un autre utilisateur a exécuté une action avant vous.
|
||||
Previous transitionned: Anciens workflows
|
||||
Previous workflow transitionned help: Workflows où vous avez exécuté une action.
|
||||
For: Pour
|
||||
|
||||
|
||||
Subscribe final: Recevoir une notification à l'étape finale
|
||||
|
Reference in New Issue
Block a user