Skip to content

Commit

Permalink
merge devel
Browse files Browse the repository at this point in the history
  • Loading branch information
usu committed Mar 31, 2024
2 parents ed26dc7 + 37794d5 commit 5745469
Show file tree
Hide file tree
Showing 21 changed files with 15,035 additions and 8,191 deletions.
8 changes: 4 additions & 4 deletions .ops/aws-setup/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .ops/aws-setup/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
},
"devDependencies": {
"@babel/eslint-parser": "7.24.1",
"@types/node": "20.11.30",
"@types/node": "20.12.2",
"eslint": "8.57.0",
"eslint-config-prettier": "9.1.0",
"eslint-plugin-import": "2.29.1",
Expand Down
2 changes: 1 addition & 1 deletion api/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,4 @@
}
}
}
}
}
2 changes: 1 addition & 1 deletion api/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion api/src/Entity/Activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class Activity extends BaseEntity implements BelongsToCampInterface {
public ?Category $category = null;

/**
* Copy Contents from this Source-Activity.
* Copy contents from this source activity.
*/
#[ApiProperty(example: '/activities/1a2b3c4d')]
#[Groups(['create'])]
Expand Down
7 changes: 7 additions & 0 deletions api/src/Entity/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,13 @@ class Category extends BaseEntity implements BelongsToCampInterface, CopyFromPro
#[ORM\OneToMany(targetEntity: Activity::class, mappedBy: 'category', orphanRemoval: true)]
public Collection $activities;

/**
* Copy contents from this source category or activity.
*/
#[ApiProperty(example: '/categories/1a2b3c4d')]
#[Groups(['create'])]
public null|Activity|Category $copyCategorySource;

/**
* The id of the category that was used as a template for creating this category. Internal for now, is
* not published through the API.
Expand Down
7 changes: 7 additions & 0 deletions api/src/State/CategoryCreateProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use App\Entity\ContentNode\ColumnLayout;
use App\Entity\ContentType;
use App\State\Util\AbstractPersistProcessor;
use App\Util\EntityMap;
use Doctrine\ORM\EntityManagerInterface;

/**
Expand Down Expand Up @@ -35,6 +36,12 @@ public function onBefore($data, Operation $operation, array $uriVariables = [],
$rootContentNode->data = ['columns' => [['slot' => '1', 'width' => 12]]];
$data->setRootContentNode($rootContentNode);

if (isset($data->copyCategorySource)) {
// CopyActivity Source is set -> copy it's content (rootContentNode)
$entityMap = new EntityMap();
$rootContentNode->copyFromPrototype($data->copyCategorySource->getRootContentNode(), $entityMap);
}

return $data;
}
}
101 changes: 99 additions & 2 deletions api/tests/Api/Categories/CreateCategoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ public function testCreateCategoryCreatesNewColumnLayoutAsRootContentNode() {

$this->assertResponseStatusCodeSame(201);
$newestColumnLayout = $this->getEntityManager()->getRepository(ContentNode::class)
->findBy(['contentType' => static::$fixtures['contentTypeColumnLayout']], ['createTime' => 'DESC'])[0]
->findBy(['contentType' => static::$fixtures['contentTypeColumnLayout'], 'instanceName' => null], ['createTime' => 'DESC'], 1)[0]
;
$this->assertJsonContains(['_links' => [
'rootContentNode' => ['href' => '/content_node/column_layouts/'.$newestColumnLayout->getId()],
'rootContentNode' => ['href' => $this->getIriFor($newestColumnLayout)],
]]);
}

Expand Down Expand Up @@ -456,6 +456,102 @@ public function testCreateCategoryValidatesInvalidNumberingStyle() {
]);
}

public function testCreateCategoryFromCopySourceValidatesAccess() {
static::createClientWithCredentials(['email' => static::$fixtures['user8memberOnlyInCamp2']->getEmail()])->request(
'POST',
'/categories',
['json' => $this->getExampleWritePayload(
[
'camp' => $this->getIriFor('camp2'),
'copyCategorySource' => $this->getIriFor('category1'),
]
)]
);

// No Access on category1 -> BadRequest
$this->assertResponseStatusCodeSame(400);
}

public function testCreateCategoryFromCopySourceWithinSameCamp() {
static::createClientWithCredentials()->request(
'POST',
'/categories',
['json' => $this->getExampleWritePayload(
[
'camp' => $this->getIriFor('camp1'),
'copyCategorySource' => $this->getIriFor('category1'),
],
)]
);

// Category created
$this->assertResponseStatusCodeSame(201);
}

public function testCreateCategoryFromCopySourceAcrossCamp() {
static::createClientWithCredentials()->request(
'POST',
'/categories',
['json' => $this->getExampleWritePayload(
[
'camp' => $this->getIriFor('camp2'),
'copyCategorySource' => $this->getIriFor('category1'),
],
)]
);

// Category created
$this->assertResponseStatusCodeSame(201);
}

public function testCreateCategoryFromCopySourceActivityValidatesAccess() {
static::createClientWithCredentials(['email' => static::$fixtures['user8memberOnlyInCamp2']->getEmail()])->request(
'POST',
'/categories',
['json' => $this->getExampleWritePayload(
[
'camp' => $this->getIriFor('camp2'),
'copyCategorySource' => $this->getIriFor('activity1'),
]
)]
);

// No Access on activity1 -> BadRequest
$this->assertResponseStatusCodeSame(400);
}

public function testCreateCategoryFromCopySourceActivityWithinSameCamp() {
static::createClientWithCredentials()->request(
'POST',
'/categories',
['json' => $this->getExampleWritePayload(
[
'camp' => $this->getIriFor('camp1'),
'copyCategorySource' => $this->getIriFor('activity1'),
],
)]
);

// Category created
$this->assertResponseStatusCodeSame(201);
}

public function testCreateCategoryFromCopySourceActivityAcrossCamp() {
static::createClientWithCredentials()->request(
'POST',
'/categories',
['json' => $this->getExampleWritePayload(
[
'camp' => $this->getIriFor('camp2'),
'copyCategorySource' => $this->getIriFor('activity1'),
],
)]
);

// Category created
$this->assertResponseStatusCodeSame(201);
}

/**
* @throws RedirectionExceptionInterface
* @throws DecodingExceptionInterface
Expand Down Expand Up @@ -488,6 +584,7 @@ public function getExampleWritePayload($attributes = [], $except = []) {
Category::class,
Post::class,
array_merge([
'copyCategorySource' => null,
'camp' => $this->getIriFor('camp1'),
'preferredContentTypes' => [$this->getIriFor('contentTypeSafetyConcept')],
], $attributes),
Expand Down
Loading

0 comments on commit 5745469

Please sign in to comment.