From 073e75156bd0fb02a783b3ee40289ed4dd3af21f Mon Sep 17 00:00:00 2001 From: Edward Hibbert Date: Wed, 17 May 2023 15:13:14 +0100 Subject: [PATCH] NetworkCoordinator sees create event option but can't actually create. --- app/Helpers/Fixometer.php | 13 ++++--------- tests/Feature/Events/CreateEventTest.php | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/app/Helpers/Fixometer.php b/app/Helpers/Fixometer.php index 6f903c7ee..9ed8ea144 100644 --- a/app/Helpers/Fixometer.php +++ b/app/Helpers/Fixometer.php @@ -114,7 +114,7 @@ public static function userHasViewPartyPermission($partyId, $userId = null) } } - if (self::hasRole($user, 'Host') && self::userIsHostOfGroup($group->idgroups, $userId)) { + if (self::userIsHostOfGroup($group->idgroups, $userId)) { return true; } @@ -124,6 +124,7 @@ public static function userHasViewPartyPermission($partyId, $userId = null) public static function userHasEditPartyPermission($partyId, $userId = null) { $party = Party::findOrFail($partyId); + $group = $party->theGroup; if (is_null($userId)) { if (empty(Auth::user())) { @@ -140,7 +141,6 @@ public static function userHasEditPartyPermission($partyId, $userId = null) } if (self::hasRole($user, 'NetworkCoordinator')) { - $group = $party->theGroup; foreach ($group->networks as $network) { if ($network->coordinators->contains($user)) { return true; @@ -148,13 +148,8 @@ public static function userHasEditPartyPermission($partyId, $userId = null) } } - if (self::hasRole($user, 'Host')) { - $group_id_of_event = Party::where('idevents', $partyId)->value('group'); - if (self::userIsHostOfGroup($group_id_of_event, $userId)) { - return true; - } elseif (empty(DB::table('events_users')->where('event', $partyId)->where('user', $user->id)->first())) { - return false; - } + if (self::userIsHostOfGroup($group->idgroups, $userId)) { + return true; } return false; diff --git a/tests/Feature/Events/CreateEventTest.php b/tests/Feature/Events/CreateEventTest.php index ef168c7f4..86ef97583 100644 --- a/tests/Feature/Events/CreateEventTest.php +++ b/tests/Feature/Events/CreateEventTest.php @@ -736,5 +736,27 @@ public function network_coordinator_other_group() { self::assertEquals(2, count($groups)); self::assertEquals($groupNotInNetwork->idgroups, $groups[0]['idgroups']); self::assertEquals($groupInNetwork->idgroups, $groups[1]['idgroups']); + + // Create the event. + $eventAttributes = Party::factory()->raw(); + $eventAttributes['group'] = $idgroup; + + $event_start = Carbon::createFromTimestamp('tomorrow')->setTimezone('UTC'); + $event_end = Carbon::createFromTimestamp('tomorrow')->setTimezone('UTC')->addHour(2); + + $eventAttributes['event_start_utc'] = $event_start->toIso8601String(); + $eventAttributes['event_end_utc'] = $event_end->toIso8601String(); + + $response = $this->post('/party/create/', $eventAttributes); + $response->assertRedirect(); + + // Should redirect to edit page. + $redirectTo = $response->getTargetUrl(); + $p = strrpos($redirectTo, '/'); + $idevents = substr($redirectTo, $p + 1); + self::assertNotNull($idevents); + + $response = $this->get('/party/edit/'.$idevents); + $response->assertSuccessful(); } }