fixed: voter and permissions in accompanying course document

This commit is contained in:
Julien Fastré 2022-07-11 12:55:02 +02:00
parent 3bb8b713d1
commit ab08dab88a
5 changed files with 36 additions and 33 deletions

View File

@ -11,6 +11,7 @@ declare(strict_types=1);
namespace Chill\DocStoreBundle\Entity; namespace Chill\DocStoreBundle\Entity;
use Chill\MainBundle\Entity\HasScopesInterface;
use Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
@ -18,7 +19,7 @@ use Doctrine\ORM\Mapping as ORM;
* @ORM\Entity * @ORM\Entity
* @ORM\Table("chill_doc.accompanyingcourse_document") * @ORM\Table("chill_doc.accompanyingcourse_document")
*/ */
class AccompanyingCourseDocument extends Document class AccompanyingCourseDocument extends Document implements HasScopesInterface
{ {
/** /**
* @ORM\ManyToOne(targetEntity=AccompanyingPeriod::class) * @ORM\ManyToOne(targetEntity=AccompanyingPeriod::class)
@ -31,6 +32,15 @@ class AccompanyingCourseDocument extends Document
return $this->course; return $this->course;
} }
public function getScopes(): iterable
{
if (null !== $this->course) {
return [];
}
return $this->course->getScopes();
}
public function setCourse(?AccompanyingPeriod $course): self public function setCourse(?AccompanyingPeriod $course): self
{ {
$this->course = $course; $this->course = $course;

View File

@ -16,8 +16,6 @@ use Chill\MainBundle\Doctrine\Model\TrackCreationInterface;
use Chill\MainBundle\Doctrine\Model\TrackCreationTrait; use Chill\MainBundle\Doctrine\Model\TrackCreationTrait;
use Chill\MainBundle\Doctrine\Model\TrackUpdateInterface; use Chill\MainBundle\Doctrine\Model\TrackUpdateInterface;
use Chill\MainBundle\Doctrine\Model\TrackUpdateTrait; use Chill\MainBundle\Doctrine\Model\TrackUpdateTrait;
use Chill\MainBundle\Entity\HasScopeInterface;
use Chill\MainBundle\Entity\Scope;
use Chill\MainBundle\Entity\User; use Chill\MainBundle\Entity\User;
use DateTimeInterface; use DateTimeInterface;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
@ -26,7 +24,7 @@ use Symfony\Component\Validator\Constraints as Assert;
/** /**
* @ORM\MappedSuperclass * @ORM\MappedSuperclass
*/ */
class Document implements HasScopeInterface, TrackCreationInterface, TrackUpdateInterface class Document implements TrackCreationInterface, TrackUpdateInterface
{ {
use TrackCreationTrait; use TrackCreationTrait;
@ -70,13 +68,6 @@ class Document implements HasScopeInterface, TrackCreationInterface, TrackUpdate
*/ */
private $object; private $object;
/**
* @ORM\ManyToOne(targetEntity="Chill\MainBundle\Entity\Scope")
*
* @var \Chill\MainBundle\Entity\Scope The document's center
*/
private $scope;
/** /**
* @ORM\ManyToOne(targetEntity="Chill\DocGeneratorBundle\Entity\DocGeneratorTemplate") * @ORM\ManyToOne(targetEntity="Chill\DocGeneratorBundle\Entity\DocGeneratorTemplate")
*/ */
@ -122,16 +113,6 @@ class Document implements HasScopeInterface, TrackCreationInterface, TrackUpdate
return $this->object; return $this->object;
} }
/**
* Get scope.
*
* @return \Chill\MainBundle\Entity\Scope
*/
public function getScope(): ?Scope
{
return $this->scope;
}
public function getTemplate(): ?DocGeneratorTemplate public function getTemplate(): ?DocGeneratorTemplate
{ {
return $this->template; return $this->template;
@ -175,13 +156,6 @@ class Document implements HasScopeInterface, TrackCreationInterface, TrackUpdate
return $this; return $this;
} }
public function setScope($scope): self
{
$this->scope = $scope;
return $this;
}
public function setTemplate(?DocGeneratorTemplate $template): self public function setTemplate(?DocGeneratorTemplate $template): self
{ {
$this->template = $template; $this->template = $template;

View File

@ -13,6 +13,7 @@ namespace Chill\DocStoreBundle\Entity;
use Chill\MainBundle\Entity\HasCenterInterface; use Chill\MainBundle\Entity\HasCenterInterface;
use Chill\MainBundle\Entity\HasScopeInterface; use Chill\MainBundle\Entity\HasScopeInterface;
use Chill\MainBundle\Entity\Scope;
use Chill\PersonBundle\Entity\Person; use Chill\PersonBundle\Entity\Person;
use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping as ORM;
@ -27,6 +28,13 @@ class PersonDocument extends Document implements HasCenterInterface, HasScopeInt
*/ */
private Person $person; private Person $person;
/**
* @ORM\ManyToOne(targetEntity="Chill\MainBundle\Entity\Scope")
*
* @var \Chill\MainBundle\Entity\Scope The document's center
*/
private $scope;
public function getCenter() public function getCenter()
{ {
return $this->getPerson()->getCenter(); return $this->getPerson()->getCenter();
@ -37,10 +45,22 @@ class PersonDocument extends Document implements HasCenterInterface, HasScopeInt
return $this->person; return $this->person;
} }
public function getScope(): ?Scope
{
return $this->scope;
}
public function setPerson($person): self public function setPerson($person): self
{ {
$this->person = $person; $this->person = $person;
return $this; return $this;
} }
public function setScope($scope): self
{
$this->scope = $scope;
return $this;
}
} }

View File

@ -88,10 +88,5 @@ class AccompanyingCourseDocumentType extends AbstractType
$resolver->setDefaults([ $resolver->setDefaults([
'data_class' => Document::class, 'data_class' => Document::class,
]); ]);
// $resolver->setRequired(['role', 'center'])
// ->setAllowedTypes('role', [ \Symfony\Component\Security\Core\Role\Role::class ])
// ->setAllowedTypes('center', [ \Chill\MainBundle\Entity\Center::class ])
// ;
} }
} }

View File

@ -106,6 +106,10 @@ class AccompanyingCourseDocumentVoter extends AbstractChillVoter implements Prov
) { ) {
return false; return false;
} }
if (self::CREATE === $attribute && null !== $subject->getCourse()) {
return $this->voterHelper->voteOnAttribute($attribute, $subject->getCourse(), $token);
}
} }
return $this->voterHelper->voteOnAttribute($attribute, $subject, $token); return $this->voterHelper->voteOnAttribute($attribute, $subject, $token);