Skip to content

Commit 3f3b7d4

Browse files
committed
Allow sharing a camp
1 parent 2621381 commit 3f3b7d4

28 files changed

+417
-49
lines changed

api/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,6 @@ docker compose down && docker compose up
5555
```
5656
or
5757
```shell
58-
docker-compsoe stop php; docker compose rm php; docker compose up
58+
docker compose stop api; docker compose rm api; docker compose up
5959
```
6060
if you don't want to restart the frontend.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace DoctrineMigrations;
6+
7+
use Doctrine\DBAL\Schema\Schema;
8+
use Doctrine\Migrations\AbstractMigration;
9+
10+
final class Version20250821113132 extends AbstractMigration {
11+
public function getDescription(): string {
12+
return 'Add isShared flag on camps';
13+
}
14+
15+
public function up(Schema $schema): void {
16+
$this->addSql('ALTER TABLE camp ADD isShared BOOLEAN DEFAULT FALSE NOT NULL');
17+
$this->addSql('CREATE INDEX IDX_C1944230D2E4FE61 ON camp (isShared)');
18+
}
19+
20+
public function down(Schema $schema): void {
21+
$this->addSql('DROP INDEX IDX_C1944230D2E4FE61');
22+
$this->addSql('ALTER TABLE camp DROP isShared');
23+
}
24+
}

api/src/Entity/Activity.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@
3232
operations: [
3333
new Get(
3434
normalizationContext: self::ITEM_NORMALIZATION_CONTEXT,
35-
security: 'is_granted("CAMP_COLLABORATOR", object) or is_granted("CAMP_IS_PROTOTYPE", object)'
35+
security: 'is_granted("CAMP_COLLABORATOR", object) or
36+
is_granted("CAMP_IS_SHARED", object) or
37+
is_granted("CAMP_IS_PROTOTYPE", object)'
3638
),
3739
new Patch(
3840
normalizationContext: self::ITEM_NORMALIZATION_CONTEXT,
@@ -53,7 +55,9 @@
5355
'campId' => new Link(
5456
toProperty: 'camp',
5557
fromClass: Camp::class,
56-
security: 'is_granted("CAMP_COLLABORATOR", camp) or is_granted("CAMP_IS_PROTOTYPE", camp)'
58+
security: 'is_granted("CAMP_COLLABORATOR", camp) or
59+
is_granted("CAMP_IS_SHARED", camp) or
60+
is_granted("CAMP_IS_PROTOTYPE", camp)'
5761
),
5862
],
5963
normalizationContext: self::COLLECTION_NORMALIZATION_CONTEXT,

api/src/Entity/ActivityProgressLabel.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@
2929
operations: [
3030
new Get(
3131
normalizationContext: self::ITEM_NORMALIZATION_CONTEXT,
32-
security: 'is_granted("CAMP_COLLABORATOR", object) or is_granted("CAMP_IS_PROTOTYPE", object)'
32+
security: 'is_granted("CAMP_COLLABORATOR", object) or
33+
is_granted("CAMP_IS_SHARED", object) or
34+
is_granted("CAMP_IS_PROTOTYPE", object)'
3335
),
3436
new Patch(
3537
normalizationContext: self::ITEM_NORMALIZATION_CONTEXT,
@@ -50,7 +52,9 @@
5052
'campId' => new Link(
5153
toProperty: 'camp',
5254
fromClass: Camp::class,
53-
security: 'is_granted("CAMP_COLLABORATOR", camp) or is_granted("CAMP_IS_PROTOTYPE", camp)'
55+
security: 'is_granted("CAMP_COLLABORATOR", camp) or
56+
is_granted("CAMP_IS_SHARED", camp) or
57+
is_granted("CAMP_IS_PROTOTYPE", camp)'
5458
),
5559
],
5660
security: 'is_fully_authenticated()',

api/src/Entity/Camp.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@
3232
#[ApiResource(
3333
operations: [
3434
new Get(
35-
security: 'is_granted("CAMP_COLLABORATOR", object) or is_granted("CAMP_IS_PROTOTYPE", object)',
35+
security: 'is_granted("CAMP_COLLABORATOR", object) or
36+
is_granted("CAMP_IS_SHARED", object) or
37+
is_granted("CAMP_IS_PROTOTYPE", object)',
3638
normalizationContext: self::ITEM_NORMALIZATION_CONTEXT,
3739
),
3840
new Patch(
@@ -62,6 +64,8 @@
6264
#[ApiFilter(filterClass: SearchFilter::class, properties: ['isPrototype'])]
6365
#[ORM\Entity(repositoryClass: CampRepository::class)]
6466
#[ORM\Index(columns: ['isPrototype'])]
67+
#[ORM\Index(columns: ['isShared'])]
68+
#[ORM\Index(columns: ['updateTime'])] // TODO unclear why this is necessary, but doctrine forgot about this index from BaseEntity...
6569
class Camp extends BaseEntity implements BelongsToCampInterface, CopyFromPrototypeInterface {
6670
public const ITEM_NORMALIZATION_CONTEXT = [
6771
'groups' => ['read', 'Camp:Periods', 'Period:Days', 'Camp:CampCollaborations', 'CampCollaboration:User'],
@@ -181,6 +185,17 @@ class Camp extends BaseEntity implements BelongsToCampInterface, CopyFromPrototy
181185
#[Groups(['create'])]
182186
public ?Camp $campPrototype = null;
183187

188+
/**
189+
* Whether the programme of this camp is publicly available to anyone (except for
190+
* personal data such as camp collaborations, personal material lists,
191+
* responsibilities and comments).
192+
*/
193+
#[Assert\Type('bool')]
194+
#[ApiProperty(example: true)]
195+
#[Groups(['read', 'write'])]
196+
#[ORM\Column(type: 'boolean', nullable: false, options: ['default' => false])]
197+
public bool $isShared = false;
198+
184199
/**
185200
* Whether this camp may serve as a template for creating other camps.
186201
*/

api/src/Entity/CampCollaboration.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@
6767
'campId' => new Link(
6868
toProperty: 'camp',
6969
fromClass: Camp::class,
70-
security: 'is_granted("CAMP_COLLABORATOR", camp) or is_granted("CAMP_IS_PROTOTYPE", camp)'
70+
security: 'is_granted("CAMP_COLLABORATOR", camp) or
71+
is_granted("CAMP_IS_SHARED", camp) or
72+
is_granted("CAMP_IS_PROTOTYPE", camp)'
7173
),
7274
],
7375
security: 'is_fully_authenticated()',

api/src/Entity/Category.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@
3535
operations: [
3636
new Get(
3737
normalizationContext: self::ITEM_NORMALIZATION_CONTEXT,
38-
security: 'is_granted("CAMP_COLLABORATOR", object) or is_granted("CAMP_IS_PROTOTYPE", object)'
38+
security: 'is_granted("CAMP_COLLABORATOR", object) or
39+
is_granted("CAMP_IS_SHARED", object) or
40+
is_granted("CAMP_IS_PROTOTYPE", object)'
3941
),
4042
new Patch(
4143
denormalizationContext: ['groups' => ['write', 'update']],
@@ -63,7 +65,9 @@
6365
'campId' => new Link(
6466
fromClass: Camp::class,
6567
toProperty: 'camp',
66-
security: 'is_granted("CAMP_COLLABORATOR", camp) or is_granted("CAMP_IS_PROTOTYPE", camp)'
68+
security: 'is_granted("CAMP_COLLABORATOR", camp) or
69+
is_granted("CAMP_IS_SHARED", camp) or
70+
is_granted("CAMP_IS_PROTOTYPE", camp)'
6771
),
6872
],
6973
extraProperties: [

api/src/Entity/Checklist.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
new Get(
3232
security: 'is_granted("CHECKLIST_IS_PROTOTYPE", object) or
3333
is_granted("CAMP_IS_PROTOTYPE", object) or
34+
is_granted("CAMP_IS_SHARED", object) or
3435
is_granted("CAMP_COLLABORATOR", object)
3536
'
3637
),
@@ -62,7 +63,9 @@
6263
'campId' => new Link(
6364
toProperty: 'camp',
6465
fromClass: Camp::class,
65-
security: 'is_granted("CAMP_COLLABORATOR", camp) or is_granted("CAMP_IS_PROTOTYPE", camp)'
66+
security: 'is_granted("CAMP_COLLABORATOR", camp) or
67+
is_granted("CAMP_IS_SHARED", camp) or
68+
is_granted("CAMP_IS_PROTOTYPE", camp)'
6669
),
6770
],
6871
extraProperties: [

api/src/Entity/ChecklistItem.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@
3232
#[ApiResource(
3333
operations: [
3434
new Get(
35-
security: 'is_granted("CHECKLIST_IS_PROTOTYPE", object) or
36-
is_granted("CAMP_IS_PROTOTYPE", object) or
35+
security: 'is_granted("CHECKLIST_IS_PROTOTYPE", object) or
36+
is_granted("CAMP_IS_PROTOTYPE", object) or
37+
is_granted("CAMP_IS_SHARED", object) or
3738
is_granted("CAMP_COLLABORATOR", object)
3839
'
3940
),
@@ -63,8 +64,9 @@
6364
'checklistId' => new Link(
6465
fromClass: Checklist::class,
6566
toProperty: 'checklist',
66-
security: 'is_granted("CHECKLIST_IS_PROTOTYPE", checklist) or
67-
is_granted("CAMP_IS_PROTOTYPE", checklist) or
67+
security: 'is_granted("CHECKLIST_IS_PROTOTYPE", checklist) or
68+
is_granted("CAMP_IS_PROTOTYPE", checklist) or
69+
is_granted("CAMP_IS_SHARED", checklist) or
6870
is_granted("CAMP_COLLABORATOR", checklist)'
6971
),
7072
],

api/src/Entity/Comment.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@
4545
'activityId' => new Link(
4646
toProperty: 'activity',
4747
fromClass: Activity::class,
48-
security: 'is_granted("CAMP_COLLABORATOR", activity)',
48+
security: 'is_granted("CAMP_COLLABORATOR", activity) or
49+
is_granted("CAMP_IS_SHARED", activity) or
50+
is_granted("CAMP_IS_PROTOTYPE", activity)',
4951
),
5052
],
5153
security: 'is_fully_authenticated()',

0 commit comments

Comments
 (0)