diff --git a/src/Bundle/ChillActivityBundle/Controller/ActivityController.php b/src/Bundle/ChillActivityBundle/Controller/ActivityController.php index a89b1d67c..5f7075aaf 100644 --- a/src/Bundle/ChillActivityBundle/Controller/ActivityController.php +++ b/src/Bundle/ChillActivityBundle/Controller/ActivityController.php @@ -198,7 +198,7 @@ final class ActivityController extends AbstractController // $this->denyAccessUnlessGranted('CHILL_ACTIVITY_UPDATE', $entity); $form = $this->createForm(ActivityType::class, $entity, [ - 'center' => $entity->getCenter(), + 'center' => $entity->getCenters()[0] ?? null, 'role' => new Role('CHILL_ACTIVITY_UPDATE'), 'activityType' => $entity->getActivityType(), 'accompanyingPeriod' => $accompanyingPeriod, diff --git a/src/Bundle/ChillActivityBundle/Entity/Activity.php b/src/Bundle/ChillActivityBundle/Entity/Activity.php index c947e7474..75729ca95 100644 --- a/src/Bundle/ChillActivityBundle/Entity/Activity.php +++ b/src/Bundle/ChillActivityBundle/Entity/Activity.php @@ -17,6 +17,7 @@ use Chill\MainBundle\Entity\Center; use Chill\MainBundle\Entity\Embeddable\CommentEmbeddable; use Chill\MainBundle\Entity\Embeddable\PrivateCommentEmbeddable; use Chill\MainBundle\Entity\HasCenterInterface; +use Chill\MainBundle\Entity\HasCentersInterface; use Chill\MainBundle\Entity\HasScopesInterface; use Chill\MainBundle\Entity\Location; use Chill\MainBundle\Entity\Scope; @@ -55,7 +56,7 @@ use Symfony\Component\Validator\Constraints as Assert; * getUserFunction="getUser", * path="scope") */ -class Activity implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterface, HasCenterInterface, HasScopesInterface +class Activity implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterface, HasCentersInterface, HasScopesInterface { public const SENTRECEIVED_RECEIVED = 'received'; @@ -306,13 +307,15 @@ class Activity implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterfac * get the center * center is extracted from person. */ - public function getCenter(): ?Center + public function getCenters(): array { if ($this->person instanceof Person) { - return $this->person->getCenter(); + return [$this->person->getCenter()]; + } elseif ($this->getAccompanyingPeriod() instanceof AccompanyingPeriod) { + return $this->getAccompanyingPeriod()->getCenters(); } - return null; + return []; } public function getComment(): CommentEmbeddable @@ -422,7 +425,7 @@ class Activity implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterfac return $this->scope; } - public function getScopes(): array + public function getScopes(): iterable { if (null !== $this->getAccompanyingPeriod()) { return $this->getAccompanyingPeriod()->getScopes(); diff --git a/src/Bundle/ChillActivityBundle/Form/ActivityType.php b/src/Bundle/ChillActivityBundle/Form/ActivityType.php index b2d88f0db..88356a5c6 100644 --- a/src/Bundle/ChillActivityBundle/Form/ActivityType.php +++ b/src/Bundle/ChillActivityBundle/Form/ActivityType.php @@ -14,7 +14,9 @@ namespace Chill\ActivityBundle\Form; use Chill\ActivityBundle\Entity\Activity; use Chill\ActivityBundle\Entity\ActivityPresence; use Chill\ActivityBundle\Entity\ActivityReason; +use Chill\ActivityBundle\Security\Authorization\ActivityVoter; use Chill\DocStoreBundle\Form\StoredObjectType; +use Chill\MainBundle\Entity\Center; use Chill\MainBundle\Entity\Location; use Chill\MainBundle\Entity\User; use Chill\MainBundle\Form\Type\ChillCollectionType; @@ -51,6 +53,7 @@ use Symfony\Component\Form\FormEvents; use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; +use Symfony\Component\Security\Core\Role\Role; use function in_array; class ActivityType extends AbstractType @@ -110,12 +113,11 @@ class ActivityType extends AbstractType $activityType = $options['activityType']; // TODO revoir la gestion des center au niveau du form des activité. - if ($options['center']) { + if ($options['center'] && null !== $options['data']->getPerson()) { $builder->add('scope', ScopePickerType::class, [ 'center' => $options['center'], - 'role' => $options['role'], - // TODO make required again once scope and rights are fixed - 'required' => false, + 'role' => ActivityVoter::CREATE === (string) $options['role'] ? ActivityVoter::CREATE_PERSON : (string) $options['role'], + 'required' => true, ]); } @@ -441,8 +443,8 @@ class ActivityType extends AbstractType $resolver ->setRequired(['center', 'role', 'activityType', 'accompanyingPeriod']) - ->setAllowedTypes('center', ['null', 'Chill\MainBundle\Entity\Center']) - ->setAllowedTypes('role', 'Symfony\Component\Security\Core\Role\Role') + ->setAllowedTypes('center', ['null', Center::class]) + ->setAllowedTypes('role', [Role::class, 'string']) ->setAllowedTypes('activityType', \Chill\ActivityBundle\Entity\ActivityType::class) ->setAllowedTypes('accompanyingPeriod', [\Chill\PersonBundle\Entity\AccompanyingPeriod::class, 'null']); } diff --git a/src/Bundle/ChillEventBundle/migrations/Version20160318111334.php b/src/Bundle/ChillEventBundle/migrations/Version20160318111334.php index 241003abf..e879f1d29 100644 --- a/src/Bundle/ChillEventBundle/migrations/Version20160318111334.php +++ b/src/Bundle/ChillEventBundle/migrations/Version20160318111334.php @@ -126,7 +126,7 @@ class Version20160318111334 extends AbstractMigration $this->addSql('ALTER TABLE chill_event_participation ' . 'ADD CONSTRAINT FK_4E7768AC217BBB47 ' . 'FOREIGN KEY (person_id) ' - . 'REFERENCES Person (id) ' + . 'REFERENCES chill_person_person(id) ' . 'NOT DEFERRABLE INITIALLY IMMEDIATE'); $this->addSql('ALTER TABLE chill_event_participation ' . 'ADD CONSTRAINT FK_4E7768ACD60322AC '