add route for scope on participation

This commit is contained in:
Julien Fastré 2021-05-13 17:44:54 +02:00
parent f3eb418409
commit f1d5d9840e
4 changed files with 122 additions and 4 deletions

View File

@ -24,13 +24,16 @@ use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\Collection; use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\ArrayCollection;
use Chill\MainBundle\Entity\RoleScope; use Chill\MainBundle\Entity\RoleScope;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Serializer\Annotation\DiscriminatorMap;
/** /**
* @ORM\Entity() * @ORM\Entity()
* @ORM\Table(name="scopes") * @ORM\Table(name="scopes")
* @ORM\Cache(usage="NONSTRICT_READ_WRITE", region="acl_cache_region") * @ORM\Cache(usage="NONSTRICT_READ_WRITE", region="acl_cache_region")
* * @DiscriminatorMap(typeProperty="type", mapping={
* @author Julien Fastré <julien.fastre@champs-libres.coop> * "scope"=Scope::class
* })
*/ */
class Scope class Scope
{ {
@ -40,6 +43,7 @@ class Scope
* @ORM\Id * @ORM\Id
* @ORM\Column(name="id", type="integer") * @ORM\Column(name="id", type="integer")
* @ORM\GeneratedValue(strategy="AUTO") * @ORM\GeneratedValue(strategy="AUTO")
* @Groups({"read"})
*/ */
private $id; private $id;
@ -49,6 +53,7 @@ class Scope
* @var array * @var array
* *
* @ORM\Column(type="json_array") * @ORM\Column(type="json_array")
* @Groups({"read"})
*/ */
private $name = []; private $name = [];

View File

@ -16,6 +16,7 @@ use Chill\ThirdPartyBundle\Entity\ThirdParty;
use Symfony\Component\Serializer\Exception\RuntimeException; use Symfony\Component\Serializer\Exception\RuntimeException;
use Chill\PersonBundle\Entity\AccompanyingPeriod\Resource; use Chill\PersonBundle\Entity\AccompanyingPeriod\Resource;
use Chill\PersonBundle\Entity\AccompanyingPeriod\Comment; use Chill\PersonBundle\Entity\AccompanyingPeriod\Comment;
use Chill\MainBundle\Entity\Scope;
class AccompanyingCourseApiController extends ApiController class AccompanyingCourseApiController extends ApiController
{ {
@ -72,6 +73,11 @@ class AccompanyingCourseApiController extends ApiController
return $this->addRemoveSomething('resource', $id, $request, $_format, 'resource', Resource::class); 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 public function commentApi($id, Request $request, string $_format): Response
{ {
return $this->addRemoveSomething('comment', $id, $request, $_format, 'comment', Comment::class); return $this->addRemoveSomething('comment', $id, $request, $_format, 'comment', Comment::class);

View File

@ -377,6 +377,18 @@ class ChillPersonExtension extends Extension implements PrependExtensionInterfac
Request::METHOD_POST => \Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter::SEE, Request::METHOD_POST => \Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter::SEE,
Request::METHOD_DELETE=> \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
]
] ]
] ]

View File

@ -1,11 +1,41 @@
components: components:
schemas: schemas:
# should go to main
Date: Date:
type: object type: object
properties: properties:
datetime: datetime:
type: string type: string
format: date-time 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: Person:
type: object type: object
properties: properties:
@ -413,7 +443,7 @@ paths:
delete: delete:
tags: tags:
- person - person
summary: "Remove the resource" summary: "Remove the comment"
parameters: parameters:
- name: id - name: id
in: path in: path
@ -424,7 +454,7 @@ paths:
format: integer format: integer
minimum: 1 minimum: 1
requestBody: requestBody:
description: "A resource" description: "A comment"
required: true required: true
content: content:
application/json: application/json:
@ -439,3 +469,68 @@ paths:
description: "OK" description: "OK"
422: 422:
description: "object with validation errors" 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"