diff --git a/src/Controllers/Admin/UserWorkLogController.php b/src/Controllers/Admin/UserWorkLogController.php index 4289e332..69453bb0 100644 --- a/src/Controllers/Admin/UserWorkLogController.php +++ b/src/Controllers/Admin/UserWorkLogController.php @@ -64,9 +64,9 @@ class UserWorkLogController extends BaseController $user = $this->user->findOrFail($userId); $data = $this->validate($request, [ - 'work_date' => 'required|date:Y-m-d', + 'work_date' => 'required|date:Y-m-d', 'work_hours' => 'float|min:0', - 'comment' => 'required|max:200', + 'comment' => 'required|max:200', ]); if (isset($worklogId)) { @@ -85,6 +85,16 @@ class UserWorkLogController extends BaseController $worklog->comment = $data['comment']; $worklog->save(); + $this->log->info( + 'Added worklog for {name} ({id}) at {time} about {hours}h: {text}', + [ + 'name' => $user->name, + 'id' => $user->id, + 'time' => $worklog->worked_at, + 'hours' => $worklog->hours, + 'text' => $worklog->comment, + ] + ); $this->addNotification(isset($worklogId) ? 'worklog.edit.success' : 'worklog.add.success'); return $this->redirect->to('/users?action=view&user_id=' . $userId); diff --git a/tests/Unit/Controllers/Admin/UserWorkLogControllerTest.php b/tests/Unit/Controllers/Admin/UserWorkLogControllerTest.php index 92bec537..13682685 100644 --- a/tests/Unit/Controllers/Admin/UserWorkLogControllerTest.php +++ b/tests/Unit/Controllers/Admin/UserWorkLogControllerTest.php @@ -109,7 +109,7 @@ class UserWorkLogControllerTest extends ControllerTest /** * @covers \Engelsystem\Controllers\Admin\UserWorkLogController::saveWorklog */ - public function testSaveWorklogWithUnkownUserIdThrows(): void + public function testSaveWorklogWithUnknownUserIdThrows(): void { $request = $this->request->withAttribute('user_id', 1234)->withParsedBody([]); $this->expectException(ModelNotFoundException::class); @@ -147,6 +147,8 @@ class UserWorkLogControllerTest extends ControllerTest $this->controller->saveWorklog($request); $this->assertHasNotification('worklog.add.success'); + $this->assertTrue($this->log->hasInfoThatContains('Added worklog for')); + $this->assertEquals(1, $this->user->worklogs->count()); $new_worklog = $this->user->worklogs[0]; $this->assertEquals($this->user->id, $new_worklog->user->id);