mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-10-17 10:13:16 +01:00
Compare commits
8 Commits
feature/ru
...
778dee6a3b
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
778dee6a3b | ||
|
|
b73cdc4bb5 | ||
|
|
e82c601449 | ||
|
|
f65a1532ad | ||
|
|
b42e84294c | ||
|
|
1863953a23 | ||
|
|
ce9413a55e | ||
|
|
b08364770c |
@@ -39,7 +39,7 @@ class SelfHostDatabaseConsistency extends Command
|
||||
$problems = DB::table('time_entries')
|
||||
->select(['time_entries.id as id'])
|
||||
->join('tasks', 'time_entries.task_id', '=', 'tasks.id')
|
||||
->where('tasks.project_id', '!=', DB::raw('time_entries.project_id'))
|
||||
->whereRaw('tasks.project_id is distinct from time_entries.project_id')
|
||||
->get();
|
||||
$this->logProblems($problems, 'Time entries have a task that does not belong to the project of the time entry', $hadAProblem);
|
||||
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Exceptions\Api;
|
||||
|
||||
class TimeEntryMemberCanNotBeChangedWhileRunningApiException extends ApiException
|
||||
{
|
||||
public const string KEY = 'time_entry_member_can_not_be_changed_while_running';
|
||||
|
||||
public function report(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@ use App\Exceptions\Api\FeatureIsNotAvailableInFreePlanApiException;
|
||||
use App\Exceptions\Api\OverlappingTimeEntryApiException;
|
||||
use App\Exceptions\Api\PdfRendererIsNotConfiguredException;
|
||||
use App\Exceptions\Api\TimeEntryCanNotBeRestartedApiException;
|
||||
use App\Exceptions\Api\TimeEntryMemberCanNotBeChangedWhileRunningApiException;
|
||||
use App\Exceptions\Api\TimeEntryStillRunningApiException;
|
||||
use App\Http\Requests\V1\TimeEntry\TimeEntryAggregateExportRequest;
|
||||
use App\Http\Requests\V1\TimeEntry\TimeEntryAggregateRequest;
|
||||
@@ -51,6 +52,7 @@ use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Blade;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
@@ -613,7 +615,24 @@ class TimeEntryController extends Controller
|
||||
$this->checkPermission($organization, 'time-entries:create:all');
|
||||
}
|
||||
|
||||
if ($request->input('end') === null && TimeEntry::query()->whereBelongsTo($member, 'member')->where('end', null)->exists()) {
|
||||
// Lock the creation of running time entries per user, so that concurrent requests can not create more than one running time entry
|
||||
$lock = $request->input('end') === null ? Cache::lock('time-entries:running:'.$member->user_id, 10) : null;
|
||||
$lock?->block(5);
|
||||
|
||||
try {
|
||||
return $this->storeTimeEntry($organization, $member, $request);
|
||||
} finally {
|
||||
$lock?->release();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws TimeEntryStillRunningApiException
|
||||
*/
|
||||
private function storeTimeEntry(Organization $organization, Member $member, TimeEntryStoreRequest $request): JsonResource
|
||||
{
|
||||
// A user can only have one running time entry, across all organizations
|
||||
if ($request->input('end') === null && TimeEntry::query()->where('user_id', $member->user_id)->whereNull('end')->exists()) {
|
||||
throw new TimeEntryStillRunningApiException;
|
||||
}
|
||||
|
||||
@@ -650,7 +669,7 @@ class TimeEntryController extends Controller
|
||||
*
|
||||
* To stop a running timer, set `end` to the stop time (UTC). Times the user gives in their own timezone must be converted to UTC first.
|
||||
*
|
||||
* @throws AuthorizationException|TimeEntryCanNotBeRestartedApiException
|
||||
* @throws AuthorizationException|TimeEntryCanNotBeRestartedApiException|TimeEntryMemberCanNotBeChangedWhileRunningApiException
|
||||
*
|
||||
* @operationId updateTimeEntry
|
||||
*/
|
||||
@@ -676,6 +695,11 @@ class TimeEntryController extends Controller
|
||||
$effectiveEnd = $request->has('end') ? ($request->input('end') !== null ? Carbon::parse($request->input('end')) : null) : $timeEntry->end;
|
||||
$this->assertNoOverlap($organization, $effectiveMember, $effectiveStart, $effectiveEnd, $timeEntry);
|
||||
|
||||
// The new member could already have a running time entry
|
||||
if ($effectiveEnd === null && $newMember !== null && $newMember->getKey() !== $timeEntry->member_id) {
|
||||
throw new TimeEntryMemberCanNotBeChangedWhileRunningApiException;
|
||||
}
|
||||
|
||||
$oldProject = $timeEntry->project;
|
||||
$oldTask = $timeEntry->task;
|
||||
|
||||
@@ -695,6 +719,10 @@ class TimeEntryController extends Controller
|
||||
$timeEntry->member()->associate($newMember);
|
||||
$timeEntry->user()->associate($newMember->user);
|
||||
}
|
||||
// If project is changed, but task is not, we remove the old task from the time entry
|
||||
if ($request->has('project_id') && ! $request->has('task_id') && $oldTask !== null && $oldTask->project_id !== $project?->getKey()) {
|
||||
$timeEntry->task()->disassociate();
|
||||
}
|
||||
$timeEntry->description = $request->input('description', $timeEntry->description) ?? '';
|
||||
$timeEntry->setComputedAttributeValue('billable_rate');
|
||||
$timeEntry->save();
|
||||
@@ -801,6 +829,12 @@ class TimeEntryController extends Controller
|
||||
|
||||
continue;
|
||||
}
|
||||
// The new member could already have a running time entry
|
||||
if ($newMember !== null && $timeEntry->end === null && $newMember->getKey() !== $timeEntry->member_id) {
|
||||
$error->push($id);
|
||||
|
||||
continue;
|
||||
}
|
||||
$oldProject = $timeEntry->project;
|
||||
$oldTask = $timeEntry->task;
|
||||
|
||||
@@ -810,7 +844,7 @@ class TimeEntryController extends Controller
|
||||
$timeEntry->user_id = $newMember->user_id;
|
||||
}
|
||||
// If project is changed, but task is not, we remove the old task from the time entry
|
||||
if ($oldProject !== null && $project !== null && $oldProject->isNot($project) && $task === null) {
|
||||
if ($request->has('changes.project_id') && ! $request->has('changes.task_id') && $oldTask !== null && $oldTask->project_id !== $project?->getKey()) {
|
||||
$timeEntry->task()->disassociate();
|
||||
}
|
||||
if ($overwriteClient) {
|
||||
|
||||
@@ -116,13 +116,13 @@ class ReportPropertiesDto implements Castable
|
||||
$dto->end = $data->end !== null ? Carbon::createFromFormat('Y-m-d\TH:i:s\Z', $data->end) : null;
|
||||
$dto->start = $data->start !== null ? Carbon::createFromFormat('Y-m-d\TH:i:s\Z', $data->start) : null;
|
||||
$dto->active = $data->active;
|
||||
$dto->memberIds = $data->memberIds !== null ? TimeEntryFilter::idArrayToCollection($data->memberIds) : null;
|
||||
$dto->setMemberIds($data->memberIds !== null ? (array) $data->memberIds : null);
|
||||
$dto->billable = $data->billable;
|
||||
$dto->clientIds = $data->clientIds !== null ? TimeEntryFilter::idArrayToCollection($data->clientIds) : null;
|
||||
$dto->projectIds = $data->projectIds !== null ? TimeEntryFilter::idArrayToCollection($data->projectIds) : null;
|
||||
$dto->tagIds = $data->tagIds !== null ? TimeEntryFilter::idArrayToCollection($data->tagIds) : null;
|
||||
$dto->setClientIds($data->clientIds !== null ? (array) $data->clientIds : null);
|
||||
$dto->setProjectIds($data->projectIds !== null ? (array) $data->projectIds : null);
|
||||
$dto->setTagIds($data->tagIds !== null ? (array) $data->tagIds : null);
|
||||
$dto->tagMatchType = isset($data->tagMatchType) ? TagMatchType::from($data->tagMatchType) : null;
|
||||
$dto->taskIds = $data->taskIds ? TimeEntryFilter::idArrayToCollection($data->taskIds) : null;
|
||||
$dto->setTaskIds($data->taskIds !== null ? (array) $data->taskIds : null);
|
||||
$dto->group = TimeEntryAggregationType::from($data->group);
|
||||
$dto->subGroup = TimeEntryAggregationType::from($data->subGroup);
|
||||
$dto->historyGroup = TimeEntryAggregationTypeInterval::from($data->historyGroup);
|
||||
@@ -184,7 +184,7 @@ class ReportPropertiesDto implements Castable
|
||||
*/
|
||||
public function setMemberIds(?array $memberIds): void
|
||||
{
|
||||
$this->memberIds = $memberIds !== null ? TimeEntryFilter::idArrayToCollection($memberIds) : null;
|
||||
$this->memberIds = $memberIds !== null && count($memberIds) > 0 ? TimeEntryFilter::idArrayToCollection($memberIds) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -192,7 +192,7 @@ class ReportPropertiesDto implements Castable
|
||||
*/
|
||||
public function setClientIds(?array $clientIds): void
|
||||
{
|
||||
$this->clientIds = $clientIds !== null ? TimeEntryFilter::idArrayToCollection($clientIds) : null;
|
||||
$this->clientIds = $clientIds !== null && count($clientIds) > 0 ? TimeEntryFilter::idArrayToCollection($clientIds) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -200,7 +200,7 @@ class ReportPropertiesDto implements Castable
|
||||
*/
|
||||
public function setProjectIds(?array $projectIds): void
|
||||
{
|
||||
$this->projectIds = $projectIds !== null ? TimeEntryFilter::idArrayToCollection($projectIds) : null;
|
||||
$this->projectIds = $projectIds !== null && count($projectIds) > 0 ? TimeEntryFilter::idArrayToCollection($projectIds) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -208,7 +208,7 @@ class ReportPropertiesDto implements Castable
|
||||
*/
|
||||
public function setTagIds(?array $tagIds): void
|
||||
{
|
||||
$this->tagIds = $tagIds !== null ? TimeEntryFilter::idArrayToCollection($tagIds) : null;
|
||||
$this->tagIds = $tagIds !== null && count($tagIds) > 0 ? TimeEntryFilter::idArrayToCollection($tagIds) : null;
|
||||
}
|
||||
|
||||
public function setTagMatchType(?TagMatchType $tagMatchType): void
|
||||
@@ -221,6 +221,6 @@ class ReportPropertiesDto implements Castable
|
||||
*/
|
||||
public function setTaskIds(?array $taskIds): void
|
||||
{
|
||||
$this->taskIds = $taskIds !== null ? TimeEntryFilter::idArrayToCollection($taskIds) : null;
|
||||
$this->taskIds = $taskIds !== null && count($taskIds) > 0 ? TimeEntryFilter::idArrayToCollection($taskIds) : null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -211,6 +211,10 @@ class SolidtimeImporter extends DefaultImporter
|
||||
|
||||
// Time entries
|
||||
foreach ($timeEntriesReader as $timeEntryRow) {
|
||||
// Running time entries are skipped, since the user could already have a running time entry
|
||||
if ($timeEntryRow['end'] === '') {
|
||||
continue;
|
||||
}
|
||||
$userId = $this->userImportHelper->getKeyByExternalIdentifier($timeEntryRow['user_id']);
|
||||
if ($userId === null) {
|
||||
throw new ImportException('Time entry references a user that does not exist in the import');
|
||||
@@ -286,22 +290,18 @@ class SolidtimeImporter extends DefaultImporter
|
||||
}
|
||||
$timeEntry->start = $start->utc();
|
||||
|
||||
if ($timeEntryRow['end'] !== '') {
|
||||
try {
|
||||
$end = Carbon::createFromFormat('Y-m-d\TH:i:s\Z', $timeEntryRow['end'], 'UTC');
|
||||
} catch (InvalidFormatException) {
|
||||
throw new ImportException('End date ("'.$timeEntryRow['end'].'") is invalid');
|
||||
}
|
||||
if ($end === null) {
|
||||
throw new ImportException('End date ("'.$timeEntryRow['end'].'") is invalid');
|
||||
}
|
||||
if ($end->lt($start)) {
|
||||
throw new ImportException('End date ("'.$timeEntryRow['end'].'") is before start date ("'.$timeEntryRow['start'].'")');
|
||||
}
|
||||
$timeEntry->end = $end->utc();
|
||||
} else {
|
||||
$timeEntry->end = null;
|
||||
try {
|
||||
$end = Carbon::createFromFormat('Y-m-d\TH:i:s\Z', $timeEntryRow['end'], 'UTC');
|
||||
} catch (InvalidFormatException) {
|
||||
throw new ImportException('End date ("'.$timeEntryRow['end'].'") is invalid');
|
||||
}
|
||||
if ($end === null) {
|
||||
throw new ImportException('End date ("'.$timeEntryRow['end'].'") is invalid');
|
||||
}
|
||||
if ($end->lt($start)) {
|
||||
throw new ImportException('End date ("'.$timeEntryRow['end'].'") is before start date ("'.$timeEntryRow['start'].'")');
|
||||
}
|
||||
$timeEntry->end = $end->utc();
|
||||
|
||||
if ($timeEntryRow['still_active_email_sent_at'] !== '') {
|
||||
try {
|
||||
|
||||
@@ -159,6 +159,13 @@ class MemberService
|
||||
|
||||
public function assignOrganizationEntitiesToDifferentMember(Organization $organization, Member $fromMember, Member $toMember): void
|
||||
{
|
||||
// Running time entries are deleted instead of moved, since $toMember could already have a running time entry
|
||||
TimeEntry::query()
|
||||
->whereBelongsTo($organization, 'organization')
|
||||
->whereBelongsTo($fromMember, 'member')
|
||||
->whereNull('end')
|
||||
->delete();
|
||||
|
||||
// Time entries
|
||||
TimeEntry::query()
|
||||
->whereBelongsTo($organization, 'organization')
|
||||
|
||||
@@ -133,7 +133,8 @@ class TimeEntryFilter
|
||||
*/
|
||||
public function addMemberIdsFilter(?array $memberIds): self
|
||||
{
|
||||
if ($memberIds === null) {
|
||||
// An empty selection is no constraint, the same as null
|
||||
if ($memberIds === null || count($memberIds) === 0) {
|
||||
return $this;
|
||||
}
|
||||
$this->builder->whereIn('member_id', $memberIds);
|
||||
@@ -203,6 +204,10 @@ class TimeEntryFilter
|
||||
}
|
||||
$includeNone = in_array(self::NONE_VALUE, $clientIds, true);
|
||||
$clientIds = array_values(array_filter($clientIds, fn (string $id): bool => $id !== self::NONE_VALUE));
|
||||
// An empty selection (no client IDs and not filtering for "none") is no constraint, so apply nothing
|
||||
if (count($clientIds) === 0 && ! $includeNone) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
$this->builder->where(function (Builder $builder) use ($clientIds, $includeNone): void {
|
||||
if (count($clientIds) > 0) {
|
||||
@@ -226,6 +231,10 @@ class TimeEntryFilter
|
||||
}
|
||||
$includeNone = in_array(self::NONE_VALUE, $projectIds, true);
|
||||
$projectIds = array_values(array_filter($projectIds, fn (string $id): bool => $id !== self::NONE_VALUE));
|
||||
// An empty selection (no project IDs and not filtering for "none") is no constraint, so apply nothing
|
||||
if (count($projectIds) === 0 && ! $includeNone) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
$this->builder->where(function (Builder $builder) use ($projectIds, $includeNone): void {
|
||||
if (count($projectIds) > 0) {
|
||||
@@ -291,6 +300,10 @@ class TimeEntryFilter
|
||||
}
|
||||
$includeNone = in_array(self::NONE_VALUE, $taskIds, true);
|
||||
$taskIds = array_values(array_filter($taskIds, fn (string $id): bool => $id !== self::NONE_VALUE));
|
||||
// An empty selection (no task IDs and not filtering for "none") is no constraint, so apply nothing
|
||||
if (count($taskIds) === 0 && ! $includeNone) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
$this->builder->where(function (Builder $builder) use ($taskIds, $includeNone): void {
|
||||
if (count($taskIds) > 0) {
|
||||
|
||||
@@ -19,6 +19,7 @@ use App\Exceptions\Api\PdfRendererIsNotConfiguredException;
|
||||
use App\Exceptions\Api\PersonalAccessClientIsNotConfiguredException;
|
||||
use App\Exceptions\Api\ThisPlaceholderCanNotBeInvitedUseTheMergeToolInsteadException;
|
||||
use App\Exceptions\Api\TimeEntryCanNotBeRestartedApiException;
|
||||
use App\Exceptions\Api\TimeEntryMemberCanNotBeChangedWhileRunningApiException;
|
||||
use App\Exceptions\Api\TimeEntryStillRunningApiException;
|
||||
use App\Exceptions\Api\UserIsAlreadyMemberOfOrganizationApiException;
|
||||
use App\Exceptions\Api\UserIsAlreadyMemberOfProjectApiException;
|
||||
@@ -31,6 +32,7 @@ return [
|
||||
TimeEntryStillRunningApiException::KEY => 'Time entry is still running',
|
||||
UserNotPlaceholderApiException::KEY => 'The given user is not a placeholder',
|
||||
TimeEntryCanNotBeRestartedApiException::KEY => 'Time entry is already stopped and can not be restarted',
|
||||
TimeEntryMemberCanNotBeChangedWhileRunningApiException::KEY => 'The member of a running time entry can not be changed',
|
||||
InactiveUserCanNotBeUsedApiException::KEY => 'Inactive user can not be used',
|
||||
UserIsAlreadyMemberOfOrganizationApiException::KEY => 'User is already a member of the organization',
|
||||
UserIsAlreadyMemberOfProjectApiException::KEY => 'User is already a member of the project',
|
||||
|
||||
3
resources/testfiles/solidtime_import_test_3/clients.csv
Normal file
3
resources/testfiles/solidtime_import_test_3/clients.csv
Normal file
@@ -0,0 +1,3 @@
|
||||
id,name,organization_id,archived_at,created_at,updated_at
|
||||
b4187a44-41f4-46d7-8460-f15a25b3aad6,"Big Company",ee5a8cd6-312f-4ae6-b044-e2014f09ecc2,,2024-08-22T10:36:48Z,2024-08-22T10:36:48Z
|
||||
e5a4d8f5-81ae-4606-8e84-6ab1ffa58b72,"Other Company (Archived)",ee5a8cd6-312f-4ae6-b044-e2014f09ecc2,2024-08-22T10:36:48Z,2024-08-22T10:36:48Z,2024-08-22T10:36:48Z
|
||||
|
2
resources/testfiles/solidtime_import_test_3/members.csv
Normal file
2
resources/testfiles/solidtime_import_test_3/members.csv
Normal file
@@ -0,0 +1,2 @@
|
||||
id,user_id,name,email,organization_id,billable_rate,role,created_at,updated_at
|
||||
06e6e605-86bd-417b-b75d-02f671e5d520,0446cdd8-3ad1-43d6-9231-9e0dc4eeb71c,"Peter Tester",peter.test@email.test,ee5a8cd6-312f-4ae6-b044-e2014f09ecc2,,admin,2024-08-22T10:36:48Z,2024-08-22T10:36:48Z
|
||||
|
1
resources/testfiles/solidtime_import_test_3/meta.json
Normal file
1
resources/testfiles/solidtime_import_test_3/meta.json
Normal file
@@ -0,0 +1 @@
|
||||
{"id":"d6a324ee-58d5-4096-8069-c63bd55608f7","version":"1.0","organizations":["ee5a8cd6-312f-4ae6-b044-e2014f09ecc2"],"exported_at":"2024-08-26T18:21:59Z"}
|
||||
@@ -0,0 +1 @@
|
||||
id,email,organization_id,role,created_at,updated_at
|
||||
|
@@ -0,0 +1,2 @@
|
||||
id,name,billable_rate,currency,created_at,updated_at
|
||||
ee5a8cd6-312f-4ae6-b044-e2014f09ecc2,"ACME Corp",,EUR,2024-08-22T10:36:48Z,2024-08-22T10:36:48Z
|
||||
|
@@ -0,0 +1,2 @@
|
||||
id,billable_rate,project_id,user_id,member_id,created_at,updated_at
|
||||
180a1a98-2f1c-4596-86e4-63a6be0d7b1d,10002,06e79ec4-33f8-4730-804c-d03c014991d1,0446cdd8-3ad1-43d6-9231-9e0dc4eeb71c,06e6e605-86bd-417b-b75d-02f671e5d520,2024-08-22T10:36:48Z,2024-08-22T10:36:48Z
|
||||
|
4
resources/testfiles/solidtime_import_test_3/projects.csv
Normal file
4
resources/testfiles/solidtime_import_test_3/projects.csv
Normal file
@@ -0,0 +1,4 @@
|
||||
id,name,color,billable_rate,is_public,client_id,organization_id,is_billable,archived_at,created_at,updated_at
|
||||
06e79ec4-33f8-4730-804c-d03c014991d1,"Project for Big Company",#ec407a,10001,false,b4187a44-41f4-46d7-8460-f15a25b3aad6,ee5a8cd6-312f-4ae6-b044-e2014f09ecc2,true,,2024-08-22T10:36:48Z,2024-08-22T10:36:48Z
|
||||
622c74a9-7e64-44c2-9426-2a37ac738206,"Project without Client",#ef5350,,false,,ee5a8cd6-312f-4ae6-b044-e2014f09ecc2,false,,2024-08-22T10:36:48Z,2024-08-22T10:36:48Z
|
||||
aa831162-dbb2-4cfe-bfe0-5e3a252c66f0,"Project (Archived)",#6a407f,,true,e5a4d8f5-81ae-4606-8e84-6ab1ffa58b72,ee5a8cd6-312f-4ae6-b044-e2014f09ecc2,true,2024-08-25T10:00:00Z,2024-08-22T10:36:48Z,2024-08-22T10:36:48Z
|
||||
|
3
resources/testfiles/solidtime_import_test_3/tags.csv
Normal file
3
resources/testfiles/solidtime_import_test_3/tags.csv
Normal file
@@ -0,0 +1,3 @@
|
||||
id,name,organization_id,created_at,updated_at
|
||||
2c5c2da7-9ef8-4410-bb8f-6e0a90f9d2c7,Development,ee5a8cd6-312f-4ae6-b044-e2014f09ecc2,2024-08-22T10:36:48Z,2024-08-22T10:36:48Z
|
||||
bf6c0ac5-2587-474b-8983-40bb3ea8002f,Backend,ee5a8cd6-312f-4ae6-b044-e2014f09ecc2,2024-08-22T10:36:48Z,2024-08-22T10:36:48Z
|
||||
|
3
resources/testfiles/solidtime_import_test_3/tasks.csv
Normal file
3
resources/testfiles/solidtime_import_test_3/tasks.csv
Normal file
@@ -0,0 +1,3 @@
|
||||
id,name,project_id,organization_id,done_at,created_at,updated_at
|
||||
b49688a0-94f3-4cb3-9ca1-5003de955fb0,"Task 1",06e79ec4-33f8-4730-804c-d03c014991d1,ee5a8cd6-312f-4ae6-b044-e2014f09ecc2,,2024-08-22T10:36:48Z,2024-08-22T10:36:48Z
|
||||
b49688a0-94f3-4cb3-9ca1-5003de955fb0,"Task 2",06e79ec4-33f8-4730-804c-d03c014991d1,ee5a8cd6-312f-4ae6-b044-e2014f09ecc2,2024-08-24T10:00:00Z,2024-08-22T10:36:48Z,2024-08-22T10:36:48Z
|
||||
|
@@ -0,0 +1,5 @@
|
||||
id,description,start,end,billable_rate,billable,type,member_id,user_id,organization_id,client_id,project_id,task_id,tags,is_imported,still_active_email_sent_at,created_at,updated_at
|
||||
00aae3be-18fc-462d-bee4-350fb605b2f3,,2024-03-04T09:23:52Z,2024-03-04T09:23:52Z,,false,,06e6e605-86bd-417b-b75d-02f671e5d520,0446cdd8-3ad1-43d6-9231-9e0dc4eeb71c,ee5a8cd6-312f-4ae6-b044-e2014f09ecc2,,,,"[""2c5c2da7-9ef8-4410-bb8f-6e0a90f9d2c7"",""bf6c0ac5-2587-474b-8983-40bb3ea8002f""]",false,,2024-08-22T10:36:48Z,2024-08-22T10:36:48Z
|
||||
1c7a905d-aa12-4d08-bc41-7e92577e7cdf,"Working hard",2024-03-04T09:23:00Z,2024-03-04T10:23:01Z,,true,work,06e6e605-86bd-417b-b75d-02f671e5d520,0446cdd8-3ad1-43d6-9231-9e0dc4eeb71c,ee5a8cd6-312f-4ae6-b044-e2014f09ecc2,b4187a44-41f4-46d7-8460-f15a25b3aad6,06e79ec4-33f8-4730-804c-d03c014991d1,b49688a0-94f3-4cb3-9ca1-5003de955fb0,[],false,,2024-08-22T10:36:48Z,2024-08-22T10:36:48Z
|
||||
9f2f5b83-3a6b-4a9c-8d21-4f1e5cf1b7aa,"Lunch break",2024-03-04T12:00:00Z,2024-03-04T12:30:00Z,,false,break,06e6e605-86bd-417b-b75d-02f671e5d520,0446cdd8-3ad1-43d6-9231-9e0dc4eeb71c,ee5a8cd6-312f-4ae6-b044-e2014f09ecc2,,,,[],false,,2024-08-22T10:36:48Z,2024-08-22T10:36:48Z
|
||||
5d0e8c4a-7b1f-4e2a-9c3d-8a6b2f1e4c7d,"Still running",2024-03-04T13:00:00Z,,,true,work,06e6e605-86bd-417b-b75d-02f671e5d520,0446cdd8-3ad1-43d6-9231-9e0dc4eeb71c,ee5a8cd6-312f-4ae6-b044-e2014f09ecc2,,,,[],false,,2024-08-22T10:36:48Z,2024-08-22T10:36:48Z
|
||||
|
@@ -39,6 +39,26 @@ class SelfHostDatabaseConsistencyCommandTest extends TestCaseWithDatabase
|
||||
$this->assertSame("Consistency problem: Time entries have a task that does not belong to the project of the time entry\n - ".$timeEntry->getKey()."\n", $output);
|
||||
}
|
||||
|
||||
public function test_checks_that_task_need_to_be_part_of_project_in_time_entries_with_no_project_in_time_entry(): void
|
||||
{
|
||||
// Arrange
|
||||
$user = $this->createUserWithRole(Role::Owner);
|
||||
$project = Project::factory()->forOrganization($user->organization)->create();
|
||||
$task = Task::factory()->forOrganization($user->organization)->forProject($project)->create();
|
||||
$timeEntry = TimeEntry::factory()->forMember($user->member)->forTask($task)->create([
|
||||
'project_id' => null,
|
||||
'client_id' => null,
|
||||
]);
|
||||
|
||||
// Act
|
||||
$exitCode = $this->withoutMockingConsoleOutput()->artisan('self-host:database-consistency');
|
||||
|
||||
// Assert
|
||||
$this->assertSame(Command::FAILURE, $exitCode);
|
||||
$output = Artisan::output();
|
||||
$this->assertSame("Consistency problem: Time entries have a task that does not belong to the project of the time entry\n - ".$timeEntry->getKey()."\n", $output);
|
||||
}
|
||||
|
||||
public function test_checks_that_client_id_is_the_client_id_of_the_project(): void
|
||||
{
|
||||
// Arrange
|
||||
|
||||
@@ -390,6 +390,40 @@ class MemberEndpointTest extends ApiEndpointTestAbstract
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_merge_into_deletes_running_time_entries_of_source_member(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission([
|
||||
'members:merge-into',
|
||||
]);
|
||||
$userSource = User::factory()->placeholder()->create();
|
||||
$memberSource = Member::factory()->forUser($userSource)->forOrganization($data->organization)->role(Role::Placeholder)->create();
|
||||
$runningTimeEntrySource = TimeEntry::factory()->forOrganization($data->organization)->forMember($memberSource)->active()->create();
|
||||
TimeEntry::factory()->forOrganization($data->organization)->forMember($memberSource)->createMany(2);
|
||||
|
||||
$userDestination = User::factory()->create();
|
||||
$memberDestination = Member::factory()->forUser($userDestination)->forOrganization($data->organization)->role(Role::Admin)->create();
|
||||
$runningTimeEntryDestination = TimeEntry::factory()->forOrganization($data->organization)->forMember($memberDestination)->active()->create();
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->postJson(route('api.v1.members.merge-into', [$data->organization->getKey(), $memberSource->getKey()]), [
|
||||
'member_id' => $memberDestination->getKey(),
|
||||
]);
|
||||
|
||||
// Assert
|
||||
$response->assertStatus(204);
|
||||
$this->assertDatabaseMissing(Member::class, [
|
||||
'id' => $memberSource->getKey(),
|
||||
]);
|
||||
$this->assertDatabaseMissing(TimeEntry::class, [
|
||||
'id' => $runningTimeEntrySource->getKey(),
|
||||
]);
|
||||
$memberDestination->refresh();
|
||||
$this->assertCount(3, $memberDestination->timeEntries);
|
||||
$this->assertSame([$runningTimeEntryDestination->getKey()], TimeEntry::query()->whereBelongsTo($userDestination, 'user')->whereNull('end')->pluck('id')->all());
|
||||
}
|
||||
|
||||
public function test_merge_into_assigns_resources_of_source_member_to_destination_member_and_deletes_member_with_existing_destination_resources(): void
|
||||
{
|
||||
// Arrange
|
||||
|
||||
@@ -606,6 +606,51 @@ class ReportEndpointTest extends ApiEndpointTestAbstract
|
||||
);
|
||||
}
|
||||
|
||||
public function test_store_endpoint_stores_empty_id_filters_as_null(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission([
|
||||
'reports:create',
|
||||
]);
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->postJson(route('api.v1.reports.store', [$data->organization->getKey()]), [
|
||||
'name' => 'Test Report with empty Filters',
|
||||
'is_public' => false,
|
||||
'properties' => [
|
||||
'start' => Carbon::now()->subDays(30)->toIso8601ZuluString(),
|
||||
'end' => Carbon::now()->toIso8601ZuluString(),
|
||||
'group' => TimeEntryAggregationType::Project->value,
|
||||
'sub_group' => TimeEntryAggregationType::Task->value,
|
||||
'history_group' => TimeEntryAggregationType::Day->value,
|
||||
'member_ids' => [],
|
||||
'project_ids' => [],
|
||||
'client_ids' => [],
|
||||
'tag_ids' => [],
|
||||
'task_ids' => [],
|
||||
],
|
||||
]);
|
||||
|
||||
// Assert
|
||||
$response->assertStatus(201);
|
||||
$response->assertJson(fn (AssertableJson $json) => $json
|
||||
->where('data.properties.member_ids', null)
|
||||
->where('data.properties.project_ids', null)
|
||||
->where('data.properties.client_ids', null)
|
||||
->where('data.properties.tag_ids', null)
|
||||
->where('data.properties.task_ids', null)
|
||||
->etc()
|
||||
);
|
||||
/** @var Report $report */
|
||||
$report = Report::query()->findOrFail($response->json('data.id'));
|
||||
$this->assertNull($report->properties->memberIds);
|
||||
$this->assertNull($report->properties->projectIds);
|
||||
$this->assertNull($report->properties->clientIds);
|
||||
$this->assertNull($report->properties->tagIds);
|
||||
$this->assertNull($report->properties->taskIds);
|
||||
}
|
||||
|
||||
public function test_store_endpoint_creates_report_with_none_filter_values(): void
|
||||
{
|
||||
// Arrange
|
||||
|
||||
@@ -24,7 +24,9 @@ use App\Models\Task;
|
||||
use App\Models\TimeEntry;
|
||||
use App\Models\User;
|
||||
use App\Service\TimeEntryFilter;
|
||||
use Illuminate\Contracts\Cache\LockTimeoutException;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
@@ -2444,6 +2446,77 @@ class TimeEntryEndpointTest extends ApiEndpointTestAbstract
|
||||
$response->assertJsonPath('error', true);
|
||||
}
|
||||
|
||||
public function test_store_endpoint_fails_if_user_already_has_active_time_entry_in_another_organization(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission([
|
||||
'time-entries:create:own',
|
||||
]);
|
||||
$otherOrganization = Organization::factory()->create();
|
||||
$otherMember = Member::factory()->forOrganization($otherOrganization)->forUser($data->user)->create();
|
||||
TimeEntry::factory()->forOrganization($otherOrganization)->forMember($otherMember)->active()->create();
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->postJson(route('api.v1.time-entries.store', [$data->organization->getKey()]), [
|
||||
'billable' => true,
|
||||
'start' => Carbon::now()->toIso8601ZuluString(),
|
||||
'end' => null,
|
||||
'member_id' => $data->member->getKey(),
|
||||
]);
|
||||
|
||||
// Assert
|
||||
$response->assertStatus(400);
|
||||
$response->assertJsonPath('key', 'time_entry_still_running');
|
||||
$this->assertSame(0, TimeEntry::query()->whereBelongsTo($data->organization, 'organization')->count());
|
||||
}
|
||||
|
||||
public function test_store_endpoint_releases_running_time_entry_lock_after_request(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission([
|
||||
'time-entries:create:own',
|
||||
]);
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->postJson(route('api.v1.time-entries.store', [$data->organization->getKey()]), [
|
||||
'billable' => true,
|
||||
'start' => Carbon::now()->toIso8601ZuluString(),
|
||||
'end' => null,
|
||||
'member_id' => $data->member->getKey(),
|
||||
]);
|
||||
|
||||
// Assert
|
||||
$response->assertStatus(201);
|
||||
$this->assertTrue(Cache::lock('time-entries:running:'.$data->user->getKey(), 10)->get());
|
||||
}
|
||||
|
||||
public function test_store_endpoint_waits_for_running_time_entry_lock_and_fails_if_it_is_not_released(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission([
|
||||
'time-entries:create:own',
|
||||
]);
|
||||
Cache::lock('time-entries:running:'.$data->user->getKey(), 10)->get();
|
||||
$this->withoutExceptionHandling();
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
try {
|
||||
$this->postJson(route('api.v1.time-entries.store', [$data->organization->getKey()]), [
|
||||
'billable' => true,
|
||||
'start' => Carbon::now()->toIso8601ZuluString(),
|
||||
'end' => null,
|
||||
'member_id' => $data->member->getKey(),
|
||||
]);
|
||||
$this->fail('Expected LockTimeoutException');
|
||||
} catch (LockTimeoutException) {
|
||||
// Assert
|
||||
$this->assertSame(0, TimeEntry::query()->count());
|
||||
}
|
||||
}
|
||||
|
||||
public function test_store_endpoint_validation_fails_if_task_id_does_not_belong_to_project_id(): void
|
||||
{
|
||||
// Arrange
|
||||
@@ -2780,6 +2853,90 @@ class TimeEntryEndpointTest extends ApiEndpointTestAbstract
|
||||
});
|
||||
}
|
||||
|
||||
public function test_update_endpoint_removes_task_if_project_is_changed_without_setting_a_new_task(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission([
|
||||
'time-entries:update:own',
|
||||
'projects:view:all',
|
||||
]);
|
||||
$project1 = Project::factory()->forOrganization($data->organization)->create();
|
||||
$project2 = Project::factory()->forOrganization($data->organization)->create();
|
||||
$task1 = Task::factory()->forProject($project1)->forOrganization($data->organization)->create();
|
||||
$timeEntry = TimeEntry::factory()->forOrganization($data->organization)->forProject($project1)->forTask($task1)->forMember($data->member)->create();
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->putJson(route('api.v1.time-entries.update', [$data->organization->getKey(), $timeEntry->getKey()]), [
|
||||
'project_id' => $project2->getKey(),
|
||||
]);
|
||||
|
||||
// Assert
|
||||
$response->assertValid();
|
||||
$this->assertResponseCode($response, 200);
|
||||
$response->assertJsonPath('data.project_id', $project2->getKey());
|
||||
$response->assertJsonPath('data.task_id', null);
|
||||
$this->assertDatabaseHas(TimeEntry::class, [
|
||||
'id' => $timeEntry->getKey(),
|
||||
'project_id' => $project2->getKey(),
|
||||
'task_id' => null,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_update_endpoint_removes_task_if_project_is_removed_without_removing_the_task(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission([
|
||||
'time-entries:update:own',
|
||||
'projects:view:all',
|
||||
]);
|
||||
$project = Project::factory()->forOrganization($data->organization)->create();
|
||||
$task = Task::factory()->forProject($project)->forOrganization($data->organization)->create();
|
||||
$timeEntry = TimeEntry::factory()->forOrganization($data->organization)->forProject($project)->forTask($task)->forMember($data->member)->create();
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->putJson(route('api.v1.time-entries.update', [$data->organization->getKey(), $timeEntry->getKey()]), [
|
||||
'project_id' => null,
|
||||
]);
|
||||
|
||||
// Assert
|
||||
$response->assertValid();
|
||||
$this->assertResponseCode($response, 200);
|
||||
$this->assertDatabaseHas(TimeEntry::class, [
|
||||
'id' => $timeEntry->getKey(),
|
||||
'project_id' => null,
|
||||
'task_id' => null,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_update_endpoint_keeps_task_if_project_is_set_to_the_project_of_the_task(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission([
|
||||
'time-entries:update:own',
|
||||
'projects:view:all',
|
||||
]);
|
||||
$project = Project::factory()->forOrganization($data->organization)->create();
|
||||
$task = Task::factory()->forProject($project)->forOrganization($data->organization)->create();
|
||||
$timeEntry = TimeEntry::factory()->forOrganization($data->organization)->forProject($project)->forTask($task)->forMember($data->member)->create();
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->putJson(route('api.v1.time-entries.update', [$data->organization->getKey(), $timeEntry->getKey()]), [
|
||||
'project_id' => $project->getKey(),
|
||||
]);
|
||||
|
||||
// Assert
|
||||
$response->assertValid();
|
||||
$this->assertResponseCode($response, 200);
|
||||
$this->assertDatabaseHas(TimeEntry::class, [
|
||||
'id' => $timeEntry->getKey(),
|
||||
'project_id' => $project->getKey(),
|
||||
'task_id' => $task->getKey(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_update_endpoint_fails_if_employee_tries_to_update_time_entry_to_private_project_without_access(): void
|
||||
{
|
||||
// Arrange
|
||||
@@ -3259,6 +3416,80 @@ class TimeEntryEndpointTest extends ApiEndpointTestAbstract
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_update_endpoint_fails_if_member_of_running_time_entry_is_changed(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission([
|
||||
'time-entries:update:all',
|
||||
]);
|
||||
$otherMember = Member::factory()->forOrganization($data->organization)->role(Role::Employee)->create();
|
||||
$timeEntry = TimeEntry::factory()->forOrganization($data->organization)->forMember($data->member)->active()->create();
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->putJson(route('api.v1.time-entries.update', [$data->organization->getKey(), $timeEntry->getKey()]), [
|
||||
'member_id' => $otherMember->getKey(),
|
||||
]);
|
||||
|
||||
// Assert
|
||||
$response->assertStatus(400);
|
||||
$response->assertJsonPath('key', 'time_entry_member_can_not_be_changed_while_running');
|
||||
$this->assertDatabaseHas(TimeEntry::class, [
|
||||
'id' => $timeEntry->getKey(),
|
||||
'member_id' => $data->member->getKey(),
|
||||
'user_id' => $data->user->getKey(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_update_endpoint_can_update_running_time_entry_with_unchanged_member_id(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission([
|
||||
'time-entries:update:own',
|
||||
]);
|
||||
$timeEntry = TimeEntry::factory()->forOrganization($data->organization)->forMember($data->member)->active()->create();
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->putJson(route('api.v1.time-entries.update', [$data->organization->getKey(), $timeEntry->getKey()]), [
|
||||
'member_id' => $data->member->getKey(),
|
||||
'description' => 'New description',
|
||||
]);
|
||||
|
||||
// Assert
|
||||
$response->assertStatus(200);
|
||||
$this->assertDatabaseHas(TimeEntry::class, [
|
||||
'id' => $timeEntry->getKey(),
|
||||
'description' => 'New description',
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_update_endpoint_can_stop_running_time_entry_and_change_member_in_the_same_request(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission([
|
||||
'time-entries:update:all',
|
||||
]);
|
||||
$otherUser = User::factory()->create();
|
||||
$otherMember = Member::factory()->forOrganization($data->organization)->forUser($otherUser)->role(Role::Employee)->create();
|
||||
$timeEntry = TimeEntry::factory()->forOrganization($data->organization)->forMember($data->member)->active()->create();
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->putJson(route('api.v1.time-entries.update', [$data->organization->getKey(), $timeEntry->getKey()]), [
|
||||
'member_id' => $otherMember->getKey(),
|
||||
'end' => Carbon::now()->toIso8601ZuluString(),
|
||||
]);
|
||||
|
||||
// Assert
|
||||
$response->assertStatus(200);
|
||||
$this->assertDatabaseHas(TimeEntry::class, [
|
||||
'id' => $timeEntry->getKey(),
|
||||
'member_id' => $otherMember->getKey(),
|
||||
'user_id' => $otherUser->getKey(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_update_endpoint_can_update_project_and_automatically_set_client(): void
|
||||
{
|
||||
// Arrange
|
||||
@@ -3902,6 +4133,44 @@ class TimeEntryEndpointTest extends ApiEndpointTestAbstract
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_update_multiple_removes_task_from_time_entries_if_project_is_removed_without_removing_the_task(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission([
|
||||
'time-entries:update:own',
|
||||
'projects:view:all',
|
||||
]);
|
||||
$project = Project::factory()->forOrganization($data->organization)->create();
|
||||
$task = Task::factory()->forProject($project)->forOrganization($data->organization)->create();
|
||||
$timeEntry = TimeEntry::factory()->forOrganization($data->organization)->forProject($project)->forTask($task)->forMember($data->member)->create();
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->patchJson(route('api.v1.time-entries.update-multiple', [$data->organization->getKey()]), [
|
||||
'ids' => [
|
||||
$timeEntry->getKey(),
|
||||
],
|
||||
'changes' => [
|
||||
'project_id' => null,
|
||||
],
|
||||
]);
|
||||
|
||||
// Assert
|
||||
$response->assertValid();
|
||||
$this->assertResponseCode($response, 200);
|
||||
$response->assertExactJson([
|
||||
'success' => [
|
||||
$timeEntry->getKey(),
|
||||
],
|
||||
'error' => [],
|
||||
]);
|
||||
$this->assertDatabaseHas(TimeEntry::class, [
|
||||
'id' => $timeEntry->getKey(),
|
||||
'project_id' => null,
|
||||
'task_id' => null,
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_update_multiple_updates_own_time_entries_and_fails_for_time_entries_of_other_users_and_and_other_organizations_with_own_time_entries_permission(): void
|
||||
{
|
||||
// Arrange
|
||||
@@ -4126,6 +4395,51 @@ class TimeEntryEndpointTest extends ApiEndpointTestAbstract
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_update_multiple_does_not_change_member_of_running_time_entries(): void
|
||||
{
|
||||
// Arrange
|
||||
$data = $this->createUserWithPermission([
|
||||
'time-entries:update:all',
|
||||
]);
|
||||
$otherMember = Member::factory()->forOrganization($data->organization)->role(Role::Employee)->create();
|
||||
$runningTimeEntry = TimeEntry::factory()->forOrganization($data->organization)->forMember($data->member)->active()->create();
|
||||
$runningTimeEntryOfOtherMember = TimeEntry::factory()->forOrganization($data->organization)->forMember($otherMember)->active()->create();
|
||||
$finishedTimeEntry = TimeEntry::factory()->forOrganization($data->organization)->forMember($data->member)->create();
|
||||
Passport::actingAs($data->user);
|
||||
|
||||
// Act
|
||||
$response = $this->patchJson(route('api.v1.time-entries.update-multiple', [$data->organization->getKey()]), [
|
||||
'ids' => [
|
||||
$runningTimeEntry->getKey(),
|
||||
$runningTimeEntryOfOtherMember->getKey(),
|
||||
$finishedTimeEntry->getKey(),
|
||||
],
|
||||
'changes' => [
|
||||
'member_id' => $otherMember->getKey(),
|
||||
],
|
||||
]);
|
||||
|
||||
// Assert
|
||||
$response->assertStatus(200);
|
||||
$response->assertExactJson([
|
||||
'success' => [
|
||||
$runningTimeEntryOfOtherMember->getKey(),
|
||||
$finishedTimeEntry->getKey(),
|
||||
],
|
||||
'error' => [
|
||||
$runningTimeEntry->getKey(),
|
||||
],
|
||||
]);
|
||||
$this->assertDatabaseHas(TimeEntry::class, [
|
||||
'id' => $runningTimeEntry->getKey(),
|
||||
'member_id' => $data->member->getKey(),
|
||||
]);
|
||||
$this->assertDatabaseHas(TimeEntry::class, [
|
||||
'id' => $finishedTimeEntry->getKey(),
|
||||
'member_id' => $otherMember->getKey(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function test_update_multiple_updates_user_id_when_member_id_changes(): void
|
||||
{
|
||||
// Arrange
|
||||
|
||||
@@ -22,6 +22,7 @@ use App\Exceptions\Api\PdfRendererIsNotConfiguredException;
|
||||
use App\Exceptions\Api\PersonalAccessClientIsNotConfiguredException;
|
||||
use App\Exceptions\Api\ThisPlaceholderCanNotBeInvitedUseTheMergeToolInsteadException;
|
||||
use App\Exceptions\Api\TimeEntryCanNotBeRestartedApiException;
|
||||
use App\Exceptions\Api\TimeEntryMemberCanNotBeChangedWhileRunningApiException;
|
||||
use App\Exceptions\Api\TimeEntryStillRunningApiException;
|
||||
use App\Exceptions\Api\UserIsAlreadyMemberOfOrganizationApiException;
|
||||
use App\Exceptions\Api\UserIsAlreadyMemberOfProjectApiException;
|
||||
@@ -53,6 +54,7 @@ class ApiExceptionTest extends TestCase
|
||||
yield OverlappingTimeEntryApiException::class => [new OverlappingTimeEntryApiException];
|
||||
yield ThisPlaceholderCanNotBeInvitedUseTheMergeToolInsteadException::class => [new ThisPlaceholderCanNotBeInvitedUseTheMergeToolInsteadException];
|
||||
yield TimeEntryCanNotBeRestartedApiException::class => [new TimeEntryCanNotBeRestartedApiException];
|
||||
yield TimeEntryMemberCanNotBeChangedWhileRunningApiException::class => [new TimeEntryMemberCanNotBeChangedWhileRunningApiException];
|
||||
yield TimeEntryStillRunningApiException::class => [new TimeEntryStillRunningApiException];
|
||||
yield UserIsAlreadyMemberOfOrganizationApiException::class => [new UserIsAlreadyMemberOfOrganizationApiException];
|
||||
yield UserIsAlreadyMemberOfProjectApiException::class => [new UserIsAlreadyMemberOfProjectApiException];
|
||||
|
||||
@@ -88,4 +88,25 @@ class ReportPropertiesDtoTest extends TestCase
|
||||
$this->assertSame(TimeEntryType::Work, $dtoWork->timeEntryType);
|
||||
$this->assertSame(TimeEntryType::Break, $dtoBreak->timeEntryType);
|
||||
}
|
||||
|
||||
public function test_empty_id_filters_of_a_persisted_report_are_read_as_null(): void
|
||||
{
|
||||
// Arrange
|
||||
$properties = $this->getBaseProperties();
|
||||
$properties['memberIds'] = [];
|
||||
$properties['clientIds'] = [];
|
||||
$properties['projectIds'] = [];
|
||||
$properties['tagIds'] = [];
|
||||
$properties['taskIds'] = [];
|
||||
|
||||
// Act
|
||||
$dto = $this->castFromJson($properties);
|
||||
|
||||
// Assert
|
||||
$this->assertNull($dto->memberIds);
|
||||
$this->assertNull($dto->clientIds);
|
||||
$this->assertNull($dto->projectIds);
|
||||
$this->assertNull($dto->tagIds);
|
||||
$this->assertNull($dto->taskIds);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -164,6 +164,31 @@ class SolidtimeImporterTest extends ImporterTestAbstract
|
||||
$this->fail();
|
||||
}
|
||||
|
||||
public function test_import_skips_running_time_entries(): void
|
||||
{
|
||||
// Arrange
|
||||
$zipPath = $this->createTestZip('solidtime_import_test_3');
|
||||
$timezone = 'Europe/Vienna';
|
||||
$organization = Organization::factory()->create();
|
||||
$importer = new SolidtimeImporter;
|
||||
$importer->init($organization);
|
||||
$data = file_get_contents($zipPath);
|
||||
Queue::fake([
|
||||
RecalculateSpentTimeForProject::class,
|
||||
RecalculateSpentTimeForTask::class,
|
||||
]);
|
||||
|
||||
// Act
|
||||
$importer->importData($data, $timezone);
|
||||
$report = $importer->getReport();
|
||||
|
||||
// Assert
|
||||
$this->assertSame(3, $report->timeEntriesCreated);
|
||||
$this->assertSame(3, TimeEntry::query()->count());
|
||||
$this->assertSame(0, TimeEntry::query()->whereNull('end')->count());
|
||||
$this->assertNull(TimeEntry::query()->where('description', 'Still running')->first());
|
||||
}
|
||||
|
||||
public function test_import_of_test_file_twice_succeeds(): void
|
||||
{
|
||||
// Arrange
|
||||
|
||||
@@ -228,6 +228,30 @@ class MemberServiceTest extends TestCaseWithDatabase
|
||||
$this->assertSame(0, ProjectMember::query()->whereBelongsTo($fromUserMember, 'member')->count());
|
||||
}
|
||||
|
||||
public function test_assign_organization_entities_to_different_member_deletes_running_time_entries_of_the_member(): void
|
||||
{
|
||||
// Arrange
|
||||
$organization = Organization::factory()->create();
|
||||
$fromUser = User::factory()->create();
|
||||
$toUser = User::factory()->create();
|
||||
$fromUserMember = Member::factory()->forOrganization($organization)->forUser($fromUser)->create();
|
||||
$toUserMember = Member::factory()->forOrganization($organization)->forUser($toUser)->create();
|
||||
$runningTimeEntryOfFromMember = TimeEntry::factory()->forOrganization($organization)->forMember($fromUserMember)->active()->create();
|
||||
TimeEntry::factory()->forOrganization($organization)->forMember($fromUserMember)->createMany(2);
|
||||
$runningTimeEntryOfToMember = TimeEntry::factory()->forOrganization($organization)->forMember($toUserMember)->active()->create();
|
||||
|
||||
// Act
|
||||
$this->memberService->assignOrganizationEntitiesToDifferentMember($organization, $fromUserMember, $toUserMember);
|
||||
|
||||
// Assert
|
||||
$this->assertDatabaseMissing(TimeEntry::class, [
|
||||
'id' => $runningTimeEntryOfFromMember->getKey(),
|
||||
]);
|
||||
$this->assertSame(3, TimeEntry::query()->whereBelongsTo($toUserMember, 'member')->count());
|
||||
$this->assertSame([$runningTimeEntryOfToMember->getKey()], TimeEntry::query()->whereBelongsTo($toUser, 'user')->whereNull('end')->pluck('id')->all());
|
||||
$this->assertSame(0, TimeEntry::query()->whereBelongsTo($fromUserMember, 'member')->count());
|
||||
}
|
||||
|
||||
public function test_assign_organization_entities_to_different_member_moves_all_goals_of_the_member(): void
|
||||
{
|
||||
// Arrange
|
||||
|
||||
@@ -416,6 +416,81 @@ class TimeEntryFilterTest extends TestCaseWithDatabase
|
||||
$this->assertCount(3, $builderContains->get());
|
||||
}
|
||||
|
||||
public function test_add_member_ids_filter_with_empty_array_applies_no_filter(): void
|
||||
{
|
||||
// Arrange
|
||||
TimeEntry::factory()->createMany(2);
|
||||
|
||||
$builder = TimeEntry::query();
|
||||
$filter = new TimeEntryFilter($builder);
|
||||
|
||||
// Act
|
||||
$filter->addMemberIdsFilter([]);
|
||||
|
||||
// Assert
|
||||
$this->assertCount(2, $builder->get());
|
||||
}
|
||||
|
||||
public function test_add_project_ids_filter_with_empty_array_applies_no_filter(): void
|
||||
{
|
||||
// Arrange
|
||||
$project = Project::factory()->create();
|
||||
TimeEntry::factory()->create([
|
||||
'project_id' => $project->getKey(),
|
||||
'organization_id' => $project->organization_id,
|
||||
]);
|
||||
TimeEntry::factory()->create(['project_id' => null]);
|
||||
|
||||
$builder = TimeEntry::query();
|
||||
$filter = new TimeEntryFilter($builder);
|
||||
|
||||
// Act
|
||||
$filter->addProjectIdsFilter([]);
|
||||
|
||||
// Assert
|
||||
$this->assertCount(2, $builder->get());
|
||||
}
|
||||
|
||||
public function test_add_task_ids_filter_with_empty_array_applies_no_filter(): void
|
||||
{
|
||||
// Arrange
|
||||
$task = Task::factory()->create();
|
||||
TimeEntry::factory()->create([
|
||||
'task_id' => $task->getKey(),
|
||||
'organization_id' => $task->organization_id,
|
||||
]);
|
||||
TimeEntry::factory()->create(['task_id' => null]);
|
||||
|
||||
$builder = TimeEntry::query();
|
||||
$filter = new TimeEntryFilter($builder);
|
||||
|
||||
// Act
|
||||
$filter->addTaskIdsFilter([]);
|
||||
|
||||
// Assert
|
||||
$this->assertCount(2, $builder->get());
|
||||
}
|
||||
|
||||
public function test_add_client_ids_filter_with_empty_array_applies_no_filter(): void
|
||||
{
|
||||
// Arrange
|
||||
$client = Client::factory()->create();
|
||||
TimeEntry::factory()->create([
|
||||
'client_id' => $client->getKey(),
|
||||
'organization_id' => $client->organization_id,
|
||||
]);
|
||||
TimeEntry::factory()->create(['client_id' => null]);
|
||||
|
||||
$builder = TimeEntry::query();
|
||||
$filter = new TimeEntryFilter($builder);
|
||||
|
||||
// Act
|
||||
$filter->addClientIdsFilter([]);
|
||||
|
||||
// Assert
|
||||
$this->assertCount(2, $builder->get());
|
||||
}
|
||||
|
||||
public function test_add_tag_ids_filter_with_null_match_type_defaults_to_contains(): void
|
||||
{
|
||||
// Arrange
|
||||
|
||||
Reference in New Issue
Block a user