Skip to content

Commit 3d85e44

Browse files
author
OpenCode Agent
committed
CampCollaborationUpdateProcessor: fix NPE if user is null
This allows changing the role again when the user did not accept the invitation yet. Bug was introduced with commit af31650.
1 parent 86424ce commit 3d85e44

2 files changed

Lines changed: 63 additions & 0 deletions

File tree

api/src/State/CampCollaborationUpdateProcessor.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ public function onBeforeStatusChange(CampCollaboration $data): CampCollaboration
5555
}
5656

5757
public function onBeforeRoleChange(CampCollaboration $data, CampCollaboration $previous): CampCollaboration {
58+
if (null === $data->user) {
59+
return $data;
60+
}
61+
5862
/** @var User $user */
5963
$user = $this->security->getUser();
6064
// If the update does not affect the own collaboration, the voter works.

api/tests/Api/CampCollaborations/UpdateCampCollaborationTest.php

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,65 @@ public function testPatchCampCollaborationInSharedCampIsDeniedForInvitedUser() {
267267
]);
268268
}
269269

270+
public function testPatchCampCollaborationRoleWithoutUserIsAllowed() {
271+
/** @var CampCollaboration $campCollaboration */
272+
$campCollaboration = static::getFixture('campCollaboration4invited');
273+
274+
static::createClientWithCredentials()->request('PATCH', '/camp_collaborations/'.$campCollaboration->getId(), [
275+
'json' => [
276+
'role' => CampCollaboration::ROLE_GUEST,
277+
],
278+
'headers' => ['Content-Type' => 'application/merge-patch+json'],
279+
]);
280+
281+
$this->assertResponseStatusCodeSame(200);
282+
$this->assertJsonContains([
283+
'role' => CampCollaboration::ROLE_GUEST,
284+
]);
285+
}
286+
287+
public function testPatchCampCollaborationRoleFromGuestToManagerWithoutUserIsAllowed() {
288+
/** @var CampCollaboration $campCollaboration */
289+
$campCollaboration = static::getFixture('campCollaboration4invited');
290+
291+
static::createClientWithCredentials()->request('PATCH', '/camp_collaborations/'.$campCollaboration->getId(), [
292+
'json' => [
293+
'role' => CampCollaboration::ROLE_MANAGER,
294+
],
295+
'headers' => ['Content-Type' => 'application/merge-patch+json'],
296+
]);
297+
298+
static::createClientWithCredentials()->request('PATCH', '/camp_collaborations/'.$campCollaboration->getId(), [
299+
'json' => [
300+
'role' => CampCollaboration::ROLE_MANAGER,
301+
],
302+
'headers' => ['Content-Type' => 'application/merge-patch+json'],
303+
]);
304+
305+
// This should succeed without errors
306+
$this->assertResponseStatusCodeSame(200);
307+
$this->assertJsonContains([
308+
'role' => 'manager',
309+
]);
310+
}
311+
312+
public function testPatchCampCollaborationDisallowsSettingUserToNull() {
313+
/** @var CampCollaboration $campCollaboration */
314+
$campCollaboration = static::getFixture('campCollaboration4invited');
315+
316+
static::createClientWithCredentials()->request('PATCH', '/camp_collaborations/'.$campCollaboration->getId(), [
317+
'json' => [
318+
'user' => null,
319+
],
320+
'headers' => ['Content-Type' => 'application/merge-patch+json'],
321+
]);
322+
323+
$this->assertResponseStatusCodeSame(400);
324+
$this->assertJsonContains([
325+
'detail' => 'Extra attributes are not allowed ("user" is unknown).',
326+
]);
327+
}
328+
270329
public function testPatchCampCollaborationDisallowsChangingInviteEmail() {
271330
$campCollaboration = static::getFixture('campCollaboration1manager');
272331
static::createClientWithCredentials()->request('PATCH', '/camp_collaborations/'.$campCollaboration->getId(), ['json' => [

0 commit comments

Comments
 (0)