Allow only one running time entry per user across organizations

The running time entry check in the store endpoint was scoped to the
member, so a user could start a time entry in each of their
organizations. The active time entry endpoint and the database
consistency check expect only one running time entry per user.
This commit is contained in:
Constantin Graf
2026-10-09 12:58:15 +02:00
parent 4a4acb2214
commit c791057f25
2 changed files with 27 additions and 1 deletions

View File

@@ -630,7 +630,8 @@ class TimeEntryController extends Controller
*/
private function storeTimeEntry(Organization $organization, Member $member, TimeEntryStoreRequest $request): JsonResource
{
if ($request->input('end') === null && TimeEntry::query()->whereBelongsTo($member, 'member')->where('end', null)->exists()) {
// 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;
}