Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 25 additions & 8 deletions api/src/Entity/Activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use ApiPlatform\Metadata\Delete;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Link;
use ApiPlatform\Metadata\Patch;
use ApiPlatform\Metadata\Post;
use App\InputFilter;
Expand Down Expand Up @@ -43,16 +44,21 @@
security: 'is_granted("CAMP_MEMBER", object) or is_granted("CAMP_MANAGER", object)'
),
new GetCollection(
normalizationContext: [
'groups' => [
'read',
'Activity:ActivityProgressLabel',
'Activity:ActivityResponsibles',
'Activity:ScheduleEntries',
],
],
normalizationContext: self::COLLECTION_NORMALIZATION_CONTEXT,
security: 'is_authenticated()'
Comment on lines -46 to 48
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you planning to remove this in a next step?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As soon we know we dont use the Ressource anymore

),
new GetCollection(
uriTemplate: self::CAMP_SUBRESOURCE_URI_TEMPLATE,
uriVariables: [
'campId' => new Link(
toProperty: 'camp',
fromClass: Camp::class,
security: 'is_granted("CAMP_COLLABORATOR", camp) or is_granted("CAMP_IS_PROTOTYPE", camp)'
),
],
normalizationContext: self::COLLECTION_NORMALIZATION_CONTEXT,
security: 'is_fully_authenticated()',
),
new Post(
processor: ActivityCreateProcessor::class,
validationContext: ['groups' => ['Default', 'create']],
Expand All @@ -69,6 +75,17 @@
class Activity extends BaseEntity implements BelongsToCampInterface {
use HasRootContentNodeTrait;

public const CAMP_SUBRESOURCE_URI_TEMPLATE = '/camps/{campId}/activities{._format}';

public const COLLECTION_NORMALIZATION_CONTEXT = [
'groups' => [
'read',
'Activity:ActivityProgressLabel',
'Activity:ActivityResponsibles',
'Activity:ScheduleEntries',
],
];

public const ITEM_NORMALIZATION_CONTEXT = [
'groups' => [
'read',
Expand Down
6 changes: 5 additions & 1 deletion api/src/Entity/Camp.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,11 @@ class Camp extends BaseEntity implements BelongsToCampInterface, CopyFromPrototy
* All the programme that will be carried out during the camp. An activity may be carried out
* multiple times in the same camp.
*/
#[ApiProperty(writable: false, example: '/activities?camp=%2Fcamps%2F1a2b3c4d')]
#[ApiProperty(
writable: false,
uriTemplate: Activity::CAMP_SUBRESOURCE_URI_TEMPLATE,
example: '/camps/1a2b3c4d/activities'
)]
#[Groups(['read'])]
#[ORM\OneToMany(targetEntity: Activity::class, mappedBy: 'camp', orphanRemoval: true)]
public Collection $activities;
Expand Down
19 changes: 19 additions & 0 deletions api/tests/Api/Activities/ListActivitiesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,25 @@ public function testListActivitiesFilteredByCampIsAllowedForCollaborator() {
], $response->toArray()['_links']['items']);
}

public function testListActivitiesByCampSubresourceIsAllowedForCollaborator() {
$camp = static::getFixture('camp1');
$response = static::createClientWithCredentials()->request('GET', "/camps/{$camp->getId()}/activities");
$this->assertResponseStatusCodeSame(200);
$this->assertJsonContains([
'totalItems' => 2,
'_links' => [
'items' => [],
],
'_embedded' => [
'items' => [],
],
]);
$this->assertEqualsCanonicalizing([
['href' => $this->getIriFor('activity1')],
['href' => $this->getIriFor('activity2')],
], $response->toArray()['_links']['items']);
}

public function testListActivitiesFilteredByCampIsDeniedForUnrelatedUser() {
$camp = static::getFixture('camp1');
$response = static::createClientWithCredentials(['email' => static::$fixtures['user4unrelated']->getEmail()])
Expand Down
6 changes: 3 additions & 3 deletions api/tests/Api/Camps/ReadCampTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function testGetSingleCampIsAllowedForGuest() {
'isPrototype' => false,
'_links' => [
'creator' => ['href' => $this->getIriFor('user2member')],
'activities' => ['href' => '/activities?camp=%2Fcamps%2F'.$camp->getId()],
'activities' => ['href' => "/camps/{$camp->getId()}/activities"],
'materialLists' => ['href' => '/material_lists?camp=%2Fcamps%2F'.$camp->getId()],
'campCollaborations' => ['href' => '/camp_collaborations?camp=%2Fcamps%2F'.$camp->getId()],
'periods' => ['href' => '/periods?camp=%2Fcamps%2F'.$camp->getId()],
Expand Down Expand Up @@ -95,7 +95,7 @@ public function testGetSingleCampIsAllowedForMember() {
'isPrototype' => false,
'_links' => [
'creator' => ['href' => $this->getIriFor('user2member')],
'activities' => ['href' => '/activities?camp=%2Fcamps%2F'.$camp->getId()],
'activities' => ['href' => "/camps/{$camp->getId()}/activities"],
'materialLists' => ['href' => '/material_lists?camp=%2Fcamps%2F'.$camp->getId()],
'campCollaborations' => ['href' => '/camp_collaborations?camp=%2Fcamps%2F'.$camp->getId()],
'periods' => ['href' => '/periods?camp=%2Fcamps%2F'.$camp->getId()],
Expand Down Expand Up @@ -123,7 +123,7 @@ public function testGetSingleCampIsAllowedForManager() {
'isPrototype' => false,
'_links' => [
'creator' => ['href' => $this->getIriFor('user2member')],
'activities' => ['href' => '/activities?camp=%2Fcamps%2F'.$camp->getId()],
'activities' => ['href' => "/camps/{$camp->getId()}/activities"],
'materialLists' => ['href' => '/material_lists?camp=%2Fcamps%2F'.$camp->getId()],
'campCollaborations' => ['href' => '/camp_collaborations?camp=%2Fcamps%2F'.$camp->getId()],
'periods' => ['href' => '/periods?camp=%2Fcamps%2F'.$camp->getId()],
Expand Down
Loading