diff --git a/src/Bundle/ChillMainBundle/Entity/Scope.php b/src/Bundle/ChillMainBundle/Entity/Scope.php index 5a9e348d4..aba06ab7e 100644 --- a/src/Bundle/ChillMainBundle/Entity/Scope.php +++ b/src/Bundle/ChillMainBundle/Entity/Scope.php @@ -24,13 +24,16 @@ use Doctrine\ORM\Mapping as ORM; use Doctrine\Common\Collections\Collection; use Doctrine\Common\Collections\ArrayCollection; use Chill\MainBundle\Entity\RoleScope; +use Symfony\Component\Serializer\Annotation\Groups; +use Symfony\Component\Serializer\Annotation\DiscriminatorMap; /** * @ORM\Entity() * @ORM\Table(name="scopes") * @ORM\Cache(usage="NONSTRICT_READ_WRITE", region="acl_cache_region") - * - * @author Julien Fastré + * @DiscriminatorMap(typeProperty="type", mapping={ + * "scope"=Scope::class + * }) */ class Scope { @@ -40,6 +43,7 @@ class Scope * @ORM\Id * @ORM\Column(name="id", type="integer") * @ORM\GeneratedValue(strategy="AUTO") + * @Groups({"read"}) */ private $id; @@ -49,6 +53,7 @@ class Scope * @var array * * @ORM\Column(type="json_array") + * @Groups({"read"}) */ private $name = []; diff --git a/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseApiController.php b/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseApiController.php index 64f4d294d..7850bbee4 100644 --- a/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseApiController.php +++ b/src/Bundle/ChillPersonBundle/Controller/AccompanyingCourseApiController.php @@ -16,6 +16,7 @@ use Chill\ThirdPartyBundle\Entity\ThirdParty; use Symfony\Component\Serializer\Exception\RuntimeException; use Chill\PersonBundle\Entity\AccompanyingPeriod\Resource; use Chill\PersonBundle\Entity\AccompanyingPeriod\Comment; +use Chill\MainBundle\Entity\Scope; class AccompanyingCourseApiController extends ApiController { @@ -72,6 +73,11 @@ class AccompanyingCourseApiController extends ApiController return $this->addRemoveSomething('resource', $id, $request, $_format, 'resource', Resource::class); } + public function scopeApi($id, Request $request, string $_format): Response + { + return $this->addRemoveSomething('scope', $id, $request, $_format, 'scope', Scope::class); + } + public function commentApi($id, Request $request, string $_format): Response { return $this->addRemoveSomething('comment', $id, $request, $_format, 'comment', Comment::class); diff --git a/src/Bundle/ChillPersonBundle/DependencyInjection/ChillPersonExtension.php b/src/Bundle/ChillPersonBundle/DependencyInjection/ChillPersonExtension.php index cda8f0a81..1e56b16be 100644 --- a/src/Bundle/ChillPersonBundle/DependencyInjection/ChillPersonExtension.php +++ b/src/Bundle/ChillPersonBundle/DependencyInjection/ChillPersonExtension.php @@ -377,6 +377,18 @@ class ChillPersonExtension extends Extension implements PrependExtensionInterfac Request::METHOD_POST => \Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter::SEE, Request::METHOD_DELETE=> \Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter::SEE ] + ], + 'scope' => [ + 'methods' => [ + Request::METHOD_POST => true, + Request::METHOD_DELETE => true, + Request::METHOD_GET => false, + Request::METHOD_HEAD => false, + ], + 'roles' => [ + Request::METHOD_POST => \Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter::SEE, + Request::METHOD_DELETE=> \Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter::SEE + ] ] ] diff --git a/src/Bundle/ChillPersonBundle/chill.api.specs.yaml b/src/Bundle/ChillPersonBundle/chill.api.specs.yaml index fed3ddf6f..bfbd025e0 100644 --- a/src/Bundle/ChillPersonBundle/chill.api.specs.yaml +++ b/src/Bundle/ChillPersonBundle/chill.api.specs.yaml @@ -1,11 +1,41 @@ components: schemas: + # should go to main Date: type: object properties: datetime: type: string format: date-time + Scope: + type: object + properties: + id: + type: integer + type: + type: string + enum: + - scope + name: + type: object + additionalProperties: + type: string + example: + fr: Social + ScopeById: + type: object + properties: + id: + type: integer + type: + type: string + enum: + - scope + required: + - id + - scope + + # ok to stay here Person: type: object properties: @@ -413,7 +443,7 @@ paths: delete: tags: - person - summary: "Remove the resource" + summary: "Remove the comment" parameters: - name: id in: path @@ -424,7 +454,7 @@ paths: format: integer minimum: 1 requestBody: - description: "A resource" + description: "A comment" required: true content: application/json: @@ -439,3 +469,68 @@ paths: description: "OK" 422: description: "object with validation errors" + + /1.0/person/accompanying-course/{id}/scope.json: + post: + tags: + - person + summary: "Add a scope to the accompanying course" + parameters: + - name: id + in: path + required: true + description: The accompanying period's id + schema: + type: integer + format: integer + minimum: 1 + requestBody: + description: "A comment" + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/Scope' + examples: + add a scope: + value: + type: scope + id: 5 + responses: + 401: + description: "Unauthorized" + 404: + description: "Not found" + 200: + description: "OK" + 422: + description: "object with validation errors" + delete: + tags: + - person + summary: "Remove the scope" + parameters: + - name: id + in: path + required: true + description: The accompanying period's id + schema: + type: integer + format: integer + minimum: 1 + requestBody: + description: "A scope with his id" + required: true + content: + application/json: + schema: + $ref: '#/components/schemas/ScopeById' + responses: + 401: + description: "Unauthorized" + 404: + description: "Not found" + 200: + description: "OK" + 422: + description: "object with validation errors"