Worklog: create log entry on successfull creation
This commit is contained in:
parent
80bec733bd
commit
a60c5987ab
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue