Skip to content

Commit

Permalink
use link security
Browse files Browse the repository at this point in the history
  • Loading branch information
usu committed May 5, 2024
1 parent 0d4f1b4 commit 7e97257
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 16 deletions.
1 change: 1 addition & 0 deletions api/config/packages/api_platform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ api_platform:
version: 1.0.0
show_webby: false
use_symfony_listeners: true
enable_link_security: true
mapping:
paths:
- '%kernel.project_dir%/src/Entity'
Expand Down
6 changes: 5 additions & 1 deletion api/src/Entity/Day.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@
new GetCollection(
uriTemplate: self::PERIOD_SUBRESOURCE_URI_TEMPLATE,
uriVariables: [
'periodId' => new Link(toProperty: 'period', fromClass: Period::class),
'periodId' => new Link(
toProperty: 'period',
fromClass: Period::class,
security: 'is_granted("CAMP_COLLABORATOR", period) or is_granted("CAMP_IS_PROTOTYPE", period)'
),
],
normalizationContext: self::COLLECTION_NORMALIZATION_CONTEXT,
security: 'is_fully_authenticated()',
Expand Down
7 changes: 5 additions & 2 deletions api/src/Entity/DayResponsible.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,12 @@
new GetCollection(
uriTemplate: self::DAY_SUBRESOURCE_URI_TEMPLATE,
uriVariables: [
'dayId' => new Link(toProperty: 'day', fromClass: Day::class),
'dayId' => new Link(
toProperty: 'day',
fromClass: Day::class,
security: 'is_granted("CAMP_COLLABORATOR", day) or is_granted("CAMP_IS_PROTOTYPE", day)'
),
],
security: 'is_fully_authenticated()',
),
new Post(
securityPostDenormalize: 'is_granted("CAMP_MEMBER", object) or is_granted("CAMP_MANAGER", object)'
Expand Down
6 changes: 5 additions & 1 deletion api/src/Entity/ScheduleEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@
new GetCollection(
uriTemplate: self::PERIOD_SUBRESOURCE_URI_TEMPLATE,
uriVariables: [
'periodId' => new Link(toProperty: 'period', fromClass: Period::class),
'periodId' => new Link(
toProperty: 'period',
fromClass: Period::class,
security: 'is_granted("CAMP_COLLABORATOR", period) or is_granted("CAMP_IS_PROTOTYPE", period)'
),
],
security: 'is_fully_authenticated()',
),
Expand Down
5 changes: 1 addition & 4 deletions api/tests/Api/DayResponsibles/ListDayResponsiblesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,6 @@ public function testListDayResponsiblesAsDaySubresourceIsDeniedForUnrelatedUser(
->request('GET', '/days/'.$day->getId().'/day_responsibles')
;

$this->assertResponseStatusCodeSame(200);

$this->assertJsonContains(['totalItems' => 0]);
$this->assertArrayNotHasKey('items', $response->toArray()['_links']);
$this->assertResponseStatusCodeSame(404);
}
}
5 changes: 1 addition & 4 deletions api/tests/Api/Days/ListDaysTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,6 @@ public function testListDaysAsPeriodSubresourceIsDeniedForUnrelatedUser() {
->request('GET', '/periods/'.$period->getId().'/days')
;

$this->assertResponseStatusCodeSame(200);

$this->assertJsonContains(['totalItems' => 0]);
$this->assertArrayNotHasKey('items', $response->toArray()['_links']);
$this->assertResponseStatusCodeSame(404);
}
}
5 changes: 1 addition & 4 deletions api/tests/Api/ScheduleEntries/ListScheduleEntriesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -402,9 +402,6 @@ public function testListScheduleEntriesAsPeriodSubresourceIsDeniedForUnrelatedUs
->request('GET', '/periods/'.$period->getId().'/schedule_entries')
;

$this->assertResponseStatusCodeSame(200);

$this->assertJsonContains(['totalItems' => 0]);
$this->assertArrayNotHasKey('items', $response->toArray()['_links']);
$this->assertResponseStatusCodeSame(404);
}
}

0 comments on commit 7e97257

Please sign in to comment.