Skip to content

Commit

Permalink
[Api] Create endpoint to manage deputies
Browse files Browse the repository at this point in the history
  • Loading branch information
Remg committed Jan 7, 2025
1 parent 21037f3 commit 362ece4
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 7 deletions.
6 changes: 4 additions & 2 deletions features/api/my_teams.feature
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,8 @@ Feature:
"statutory_message",
"procurations",
"actions",
"featurebase"
"featurebase",
"circonscriptions"
],
"uuid": "e0da56db-c4c6-4aa4-ad8d-7e9505dfdd93"
}
Expand Down Expand Up @@ -425,7 +426,8 @@ Feature:
"statutory_message",
"procurations",
"actions",
"featurebase"
"featurebase",
"circonscriptions"
],
"uuid": "@uuid@"
}
Expand Down
12 changes: 8 additions & 4 deletions features/api/scopes.feature
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ Feature:
"statutory_message",
"procurations",
"actions",
"featurebase"
"featurebase",
"circonscriptions"
]
},
{
Expand Down Expand Up @@ -222,7 +223,8 @@ Feature:
"statutory_message",
"procurations",
"actions",
"featurebase"
"featurebase",
"circonscriptions"
],
"attributes": null,
"delegated_access": null
Expand Down Expand Up @@ -471,7 +473,8 @@ Feature:
"statutory_message",
"procurations",
"actions",
"featurebase"
"featurebase",
"circonscriptions"
],
"delegated_access": {
"delegator": {
Expand Down Expand Up @@ -524,7 +527,8 @@ Feature:
"statutory_message",
"procurations",
"actions",
"featurebase"
"featurebase",
"circonscriptions"
],
"attributes": {
"committees": [{ "name": "Comité des 3 communes", "uuid": "@uuid@" }],
Expand Down
29 changes: 29 additions & 0 deletions src/Entity/AdherentZoneBasedRole.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,41 @@

namespace App\Entity;

use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Delete;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Post;
use ApiPlatform\Metadata\Put;
use App\Adherent\Authorization\ZoneBasedRoleTypeEnum;
use App\Collection\ZoneCollection;
use App\Entity\Geo\Zone;
use App\Scope\ScopeEnum;
use Doctrine\ORM\Mapping as ORM;
use Ramsey\Uuid\Uuid;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;

#[ApiResource(
operations: [
new GetCollection(
uriTemplate: '/v3/zone_based_role',
),
new Post(
uriTemplate: '/v3/zone_based_role',
),
new Put(
uriTemplate: '/v3/zone_based_role/{uuid}',
requirements: ['uuid' => '%pattern_uuid%']
),
new Delete(
uriTemplate: '/v3/zone_based_role/{uuid}',
requirements: ['uuid' => '%pattern_uuid%']
),
],
normalizationContext: ['groups' => ['zone_based_role_read']],
denormalizationContext: ['groups' => ['zone_based_role_write']],
security: 'is_granted(\'ROLE_OAUTH_SCOPE_JEMENGAGE_ADMIN\') and is_granted(\'IS_FEATURE_GRANTED\', \'circonscriptions\')'
)]
#[ORM\Entity]
class AdherentZoneBasedRole
{
Expand All @@ -19,10 +46,12 @@ class AdherentZoneBasedRole

#[Assert\Choice(choices: ZoneBasedRoleTypeEnum::ALL)]
#[Assert\NotBlank]
#[Groups(['zone_based_role_read', 'zone_based_role_write'])]
#[ORM\Column]
private ?string $type;

#[Assert\NotBlank]
#[Groups(['zone_based_role_read', 'zone_based_role_write'])]
#[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')]
#[ORM\ManyToOne(targetEntity: Adherent::class, inversedBy: 'zoneBasedRoles')]
private ?Adherent $adherent = null;
Expand Down
1 change: 1 addition & 0 deletions src/Entity/EntityIdentityTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ trait EntityIdentityTrait
'user_profile',
'zone_read',
'tax_receipt:list',
'zone_based_role_read',
])]
#[ORM\Column(type: 'uuid', unique: true)]
protected $uuid;
Expand Down
10 changes: 9 additions & 1 deletion src/Entity/EntityZoneTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,15 @@ trait EntityZoneTrait
/**
* @var ZoneCollection|Zone[]
*/
#[Groups(['phoning_campaign_read', 'phoning_campaign_write', 'read_api', 'managed_users_list', 'managed_user_read'])]
#[Groups([
'phoning_campaign_read',
'phoning_campaign_write',
'read_api',
'managed_users_list',
'managed_user_read',
'zone_based_role_read',
'zone_based_role_write',
])]
#[ORM\ManyToMany(targetEntity: Zone::class, cascade: ['persist'])]
protected Collection $zones;

Expand Down
2 changes: 2 additions & 0 deletions src/Scope/FeatureEnum.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class FeatureEnum extends Enum
public const PROCURATIONS = 'procurations';
public const ACTIONS = 'actions';
public const FEATUREBASE = 'featurebase';
public const CIRCONSCRIPTIONS = 'circonscriptions';

public const ALL = [
self::DASHBOARD,
Expand Down Expand Up @@ -60,6 +61,7 @@ class FeatureEnum extends Enum
self::PROCURATIONS,
self::ACTIONS,
self::FEATUREBASE,
self::CIRCONSCRIPTIONS,
];

public const DELEGATED_ACCESSES_BY_DEFAULT = [
Expand Down
1 change: 1 addition & 0 deletions translations/messages+intl-icu.fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1165,6 +1165,7 @@ scope.feature.committee: Comités locaux
scope.feature.designation: Désignation
scope.feature.actions: Actions
scope.feature.featurebase: 🗣 Featurebase ️
scope.feature.circonscriptions: Gestion des circonscriptions

scope.app.data_corner: DataCorner
scope.app.jemarche: Je m'engage
Expand Down

0 comments on commit 362ece4

Please sign in to comment.