mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-30 03:23:48 +00:00
Merge remote-tracking branch 'origin/master' into doc/authorizaton-documentation-update
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\TaskBundle\Controller;
|
||||
|
||||
use Chill\MainBundle\Security\Resolver\CenterResolverDispatcher;
|
||||
@@ -29,14 +31,8 @@ use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface as TranslationTranslatorInterface;
|
||||
|
||||
/**
|
||||
* Class SingleTaskController
|
||||
*
|
||||
* @package Chill\TaskBundle\Controller
|
||||
*/
|
||||
final class SingleTaskController extends AbstractController
|
||||
{
|
||||
|
||||
private EventDispatcherInterface $eventDispatcher;
|
||||
private TimelineBuilder $timelineBuilder;
|
||||
private LoggerInterface $logger;
|
||||
@@ -320,15 +316,12 @@ final class SingleTaskController extends AbstractController
|
||||
* name="chill_task_single_task_delete"
|
||||
* )
|
||||
*/
|
||||
public function deleteAction(
|
||||
Request $request,
|
||||
$id
|
||||
) {
|
||||
|
||||
public function deleteAction(Request $request, $id) {
|
||||
$course = null;
|
||||
$em = $this->getDoctrine()->getManager();
|
||||
$task = $em->getRepository(SingleTask::class)->find($id);
|
||||
|
||||
if (!$task) {
|
||||
if (null === $task) {
|
||||
throw $this->createNotFoundException('Unable to find Task entity.');
|
||||
}
|
||||
|
||||
@@ -403,19 +396,24 @@ final class SingleTaskController extends AbstractController
|
||||
}
|
||||
}
|
||||
|
||||
if($task->getContext() instanceof Person){
|
||||
return $this->render('@ChillTask/SingleTask/Person/confirm_delete.html.twig', array(
|
||||
'task' => $task,
|
||||
'delete_form' => $form->createView()
|
||||
));
|
||||
} else {
|
||||
return $this->render('@ChillTask/SingleTask/AccompanyingCourse/confirm_delete.html.twig', array(
|
||||
'task' => $task,
|
||||
'delete_form' => $form->createView(),
|
||||
'accompanyingCourse' => $course
|
||||
));
|
||||
if ($task->getContext() instanceof Person) {
|
||||
return $this->render(
|
||||
'@ChillTask/SingleTask/Person/confirm_delete.html.twig',
|
||||
[
|
||||
'task' => $task,
|
||||
'delete_form' => $form->createView(),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
return $this->render(
|
||||
'@ChillTask/SingleTask/AccompanyingCourse/confirm_delete.html.twig',
|
||||
[
|
||||
'task' => $task,
|
||||
'delete_form' => $form->createView(),
|
||||
'accompanyingCourse' => $course
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -90,11 +90,6 @@ abstract class AbstractTask implements HasScopeInterface, HasCenterInterface
|
||||
*/
|
||||
private $closed = false;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Set type
|
||||
*
|
||||
|
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Chill\TaskBundle\Entity;
|
||||
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
@@ -103,9 +104,7 @@ class SingleTask extends AbstractTask
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->taskPlaceEvents = $events = new \Doctrine\Common\Collections\ArrayCollection;
|
||||
|
||||
parent::__construct();
|
||||
$this->taskPlaceEvents = new ArrayCollection();
|
||||
}
|
||||
|
||||
|
||||
|
@@ -1,20 +1,7 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright (C) 2018 Champs Libres Cooperative <info@champs-libres.coop>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\TaskBundle\Form;
|
||||
|
||||
use Chill\MainBundle\Security\Resolver\CenterResolverDispatcher;
|
||||
@@ -48,6 +35,9 @@ class SingleTaskType extends AbstractType
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$center = null;
|
||||
$isScopeConcerned = false;
|
||||
|
||||
if (NULL !== $task = $options['data']) {
|
||||
$center = $this->centerResolverDispatcher->resolveCenter($task);
|
||||
$isScopeConcerned = $this->scopeResolverDispatcher->isConcerned($task);
|
||||
@@ -62,7 +52,8 @@ class SingleTaskType extends AbstractType
|
||||
'required' => false,
|
||||
'center' => $center,
|
||||
'role' => TaskVoter::SHOW,
|
||||
'placeholder' => 'Not assigned'
|
||||
'placeholder' => 'Not assigned',
|
||||
'attr' => [ 'class' => ' select2 ']
|
||||
])
|
||||
->add('startDate', ChillDateType::class, [
|
||||
'required' => false
|
||||
@@ -74,8 +65,7 @@ class SingleTaskType extends AbstractType
|
||||
'required' => false
|
||||
]);
|
||||
|
||||
if ($this->parameterBag->get('chill_main')['acl']['form_show_scopes']
|
||||
&& $isScopeConcerned) {
|
||||
if ($isScopeConcerned && $this->parameterBag->get('chill_main')['acl']['form_show_scopes']) {
|
||||
$builder
|
||||
->add('circle', ScopePickerType::class, [
|
||||
'center' => $center,
|
||||
|
@@ -1,26 +1,13 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright (C) 2018 Champs Libres Cooperative <info@champs-libres.coop>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\TaskBundle\Security\Authorization;
|
||||
|
||||
use Chill\EventBundle\Entity\Event;
|
||||
use Chill\MainBundle\Entity\Center;
|
||||
use Chill\MainBundle\Security\Authorization\AbstractChillVoter;
|
||||
use Chill\MainBundle\Security\Authorization\AuthorizationHelperInterface;
|
||||
use Chill\MainBundle\Security\Authorization\VoterHelperFactoryInterface;
|
||||
use Chill\MainBundle\Security\Authorization\VoterHelperInterface;
|
||||
use Chill\MainBundle\Security\Resolver\CenterResolverDispatcher;
|
||||
@@ -41,13 +28,13 @@ use Chill\TaskBundle\Security\Authorization\AuthorizationEvent;
|
||||
|
||||
final class TaskVoter extends AbstractChillVoter implements ProvideRoleHierarchyInterface
|
||||
{
|
||||
const CREATE_COURSE = 'CHILL_TASK_TASK_CREATE_FOR_COURSE';
|
||||
const CREATE_PERSON = 'CHILL_TASK_TASK_CREATE_FOR_PERSON';
|
||||
const DELETE = 'CHILL_TASK_TASK_DELETE';
|
||||
const SHOW = 'CHILL_TASK_TASK_SHOW';
|
||||
const UPDATE = 'CHILL_TASK_TASK_UPDATE';
|
||||
public const CREATE_COURSE = 'CHILL_TASK_TASK_CREATE_FOR_COURSE';
|
||||
public const CREATE_PERSON = 'CHILL_TASK_TASK_CREATE_FOR_PERSON';
|
||||
public const DELETE = 'CHILL_TASK_TASK_DELETE';
|
||||
public const SHOW = 'CHILL_TASK_TASK_SHOW';
|
||||
public const UPDATE = 'CHILL_TASK_TASK_UPDATE';
|
||||
|
||||
const ROLES = [
|
||||
public const ROLES = [
|
||||
self::CREATE_COURSE,
|
||||
self::CREATE_PERSON,
|
||||
self::DELETE,
|
||||
@@ -55,33 +42,23 @@ final class TaskVoter extends AbstractChillVoter implements ProvideRoleHierarchy
|
||||
self::UPDATE,
|
||||
];
|
||||
|
||||
protected AuthorizationHelper $authorizationHelper;
|
||||
private AccessDecisionManagerInterface $accessDecisionManager;
|
||||
|
||||
protected AccessDecisionManagerInterface $accessDecisionManager;
|
||||
private LoggerInterface $logger;
|
||||
|
||||
protected LoggerInterface $logger;
|
||||
|
||||
protected EventDispatcherInterface $eventDispatcher;
|
||||
|
||||
protected CenterResolverDispatcher $centerResolverDispatcher;
|
||||
|
||||
protected VoterHelperInterface $voter;
|
||||
private EventDispatcherInterface $eventDispatcher;
|
||||
|
||||
private VoterHelperInterface $voter;
|
||||
|
||||
public function __construct(
|
||||
VoterHelperFactoryInterface $voterHelperFactory,
|
||||
AccessDecisionManagerInterface $accessDecisionManager,
|
||||
AuthorizationHelper $authorizationHelper,
|
||||
EventDispatcherInterface $eventDispatcher,
|
||||
LoggerInterface $logger,
|
||||
CenterResolverDispatcher $centerResolverDispatcher,
|
||||
VoterHelperFactoryInterface $voterFactory
|
||||
) {
|
||||
$this->accessDecisionManager = $accessDecisionManager;
|
||||
$this->authorizationHelper = $authorizationHelper;
|
||||
$this->eventDispatcher = $eventDispatcher;
|
||||
$this->logger = $logger;
|
||||
$this->centerResolverDispatcher = $centerResolverDispatcher;
|
||||
|
||||
$this->voter = $voterFactory
|
||||
->generate(AbstractTask::class)
|
||||
@@ -89,8 +66,7 @@ final class TaskVoter extends AbstractChillVoter implements ProvideRoleHierarchy
|
||||
->addCheckFor(Person::class, [self::SHOW, self::CREATE_PERSON])
|
||||
->addCheckFor(AccompanyingPeriod::class, [self::SHOW, self::CREATE_COURSE])
|
||||
->addCheckFor(null, [self::SHOW])
|
||||
->build()
|
||||
;
|
||||
->build();
|
||||
}
|
||||
|
||||
public function supports($attribute, $subject)
|
||||
@@ -98,13 +74,6 @@ final class TaskVoter extends AbstractChillVoter implements ProvideRoleHierarchy
|
||||
return $this->voter->supports($attribute, $subject);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param string $attribute
|
||||
* @param AbstractTask $subject
|
||||
* @param TokenInterface $token
|
||||
* @return boolean
|
||||
*/
|
||||
protected function voteOnAttribute($attribute, $subject, TokenInterface $token)
|
||||
{
|
||||
$this->logger->debug(sprintf("Voting from %s class", self::class));
|
||||
@@ -118,7 +87,6 @@ final class TaskVoter extends AbstractChillVoter implements ProvideRoleHierarchy
|
||||
$this->eventDispatcher->dispatch(AuthorizationEvent::VOTE, $event);
|
||||
|
||||
if ($event->hasVote()) {
|
||||
|
||||
$this->logger->debug("The TaskVoter is overriding by "
|
||||
.AuthorizationEvent::VOTE, [
|
||||
'vote' => $event->getVote(),
|
||||
@@ -167,5 +135,4 @@ final class TaskVoter extends AbstractChillVoter implements ProvideRoleHierarchy
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -38,18 +38,18 @@ use Chill\MainBundle\Timeline\TimelineSingleQuery;
|
||||
class TaskLifeCycleEventTimelineProvider implements TimelineProviderInterface
|
||||
{
|
||||
protected EntityManagerInterface $em;
|
||||
|
||||
|
||||
protected Registry $registry;
|
||||
|
||||
|
||||
protected AuthorizationHelper $authorizationHelper;
|
||||
|
||||
protected Security $security;
|
||||
|
||||
|
||||
|
||||
|
||||
const TYPE = 'chill_task.transition';
|
||||
|
||||
|
||||
public function __construct(
|
||||
EntityManagerInterface $em,
|
||||
EntityManagerInterface $em,
|
||||
Registry $registry,
|
||||
AuthorizationHelper $authorizationHelper,
|
||||
Security $security
|
||||
@@ -64,7 +64,7 @@ class TaskLifeCycleEventTimelineProvider implements TimelineProviderInterface
|
||||
{
|
||||
$metadata = $this->em
|
||||
->getClassMetadata(SingleTaskPlaceEvent::class);
|
||||
|
||||
|
||||
switch ($context) {
|
||||
case 'person':
|
||||
[ $where, $parameters ] = $this->getWhereClauseForPerson($args['person']);
|
||||
@@ -157,7 +157,7 @@ class TaskLifeCycleEventTimelineProvider implements TimelineProviderInterface
|
||||
|
||||
|
||||
// the parameters
|
||||
$parameters = [];
|
||||
$parameters = $circleIds = [];
|
||||
|
||||
// the clause that we will fill
|
||||
$clause = "{person}.{person_id} = ? AND {task}.{circle} IN ({circle_ids})";
|
||||
@@ -212,27 +212,27 @@ class TaskLifeCycleEventTimelineProvider implements TimelineProviderInterface
|
||||
'{single_task}' => sprintf('%s.%s', $singleTask->getSchemaName(), $singleTask->getTableName()),
|
||||
'{single_task_event}' => sprintf('%s.%s', $taskEvent->getSchemaName(), $taskEvent->getTableName()),
|
||||
'{task_pk}' => $singleTask->getColumnName('id'),
|
||||
'{event_fk_task}' => $eventFkTask,
|
||||
'{event_fk_task}' => $eventFkTask,
|
||||
'{person}' => $person->getTableName(),
|
||||
'{task_person_fk}' => $taskFkPerson,
|
||||
'{person_pk}' => $personPk
|
||||
'{person_pk}' => $personPk
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
public function getEntities(array $ids)
|
||||
}
|
||||
|
||||
public function getEntities(array $ids)
|
||||
{
|
||||
$events = $this->em
|
||||
->getRepository(SingleTaskPlaceEvent::class)
|
||||
->findBy([ 'id' => $ids ])
|
||||
;
|
||||
|
||||
|
||||
return \array_combine(
|
||||
\array_map(function($e) { return $e->getId(); }, $events ),
|
||||
$events
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function getEntityTemplate($entity, $context, array $args)
|
||||
{
|
||||
$workflow = $this->registry->get($entity->getTask(),
|
||||
@@ -242,22 +242,22 @@ class TaskLifeCycleEventTimelineProvider implements TimelineProviderInterface
|
||||
// `Notice: Undefined property: Chill\TaskBundle\Entity\Task\SingleTaskPlaceEvent::$getData`
|
||||
// * fix syntax error on $entity->getData['workflow']
|
||||
// * return null if not set
|
||||
|
||||
|
||||
$transition = $this->getTransitionByName($entity->getTransition(), $workflow);
|
||||
|
||||
|
||||
return [
|
||||
'template' => 'ChillTaskBundle:Timeline:single_task_transition.html.twig',
|
||||
'template_data' => [
|
||||
'template_data' => [
|
||||
'context' => $context,
|
||||
'event' => $entity,
|
||||
'task' => $entity->getTask(),
|
||||
'transition' => $transition
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param string $name
|
||||
* @param Workflow $workflow
|
||||
* @return \Symfony\Component\Workflow\Transition
|
||||
@@ -270,7 +270,7 @@ class TaskLifeCycleEventTimelineProvider implements TimelineProviderInterface
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function supportsType($type): bool
|
||||
{
|
||||
return $type === self::TYPE;
|
||||
|
Reference in New Issue
Block a user