Worklog: create log entry on successfull creation

This commit is contained in:
Igor Scheller 2023-08-19 14:13:34 +02:00 committed by Michael Weimann
parent 80bec733bd
commit a60c5987ab
2 changed files with 15 additions and 3 deletions

View File

@ -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);

View File

@ -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);