Fixed: do not allow to create activities when no rights to do it

The ACTIVITY_FULL role does not give anymore the roles
CHILL_ACTIVITY_CREATE_PERSON and CHILL_ACTIVITY_CREATE_ACCOMPANYING_COURSE.

Tags: #BC
This commit is contained in:
Julien Fastré 2022-07-11 19:29:45 +02:00
parent ce17c15d41
commit 6998043159
7 changed files with 458 additions and 570 deletions

View File

@ -24,6 +24,7 @@ parameters:
- "/spec/" - "/spec/"
- "/var/" - "/var/"
- "/vendor/" - "/vendor/"
- "/tests/app"
# Psalm # Psalm
tasks.psalm.blocking: true tasks.psalm.blocking: true

File diff suppressed because it is too large Load Diff

View File

@ -25,16 +25,6 @@ parameters:
count: 1 count: 1
path: src/Bundle/ChillActivityBundle/Form/ActivityType.php path: src/Bundle/ChillActivityBundle/Form/ActivityType.php
-
message: "#^Only booleans are allowed in &&, mixed given on the right side\\.$#"
count: 3
path: src/Bundle/ChillActivityBundle/Form/ActivityType.php
-
message: "#^Only booleans are allowed in an if condition, mixed given\\.$#"
count: 2
path: src/Bundle/ChillActivityBundle/Form/ActivityType.php
- -
message: "#^Only booleans are allowed in an if condition, mixed given\\.$#" message: "#^Only booleans are allowed in an if condition, mixed given\\.$#"
count: 3 count: 3

View File

@ -61,8 +61,6 @@ class ChillActivityExtension extends Extension implements PrependExtensionInterf
ActivityVoter::DELETE => [ActivityVoter::SEE_DETAILS], ActivityVoter::DELETE => [ActivityVoter::SEE_DETAILS],
ActivityVoter::SEE_DETAILS => [ActivityVoter::SEE], ActivityVoter::SEE_DETAILS => [ActivityVoter::SEE],
ActivityVoter::FULL => [ ActivityVoter::FULL => [
ActivityVoter::CREATE_PERSON,
ActivityVoter::CREATE_ACCOMPANYING_COURSE,
ActivityVoter::DELETE, ActivityVoter::DELETE,
ActivityVoter::UPDATE, ActivityVoter::UPDATE,
], ],

View File

@ -16,7 +16,6 @@ use Chill\DocStoreBundle\Entity\StoredObject;
use Chill\MainBundle\Entity\Center; use Chill\MainBundle\Entity\Center;
use Chill\MainBundle\Entity\Embeddable\CommentEmbeddable; use Chill\MainBundle\Entity\Embeddable\CommentEmbeddable;
use Chill\MainBundle\Entity\Embeddable\PrivateCommentEmbeddable; use Chill\MainBundle\Entity\Embeddable\PrivateCommentEmbeddable;
use Chill\MainBundle\Entity\HasCenterInterface;
use Chill\MainBundle\Entity\HasCentersInterface; use Chill\MainBundle\Entity\HasCentersInterface;
use Chill\MainBundle\Entity\HasScopesInterface; use Chill\MainBundle\Entity\HasScopesInterface;
use Chill\MainBundle\Entity\Location; use Chill\MainBundle\Entity\Location;
@ -311,7 +310,9 @@ class Activity implements AccompanyingPeriodLinkedWithSocialIssuesEntityInterfac
{ {
if ($this->person instanceof Person) { if ($this->person instanceof Person) {
return [$this->person->getCenter()]; return [$this->person->getCenter()];
} elseif ($this->getAccompanyingPeriod() instanceof AccompanyingPeriod) { }
if ($this->getAccompanyingPeriod() instanceof AccompanyingPeriod) {
return $this->getAccompanyingPeriod()->getCenters(); return $this->getAccompanyingPeriod()->getCenters();
} }

View File

@ -25,9 +25,9 @@ use Chill\MainBundle\Form\Type\CommentType;
use Chill\MainBundle\Form\Type\PickUserDynamicType; use Chill\MainBundle\Form\Type\PickUserDynamicType;
use Chill\MainBundle\Form\Type\PrivateCommentType; use Chill\MainBundle\Form\Type\PrivateCommentType;
use Chill\MainBundle\Form\Type\ScopePickerType; use Chill\MainBundle\Form\Type\ScopePickerType;
use Chill\MainBundle\Form\Type\UserPickerType;
use Chill\MainBundle\Security\Authorization\AuthorizationHelper; use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
use Chill\MainBundle\Templating\TranslatableStringHelper; use Chill\MainBundle\Templating\TranslatableStringHelper;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Entity\Person; use Chill\PersonBundle\Entity\Person;
use Chill\PersonBundle\Entity\SocialWork\SocialAction; use Chill\PersonBundle\Entity\SocialWork\SocialAction;
use Chill\PersonBundle\Entity\SocialWork\SocialIssue; use Chill\PersonBundle\Entity\SocialWork\SocialIssue;
@ -113,7 +113,7 @@ class ActivityType extends AbstractType
$activityType = $options['activityType']; $activityType = $options['activityType'];
// TODO revoir la gestion des center au niveau du form des activité. // TODO revoir la gestion des center au niveau du form des activité.
if ($options['center'] && null !== $options['data']->getPerson()) { if ($options['center'] instanceof Center && null !== $options['data']->getPerson()) {
$builder->add('scope', ScopePickerType::class, [ $builder->add('scope', ScopePickerType::class, [
'center' => $options['center'], 'center' => $options['center'],
'role' => ActivityVoter::CREATE === (string) $options['role'] ? ActivityVoter::CREATE_PERSON : (string) $options['role'], 'role' => ActivityVoter::CREATE === (string) $options['role'] ? ActivityVoter::CREATE_PERSON : (string) $options['role'],
@ -124,7 +124,7 @@ class ActivityType extends AbstractType
/** @var ? \Chill\PersonBundle\Entity\AccompanyingPeriod $accompanyingPeriod */ /** @var ? \Chill\PersonBundle\Entity\AccompanyingPeriod $accompanyingPeriod */
$accompanyingPeriod = null; $accompanyingPeriod = null;
if ($options['accompanyingPeriod']) { if ($options['accompanyingPeriod'] instanceof AccompanyingPeriod) {
$accompanyingPeriod = $options['accompanyingPeriod']; $accompanyingPeriod = $options['accompanyingPeriod'];
} }
@ -221,7 +221,7 @@ class ActivityType extends AbstractType
]); ]);
} }
if ($activityType->isVisible('user') && $options['center']) { if ($activityType->isVisible('user') && $options['center'] instanceof Center) {
$builder->add('user', PickUserDynamicType::class, [ $builder->add('user', PickUserDynamicType::class, [
'label' => $activityType->getLabel('user'), 'label' => $activityType->getLabel('user'),
'required' => $activityType->isRequired('user'), 'required' => $activityType->isRequired('user'),

View File

@ -159,12 +159,12 @@ class ActivityVoter extends AbstractChillVoter implements ProvideRoleHierarchyIn
// transform the attribute // transform the attribute
if (self::CREATE === $attribute) { if (self::CREATE === $attribute) {
$attribute = self::CREATE_ACCOMPANYING_COURSE; return $this->voterHelper->voteOnAttribute(self::CREATE_ACCOMPANYING_COURSE, $subject, $token);
} }
} elseif ($subject instanceof Person) { } elseif ($subject instanceof Person) {
// transform the attribute // transform the attribute
if (self::CREATE === $attribute) { if (self::CREATE === $attribute) {
$attribute = self::CREATE_PERSON; return $this->voterHelper->voteOnAttribute(self::CREATE_PERSON, $subject, $token);
} }
} }