Skip to content

Commit

Permalink
Fixed update for member with role employee
Browse files Browse the repository at this point in the history
  • Loading branch information
korridor committed May 21, 2024
1 parent 5c44f25 commit 5a8dc60
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/Http/Controllers/Api/V1/TimeEntryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ public function update(Organization $organization, TimeEntry $timeEntry, TimeEnt
{
/** @var Member|null $member */
$member = $request->has('member_id') ? Member::query()->findOrFail($request->get('member_id')) : null;
if ($timeEntry->member->user_id === Auth::id() && $member?->user_id === Auth::id()) {
if ($timeEntry->member->user_id === Auth::id() && ($member === null || $member->user_id === Auth::id())) {
$this->checkPermission($organization, 'time-entries:update:own');
} else {
$this->checkPermission($organization, 'time-entries:update:all');
Expand Down
27 changes: 27 additions & 0 deletions tests/Unit/Endpoint/Api/V1/TimeEntryEndpointTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1144,6 +1144,33 @@ public function test_update_endpoint_updates_time_entry_for_current_user(): void
]);
}

public function test_update_endpoint_updates_time_entry_for_current_user_but_does_not_send_member_id(): void
{
// Arrange
$data = $this->createUserWithPermission([
'time-entries:update:own',
]);
$timeEntry = TimeEntry::factory()->forOrganization($data->organization)->forMember($data->member)->create();
$timeEntryFake = TimeEntry::factory()->withTags($data->organization)->forOrganization($data->organization)->make();
Passport::actingAs($data->user);

// Act
$response = $this->putJson(route('api.v1.time-entries.update', [$data->organization->getKey(), $timeEntry->getKey()]), [
'description' => $timeEntryFake->description,
'start' => $timeEntryFake->start->toIso8601ZuluString(),
'end' => $timeEntryFake->end->toIso8601ZuluString(),
'tags' => $timeEntryFake->tags,
]);

// Assert
$response->assertStatus(200);
$this->assertDatabaseHas(TimeEntry::class, [
'id' => $timeEntry->getKey(),
'member_id' => $data->member->getKey(),
'task_id' => $timeEntryFake->task_id,
]);
}

public function test_update_endpoint_fails_if_user_tries_to_reactivate_a_time_entry(): void
{
// Arrange
Expand Down

0 comments on commit 5a8dc60

Please sign in to comment.