Skip to content

Commit 4030b09

Browse files
committed
WIP share camps
1 parent 91a69eb commit 4030b09

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+522
-63
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
/**
11+
* Auto-generated Migration: Please modify to your needs!
12+
*/
13+
final class Version20250821113132 extends AbstractMigration
14+
{
15+
public function getDescription(): string
16+
{
17+
return 'Add isShared flag on camps';
18+
}
19+
20+
public function up(Schema $schema): void
21+
{
22+
// this up() migration is auto-generated, please modify it to your needs
23+
$this->addSql('ALTER TABLE camp ADD isShared BOOLEAN DEFAULT FALSE NOT NULL');
24+
}
25+
26+
public function down(Schema $schema): void
27+
{
28+
// this down() migration is auto-generated, please modify it to your needs
29+
$this->addSql('ALTER TABLE camp DROP isShared');
30+
}
31+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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 Version20250821120000 extends AbstractMigration
11+
{
12+
public function getDescription(): string
13+
{
14+
return 'Update user_camp view to consider shared camps';
15+
}
16+
17+
public function up(Schema $schema): void
18+
{
19+
$this->addSql(
20+
<<<'EOF'
21+
CREATE OR REPLACE VIEW public.view_user_camps
22+
AS
23+
SELECT CONCAT(u.id, c.id) id, u.id userid, c.id campid
24+
from camp c, "user" u
25+
where c.isprototype = TRUE or c.isshared = TRUE
26+
union all
27+
select cc.id, cc.userid, cc.campid
28+
from camp_collaboration cc
29+
where cc.status = 'established'
30+
EOF
31+
);
32+
}
33+
34+
public function down(Schema $schema): void
35+
{
36+
$this->addSql(
37+
<<<'EOF'
38+
CREATE OR REPLACE VIEW public.view_user_camps
39+
AS
40+
SELECT CONCAT(u.id, c.id) id, u.id userid, c.id campid
41+
from camp c, "user" u
42+
where c.isprototype = TRUE
43+
union all
44+
select cc.id, cc.userid, cc.campid
45+
from camp_collaboration cc
46+
where cc.status = 'established'
47+
EOF
48+
);
49+
}
50+
}

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 & 2 deletions
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(
@@ -68,6 +70,7 @@ class Camp extends BaseEntity implements BelongsToCampInterface, CopyFromPrototy
6870
'swagger_definition_name' => 'read',
6971
];
7072

73+
#[ApiProperty(security: 'is_granted("CAMP_COLLABORATOR", object)')]
7174
#[AssertContainsAtLeastOneManager(groups: ['update'])]
7275
#[SerializedName('campCollaborations')]
7376
#[Groups(['read'])]
@@ -181,6 +184,17 @@ class Camp extends BaseEntity implements BelongsToCampInterface, CopyFromPrototy
181184
#[Groups(['create'])]
182185
public ?Camp $campPrototype = null;
183186

187+
/**
188+
* Whether the programme of this camp is publicly available to anyone who knows its
189+
* URI (excluding collaboration-based data such as camp collaborations, personal
190+
* material lists, responsibilities and comments).
191+
*/
192+
#[Assert\Type('bool')]
193+
#[ApiProperty(example: true)]
194+
#[Groups(['read', 'write'])]
195+
#[ORM\Column(type: 'boolean', nullable: false, options: ['default' => false])]
196+
public bool $isShared = false;
197+
184198
/**
185199
* Whether this camp may serve as a template for creating other camps.
186200
*/
@@ -453,7 +467,7 @@ public function getCampCollaborations(): array {
453467
*
454468
* @return CampCollaboration[]
455469
*/
456-
#[ApiProperty(writable: false, readableLink: true)]
470+
#[ApiProperty(writable: false, readableLink: true, security: 'is_granted("CAMP_COLLABORATOR", object)')]
457471
#[SerializedName('campCollaborations')]
458472
#[Groups('Camp:CampCollaborations')]
459473
public function getEmbeddedCampCollaborations(): array {

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)