mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-10-08 05:43:18 +01:00
Compare commits
70 Commits
feature/vo
...
v0.20.1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d54296e66a | ||
|
|
95ddbf9ead | ||
|
|
70646a0dd4 | ||
|
|
5b12c09747 | ||
|
|
24023353f2 | ||
|
|
720d20c10e | ||
|
|
82ea9af8b5 | ||
|
|
169d522da0 | ||
|
|
45c7377802 | ||
|
|
8e57275cef | ||
|
|
efc6b55628 | ||
|
|
c12789376d | ||
|
|
4795812b60 | ||
|
|
0e00979ab8 | ||
|
|
f1426fcb5e | ||
|
|
23f512d4a4 | ||
|
|
637475e669 | ||
|
|
3ec2abb309 | ||
|
|
3e36b1cc01 | ||
|
|
7831bc697e | ||
|
|
602a8daa1f | ||
|
|
38b448a729 | ||
|
|
e6f071f87f | ||
|
|
693a1fa7e0 | ||
|
|
77f14b696e | ||
|
|
593372bae5 | ||
|
|
db9ca51fc4 | ||
|
|
28aba7b27a | ||
|
|
453d5ed066 | ||
|
|
ed3ba0135b | ||
|
|
fb7d945c50 | ||
|
|
9958e1c09c | ||
|
|
f00d48f1c3 | ||
|
|
7edbfd5d76 | ||
|
|
1edb940557 | ||
|
|
c9330e6cb8 | ||
|
|
0e9f652d84 | ||
|
|
d29f5706ce | ||
|
|
b2849ec04a | ||
|
|
bd69cf478c | ||
|
|
5197135d00 | ||
|
|
b09b8649b8 | ||
|
|
99fafdb8d6 | ||
|
|
b02e49c7e0 | ||
|
|
8609635d74 | ||
|
|
5a07f798b3 | ||
|
|
3af69830ee | ||
|
|
a050153bcd | ||
|
|
9d9731c7ce | ||
|
|
dfe3206614 | ||
|
|
97fd882878 | ||
|
|
111e12df12 | ||
|
|
de13c07855 | ||
|
|
29a2e994cd | ||
|
|
f6d886b218 | ||
|
|
80d98b30a1 | ||
|
|
32f2f1431b | ||
|
|
8f6d584ee9 | ||
|
|
1905cbf40c | ||
|
|
c8f668238e | ||
|
|
bf11bacdee | ||
|
|
f3c6a0b8ae | ||
|
|
619c602571 | ||
|
|
600daf44d9 | ||
|
|
a1d6c92806 | ||
|
|
ce1bd6a435 | ||
|
|
79d85227c2 | ||
|
|
885abf3333 | ||
|
|
c0c8fee6be | ||
|
|
cbcd1e51f6 |
@@ -5,7 +5,8 @@ APP_KEY=base64:UNQNf1SXeASNkWux01Rj8EnHYx8FO0kAxWNDwktclkk=
|
|||||||
APP_DEBUG=true
|
APP_DEBUG=true
|
||||||
APP_URL=https://solidtime.test
|
APP_URL=https://solidtime.test
|
||||||
APP_FORCE_HTTPS=false
|
APP_FORCE_HTTPS=false
|
||||||
APP_ENABLE_REGISTRATION=true
|
# Supported values: on, off, invite-only (true/false are supported for backwards compatibility)
|
||||||
|
APP_ENABLE_REGISTRATION=on
|
||||||
SUPER_ADMINS=admin@example.com
|
SUPER_ADMINS=admin@example.com
|
||||||
PAGINATION_PER_PAGE_DEFAULT=500
|
PAGINATION_PER_PAGE_DEFAULT=500
|
||||||
|
|
||||||
|
|||||||
12
.github/VOUCHED.td
vendored
12
.github/VOUCHED.td
vendored
@@ -14,10 +14,14 @@
|
|||||||
# Seeded 2026-07-25 from the authors of every merged pull request.
|
# Seeded 2026-07-25 from the authors of every merged pull request.
|
||||||
|
|
||||||
agross
|
agross
|
||||||
|
akolenda
|
||||||
|
bufferhead-code
|
||||||
candideu
|
candideu
|
||||||
KasparRosin
|
kasparrosin
|
||||||
korridor
|
korridor
|
||||||
Onatcer
|
nikbucher tasks table sorting
|
||||||
ShrootBuck
|
onatcer
|
||||||
smileBeda
|
shrootbuck
|
||||||
|
smilebeda
|
||||||
|
thespyder
|
||||||
utlark
|
utlark
|
||||||
|
|||||||
4
.github/workflows/build-onpremise.yml
vendored
4
.github/workflows/build-onpremise.yml
vendored
@@ -141,7 +141,7 @@ jobs:
|
|||||||
${{ env.DOCKER_REPO }}
|
${{ env.DOCKER_REPO }}
|
||||||
|
|
||||||
- name: "Login to solidtime OnPremise Registry"
|
- name: "Login to solidtime OnPremise Registry"
|
||||||
uses: docker/login-action@v4
|
uses: docker/login-action@v4.5.2
|
||||||
with:
|
with:
|
||||||
registry: registry.on-premise.solidtime.io
|
registry: registry.on-premise.solidtime.io
|
||||||
username: ${{ secrets.ONPREMISE_USERNAME }}
|
username: ${{ secrets.ONPREMISE_USERNAME }}
|
||||||
@@ -195,7 +195,7 @@ jobs:
|
|||||||
merge-multiple: true
|
merge-multiple: true
|
||||||
|
|
||||||
- name: "Login to solidtime OnPremise Registry"
|
- name: "Login to solidtime OnPremise Registry"
|
||||||
uses: docker/login-action@v4
|
uses: docker/login-action@v4.5.2
|
||||||
with:
|
with:
|
||||||
registry: registry.on-premise.solidtime.io
|
registry: registry.on-premise.solidtime.io
|
||||||
username: ${{ secrets.ONPREMISE_USERNAME }}
|
username: ${{ secrets.ONPREMISE_USERNAME }}
|
||||||
|
|||||||
2
.github/workflows/build-private.yml
vendored
2
.github/workflows/build-private.yml
vendored
@@ -177,7 +177,7 @@ jobs:
|
|||||||
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
|
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
|
||||||
|
|
||||||
- name: "Login to GitHub Container Registry"
|
- name: "Login to GitHub Container Registry"
|
||||||
uses: docker/login-action@v4
|
uses: docker/login-action@v4.5.2
|
||||||
with:
|
with:
|
||||||
registry: rg.fr-par.scw.cloud/solidtime
|
registry: rg.fr-par.scw.cloud/solidtime
|
||||||
username: nologin
|
username: nologin
|
||||||
|
|||||||
8
.github/workflows/build-public.yml
vendored
8
.github/workflows/build-public.yml
vendored
@@ -117,13 +117,13 @@ jobs:
|
|||||||
${{ env.GHCR_REPO }}
|
${{ env.GHCR_REPO }}
|
||||||
|
|
||||||
- name: "Login to Docker Hub Container Registry"
|
- name: "Login to Docker Hub Container Registry"
|
||||||
uses: docker/login-action@v4
|
uses: docker/login-action@v4.5.2
|
||||||
with:
|
with:
|
||||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||||
|
|
||||||
- name: "Login to GitHub Container Registry"
|
- name: "Login to GitHub Container Registry"
|
||||||
uses: docker/login-action@v4
|
uses: docker/login-action@v4.5.2
|
||||||
with:
|
with:
|
||||||
registry: ghcr.io
|
registry: ghcr.io
|
||||||
username: ${{ github.actor }}
|
username: ${{ github.actor }}
|
||||||
@@ -177,13 +177,13 @@ jobs:
|
|||||||
merge-multiple: true
|
merge-multiple: true
|
||||||
|
|
||||||
- name: "Login to Docker Hub"
|
- name: "Login to Docker Hub"
|
||||||
uses: docker/login-action@v4
|
uses: docker/login-action@v4.5.2
|
||||||
with:
|
with:
|
||||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||||
|
|
||||||
- name: "Login to GHCR"
|
- name: "Login to GHCR"
|
||||||
uses: docker/login-action@v4
|
uses: docker/login-action@v4.5.2
|
||||||
with:
|
with:
|
||||||
registry: ghcr.io
|
registry: ghcr.io
|
||||||
username: ${{ github.actor }}
|
username: ${{ github.actor }}
|
||||||
|
|||||||
@@ -4,9 +4,11 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace App\Actions\Fortify;
|
namespace App\Actions\Fortify;
|
||||||
|
|
||||||
|
use App\Enums\RegistrationMode;
|
||||||
use App\Enums\Weekday;
|
use App\Enums\Weekday;
|
||||||
use App\Events\NewsletterRegistered;
|
use App\Events\NewsletterRegistered;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
|
use App\Service\InvitationService;
|
||||||
use App\Service\IpLookup\IpLookupServiceContract;
|
use App\Service\IpLookup\IpLookupServiceContract;
|
||||||
use App\Service\TimezoneService;
|
use App\Service\TimezoneService;
|
||||||
use App\Service\UserService;
|
use App\Service\UserService;
|
||||||
@@ -31,13 +33,14 @@ class CreateNewUser implements CreatesNewUsers
|
|||||||
*/
|
*/
|
||||||
public function create(array $input): User
|
public function create(array $input): User
|
||||||
{
|
{
|
||||||
if (! config('app.enable_registration')) {
|
$registrationMode = RegistrationMode::fromConfig(config('app.enable_registration'));
|
||||||
|
if ($registrationMode === RegistrationMode::Off) {
|
||||||
throw ValidationException::withMessages([
|
throw ValidationException::withMessages([
|
||||||
'email' => [__('Registration is disabled.')],
|
'email' => [__('Registration is disabled.')],
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
Validator::make($input, [
|
$validated = Validator::make($input, [
|
||||||
'name' => [
|
'name' => [
|
||||||
'required',
|
'required',
|
||||||
'string',
|
'string',
|
||||||
@@ -60,6 +63,20 @@ class CreateNewUser implements CreatesNewUsers
|
|||||||
],
|
],
|
||||||
])->validate();
|
])->validate();
|
||||||
|
|
||||||
|
if ($registrationMode === RegistrationMode::InviteOnly) {
|
||||||
|
$invitationService = app(InvitationService::class);
|
||||||
|
$email = (string) $validated['email'];
|
||||||
|
if (! $invitationService->hasAcceptedInvitationForEmail($email)) {
|
||||||
|
$message = $invitationService->hasPendingInvitationForEmail($email)
|
||||||
|
? __('Please accept the organization invitation sent to your email address before registering.')
|
||||||
|
: __('Registration is only available to invited users.');
|
||||||
|
|
||||||
|
throw ValidationException::withMessages([
|
||||||
|
'email' => [$message],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$timezone = null;
|
$timezone = null;
|
||||||
if (array_key_exists('timezone', $input) && is_string($input['timezone'])) {
|
if (array_key_exists('timezone', $input) && is_string($input['timezone'])) {
|
||||||
if (app(TimezoneService::class)->isValid($input['timezone'])) {
|
if (app(TimezoneService::class)->isValid($input['timezone'])) {
|
||||||
|
|||||||
37
app/Auth/ActiveUserProvider.php
Normal file
37
app/Auth/ActiveUserProvider.php
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Auth;
|
||||||
|
|
||||||
|
use Illuminate\Auth\EloquentUserProvider;
|
||||||
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* User provider that only resolves non-placeholder users.
|
||||||
|
*
|
||||||
|
* Placeholder users are created by imports and when members are removed from an
|
||||||
|
* organization. They can share an email address with a real user, so resolving a user by
|
||||||
|
* email can return a placeholder instead of the real account. The login flow filters them
|
||||||
|
* out explicitly, but the password broker and the guard credential checks (for example the
|
||||||
|
* password confirmation) resolve users through the configured user provider.
|
||||||
|
*
|
||||||
|
* Registered as the "eloquent" provider driver in the AuthServiceProvider, so it replaces the
|
||||||
|
* built-in one for every provider in config/auth.php.
|
||||||
|
*/
|
||||||
|
class ActiveUserProvider extends EloquentUserProvider
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @param Model|null $model
|
||||||
|
* @return Builder<Model>
|
||||||
|
*/
|
||||||
|
#[\Override]
|
||||||
|
protected function newModelQuery($model = null): Builder
|
||||||
|
{
|
||||||
|
$query = parent::newModelQuery($model);
|
||||||
|
$query->getQuery()->where('is_placeholder', '=', false);
|
||||||
|
|
||||||
|
return $query;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -51,7 +51,8 @@ class TimeEntrySendStillRunningMailsCommand extends Command
|
|||||||
])
|
])
|
||||||
->whereHas('user', function (Builder $query): void {
|
->whereHas('user', function (Builder $query): void {
|
||||||
/** @var Builder<User> $query */
|
/** @var Builder<User> $query */
|
||||||
$query->where('is_placeholder', '=', false);
|
$query->where('is_placeholder', '=', false)
|
||||||
|
->where('send_time_entry_still_running_email', '=', true);
|
||||||
})
|
})
|
||||||
->orderBy('created_at', 'asc')
|
->orderBy('created_at', 'asc')
|
||||||
->chunk(500, function (Collection $timeEntries) use ($dryRun, &$sentMails): void {
|
->chunk(500, function (Collection $timeEntries) use ($dryRun, &$sentMails): void {
|
||||||
|
|||||||
29
app/Enums/RegistrationMode.php
Normal file
29
app/Enums/RegistrationMode.php
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Enums;
|
||||||
|
|
||||||
|
enum RegistrationMode: string
|
||||||
|
{
|
||||||
|
case On = 'on';
|
||||||
|
case InviteOnly = 'invite-only';
|
||||||
|
case Off = 'off';
|
||||||
|
|
||||||
|
public static function fromConfig(mixed $value): self
|
||||||
|
{
|
||||||
|
if ($value === true) {
|
||||||
|
return self::On;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($value === false || $value === null) {
|
||||||
|
return self::Off;
|
||||||
|
}
|
||||||
|
|
||||||
|
return match (strtolower(trim((string) $value))) {
|
||||||
|
'1', 'on', 'true' => self::On,
|
||||||
|
'invite-only' => self::InviteOnly,
|
||||||
|
default => self::Off,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -21,6 +21,7 @@ enum TimeEntryAggregationType: string
|
|||||||
case Billable = 'billable';
|
case Billable = 'billable';
|
||||||
case Description = 'description';
|
case Description = 'description';
|
||||||
case Tag = 'tag';
|
case Tag = 'tag';
|
||||||
|
case Type = 'type';
|
||||||
|
|
||||||
public static function fromInterval(TimeEntryAggregationTypeInterval $timeEntryAggregationTypeInterval): TimeEntryAggregationType
|
public static function fromInterval(TimeEntryAggregationTypeInterval $timeEntryAggregationTypeInterval): TimeEntryAggregationType
|
||||||
{
|
{
|
||||||
|
|||||||
15
app/Enums/TimeEntryType.php
Normal file
15
app/Enums/TimeEntryType.php
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Enums;
|
||||||
|
|
||||||
|
use Datomatic\LaravelEnumHelper\LaravelEnumHelper;
|
||||||
|
|
||||||
|
enum TimeEntryType: string
|
||||||
|
{
|
||||||
|
use LaravelEnumHelper;
|
||||||
|
|
||||||
|
case Work = 'work';
|
||||||
|
case Break = 'break';
|
||||||
|
}
|
||||||
@@ -60,7 +60,6 @@ abstract class ApiException extends Exception
|
|||||||
*/
|
*/
|
||||||
public function report(): bool
|
public function report(): bool
|
||||||
{
|
{
|
||||||
// TODO: temporary activated
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,4 +7,9 @@ namespace App\Exceptions\Api;
|
|||||||
class CanNotDeleteUserWhoIsOwnerOfOrganizationWithMultipleMembers extends ApiException
|
class CanNotDeleteUserWhoIsOwnerOfOrganizationWithMultipleMembers extends ApiException
|
||||||
{
|
{
|
||||||
public const string KEY = 'can_not_delete_user_who_is_owner_of_organization_with_multiple_members';
|
public const string KEY = 'can_not_delete_user_who_is_owner_of_organization_with_multiple_members';
|
||||||
|
|
||||||
|
public function report(): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,4 +7,9 @@ namespace App\Exceptions\Api;
|
|||||||
class CanNotRemoveOwnerFromOrganization extends ApiException
|
class CanNotRemoveOwnerFromOrganization extends ApiException
|
||||||
{
|
{
|
||||||
public const string KEY = 'can_not_remove_owner_from_organization';
|
public const string KEY = 'can_not_remove_owner_from_organization';
|
||||||
|
|
||||||
|
public function report(): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,4 +7,9 @@ namespace App\Exceptions\Api;
|
|||||||
class ChangingRoleOfPlaceholderIsNotAllowed extends ApiException
|
class ChangingRoleOfPlaceholderIsNotAllowed extends ApiException
|
||||||
{
|
{
|
||||||
public const string KEY = 'changing_role_of_placeholder_is_not_allowed';
|
public const string KEY = 'changing_role_of_placeholder_is_not_allowed';
|
||||||
|
|
||||||
|
public function report(): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,4 +7,9 @@ namespace App\Exceptions\Api;
|
|||||||
class ChangingRoleToPlaceholderIsNotAllowed extends ApiException
|
class ChangingRoleToPlaceholderIsNotAllowed extends ApiException
|
||||||
{
|
{
|
||||||
public const string KEY = 'changing_role_to_placeholder_is_not_allowed';
|
public const string KEY = 'changing_role_to_placeholder_is_not_allowed';
|
||||||
|
|
||||||
|
public function report(): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,16 @@ class EntityStillInUseApiException extends ApiException
|
|||||||
|
|
||||||
public const string KEY = 'entity_still_in_use';
|
public const string KEY = 'entity_still_in_use';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Report the exception.
|
||||||
|
*
|
||||||
|
* @return bool true means the exception handler will not report it again
|
||||||
|
*/
|
||||||
|
public function report(): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the translated message for the exception.
|
* Get the translated message for the exception.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -7,4 +7,9 @@ namespace App\Exceptions\Api;
|
|||||||
class FeatureIsNotAvailableInFreePlanApiException extends ApiException
|
class FeatureIsNotAvailableInFreePlanApiException extends ApiException
|
||||||
{
|
{
|
||||||
public const string KEY = 'feature_is_not_available_in_free_plan';
|
public const string KEY = 'feature_is_not_available_in_free_plan';
|
||||||
|
|
||||||
|
public function report(): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,4 +7,9 @@ namespace App\Exceptions\Api;
|
|||||||
class InactiveUserCanNotBeUsedApiException extends ApiException
|
class InactiveUserCanNotBeUsedApiException extends ApiException
|
||||||
{
|
{
|
||||||
public const string KEY = 'inactive_user_can_not_be_used';
|
public const string KEY = 'inactive_user_can_not_be_used';
|
||||||
|
|
||||||
|
public function report(): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,4 +7,9 @@ namespace App\Exceptions\Api;
|
|||||||
class InvitationForTheEmailAlreadyExistsApiException extends ApiException
|
class InvitationForTheEmailAlreadyExistsApiException extends ApiException
|
||||||
{
|
{
|
||||||
public const string KEY = 'invitation_for_the_email_already_exists';
|
public const string KEY = 'invitation_for_the_email_already_exists';
|
||||||
|
|
||||||
|
public function report(): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,4 +7,9 @@ namespace App\Exceptions\Api;
|
|||||||
class OnlyOwnerCanChangeOwnership extends ApiException
|
class OnlyOwnerCanChangeOwnership extends ApiException
|
||||||
{
|
{
|
||||||
public const string KEY = 'only_owner_can_change_ownership';
|
public const string KEY = 'only_owner_can_change_ownership';
|
||||||
|
|
||||||
|
public function report(): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,4 +7,9 @@ namespace App\Exceptions\Api;
|
|||||||
class OnlyPlaceholdersCanBeMergedIntoAnotherMember extends ApiException
|
class OnlyPlaceholdersCanBeMergedIntoAnotherMember extends ApiException
|
||||||
{
|
{
|
||||||
public const string KEY = 'only_placeholders_can_be_merged_into_another_member';
|
public const string KEY = 'only_placeholders_can_be_merged_into_another_member';
|
||||||
|
|
||||||
|
public function report(): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,4 +7,9 @@ namespace App\Exceptions\Api;
|
|||||||
class OrganizationHasNoSubscriptionButMultipleMembersException extends ApiException
|
class OrganizationHasNoSubscriptionButMultipleMembersException extends ApiException
|
||||||
{
|
{
|
||||||
public const string KEY = 'organization_has_no_subscription_but_multiple_members';
|
public const string KEY = 'organization_has_no_subscription_but_multiple_members';
|
||||||
|
|
||||||
|
public function report(): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,4 +7,9 @@ namespace App\Exceptions\Api;
|
|||||||
class OrganizationNeedsAtLeastOneOwner extends ApiException
|
class OrganizationNeedsAtLeastOneOwner extends ApiException
|
||||||
{
|
{
|
||||||
public const string KEY = 'organization_needs_at_least_one_owner';
|
public const string KEY = 'organization_needs_at_least_one_owner';
|
||||||
|
|
||||||
|
public function report(): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,4 +7,9 @@ namespace App\Exceptions\Api;
|
|||||||
class OverlappingTimeEntryApiException extends ApiException
|
class OverlappingTimeEntryApiException extends ApiException
|
||||||
{
|
{
|
||||||
public const string KEY = 'overlapping_time_entry';
|
public const string KEY = 'overlapping_time_entry';
|
||||||
|
|
||||||
|
public function report(): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,4 +7,9 @@ namespace App\Exceptions\Api;
|
|||||||
class ThisPlaceholderCanNotBeInvitedUseTheMergeToolInsteadException extends ApiException
|
class ThisPlaceholderCanNotBeInvitedUseTheMergeToolInsteadException extends ApiException
|
||||||
{
|
{
|
||||||
public const string KEY = 'this_placeholder_can_not_be_invited_use_the_merge_tool_instead_api_exception';
|
public const string KEY = 'this_placeholder_can_not_be_invited_use_the_merge_tool_instead_api_exception';
|
||||||
|
|
||||||
|
public function report(): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,4 +7,9 @@ namespace App\Exceptions\Api;
|
|||||||
class TimeEntryCanNotBeRestartedApiException extends ApiException
|
class TimeEntryCanNotBeRestartedApiException extends ApiException
|
||||||
{
|
{
|
||||||
public const string KEY = 'time_entry_can_not_be_restarted';
|
public const string KEY = 'time_entry_can_not_be_restarted';
|
||||||
|
|
||||||
|
public function report(): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,4 +7,14 @@ namespace App\Exceptions\Api;
|
|||||||
class TimeEntryStillRunningApiException extends ApiException
|
class TimeEntryStillRunningApiException extends ApiException
|
||||||
{
|
{
|
||||||
public const string KEY = 'time_entry_still_running';
|
public const string KEY = 'time_entry_still_running';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Report the exception.
|
||||||
|
*
|
||||||
|
* @return bool true means the exception handler will not report it again
|
||||||
|
*/
|
||||||
|
public function report(): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,4 +7,9 @@ namespace App\Exceptions\Api;
|
|||||||
class UserIsAlreadyMemberOfOrganizationApiException extends ApiException
|
class UserIsAlreadyMemberOfOrganizationApiException extends ApiException
|
||||||
{
|
{
|
||||||
public const string KEY = 'user_is_already_member_of_organization';
|
public const string KEY = 'user_is_already_member_of_organization';
|
||||||
|
|
||||||
|
public function report(): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,4 +7,9 @@ namespace App\Exceptions\Api;
|
|||||||
class UserIsAlreadyMemberOfProjectApiException extends ApiException
|
class UserIsAlreadyMemberOfProjectApiException extends ApiException
|
||||||
{
|
{
|
||||||
public const string KEY = 'user_is_already_member_of_project';
|
public const string KEY = 'user_is_already_member_of_project';
|
||||||
|
|
||||||
|
public function report(): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,4 +7,9 @@ namespace App\Exceptions\Api;
|
|||||||
class UserNotPlaceholderApiException extends ApiException
|
class UserNotPlaceholderApiException extends ApiException
|
||||||
{
|
{
|
||||||
public const string KEY = 'user_not_placeholder';
|
public const string KEY = 'user_not_placeholder';
|
||||||
|
|
||||||
|
public function report(): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,4 +7,9 @@ namespace App\Exceptions\Api;
|
|||||||
class UserResendEmailVerificationNoPendingEmailApiException extends ApiException
|
class UserResendEmailVerificationNoPendingEmailApiException extends ApiException
|
||||||
{
|
{
|
||||||
public const string KEY = 'user_resend_email_verification_no_pending_email';
|
public const string KEY = 'user_resend_email_verification_no_pending_email';
|
||||||
|
|
||||||
|
public function report(): bool
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,11 @@ namespace App\Exceptions;
|
|||||||
|
|
||||||
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
||||||
use Illuminate\Http\RedirectResponse;
|
use Illuminate\Http\RedirectResponse;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use League\OAuth2\Server\Exception\OAuthServerException;
|
||||||
|
use Symfony\Component\HttpFoundation\Exception\SuspiciousOperationException;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
|
||||||
use Throwable;
|
use Throwable;
|
||||||
|
|
||||||
class Handler extends ExceptionHandler
|
class Handler extends ExceptionHandler
|
||||||
@@ -30,6 +34,33 @@ class Handler extends ExceptionHandler
|
|||||||
$this->reportable(function (Throwable $e): void {
|
$this->reportable(function (Throwable $e): void {
|
||||||
//
|
//
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$this->dontReportWhen(fn (Throwable $e): bool => $e instanceof OAuthServerException
|
||||||
|
&& $e->getErrorType() === 'access_denied'
|
||||||
|
&& $e->getHttpStatusCode() === 401);
|
||||||
|
|
||||||
|
// A request on an untrusted host (see App\Http\Middleware\TrustHosts)
|
||||||
|
// otherwise renders as a bare "Bad request." 400. Show a message that
|
||||||
|
// says how to fix it instead. The framework has already converted the
|
||||||
|
// SuspiciousOperationException into a BadRequestHttpException by the time
|
||||||
|
// renderables run, so we match that and inspect the original.
|
||||||
|
$this->renderable(function (BadRequestHttpException $e, Request $request): ?Response {
|
||||||
|
$previous = $e->getPrevious();
|
||||||
|
|
||||||
|
if (! $previous instanceof SuspiciousOperationException
|
||||||
|
|| ! str_starts_with($previous->getMessage(), 'Untrusted Host')) {
|
||||||
|
return null; // any other bad request keeps the default response
|
||||||
|
}
|
||||||
|
|
||||||
|
$message = 'This hostname is not configured for this instance. '
|
||||||
|
.'Set APP_URL, or add the host to TRUSTED_HOSTS.';
|
||||||
|
|
||||||
|
if ($request->expectsJson()) {
|
||||||
|
return response()->json(['message' => $message], 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
return response()->view('errors.untrusted-host', ['message' => $message], 400);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public function render($request, Throwable $e): Response|RedirectResponse
|
public function render($request, Throwable $e): Response|RedirectResponse
|
||||||
|
|||||||
@@ -28,7 +28,9 @@ class ExportController extends Controller
|
|||||||
|
|
||||||
$filepath = $exportService->export($organization);
|
$filepath = $exportService->export($organization);
|
||||||
$downloadUrl = Storage::disk(config('filesystems.private'))
|
$downloadUrl = Storage::disk(config('filesystems.private'))
|
||||||
->temporaryUrl($filepath, Carbon::now()->addMinutes(10));
|
->temporaryUrl($filepath, Carbon::now()->addMinutes(10), [
|
||||||
|
'ResponseContentDisposition' => 'attachment; filename="'.basename($filepath).'"',
|
||||||
|
]);
|
||||||
|
|
||||||
return new JsonResponse([
|
return new JsonResponse([
|
||||||
'success' => true,
|
'success' => true,
|
||||||
|
|||||||
@@ -78,6 +78,9 @@ class OrganizationController extends Controller
|
|||||||
if ($request->getPreventOverlappingTimeEntries() !== null) {
|
if ($request->getPreventOverlappingTimeEntries() !== null) {
|
||||||
$organization->prevent_overlapping_time_entries = $request->getPreventOverlappingTimeEntries();
|
$organization->prevent_overlapping_time_entries = $request->getPreventOverlappingTimeEntries();
|
||||||
}
|
}
|
||||||
|
if ($request->getBreaksEnabled() !== null) {
|
||||||
|
$organization->breaks_enabled = $request->getBreaksEnabled();
|
||||||
|
}
|
||||||
$hasBillableRate = $request->has('billable_rate');
|
$hasBillableRate = $request->has('billable_rate');
|
||||||
if ($hasBillableRate) {
|
if ($hasBillableRate) {
|
||||||
$oldBillableRate = $organization->billable_rate;
|
$oldBillableRate = $organization->billable_rate;
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ class ReportController extends Controller
|
|||||||
$filter->addEnd($properties->end);
|
$filter->addEnd($properties->end);
|
||||||
$filter->addActive($properties->active);
|
$filter->addActive($properties->active);
|
||||||
$filter->addBillable($properties->billable);
|
$filter->addBillable($properties->billable);
|
||||||
|
$filter->addType($properties->timeEntryType);
|
||||||
$filter->addMemberIdsFilter($properties->memberIds?->toArray());
|
$filter->addMemberIdsFilter($properties->memberIds?->toArray());
|
||||||
$filter->addProjectIdsFilter($properties->projectIds?->toArray());
|
$filter->addProjectIdsFilter($properties->projectIds?->toArray());
|
||||||
$filter->addTagIdsFilter($properties->tagIds?->toArray(), $properties->tagMatchType);
|
$filter->addTagIdsFilter($properties->tagIds?->toArray(), $properties->tagMatchType);
|
||||||
|
|||||||
@@ -112,6 +112,7 @@ class ReportController extends Controller
|
|||||||
$properties->timezone = $timezone;
|
$properties->timezone = $timezone;
|
||||||
$properties->roundingType = $request->getPropertyRoundingType();
|
$properties->roundingType = $request->getPropertyRoundingType();
|
||||||
$properties->roundingMinutes = $request->getPropertyRoundingMinutes();
|
$properties->roundingMinutes = $request->getPropertyRoundingMinutes();
|
||||||
|
$properties->timeEntryType = $request->getPropertyTimeEntryType();
|
||||||
$report->properties = $properties;
|
$report->properties = $properties;
|
||||||
if ($isPublic) {
|
if ($isPublic) {
|
||||||
$report->share_secret = $reportService->generateSecret();
|
$report->share_secret = $reportService->generateSecret();
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ namespace App\Http\Controllers\Api\V1;
|
|||||||
|
|
||||||
use App\Enums\ExportFormat;
|
use App\Enums\ExportFormat;
|
||||||
use App\Enums\Role;
|
use App\Enums\Role;
|
||||||
|
use App\Enums\TimeEntryType;
|
||||||
use App\Exceptions\Api\FeatureIsNotAvailableInFreePlanApiException;
|
use App\Exceptions\Api\FeatureIsNotAvailableInFreePlanApiException;
|
||||||
use App\Exceptions\Api\OverlappingTimeEntryApiException;
|
use App\Exceptions\Api\OverlappingTimeEntryApiException;
|
||||||
use App\Exceptions\Api\PdfRendererIsNotConfiguredException;
|
use App\Exceptions\Api\PdfRendererIsNotConfiguredException;
|
||||||
@@ -209,6 +210,7 @@ class TimeEntryController extends Controller
|
|||||||
$filter->addTaskIdsFilter($request->input('task_ids'));
|
$filter->addTaskIdsFilter($request->input('task_ids'));
|
||||||
$filter->addClientIdsFilter($request->input('client_ids'));
|
$filter->addClientIdsFilter($request->input('client_ids'));
|
||||||
$filter->addBillableFilter($request->input('billable'));
|
$filter->addBillableFilter($request->input('billable'));
|
||||||
|
$filter->addTypeFilter($request->input('type'));
|
||||||
|
|
||||||
return $filter->get();
|
return $filter->get();
|
||||||
}
|
}
|
||||||
@@ -334,7 +336,9 @@ class TimeEntryController extends Controller
|
|||||||
|
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'download_url' => Storage::disk(config('filesystems.private'))
|
'download_url' => Storage::disk(config('filesystems.private'))
|
||||||
->temporaryUrl($path, now()->addMinutes(5)),
|
->temporaryUrl($path, now()->addMinutes(5), [
|
||||||
|
'ResponseContentDisposition' => 'attachment; filename="'.$filename.'"',
|
||||||
|
]),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -533,7 +537,7 @@ class TimeEntryController extends Controller
|
|||||||
->putFileAs($folderPath, new File($tempFolder->path($filenameTemp)), $filename);
|
->putFileAs($folderPath, new File($tempFolder->path($filenameTemp)), $filename);
|
||||||
} else {
|
} else {
|
||||||
Excel::store(
|
Excel::store(
|
||||||
new TimeEntriesReportExport($aggregatedData, $format, $currency, $group, $subGroup, $showBillableRate),
|
new TimeEntriesReportExport($aggregatedData, $format, $currency, $group, $subGroup, $showBillableRate, $localizationService),
|
||||||
$path,
|
$path,
|
||||||
config('filesystems.private'),
|
config('filesystems.private'),
|
||||||
$format->getExportPackageType(),
|
$format->getExportPackageType(),
|
||||||
@@ -545,7 +549,9 @@ class TimeEntryController extends Controller
|
|||||||
|
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'download_url' => Storage::disk(config('filesystems.private'))
|
'download_url' => Storage::disk(config('filesystems.private'))
|
||||||
->temporaryUrl($path, now()->addMinutes(5)),
|
->temporaryUrl($path, now()->addMinutes(5), [
|
||||||
|
'ResponseContentDisposition' => 'attachment; filename="'.$filename.'"',
|
||||||
|
]),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -568,6 +574,7 @@ class TimeEntryController extends Controller
|
|||||||
$filter->addTaskIdsFilter($request->input('task_ids'));
|
$filter->addTaskIdsFilter($request->input('task_ids'));
|
||||||
$filter->addClientIdsFilter($request->input('client_ids'));
|
$filter->addClientIdsFilter($request->input('client_ids'));
|
||||||
$filter->addBillableFilter($request->input('billable'));
|
$filter->addBillableFilter($request->input('billable'));
|
||||||
|
$filter->addTypeFilter($request->input('type'));
|
||||||
|
|
||||||
return $filter->get();
|
return $filter->get();
|
||||||
}
|
}
|
||||||
@@ -759,6 +766,19 @@ class TimeEntryController extends Controller
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
// Changing time entries to Break entries is only allowed when breaks are enabled in the org settings
|
||||||
|
$resultingType = isset($changes['type']) ? TimeEntryType::from($changes['type']) : $timeEntry->type;
|
||||||
|
if ($resultingType === TimeEntryType::Break && $timeEntry->type !== TimeEntryType::Break && ! $organization->breaks_enabled) {
|
||||||
|
$error->push($id);
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// Break entries can not be billable, have tags or belong to a project/task (see TimeEntry::booted)
|
||||||
|
if ($resultingType === TimeEntryType::Break && ($project !== null || $task !== null || $request->boolean('changes.billable') || count($changes['tags'] ?? []) > 0)) {
|
||||||
|
$error->push($id);
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
$oldProject = $timeEntry->project;
|
$oldProject = $timeEntry->project;
|
||||||
$oldTask = $timeEntry->task;
|
$oldTask = $timeEntry->task;
|
||||||
|
|
||||||
|
|||||||
@@ -124,6 +124,10 @@ class UserController extends Controller
|
|||||||
$user->week_start = $request->getWeekStart();
|
$user->week_start = $request->getWeekStart();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($request->getSendTimeEntryStillRunningEmail() !== null) {
|
||||||
|
$user->send_time_entry_still_running_email = $request->getSendTimeEntryStillRunningEmail();
|
||||||
|
}
|
||||||
|
|
||||||
$user->save();
|
$user->save();
|
||||||
|
|
||||||
if ($emailToVerify !== null) {
|
if ($emailToVerify !== null) {
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ class OrganizationInvitationController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
return redirect(route('register'))
|
return redirect(route('register'))
|
||||||
|
->with('registration_email', $email)
|
||||||
->with('bannerText', __('Please create an account to finish joining the :organization organization.', [
|
->with('bannerText', __('Please create an account to finish joining the :organization organization.', [
|
||||||
'organization' => $organization->name,
|
'organization' => $organization->name,
|
||||||
]))
|
]))
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ use App\Http\Middleware\PreventRequestsDuringMaintenance;
|
|||||||
use App\Http\Middleware\RedirectIfAuthenticated;
|
use App\Http\Middleware\RedirectIfAuthenticated;
|
||||||
use App\Http\Middleware\ShareInertiaData;
|
use App\Http\Middleware\ShareInertiaData;
|
||||||
use App\Http\Middleware\TrimStrings;
|
use App\Http\Middleware\TrimStrings;
|
||||||
|
use App\Http\Middleware\TrustHosts;
|
||||||
use App\Http\Middleware\TrustProxies;
|
use App\Http\Middleware\TrustProxies;
|
||||||
use App\Http\Middleware\ValidateSignature;
|
use App\Http\Middleware\ValidateSignature;
|
||||||
use App\Http\Middleware\VerifyCsrfToken;
|
use App\Http\Middleware\VerifyCsrfToken;
|
||||||
@@ -47,6 +48,7 @@ class Kernel extends HttpKernel
|
|||||||
*/
|
*/
|
||||||
protected $middleware = [
|
protected $middleware = [
|
||||||
ForceHttps::class,
|
ForceHttps::class,
|
||||||
|
TrustHosts::class,
|
||||||
TrustProxies::class,
|
TrustProxies::class,
|
||||||
HandleCors::class,
|
HandleCors::class,
|
||||||
PreventRequestsDuringMaintenance::class,
|
PreventRequestsDuringMaintenance::class,
|
||||||
|
|||||||
56
app/Http/Middleware/TrustHosts.php
Normal file
56
app/Http/Middleware/TrustHosts.php
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Http\Middleware;
|
||||||
|
|
||||||
|
use Illuminate\Http\Middleware\TrustHosts as BaseTrustHosts;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Http\Response;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rejects requests whose Host is not trusted, preventing Host-header poisoning of
|
||||||
|
* generated URLs (password reset, SSO callback, invitations). Trusted = the
|
||||||
|
* APP_URL host and its subdomains, plus TRUSTED_HOSTS (for multi-host access such
|
||||||
|
* as a Tailscale name). Health-check endpoints are exempt (probed by IP).
|
||||||
|
*/
|
||||||
|
class TrustHosts extends BaseTrustHosts
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @return array<int, string|null>
|
||||||
|
*/
|
||||||
|
public function hosts(): array
|
||||||
|
{
|
||||||
|
/** @var array<int, string> $configured */
|
||||||
|
$configured = config('app.trusted_hosts', []);
|
||||||
|
|
||||||
|
$extra = array_map(function (string $host): string {
|
||||||
|
$host = trim($host);
|
||||||
|
|
||||||
|
// "*.example.com" matches any subdomain, not the apex.
|
||||||
|
if (str_starts_with($host, '*.')) {
|
||||||
|
return '^.+\.'.preg_quote(substr($host, 2), '#').'$';
|
||||||
|
}
|
||||||
|
|
||||||
|
return '^'.preg_quote($host, '#').'$';
|
||||||
|
}, $configured);
|
||||||
|
|
||||||
|
return array_merge([$this->allSubdomainsOfApplicationUrl()], $extra);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param \Closure(Request): Response $next
|
||||||
|
*/
|
||||||
|
public function handle(Request $request, $next)
|
||||||
|
{
|
||||||
|
// Exempt health checks (probed by IP). Also reset the trusted hosts,
|
||||||
|
// since Octane leaks the static state across requests.
|
||||||
|
if ($request->is('health-check/*')) {
|
||||||
|
Request::setTrustedHosts([]);
|
||||||
|
|
||||||
|
return $next($request);
|
||||||
|
}
|
||||||
|
|
||||||
|
return parent::handle($request, $next);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -24,6 +24,7 @@ class ImportRequest extends BaseFormRequest
|
|||||||
'data' => [
|
'data' => [
|
||||||
'required',
|
'required',
|
||||||
'string',
|
'string',
|
||||||
|
'max:'.config('import.max_data_size'),
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,6 +51,9 @@ class OrganizationUpdateRequest extends BaseFormRequest
|
|||||||
'prevent_overlapping_time_entries' => [
|
'prevent_overlapping_time_entries' => [
|
||||||
'boolean',
|
'boolean',
|
||||||
],
|
],
|
||||||
|
'breaks_enabled' => [
|
||||||
|
'boolean',
|
||||||
|
],
|
||||||
'number_format' => [
|
'number_format' => [
|
||||||
Rule::enum(NumberFormat::class),
|
Rule::enum(NumberFormat::class),
|
||||||
],
|
],
|
||||||
@@ -125,4 +128,9 @@ class OrganizationUpdateRequest extends BaseFormRequest
|
|||||||
{
|
{
|
||||||
return $this->has('prevent_overlapping_time_entries') ? $this->boolean('prevent_overlapping_time_entries') : null;
|
return $this->has('prevent_overlapping_time_entries') ? $this->boolean('prevent_overlapping_time_entries') : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getBreaksEnabled(): ?bool
|
||||||
|
{
|
||||||
|
return $this->has('breaks_enabled') ? $this->boolean('breaks_enabled') : null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ use App\Enums\TagMatchType;
|
|||||||
use App\Enums\TimeEntryAggregationType;
|
use App\Enums\TimeEntryAggregationType;
|
||||||
use App\Enums\TimeEntryAggregationTypeInterval;
|
use App\Enums\TimeEntryAggregationTypeInterval;
|
||||||
use App\Enums\TimeEntryRoundingType;
|
use App\Enums\TimeEntryRoundingType;
|
||||||
|
use App\Enums\TimeEntryType;
|
||||||
use App\Enums\Weekday;
|
use App\Enums\Weekday;
|
||||||
use App\Http\Requests\V1\BaseFormRequest;
|
use App\Http\Requests\V1\BaseFormRequest;
|
||||||
use App\Models\Organization;
|
use App\Models\Organization;
|
||||||
@@ -177,6 +178,12 @@ class ReportStoreRequest extends BaseFormRequest
|
|||||||
'numeric',
|
'numeric',
|
||||||
'integer',
|
'integer',
|
||||||
],
|
],
|
||||||
|
// Filter by time entry type
|
||||||
|
'properties.time_entry_type' => [
|
||||||
|
'nullable',
|
||||||
|
'string',
|
||||||
|
Rule::enum(TimeEntryType::class),
|
||||||
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -240,6 +247,15 @@ class ReportStoreRequest extends BaseFormRequest
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getPropertyTimeEntryType(): ?TimeEntryType
|
||||||
|
{
|
||||||
|
if (! $this->has('properties.time_entry_type') || $this->input('properties.time_entry_type') === null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return TimeEntryType::from($this->input('properties.time_entry_type'));
|
||||||
|
}
|
||||||
|
|
||||||
public function getPropertyGroup(): TimeEntryAggregationType
|
public function getPropertyGroup(): TimeEntryAggregationType
|
||||||
{
|
{
|
||||||
return TimeEntryAggregationType::from($this->input('properties.group'));
|
return TimeEntryAggregationType::from($this->input('properties.group'));
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ use App\Enums\TagMatchType;
|
|||||||
use App\Enums\TimeEntryAggregationType;
|
use App\Enums\TimeEntryAggregationType;
|
||||||
use App\Enums\TimeEntryAggregationTypeInterval;
|
use App\Enums\TimeEntryAggregationTypeInterval;
|
||||||
use App\Enums\TimeEntryRoundingType;
|
use App\Enums\TimeEntryRoundingType;
|
||||||
|
use App\Enums\TimeEntryType;
|
||||||
use App\Http\Requests\V1\BaseFormRequest;
|
use App\Http\Requests\V1\BaseFormRequest;
|
||||||
use App\Models\Client;
|
use App\Models\Client;
|
||||||
use App\Models\Member;
|
use App\Models\Member;
|
||||||
@@ -183,6 +184,11 @@ class TimeEntryAggregateExportRequest extends BaseFormRequest
|
|||||||
'string',
|
'string',
|
||||||
'in:true,false',
|
'in:true,false',
|
||||||
],
|
],
|
||||||
|
// Filter by time entry type
|
||||||
|
'type' => [
|
||||||
|
'string',
|
||||||
|
Rule::enum(TimeEntryType::class),
|
||||||
|
],
|
||||||
'fill_gaps_in_time_groups' => [
|
'fill_gaps_in_time_groups' => [
|
||||||
'string',
|
'string',
|
||||||
'in:true,false',
|
'in:true,false',
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ namespace App\Http\Requests\V1\TimeEntry;
|
|||||||
use App\Enums\TagMatchType;
|
use App\Enums\TagMatchType;
|
||||||
use App\Enums\TimeEntryAggregationType;
|
use App\Enums\TimeEntryAggregationType;
|
||||||
use App\Enums\TimeEntryRoundingType;
|
use App\Enums\TimeEntryRoundingType;
|
||||||
|
use App\Enums\TimeEntryType;
|
||||||
use App\Http\Requests\V1\BaseFormRequest;
|
use App\Http\Requests\V1\BaseFormRequest;
|
||||||
use App\Models\Client;
|
use App\Models\Client;
|
||||||
use App\Models\Member;
|
use App\Models\Member;
|
||||||
@@ -169,6 +170,11 @@ class TimeEntryAggregateRequest extends BaseFormRequest
|
|||||||
'string',
|
'string',
|
||||||
'in:true,false',
|
'in:true,false',
|
||||||
],
|
],
|
||||||
|
// Filter by time entry type
|
||||||
|
'type' => [
|
||||||
|
'string',
|
||||||
|
Rule::enum(TimeEntryType::class),
|
||||||
|
],
|
||||||
'fill_gaps_in_time_groups' => [
|
'fill_gaps_in_time_groups' => [
|
||||||
'string',
|
'string',
|
||||||
'in:true,false',
|
'in:true,false',
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ namespace App\Http\Requests\V1\TimeEntry;
|
|||||||
use App\Enums\ExportFormat;
|
use App\Enums\ExportFormat;
|
||||||
use App\Enums\TagMatchType;
|
use App\Enums\TagMatchType;
|
||||||
use App\Enums\TimeEntryRoundingType;
|
use App\Enums\TimeEntryRoundingType;
|
||||||
|
use App\Enums\TimeEntryType;
|
||||||
use App\Models\Client;
|
use App\Models\Client;
|
||||||
use App\Models\Member;
|
use App\Models\Member;
|
||||||
use App\Models\Organization;
|
use App\Models\Organization;
|
||||||
@@ -155,6 +156,11 @@ class TimeEntryIndexExportRequest extends TimeEntryIndexRequest
|
|||||||
'string',
|
'string',
|
||||||
'in:true,false',
|
'in:true,false',
|
||||||
],
|
],
|
||||||
|
// Filter by time entry type
|
||||||
|
'type' => [
|
||||||
|
'string',
|
||||||
|
Rule::enum(TimeEntryType::class),
|
||||||
|
],
|
||||||
// Limit the number of returned time entries (default: 150)
|
// Limit the number of returned time entries (default: 150)
|
||||||
'limit' => [
|
'limit' => [
|
||||||
'integer',
|
'integer',
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ namespace App\Http\Requests\V1\TimeEntry;
|
|||||||
|
|
||||||
use App\Enums\TagMatchType;
|
use App\Enums\TagMatchType;
|
||||||
use App\Enums\TimeEntryRoundingType;
|
use App\Enums\TimeEntryRoundingType;
|
||||||
|
use App\Enums\TimeEntryType;
|
||||||
use App\Http\Requests\V1\BaseFormRequest;
|
use App\Http\Requests\V1\BaseFormRequest;
|
||||||
use App\Models\Client;
|
use App\Models\Client;
|
||||||
use App\Models\Member;
|
use App\Models\Member;
|
||||||
@@ -148,6 +149,11 @@ class TimeEntryIndexRequest extends BaseFormRequest
|
|||||||
'string',
|
'string',
|
||||||
'in:true,false',
|
'in:true,false',
|
||||||
],
|
],
|
||||||
|
// Filter by time entry type
|
||||||
|
'type' => [
|
||||||
|
'string',
|
||||||
|
Rule::enum(TimeEntryType::class),
|
||||||
|
],
|
||||||
// Limit the number of returned time entries (default: 150)
|
// Limit the number of returned time entries (default: 150)
|
||||||
'limit' => [
|
'limit' => [
|
||||||
'integer',
|
'integer',
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace App\Http\Requests\V1\TimeEntry;
|
namespace App\Http\Requests\V1\TimeEntry;
|
||||||
|
|
||||||
|
use App\Enums\TimeEntryType;
|
||||||
use App\Http\Requests\V1\BaseFormRequest;
|
use App\Http\Requests\V1\BaseFormRequest;
|
||||||
use App\Models\Member;
|
use App\Models\Member;
|
||||||
use App\Models\Organization;
|
use App\Models\Organization;
|
||||||
@@ -14,6 +15,7 @@ use App\Service\PermissionStore;
|
|||||||
use Illuminate\Contracts\Validation\ValidationRule;
|
use Illuminate\Contracts\Validation\ValidationRule;
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
use Illuminate\Validation\Rule;
|
||||||
use Korridor\LaravelModelValidationRules\Rules\ExistsEloquent;
|
use Korridor\LaravelModelValidationRules\Rules\ExistsEloquent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -24,7 +26,7 @@ class TimeEntryStoreRequest extends BaseFormRequest
|
|||||||
/**
|
/**
|
||||||
* Get the validation rules that apply to the request.
|
* Get the validation rules that apply to the request.
|
||||||
*
|
*
|
||||||
* @return array<string, array<string|ValidationRule>>
|
* @return array<string, array<string|\Closure|ValidationRule|\Illuminate\Contracts\Validation\Rule>>
|
||||||
*/
|
*/
|
||||||
public function rules(): array
|
public function rules(): array
|
||||||
{
|
{
|
||||||
@@ -42,6 +44,7 @@ class TimeEntryStoreRequest extends BaseFormRequest
|
|||||||
'nullable',
|
'nullable',
|
||||||
'string',
|
'string',
|
||||||
'required_with:task_id',
|
'required_with:task_id',
|
||||||
|
'prohibited_if:type,break',
|
||||||
ExistsEloquent::make(Project::class, null, function (Builder $builder): Builder {
|
ExistsEloquent::make(Project::class, null, function (Builder $builder): Builder {
|
||||||
/** @var Builder<Project> $builder */
|
/** @var Builder<Project> $builder */
|
||||||
$builder = $builder->whereBelongsTo($this->organization, 'organization');
|
$builder = $builder->whereBelongsTo($this->organization, 'organization');
|
||||||
@@ -60,6 +63,7 @@ class TimeEntryStoreRequest extends BaseFormRequest
|
|||||||
'task_id' => [
|
'task_id' => [
|
||||||
'nullable',
|
'nullable',
|
||||||
'string',
|
'string',
|
||||||
|
'prohibited_if:type,break',
|
||||||
ExistsEloquent::make(Task::class, null, function (Builder $builder): Builder {
|
ExistsEloquent::make(Task::class, null, function (Builder $builder): Builder {
|
||||||
/** @var Builder<Task> $builder */
|
/** @var Builder<Task> $builder */
|
||||||
return $builder->whereBelongsTo($this->organization, 'organization');
|
return $builder->whereBelongsTo($this->organization, 'organization');
|
||||||
@@ -85,6 +89,16 @@ class TimeEntryStoreRequest extends BaseFormRequest
|
|||||||
'billable' => [
|
'billable' => [
|
||||||
'required',
|
'required',
|
||||||
'boolean',
|
'boolean',
|
||||||
|
'declined_if:type,break',
|
||||||
|
],
|
||||||
|
// Type of the time entry (work time or a break)
|
||||||
|
'type' => [
|
||||||
|
Rule::enum(TimeEntryType::class),
|
||||||
|
function (string $attribute, mixed $value, \Closure $fail): void {
|
||||||
|
if ($value === TimeEntryType::Break->value && ! $this->organization->breaks_enabled) {
|
||||||
|
$fail('Breaks are disabled for this organization.');
|
||||||
|
}
|
||||||
|
},
|
||||||
],
|
],
|
||||||
// Description of time entry
|
// Description of time entry
|
||||||
'description' => [
|
'description' => [
|
||||||
@@ -96,6 +110,7 @@ class TimeEntryStoreRequest extends BaseFormRequest
|
|||||||
'tags' => [
|
'tags' => [
|
||||||
'nullable',
|
'nullable',
|
||||||
'array',
|
'array',
|
||||||
|
'prohibited_if:type,break',
|
||||||
],
|
],
|
||||||
'tags.*' => [
|
'tags.*' => [
|
||||||
ExistsEloquent::make(Tag::class, null, function (Builder $builder): Builder {
|
ExistsEloquent::make(Tag::class, null, function (Builder $builder): Builder {
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace App\Http\Requests\V1\TimeEntry;
|
namespace App\Http\Requests\V1\TimeEntry;
|
||||||
|
|
||||||
|
use App\Enums\TimeEntryType;
|
||||||
use App\Http\Requests\V1\BaseFormRequest;
|
use App\Http\Requests\V1\BaseFormRequest;
|
||||||
use App\Models\Member;
|
use App\Models\Member;
|
||||||
use App\Models\Organization;
|
use App\Models\Organization;
|
||||||
@@ -14,6 +15,7 @@ use App\Service\PermissionStore;
|
|||||||
use Illuminate\Contracts\Validation\ValidationRule;
|
use Illuminate\Contracts\Validation\ValidationRule;
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
use Illuminate\Validation\Rule;
|
||||||
use Korridor\LaravelModelValidationRules\Rules\ExistsEloquent;
|
use Korridor\LaravelModelValidationRules\Rules\ExistsEloquent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -24,7 +26,7 @@ class TimeEntryUpdateMultipleRequest extends BaseFormRequest
|
|||||||
/**
|
/**
|
||||||
* Get the validation rules that apply to the request.
|
* Get the validation rules that apply to the request.
|
||||||
*
|
*
|
||||||
* @return array<string, array<string|ValidationRule>>
|
* @return array<string, array<string|ValidationRule|\Illuminate\Contracts\Validation\Rule>>
|
||||||
*/
|
*/
|
||||||
public function rules(): array
|
public function rules(): array
|
||||||
{
|
{
|
||||||
@@ -54,6 +56,7 @@ class TimeEntryUpdateMultipleRequest extends BaseFormRequest
|
|||||||
'nullable',
|
'nullable',
|
||||||
'string',
|
'string',
|
||||||
'required_with:task_id',
|
'required_with:task_id',
|
||||||
|
'prohibited_if:changes.type,break',
|
||||||
ExistsEloquent::make(Project::class, null, function (Builder $builder): Builder {
|
ExistsEloquent::make(Project::class, null, function (Builder $builder): Builder {
|
||||||
/** @var Builder<Project> $builder */
|
/** @var Builder<Project> $builder */
|
||||||
$builder = $builder->whereBelongsTo($this->organization, 'organization');
|
$builder = $builder->whereBelongsTo($this->organization, 'organization');
|
||||||
@@ -72,6 +75,7 @@ class TimeEntryUpdateMultipleRequest extends BaseFormRequest
|
|||||||
'changes.task_id' => [
|
'changes.task_id' => [
|
||||||
'nullable',
|
'nullable',
|
||||||
'string',
|
'string',
|
||||||
|
'prohibited_if:changes.type,break',
|
||||||
ExistsEloquent::make(Task::class, null, function (Builder $builder): Builder {
|
ExistsEloquent::make(Task::class, null, function (Builder $builder): Builder {
|
||||||
/** @var Builder<Task> $builder */
|
/** @var Builder<Task> $builder */
|
||||||
return $builder->whereBelongsTo($this->organization, 'organization');
|
return $builder->whereBelongsTo($this->organization, 'organization');
|
||||||
@@ -84,7 +88,13 @@ class TimeEntryUpdateMultipleRequest extends BaseFormRequest
|
|||||||
],
|
],
|
||||||
// Whether time entry is billable
|
// Whether time entry is billable
|
||||||
'changes.billable' => [
|
'changes.billable' => [
|
||||||
|
'sometimes',
|
||||||
'boolean',
|
'boolean',
|
||||||
|
'declined_if:changes.type,break',
|
||||||
|
],
|
||||||
|
// Type of the time entry (work time or a break)
|
||||||
|
'changes.type' => [
|
||||||
|
Rule::enum(TimeEntryType::class),
|
||||||
],
|
],
|
||||||
// Description of time entry
|
// Description of time entry
|
||||||
'changes.description' => [
|
'changes.description' => [
|
||||||
@@ -96,6 +106,7 @@ class TimeEntryUpdateMultipleRequest extends BaseFormRequest
|
|||||||
'changes.tags' => [
|
'changes.tags' => [
|
||||||
'nullable',
|
'nullable',
|
||||||
'array',
|
'array',
|
||||||
|
'prohibited_if:changes.type,break',
|
||||||
],
|
],
|
||||||
'changes.tags.*' => [
|
'changes.tags.*' => [
|
||||||
'string',
|
'string',
|
||||||
|
|||||||
@@ -4,16 +4,21 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace App\Http\Requests\V1\TimeEntry;
|
namespace App\Http\Requests\V1\TimeEntry;
|
||||||
|
|
||||||
|
use App\Enums\TimeEntryType;
|
||||||
use App\Http\Requests\V1\BaseFormRequest;
|
use App\Http\Requests\V1\BaseFormRequest;
|
||||||
use App\Models\Member;
|
use App\Models\Member;
|
||||||
use App\Models\Organization;
|
use App\Models\Organization;
|
||||||
use App\Models\Project;
|
use App\Models\Project;
|
||||||
use App\Models\Tag;
|
use App\Models\Tag;
|
||||||
use App\Models\Task;
|
use App\Models\Task;
|
||||||
|
use App\Models\TimeEntry;
|
||||||
use App\Service\PermissionStore;
|
use App\Service\PermissionStore;
|
||||||
use Illuminate\Contracts\Validation\ValidationRule;
|
use Illuminate\Contracts\Validation\ValidationRule;
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
use Illuminate\Validation\ConditionalRules;
|
||||||
|
use Illuminate\Validation\Rule;
|
||||||
|
use Illuminate\Validation\Rules\ProhibitedIf;
|
||||||
use Korridor\LaravelModelValidationRules\Rules\ExistsEloquent;
|
use Korridor\LaravelModelValidationRules\Rules\ExistsEloquent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -24,10 +29,19 @@ class TimeEntryUpdateRequest extends BaseFormRequest
|
|||||||
/**
|
/**
|
||||||
* Get the validation rules that apply to the request.
|
* Get the validation rules that apply to the request.
|
||||||
*
|
*
|
||||||
* @return array<string, array<string|ValidationRule>>
|
* @return array<string, array<string|\Closure|ValidationRule|\Illuminate\Contracts\Validation\Rule|ProhibitedIf|ConditionalRules>>
|
||||||
*/
|
*/
|
||||||
public function rules(): array
|
public function rules(): array
|
||||||
{
|
{
|
||||||
|
// Break restrictions need to apply based on the type the entry will have after the
|
||||||
|
// update, not only when the payload itself contains type=break.
|
||||||
|
$timeEntry = $this->route('timeEntry');
|
||||||
|
$timeEntry = $timeEntry instanceof TimeEntry ? $timeEntry : null;
|
||||||
|
$resultingType = $this->has('type')
|
||||||
|
? TimeEntryType::tryFrom((string) $this->input('type'))
|
||||||
|
: $timeEntry?->type;
|
||||||
|
$isBreak = $resultingType === TimeEntryType::Break;
|
||||||
|
|
||||||
return [
|
return [
|
||||||
// ID of the organization member that the time entry should belong to
|
// ID of the organization member that the time entry should belong to
|
||||||
'member_id' => [
|
'member_id' => [
|
||||||
@@ -42,6 +56,7 @@ class TimeEntryUpdateRequest extends BaseFormRequest
|
|||||||
'nullable',
|
'nullable',
|
||||||
'string',
|
'string',
|
||||||
'required_with:task_id',
|
'required_with:task_id',
|
||||||
|
Rule::prohibitedIf($isBreak),
|
||||||
ExistsEloquent::make(Project::class, null, function (Builder $builder): Builder {
|
ExistsEloquent::make(Project::class, null, function (Builder $builder): Builder {
|
||||||
/** @var Builder<Project> $builder */
|
/** @var Builder<Project> $builder */
|
||||||
$builder = $builder->whereBelongsTo($this->organization, 'organization');
|
$builder = $builder->whereBelongsTo($this->organization, 'organization');
|
||||||
@@ -60,6 +75,7 @@ class TimeEntryUpdateRequest extends BaseFormRequest
|
|||||||
'task_id' => [
|
'task_id' => [
|
||||||
'nullable',
|
'nullable',
|
||||||
'string',
|
'string',
|
||||||
|
Rule::prohibitedIf($isBreak),
|
||||||
ExistsEloquent::make(Task::class, null, function (Builder $builder): Builder {
|
ExistsEloquent::make(Task::class, null, function (Builder $builder): Builder {
|
||||||
/** @var Builder<Task> $builder */
|
/** @var Builder<Task> $builder */
|
||||||
return $builder->whereBelongsTo($this->organization, 'organization');
|
return $builder->whereBelongsTo($this->organization, 'organization');
|
||||||
@@ -82,7 +98,22 @@ class TimeEntryUpdateRequest extends BaseFormRequest
|
|||||||
],
|
],
|
||||||
// Whether time entry is billable
|
// Whether time entry is billable
|
||||||
'billable' => [
|
'billable' => [
|
||||||
|
'sometimes',
|
||||||
'boolean',
|
'boolean',
|
||||||
|
Rule::when($isBreak, ['declined']),
|
||||||
|
],
|
||||||
|
// Type of the time entry (work time or a break)
|
||||||
|
'type' => [
|
||||||
|
Rule::enum(TimeEntryType::class),
|
||||||
|
function (string $attribute, mixed $value, \Closure $fail) use ($timeEntry): void {
|
||||||
|
// While breaks are disabled, entries that already are breaks may stay
|
||||||
|
// breaks, but converting a work entry to a break is not allowed.
|
||||||
|
if ($value === TimeEntryType::Break->value
|
||||||
|
&& ! $this->organization->breaks_enabled
|
||||||
|
&& $timeEntry?->type !== TimeEntryType::Break) {
|
||||||
|
$fail('Breaks are disabled for this organization.');
|
||||||
|
}
|
||||||
|
},
|
||||||
],
|
],
|
||||||
// Description of time entry
|
// Description of time entry
|
||||||
'description' => [
|
'description' => [
|
||||||
@@ -94,6 +125,7 @@ class TimeEntryUpdateRequest extends BaseFormRequest
|
|||||||
'tags' => [
|
'tags' => [
|
||||||
'nullable',
|
'nullable',
|
||||||
'array',
|
'array',
|
||||||
|
Rule::prohibitedIf($isBreak),
|
||||||
],
|
],
|
||||||
'tags.*' => [
|
'tags.*' => [
|
||||||
'string',
|
'string',
|
||||||
|
|||||||
@@ -58,6 +58,9 @@ class UserUpdateRequest extends BaseFormRequest
|
|||||||
'week_start' => [
|
'week_start' => [
|
||||||
Rule::enum(Weekday::class),
|
Rule::enum(Weekday::class),
|
||||||
],
|
],
|
||||||
|
'send_time_entry_still_running_email' => [
|
||||||
|
'boolean',
|
||||||
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,6 +84,13 @@ class UserUpdateRequest extends BaseFormRequest
|
|||||||
return $this->has('week_start') ? Weekday::from($this->input('week_start')) : null;
|
return $this->has('week_start') ? Weekday::from($this->input('week_start')) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getSendTimeEntryStillRunningEmail(): ?bool
|
||||||
|
{
|
||||||
|
return $this->has('send_time_entry_still_running_email')
|
||||||
|
? $this->boolean('send_time_entry_still_running_email')
|
||||||
|
: null;
|
||||||
|
}
|
||||||
|
|
||||||
public function hasPhotoKey(): bool
|
public function hasPhotoKey(): bool
|
||||||
{
|
{
|
||||||
return $this->has('photo');
|
return $this->has('photo');
|
||||||
|
|||||||
@@ -57,6 +57,8 @@ class OrganizationResource extends BaseResource
|
|||||||
'employees_can_manage_tasks' => $this->resource->employees_can_manage_tasks,
|
'employees_can_manage_tasks' => $this->resource->employees_can_manage_tasks,
|
||||||
/** @var bool $prevent_overlapping_time_entries Prevent creating overlapping time entries (only new entries) */
|
/** @var bool $prevent_overlapping_time_entries Prevent creating overlapping time entries (only new entries) */
|
||||||
'prevent_overlapping_time_entries' => $this->resource->prevent_overlapping_time_entries,
|
'prevent_overlapping_time_entries' => $this->resource->prevent_overlapping_time_entries,
|
||||||
|
/** @var bool $breaks_enabled Whether members of the organization can track breaks */
|
||||||
|
'breaks_enabled' => $this->resource->breaks_enabled,
|
||||||
/** @var string $currency Currency code (ISO 4217) */
|
/** @var string $currency Currency code (ISO 4217) */
|
||||||
'currency' => $this->resource->currency,
|
'currency' => $this->resource->currency,
|
||||||
/** @var string $currency_symbol Currency symbol */
|
/** @var string $currency_symbol Currency symbol */
|
||||||
|
|||||||
@@ -50,6 +50,8 @@ class DetailedReportResource extends BaseResource
|
|||||||
'member_ids' => $this->resource->properties->memberIds?->toArray(),
|
'member_ids' => $this->resource->properties->memberIds?->toArray(),
|
||||||
/** @var bool|null $billable Filter by billable status */
|
/** @var bool|null $billable Filter by billable status */
|
||||||
'billable' => $this->resource->properties->billable,
|
'billable' => $this->resource->properties->billable,
|
||||||
|
/** @var string|null $time_entry_type Filter by time entry type */
|
||||||
|
'time_entry_type' => $this->resource->properties->timeEntryType?->value,
|
||||||
/** @var array<string>|null $client_ids Filter by client IDs, client IDs are OR combined */
|
/** @var array<string>|null $client_ids Filter by client IDs, client IDs are OR combined */
|
||||||
'client_ids' => $this->resource->properties->clientIds?->toArray(),
|
'client_ids' => $this->resource->properties->clientIds?->toArray(),
|
||||||
/** @var array<string>|null $project_ids Filter by project IDs, project IDs are OR combined */
|
/** @var array<string>|null $project_ids Filter by project IDs, project IDs are OR combined */
|
||||||
|
|||||||
@@ -47,6 +47,8 @@ class TimeEntryResource extends BaseResource
|
|||||||
'tags' => $this->resource->tags ?? [],
|
'tags' => $this->resource->tags ?? [],
|
||||||
/** @var bool $billable Whether time entry is billable */
|
/** @var bool $billable Whether time entry is billable */
|
||||||
'billable' => $this->resource->billable,
|
'billable' => $this->resource->billable,
|
||||||
|
/** @var string $type Type of the time entry (`work` time or a `break`) */
|
||||||
|
'type' => $this->resource->type->value,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,6 +36,8 @@ class UserResource extends BaseResource
|
|||||||
'timezone' => $this->resource->timezone,
|
'timezone' => $this->resource->timezone,
|
||||||
/** @var Weekday $week_start Starting day of the week */
|
/** @var Weekday $week_start Starting day of the week */
|
||||||
'week_start' => $this->resource->week_start->value,
|
'week_start' => $this->resource->week_start->value,
|
||||||
|
/** @var bool $send_time_entry_still_running_email Whether to email the user when a time entry has been running for more than 8 hours */
|
||||||
|
'send_time_entry_still_running_email' => $this->resource->send_time_entry_still_running_email,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ use OwenIt\Auditing\Contracts\Auditable as AuditableContract;
|
|||||||
* @property bool $employees_can_see_billable_rates
|
* @property bool $employees_can_see_billable_rates
|
||||||
* @property bool $employees_can_manage_tasks
|
* @property bool $employees_can_manage_tasks
|
||||||
* @property bool $prevent_overlapping_time_entries
|
* @property bool $prevent_overlapping_time_entries
|
||||||
|
* @property bool $breaks_enabled
|
||||||
* @property User $owner
|
* @property User $owner
|
||||||
* @property Carbon|null $created_at
|
* @property Carbon|null $created_at
|
||||||
* @property Carbon|null $updated_at
|
* @property Carbon|null $updated_at
|
||||||
@@ -70,6 +71,7 @@ class Organization extends Model implements AuditableContract
|
|||||||
'employees_can_see_billable_rates' => 'boolean',
|
'employees_can_see_billable_rates' => 'boolean',
|
||||||
'employees_can_manage_tasks' => 'boolean',
|
'employees_can_manage_tasks' => 'boolean',
|
||||||
'prevent_overlapping_time_entries' => 'boolean',
|
'prevent_overlapping_time_entries' => 'boolean',
|
||||||
|
'breaks_enabled' => 'boolean',
|
||||||
'number_format' => NumberFormat::class,
|
'number_format' => NumberFormat::class,
|
||||||
'currency_format' => CurrencyFormat::class,
|
'currency_format' => CurrencyFormat::class,
|
||||||
'date_format' => DateFormat::class,
|
'date_format' => DateFormat::class,
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
|
use App\Enums\TimeEntryType;
|
||||||
use App\Models\Concerns\CustomAuditable;
|
use App\Models\Concerns\CustomAuditable;
|
||||||
use App\Models\Concerns\HasUuids;
|
use App\Models\Concerns\HasUuids;
|
||||||
use App\Service\BillableRateService;
|
use App\Service\BillableRateService;
|
||||||
@@ -28,6 +29,7 @@ use Staudenmeir\EloquentJsonRelations\Relations\BelongsToJson;
|
|||||||
* @property Carbon|null $end
|
* @property Carbon|null $end
|
||||||
* @property int|null $billable_rate Billable rate per hour in cents
|
* @property int|null $billable_rate Billable rate per hour in cents
|
||||||
* @property bool $billable
|
* @property bool $billable
|
||||||
|
* @property TimeEntryType $type
|
||||||
* @property array<string> $tags
|
* @property array<string> $tags
|
||||||
* @property string $user_id
|
* @property string $user_id
|
||||||
* @property string $member_id
|
* @property string $member_id
|
||||||
@@ -71,12 +73,20 @@ class TimeEntry extends Model implements AuditableContract
|
|||||||
'start' => 'datetime',
|
'start' => 'datetime',
|
||||||
'end' => 'datetime',
|
'end' => 'datetime',
|
||||||
'billable' => 'bool',
|
'billable' => 'bool',
|
||||||
|
'type' => TimeEntryType::class,
|
||||||
'tags' => 'array',
|
'tags' => 'array',
|
||||||
'billable_rate' => 'int',
|
'billable_rate' => 'int',
|
||||||
'is_imported' => 'bool',
|
'is_imported' => 'bool',
|
||||||
'still_active_email_sent_at' => 'datetime',
|
'still_active_email_sent_at' => 'datetime',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array<string, string>
|
||||||
|
*/
|
||||||
|
protected $attributes = [
|
||||||
|
'type' => 'work',
|
||||||
|
];
|
||||||
|
|
||||||
public const array SELECT_COLUMNS = [
|
public const array SELECT_COLUMNS = [
|
||||||
'id',
|
'id',
|
||||||
'description',
|
'description',
|
||||||
@@ -84,6 +94,7 @@ class TimeEntry extends Model implements AuditableContract
|
|||||||
'end',
|
'end',
|
||||||
'billable_rate',
|
'billable_rate',
|
||||||
'billable',
|
'billable',
|
||||||
|
'type',
|
||||||
'user_id',
|
'user_id',
|
||||||
'organization_id',
|
'organization_id',
|
||||||
'project_id',
|
'project_id',
|
||||||
@@ -117,6 +128,21 @@ class TimeEntry extends Model implements AuditableContract
|
|||||||
'billable_rate',
|
'billable_rate',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
protected static function booted(): void
|
||||||
|
{
|
||||||
|
// Break entries can never be billable, have tags or belong to a project/task.
|
||||||
|
static::saving(function (TimeEntry $timeEntry): void {
|
||||||
|
if ($timeEntry->type === TimeEntryType::Break) {
|
||||||
|
$timeEntry->billable = false;
|
||||||
|
$timeEntry->billable_rate = null;
|
||||||
|
$timeEntry->project_id = null;
|
||||||
|
$timeEntry->task_id = null;
|
||||||
|
$timeEntry->client_id = null;
|
||||||
|
$timeEntry->tags = [];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public function getBillableRateComputed(): ?int
|
public function getBillableRateComputed(): ?int
|
||||||
{
|
{
|
||||||
return app(BillableRateService::class)->getBillableRateForTimeEntry($this);
|
return app(BillableRateService::class)->getBillableRateForTimeEntry($this);
|
||||||
@@ -173,6 +199,16 @@ class TimeEntry extends Model implements AuditableContract
|
|||||||
$builder->whereJsonContains('tags', $tag->getKey());
|
$builder->whereJsonContains('tags', $tag->getKey());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Only work entries — breaks do not count toward tracked/billable time.
|
||||||
|
*
|
||||||
|
* @param Builder<TimeEntry> $builder
|
||||||
|
*/
|
||||||
|
public function scopeWorkTime(Builder $builder): void
|
||||||
|
{
|
||||||
|
$builder->where('type', '=', TimeEntryType::Work);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return BelongsTo<User, $this>
|
* @return BelongsTo<User, $this>
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -38,10 +38,14 @@ use OwenIt\Auditing\Contracts\Auditable as AuditableContract;
|
|||||||
* @property string|null $pending_email
|
* @property string|null $pending_email
|
||||||
* @property Carbon|null $email_verified_at
|
* @property Carbon|null $email_verified_at
|
||||||
* @property string|null $password
|
* @property string|null $password
|
||||||
|
* @property string|null $remember_token
|
||||||
* @property string|null $two_factor_secret
|
* @property string|null $two_factor_secret
|
||||||
|
* @property string|null $two_factor_recovery_codes
|
||||||
|
* @property Carbon|null $two_factor_confirmed_at
|
||||||
* @property string $timezone
|
* @property string $timezone
|
||||||
* @property bool $is_placeholder
|
* @property bool $is_placeholder
|
||||||
* @property Weekday $week_start
|
* @property Weekday $week_start
|
||||||
|
* @property bool $send_time_entry_still_running_email
|
||||||
* @property string|null $profile_photo_path
|
* @property string|null $profile_photo_path
|
||||||
* @property-read Organization|null $currentOrganization
|
* @property-read Organization|null $currentOrganization
|
||||||
* @property-read string $profile_photo_url
|
* @property-read string $profile_photo_url
|
||||||
@@ -108,6 +112,7 @@ class User extends Authenticatable implements AuditableContract, FilamentUser, M
|
|||||||
'is_admin' => 'boolean',
|
'is_admin' => 'boolean',
|
||||||
'is_placeholder' => 'boolean',
|
'is_placeholder' => 'boolean',
|
||||||
'week_start' => Weekday::class,
|
'week_start' => Weekday::class,
|
||||||
|
'send_time_entry_still_running_email' => 'boolean',
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -117,6 +122,7 @@ class User extends Authenticatable implements AuditableContract, FilamentUser, M
|
|||||||
*/
|
*/
|
||||||
protected $attributes = [
|
protected $attributes = [
|
||||||
'week_start' => Weekday::Monday,
|
'week_start' => Weekday::Monday,
|
||||||
|
'send_time_entry_still_running_email' => true,
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -147,7 +153,9 @@ class User extends Authenticatable implements AuditableContract, FilamentUser, M
|
|||||||
|
|
||||||
public function canAccessPanel(Panel $panel): bool
|
public function canAccessPanel(Panel $panel): bool
|
||||||
{
|
{
|
||||||
return in_array($this->email, config('auth.super_admins', []), true) && $this->hasVerifiedEmail();
|
return $this->is_placeholder === false
|
||||||
|
&& in_array($this->email, config('auth.super_admins', []), true)
|
||||||
|
&& $this->hasVerifiedEmail();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isMemberOfOrganization(Organization $organization): bool
|
public function isMemberOfOrganization(Organization $organization): bool
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ use App\Service\BillingContract;
|
|||||||
use App\Service\IpLookup\IpLookupServiceContract;
|
use App\Service\IpLookup\IpLookupServiceContract;
|
||||||
use App\Service\IpLookup\NoIpLookupService;
|
use App\Service\IpLookup\NoIpLookupService;
|
||||||
use App\Service\PermissionStore;
|
use App\Service\PermissionStore;
|
||||||
|
use DateTimeInterface;
|
||||||
use Dedoc\Scramble\Scramble;
|
use Dedoc\Scramble\Scramble;
|
||||||
use Dedoc\Scramble\Support\Generator\OpenApi;
|
use Dedoc\Scramble\Support\Generator\OpenApi;
|
||||||
use Dedoc\Scramble\Support\Generator\SecurityScheme;
|
use Dedoc\Scramble\Support\Generator\SecurityScheme;
|
||||||
@@ -29,8 +30,13 @@ use Filament\Tables\Table;
|
|||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Database\Eloquent\Relations\Relation;
|
use Illuminate\Database\Eloquent\Relations\Relation;
|
||||||
use Illuminate\Foundation\Application;
|
use Illuminate\Foundation\Application;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\Route;
|
use Illuminate\Support\Facades\Route;
|
||||||
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
use Illuminate\Support\Facades\URL;
|
||||||
use Illuminate\Support\ServiceProvider;
|
use Illuminate\Support\ServiceProvider;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
use Symfony\Component\HttpFoundation\StreamedResponse;
|
||||||
|
|
||||||
class AppServiceProvider extends ServiceProvider
|
class AppServiceProvider extends ServiceProvider
|
||||||
{
|
{
|
||||||
@@ -98,6 +104,27 @@ class AppServiceProvider extends ServiceProvider
|
|||||||
$this->app->bind(IpLookupServiceContract::class, NoIpLookupService::class);
|
$this->app->bind(IpLookupServiceContract::class, NoIpLookupService::class);
|
||||||
$this->app->bind(BillingContract::class);
|
$this->app->bind(BillingContract::class);
|
||||||
|
|
||||||
|
// Storage
|
||||||
|
// The local driver ignores the ResponseContentDisposition option of temporaryUrl,
|
||||||
|
// so mirror it through the signed query parameters of the storage route.
|
||||||
|
$privateDisk = config('filesystems.private');
|
||||||
|
if (config('filesystems.disks.'.$privateDisk.'.driver') === 'local') {
|
||||||
|
$disk = Storage::disk($privateDisk);
|
||||||
|
$disk->serveUsing(function (Request $request, string $path, array $headers) use ($disk): StreamedResponse {
|
||||||
|
return $disk->response($path, null, $headers, $request->query('disposition', 'inline'));
|
||||||
|
});
|
||||||
|
$disk->buildTemporaryUrlsUsing(function (string $path, DateTimeInterface $expiration, array $options) use ($privateDisk): string {
|
||||||
|
$parameters = array_filter([
|
||||||
|
'path' => $path,
|
||||||
|
'disposition' => isset($options['ResponseContentDisposition'])
|
||||||
|
? Str::before($options['ResponseContentDisposition'], ';')
|
||||||
|
: null,
|
||||||
|
]);
|
||||||
|
|
||||||
|
return url(URL::temporarySignedRoute('storage.'.$privateDisk, $expiration, $parameters, absolute: false));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Routing
|
// Routing
|
||||||
Route::model('member', Member::class);
|
Route::model('member', Member::class);
|
||||||
Route::model('invitation', OrganizationInvitation::class);
|
Route::model('invitation', OrganizationInvitation::class);
|
||||||
|
|||||||
@@ -4,11 +4,14 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace App\Providers;
|
namespace App\Providers;
|
||||||
|
|
||||||
|
use App\Auth\ActiveUserProvider;
|
||||||
use App\Models\Passport\AuthCode;
|
use App\Models\Passport\AuthCode;
|
||||||
use App\Models\Passport\Client;
|
use App\Models\Passport\Client;
|
||||||
use App\Models\Passport\RefreshToken;
|
use App\Models\Passport\RefreshToken;
|
||||||
use App\Models\Passport\Token;
|
use App\Models\Passport\Token;
|
||||||
|
use Illuminate\Contracts\Foundation\Application;
|
||||||
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
|
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
|
||||||
|
use Illuminate\Support\Facades\Auth;
|
||||||
use Laravel\Passport\Passport;
|
use Laravel\Passport\Passport;
|
||||||
|
|
||||||
class AuthServiceProvider extends ServiceProvider
|
class AuthServiceProvider extends ServiceProvider
|
||||||
@@ -26,6 +29,13 @@ class AuthServiceProvider extends ServiceProvider
|
|||||||
*/
|
*/
|
||||||
public function boot(): void
|
public function boot(): void
|
||||||
{
|
{
|
||||||
|
// Replaces the built-in eloquent user provider, so that no authentication flow can
|
||||||
|
// resolve a placeholder user. The driver name is kept, because Passport recognizes
|
||||||
|
// only providers that are configured with the driver "eloquent".
|
||||||
|
Auth::provider('eloquent', function (Application $app, array $config): ActiveUserProvider {
|
||||||
|
return new ActiveUserProvider($app->make('hash'), $config['model']);
|
||||||
|
});
|
||||||
|
|
||||||
// define scopes for passport tokens
|
// define scopes for passport tokens
|
||||||
Passport::tokensCan([
|
Passport::tokensCan([
|
||||||
'create' => 'Create resources',
|
'create' => 'Create resources',
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ class FortifyServiceProvider extends ServiceProvider
|
|||||||
|
|
||||||
Fortify::registerView(function () {
|
Fortify::registerView(function () {
|
||||||
return Inertia::render('Auth/Register', [
|
return Inertia::render('Auth/Register', [
|
||||||
|
'email' => session('registration_email', ''),
|
||||||
'terms_url' => config('auth.terms_url'),
|
'terms_url' => config('auth.terms_url'),
|
||||||
'privacy_policy_url' => config('auth.privacy_policy_url'),
|
'privacy_policy_url' => config('auth.privacy_policy_url'),
|
||||||
'newsletter_consent' => config('auth.newsletter_consent'),
|
'newsletter_consent' => config('auth.newsletter_consent'),
|
||||||
|
|||||||
@@ -33,8 +33,8 @@ class RouteServiceProvider extends ServiceProvider
|
|||||||
}
|
}
|
||||||
|
|
||||||
return $request->user()
|
return $request->user()
|
||||||
? Limit::perMinute(200)->by($request->user()->id)
|
? Limit::perMinute(config('app.api_rate_limit_authenticated_per_minute'))->by($request->user()->id)
|
||||||
: Limit::perMinute(60)->by($request->ip());
|
: Limit::perMinute(config('app.api_rate_limit_guest_per_minute'))->by($request->ip());
|
||||||
});
|
});
|
||||||
|
|
||||||
$this->routes(function (): void {
|
$this->routes(function (): void {
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace App\Service;
|
namespace App\Service;
|
||||||
|
|
||||||
|
use App\Enums\TimeEntryType;
|
||||||
use App\Enums\Weekday;
|
use App\Enums\Weekday;
|
||||||
use App\Models\Organization;
|
use App\Models\Organization;
|
||||||
use App\Models\Project;
|
use App\Models\Project;
|
||||||
@@ -154,6 +155,7 @@ class DashboardService
|
|||||||
->select(DB::raw('DATE('.$dateWithTimeZone.') as date, round(sum(extract(epoch from (coalesce("end", now()) - start)))) as aggregate'))
|
->select(DB::raw('DATE('.$dateWithTimeZone.') as date, round(sum(extract(epoch from (coalesce("end", now()) - start)))) as aggregate'))
|
||||||
->where('user_id', '=', $user->getKey())
|
->where('user_id', '=', $user->getKey())
|
||||||
->where('organization_id', '=', $organization->getKey())
|
->where('organization_id', '=', $organization->getKey())
|
||||||
|
->workTime()
|
||||||
->groupBy(DB::raw('DATE('.$dateWithTimeZone.')'))
|
->groupBy(DB::raw('DATE('.$dateWithTimeZone.')'))
|
||||||
->orderBy('date');
|
->orderBy('date');
|
||||||
|
|
||||||
@@ -195,6 +197,7 @@ class DashboardService
|
|||||||
->select(DB::raw('DATE('.$dateWithTimeZone.') as date, round(sum(extract(epoch from (coalesce("end", now()) - start)))) as aggregate'))
|
->select(DB::raw('DATE('.$dateWithTimeZone.') as date, round(sum(extract(epoch from (coalesce("end", now()) - start)))) as aggregate'))
|
||||||
->where('user_id', '=', $user->getKey())
|
->where('user_id', '=', $user->getKey())
|
||||||
->where('organization_id', '=', $organization->getKey())
|
->where('organization_id', '=', $organization->getKey())
|
||||||
|
->workTime()
|
||||||
->groupBy(DB::raw('DATE('.$dateWithTimeZone.')'))
|
->groupBy(DB::raw('DATE('.$dateWithTimeZone.')'))
|
||||||
->orderBy('date');
|
->orderBy('date');
|
||||||
|
|
||||||
@@ -222,7 +225,8 @@ class DashboardService
|
|||||||
$query = TimeEntry::query()
|
$query = TimeEntry::query()
|
||||||
->select(DB::raw('round(sum(extract(epoch from (coalesce("end", now()) - start)))) as aggregate'))
|
->select(DB::raw('round(sum(extract(epoch from (coalesce("end", now()) - start)))) as aggregate'))
|
||||||
->where('user_id', '=', $user->getKey())
|
->where('user_id', '=', $user->getKey())
|
||||||
->where('organization_id', '=', $organization->getKey());
|
->where('organization_id', '=', $organization->getKey())
|
||||||
|
->workTime();
|
||||||
|
|
||||||
$query = $this->constrainDateByPossibleDates($query, $possibleDays, $timezone);
|
$query = $this->constrainDateByPossibleDates($query, $possibleDays, $timezone);
|
||||||
/** @var Collection<int, object{aggregate: int}> $resultDb */
|
/** @var Collection<int, object{aggregate: int}> $resultDb */
|
||||||
@@ -290,6 +294,7 @@ class DashboardService
|
|||||||
->select(DB::raw('project_id, round(sum(extract(epoch from (coalesce("end", now()) - start)))) as aggregate'))
|
->select(DB::raw('project_id, round(sum(extract(epoch from (coalesce("end", now()) - start)))) as aggregate'))
|
||||||
->where('user_id', '=', $user->getKey())
|
->where('user_id', '=', $user->getKey())
|
||||||
->where('organization_id', '=', $organization->getKey())
|
->where('organization_id', '=', $organization->getKey())
|
||||||
|
->workTime()
|
||||||
->groupBy('project_id');
|
->groupBy('project_id');
|
||||||
|
|
||||||
$query = $this->constrainDateByCurrentWeek($query, $timezone, $user->week_start);
|
$query = $this->constrainDateByCurrentWeek($query, $timezone, $user->week_start);
|
||||||
@@ -433,7 +438,8 @@ class DashboardService
|
|||||||
JOIN time_entries ON time_entries.start < time_ranges."end"
|
JOIN time_entries ON time_entries.start < time_ranges."end"
|
||||||
AND coalesce(time_entries."end", :now::timestamp) > time_ranges.start
|
AND coalesce(time_entries."end", :now::timestamp) > time_ranges.start
|
||||||
WHERE time_entries.user_id = :user_id and
|
WHERE time_entries.user_id = :user_id and
|
||||||
time_entries.organization_id = :organization_id
|
time_entries.organization_id = :organization_id and
|
||||||
|
time_entries.type = :work_type
|
||||||
GROUP BY time_ranges.start
|
GROUP BY time_ranges.start
|
||||||
ORDER BY time_ranges.start
|
ORDER BY time_ranges.start
|
||||||
', [
|
', [
|
||||||
@@ -442,6 +448,7 @@ class DashboardService
|
|||||||
'user_id' => $user->getKey(),
|
'user_id' => $user->getKey(),
|
||||||
'organization_id' => $organization->getKey(),
|
'organization_id' => $organization->getKey(),
|
||||||
'now' => Carbon::now()->toDateTimeString(),
|
'now' => Carbon::now()->toDateTimeString(),
|
||||||
|
'work_type' => TimeEntryType::Work->value,
|
||||||
]))->pluck('aggregate', 'start');
|
]))->pluck('aggregate', 'start');
|
||||||
|
|
||||||
$response = [];
|
$response = [];
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ use App\Enums\TagMatchType;
|
|||||||
use App\Enums\TimeEntryAggregationType;
|
use App\Enums\TimeEntryAggregationType;
|
||||||
use App\Enums\TimeEntryAggregationTypeInterval;
|
use App\Enums\TimeEntryAggregationTypeInterval;
|
||||||
use App\Enums\TimeEntryRoundingType;
|
use App\Enums\TimeEntryRoundingType;
|
||||||
|
use App\Enums\TimeEntryType;
|
||||||
use App\Enums\Weekday;
|
use App\Enums\Weekday;
|
||||||
use App\Service\TimeEntryFilter;
|
use App\Service\TimeEntryFilter;
|
||||||
use Illuminate\Contracts\Database\Eloquent\Castable;
|
use Illuminate\Contracts\Database\Eloquent\Castable;
|
||||||
@@ -68,6 +69,8 @@ class ReportPropertiesDto implements Castable
|
|||||||
|
|
||||||
public ?int $roundingMinutes = null;
|
public ?int $roundingMinutes = null;
|
||||||
|
|
||||||
|
public ?TimeEntryType $timeEntryType = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the caster class to use when casting from / to this cast target.
|
* Get the caster class to use when casting from / to this cast target.
|
||||||
*
|
*
|
||||||
@@ -129,6 +132,12 @@ class ReportPropertiesDto implements Castable
|
|||||||
$dto->roundingType = isset($data->roundingType) ? TimeEntryRoundingType::from($data->roundingType) : null;
|
$dto->roundingType = isset($data->roundingType) ? TimeEntryRoundingType::from($data->roundingType) : null;
|
||||||
// Note: roundingMinutes was added later so it is possible that the value is missing in persisted reports in the DB
|
// Note: roundingMinutes was added later so it is possible that the value is missing in persisted reports in the DB
|
||||||
$dto->roundingMinutes = isset($data->roundingMinutes) ? (int) $data->roundingMinutes : null;
|
$dto->roundingMinutes = isset($data->roundingMinutes) ? (int) $data->roundingMinutes : null;
|
||||||
|
// Note: timeEntryType was added later, reports persisted before that are missing the value and default to "work"
|
||||||
|
if (property_exists($data, 'timeEntryType')) {
|
||||||
|
$dto->timeEntryType = $data->timeEntryType !== null ? TimeEntryType::from($data->timeEntryType) : null;
|
||||||
|
} else {
|
||||||
|
$dto->timeEntryType = TimeEntryType::Work;
|
||||||
|
}
|
||||||
|
|
||||||
return $dto;
|
return $dto;
|
||||||
}
|
}
|
||||||
@@ -157,6 +166,7 @@ class ReportPropertiesDto implements Castable
|
|||||||
'timezone' => $value->timezone,
|
'timezone' => $value->timezone,
|
||||||
'roundingType' => $value->roundingType?->value,
|
'roundingType' => $value->roundingType?->value,
|
||||||
'roundingMinutes' => $value->roundingMinutes,
|
'roundingMinutes' => $value->roundingMinutes,
|
||||||
|
'timeEntryType' => $value->timeEntryType?->value,
|
||||||
];
|
];
|
||||||
|
|
||||||
$jsonString = json_encode($data);
|
$jsonString = json_encode($data);
|
||||||
|
|||||||
@@ -107,6 +107,7 @@ class ExportService
|
|||||||
'end',
|
'end',
|
||||||
'billable_rate',
|
'billable_rate',
|
||||||
'billable',
|
'billable',
|
||||||
|
'type',
|
||||||
'member_id',
|
'member_id',
|
||||||
'user_id',
|
'user_id',
|
||||||
'organization_id',
|
'organization_id',
|
||||||
@@ -131,6 +132,7 @@ class ExportService
|
|||||||
$timeEntry->end?->toIso8601ZuluString() ?? '',
|
$timeEntry->end?->toIso8601ZuluString() ?? '',
|
||||||
$timeEntry->billable_rate ?? '',
|
$timeEntry->billable_rate ?? '',
|
||||||
$timeEntry->billable ? 'true' : 'false',
|
$timeEntry->billable ? 'true' : 'false',
|
||||||
|
$timeEntry->type->value,
|
||||||
$timeEntry->member_id,
|
$timeEntry->member_id,
|
||||||
$timeEntry->user_id,
|
$timeEntry->user_id,
|
||||||
$timeEntry->organization_id,
|
$timeEntry->organization_id,
|
||||||
|
|||||||
@@ -9,11 +9,8 @@ use App\Service\Import\Importers\ImporterContract;
|
|||||||
use App\Service\Import\Importers\ImporterProvider;
|
use App\Service\Import\Importers\ImporterProvider;
|
||||||
use App\Service\Import\Importers\ImportException;
|
use App\Service\Import\Importers\ImportException;
|
||||||
use App\Service\Import\Importers\ReportDto;
|
use App\Service\Import\Importers\ReportDto;
|
||||||
use Illuminate\Support\Carbon;
|
|
||||||
use Illuminate\Support\Facades\Cache;
|
use Illuminate\Support\Facades\Cache;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
use Illuminate\Support\Facades\Storage;
|
|
||||||
use Illuminate\Support\Str;
|
|
||||||
|
|
||||||
class ImportService
|
class ImportService
|
||||||
{
|
{
|
||||||
@@ -25,8 +22,6 @@ class ImportService
|
|||||||
/** @var ImporterContract $importer */
|
/** @var ImporterContract $importer */
|
||||||
$importer = app(ImporterProvider::class)->getImporter($importerType);
|
$importer = app(ImporterProvider::class)->getImporter($importerType);
|
||||||
$importer->init($organization);
|
$importer->init($organization);
|
||||||
Storage::disk(config('filesystems.default'))
|
|
||||||
->put('import/'.Carbon::now()->toDateString().'-'.$organization->getKey().'-'.Str::uuid(), $data);
|
|
||||||
|
|
||||||
$lock = Cache::lock('import:'.$organization->getKey(), config('octane.max_execution_time', 60) + 1);
|
$lock = Cache::lock('import:'.$organization->getKey(), config('octane.max_execution_time', 60) + 1);
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ declare(strict_types=1);
|
|||||||
namespace App\Service\Import\Importers;
|
namespace App\Service\Import\Importers;
|
||||||
|
|
||||||
use App\Enums\Role;
|
use App\Enums\Role;
|
||||||
|
use App\Enums\TimeEntryType;
|
||||||
use App\Jobs\RecalculateSpentTimeForProject;
|
use App\Jobs\RecalculateSpentTimeForProject;
|
||||||
use App\Jobs\RecalculateSpentTimeForTask;
|
use App\Jobs\RecalculateSpentTimeForTask;
|
||||||
use App\Models\TimeEntry;
|
use App\Models\TimeEntry;
|
||||||
@@ -71,8 +72,12 @@ class ClockifyTimeEntriesImporter extends DefaultImporter
|
|||||||
'role' => Role::Placeholder->value,
|
'role' => Role::Placeholder->value,
|
||||||
]);
|
]);
|
||||||
$member = $this->memberImportHelper->getModelById($memberId);
|
$member = $this->memberImportHelper->getModelById($memberId);
|
||||||
|
// Clockify allows a project/task/client/tags/billable on breaks, but those are
|
||||||
|
// meaningless for non-work time. Detect breaks up front and skip creating any of
|
||||||
|
// that so a break can't spawn an orphan project/tag or inflate the import counts.
|
||||||
|
$isBreak = isset($record['Type']) && strtolower($record['Type']) === 'break';
|
||||||
$clientId = null;
|
$clientId = null;
|
||||||
if (($record['Client'] ?? '') !== '') {
|
if (! $isBreak && ($record['Client'] ?? '') !== '') {
|
||||||
$clientId = $this->clientImportHelper->getKey([
|
$clientId = $this->clientImportHelper->getKey([
|
||||||
'name' => $record['Client'],
|
'name' => $record['Client'],
|
||||||
'organization_id' => $this->organization->id,
|
'organization_id' => $this->organization->id,
|
||||||
@@ -81,7 +86,7 @@ class ClockifyTimeEntriesImporter extends DefaultImporter
|
|||||||
$projectId = null;
|
$projectId = null;
|
||||||
$project = null;
|
$project = null;
|
||||||
$projectMember = null;
|
$projectMember = null;
|
||||||
if ($record['Project'] !== '') {
|
if (! $isBreak && $record['Project'] !== '') {
|
||||||
$projectId = $this->projectImportHelper->getKey([
|
$projectId = $this->projectImportHelper->getKey([
|
||||||
'name' => $record['Project'],
|
'name' => $record['Project'],
|
||||||
'client_id' => $clientId,
|
'client_id' => $clientId,
|
||||||
@@ -97,7 +102,7 @@ class ClockifyTimeEntriesImporter extends DefaultImporter
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
$taskId = null;
|
$taskId = null;
|
||||||
if ($taskKey !== null && $record[$taskKey] !== '') {
|
if (! $isBreak && $taskKey !== null && $record[$taskKey] !== '') {
|
||||||
$taskId = $this->taskImportHelper->getKey([
|
$taskId = $this->taskImportHelper->getKey([
|
||||||
'name' => $record[$taskKey],
|
'name' => $record[$taskKey],
|
||||||
'project_id' => $projectId,
|
'project_id' => $projectId,
|
||||||
@@ -123,7 +128,12 @@ class ClockifyTimeEntriesImporter extends DefaultImporter
|
|||||||
}
|
}
|
||||||
$timeEntry->billable = $record['Billable'] === 'Yes';
|
$timeEntry->billable = $record['Billable'] === 'Yes';
|
||||||
}
|
}
|
||||||
$timeEntry->tags = $this->getTags($record['Tags']);
|
if ($isBreak) {
|
||||||
|
// Breaks can not be billable or belong to a project/task (already skipped above)
|
||||||
|
$timeEntry->type = TimeEntryType::Break;
|
||||||
|
$timeEntry->billable = false;
|
||||||
|
}
|
||||||
|
$timeEntry->tags = $isBreak ? [] : $this->getTags($record['Tags']);
|
||||||
$timeEntry->is_imported = true;
|
$timeEntry->is_imported = true;
|
||||||
|
|
||||||
// Start
|
// Start
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ declare(strict_types=1);
|
|||||||
namespace App\Service\Import\Importers;
|
namespace App\Service\Import\Importers;
|
||||||
|
|
||||||
use App\Enums\Role;
|
use App\Enums\Role;
|
||||||
|
use App\Enums\TimeEntryType;
|
||||||
use App\Jobs\RecalculateSpentTimeForProject;
|
use App\Jobs\RecalculateSpentTimeForProject;
|
||||||
use App\Jobs\RecalculateSpentTimeForTask;
|
use App\Jobs\RecalculateSpentTimeForTask;
|
||||||
use App\Models\TimeEntry;
|
use App\Models\TimeEntry;
|
||||||
@@ -15,7 +16,6 @@ use Illuminate\Support\Str;
|
|||||||
use League\Csv\Reader;
|
use League\Csv\Reader;
|
||||||
use Override;
|
use Override;
|
||||||
use Spatie\TemporaryDirectory\TemporaryDirectory;
|
use Spatie\TemporaryDirectory\TemporaryDirectory;
|
||||||
use ZipArchive;
|
|
||||||
|
|
||||||
class SolidtimeImporter extends DefaultImporter
|
class SolidtimeImporter extends DefaultImporter
|
||||||
{
|
{
|
||||||
@@ -33,16 +33,10 @@ class SolidtimeImporter extends DefaultImporter
|
|||||||
$temporaryDirectoryZip = null;
|
$temporaryDirectoryZip = null;
|
||||||
$temporaryDirectory = null;
|
$temporaryDirectory = null;
|
||||||
try {
|
try {
|
||||||
$zip = new ZipArchive;
|
|
||||||
$temporaryDirectoryZip = TemporaryDirectory::make();
|
$temporaryDirectoryZip = TemporaryDirectory::make();
|
||||||
file_put_contents($temporaryDirectoryZip->path('import.zip'), $data);
|
file_put_contents($temporaryDirectoryZip->path('import.zip'), $data);
|
||||||
$res = $zip->open($temporaryDirectoryZip->path('import.zip'), ZipArchive::RDONLY);
|
|
||||||
if ($res !== true) {
|
|
||||||
throw new ImportException('Invalid ZIP, error code: '.$res);
|
|
||||||
}
|
|
||||||
$temporaryDirectory = TemporaryDirectory::make();
|
$temporaryDirectory = TemporaryDirectory::make();
|
||||||
$zip->extractTo($temporaryDirectory->path());
|
app(ZipImportHelper::class)->extract($temporaryDirectoryZip->path('import.zip'), $temporaryDirectory->path());
|
||||||
$zip->close();
|
|
||||||
|
|
||||||
if (! file_exists($temporaryDirectory->path('meta.json'))) {
|
if (! file_exists($temporaryDirectory->path('meta.json'))) {
|
||||||
throw new ImportException('File "meta.json" missing in ZIP');
|
throw new ImportException('File "meta.json" missing in ZIP');
|
||||||
@@ -255,6 +249,14 @@ class SolidtimeImporter extends DefaultImporter
|
|||||||
throw new ImportException('Invalid billable value');
|
throw new ImportException('Invalid billable value');
|
||||||
}
|
}
|
||||||
$timeEntry->billable = $timeEntryRow['billable'] === 'true';
|
$timeEntry->billable = $timeEntryRow['billable'] === 'true';
|
||||||
|
// The type column does not exist in old exports
|
||||||
|
if (($timeEntryRow['type'] ?? '') !== '') {
|
||||||
|
$type = TimeEntryType::tryFrom($timeEntryRow['type']);
|
||||||
|
if ($type === null) {
|
||||||
|
throw new ImportException('Invalid type value');
|
||||||
|
}
|
||||||
|
$timeEntry->type = $type;
|
||||||
|
}
|
||||||
$timeEntry->tags = $this->getTags($timeEntryRow['tags']);
|
$timeEntry->tags = $this->getTags($timeEntryRow['tags']);
|
||||||
$timeEntry->is_imported = true;
|
$timeEntry->is_imported = true;
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ use Illuminate\Support\Str;
|
|||||||
use Override;
|
use Override;
|
||||||
use Spatie\TemporaryDirectory\TemporaryDirectory;
|
use Spatie\TemporaryDirectory\TemporaryDirectory;
|
||||||
use ValueError;
|
use ValueError;
|
||||||
use ZipArchive;
|
|
||||||
|
|
||||||
class TogglDataImporter extends DefaultImporter
|
class TogglDataImporter extends DefaultImporter
|
||||||
{
|
{
|
||||||
@@ -26,16 +25,10 @@ class TogglDataImporter extends DefaultImporter
|
|||||||
$temporaryDirectoryZip = null;
|
$temporaryDirectoryZip = null;
|
||||||
$temporaryDirectory = null;
|
$temporaryDirectory = null;
|
||||||
try {
|
try {
|
||||||
$zip = new ZipArchive;
|
|
||||||
$temporaryDirectoryZip = TemporaryDirectory::make();
|
$temporaryDirectoryZip = TemporaryDirectory::make();
|
||||||
file_put_contents($temporaryDirectoryZip->path('import.zip'), $data);
|
file_put_contents($temporaryDirectoryZip->path('import.zip'), $data);
|
||||||
$res = $zip->open($temporaryDirectoryZip->path('import.zip'), ZipArchive::RDONLY);
|
|
||||||
if ($res !== true) {
|
|
||||||
throw new ImportException('Invalid ZIP, error code: '.$res);
|
|
||||||
}
|
|
||||||
$temporaryDirectory = TemporaryDirectory::make();
|
$temporaryDirectory = TemporaryDirectory::make();
|
||||||
$zip->extractTo($temporaryDirectory->path());
|
app(ZipImportHelper::class)->extract($temporaryDirectoryZip->path('import.zip'), $temporaryDirectory->path());
|
||||||
$zip->close();
|
|
||||||
if (! file_exists($temporaryDirectory->path('clients.json'))) {
|
if (! file_exists($temporaryDirectory->path('clients.json'))) {
|
||||||
throw new ImportException('File "clients.json" missing in ZIP');
|
throw new ImportException('File "clients.json" missing in ZIP');
|
||||||
}
|
}
|
||||||
|
|||||||
129
app/Service/Import/Importers/ZipImportHelper.php
Normal file
129
app/Service/Import/Importers/ZipImportHelper.php
Normal file
@@ -0,0 +1,129 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Service\Import\Importers;
|
||||||
|
|
||||||
|
use ZipArchive;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extracts uploaded ZIP archives with limits on file count, total uncompressed
|
||||||
|
* size and entry paths, so a small malicious archive can not fill the disk
|
||||||
|
* (decompression bomb) or write outside the target directory (zip slip).
|
||||||
|
*/
|
||||||
|
class ZipImportHelper
|
||||||
|
{
|
||||||
|
private const int CHUNK_SIZE = 1024 * 1024;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws ImportException
|
||||||
|
*/
|
||||||
|
public function extract(string $zipPath, string $targetPath): void
|
||||||
|
{
|
||||||
|
$zip = new ZipArchive;
|
||||||
|
$res = $zip->open($zipPath, ZipArchive::RDONLY);
|
||||||
|
if ($res !== true) {
|
||||||
|
throw new ImportException('Invalid ZIP, error code: '.$res);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$maxFiles = (int) config('import.zip_max_files');
|
||||||
|
$maxUncompressedSize = (int) config('import.zip_max_uncompressed_size');
|
||||||
|
|
||||||
|
if ($zip->numFiles > $maxFiles) {
|
||||||
|
throw new ImportException('ZIP contains too many files, maximum is '.$maxFiles);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check the sizes declared in the archive before writing anything to disk
|
||||||
|
$declaredSize = 0;
|
||||||
|
for ($index = 0; $index < $zip->numFiles; $index++) {
|
||||||
|
$stat = $zip->statIndex($index);
|
||||||
|
if ($stat === false) {
|
||||||
|
throw new ImportException('Invalid ZIP entry');
|
||||||
|
}
|
||||||
|
$this->validateEntryName($stat['name']);
|
||||||
|
$declaredSize += $stat['size'];
|
||||||
|
if ($declaredSize > $maxUncompressedSize) {
|
||||||
|
throw new ImportException('ZIP uncompressed size exceeds the maximum of '.$maxUncompressedSize.' bytes');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// The declared sizes can be forged, so the written bytes are counted as well
|
||||||
|
$writtenSize = 0;
|
||||||
|
for ($index = 0; $index < $zip->numFiles; $index++) {
|
||||||
|
$stat = $zip->statIndex($index);
|
||||||
|
if ($stat === false) {
|
||||||
|
throw new ImportException('Invalid ZIP entry');
|
||||||
|
}
|
||||||
|
$name = $stat['name'];
|
||||||
|
$entryPath = $targetPath.DIRECTORY_SEPARATOR.$name;
|
||||||
|
|
||||||
|
if (str_ends_with($name, '/')) {
|
||||||
|
$this->ensureDirectoryExists($entryPath);
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$this->ensureDirectoryExists(dirname($entryPath));
|
||||||
|
|
||||||
|
$stream = $zip->getStreamIndex($index);
|
||||||
|
if ($stream === false) {
|
||||||
|
throw new ImportException('ZIP entry "'.$name.'" can not be read');
|
||||||
|
}
|
||||||
|
$target = fopen($entryPath, 'wb');
|
||||||
|
if ($target === false) {
|
||||||
|
fclose($stream);
|
||||||
|
throw new ImportException('ZIP entry "'.$name.'" can not be extracted');
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
while (! feof($stream)) {
|
||||||
|
$chunk = fread($stream, self::CHUNK_SIZE);
|
||||||
|
if ($chunk === false) {
|
||||||
|
throw new ImportException('ZIP entry "'.$name.'" can not be read');
|
||||||
|
}
|
||||||
|
$writtenSize += strlen($chunk);
|
||||||
|
if ($writtenSize > $maxUncompressedSize) {
|
||||||
|
throw new ImportException('ZIP uncompressed size exceeds the maximum of '.$maxUncompressedSize.' bytes');
|
||||||
|
}
|
||||||
|
fwrite($target, $chunk);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
fclose($target);
|
||||||
|
fclose($stream);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
$zip->close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws ImportException
|
||||||
|
*/
|
||||||
|
private function validateEntryName(string $name): void
|
||||||
|
{
|
||||||
|
if ($name === '' || str_contains($name, "\0") || str_contains($name, '\\') || str_starts_with($name, '/')) {
|
||||||
|
throw new ImportException('ZIP contains an invalid file path: "'.$name.'"');
|
||||||
|
}
|
||||||
|
if (preg_match('/^[a-zA-Z]:/', $name) === 1) {
|
||||||
|
throw new ImportException('ZIP contains an invalid file path: "'.$name.'"');
|
||||||
|
}
|
||||||
|
foreach (explode('/', rtrim($name, '/')) as $segment) {
|
||||||
|
if ($segment === '' || $segment === '..') {
|
||||||
|
throw new ImportException('ZIP contains an invalid file path: "'.$name.'"');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws ImportException
|
||||||
|
*/
|
||||||
|
private function ensureDirectoryExists(string $path): void
|
||||||
|
{
|
||||||
|
if (is_dir($path)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (! mkdir($path, 0700, true) && ! is_dir($path)) {
|
||||||
|
throw new ImportException('Directory "'.$path.'" can not be created');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -18,11 +18,31 @@ use Illuminate\Support\Facades\Mail;
|
|||||||
|
|
||||||
class InvitationService
|
class InvitationService
|
||||||
{
|
{
|
||||||
|
public function hasAcceptedInvitationForEmail(string $email): bool
|
||||||
|
{
|
||||||
|
return OrganizationInvitation::query()
|
||||||
|
->whereRaw('lower(email) = ?', [strtolower($email)])
|
||||||
|
->whereNotNull('accepted_at')
|
||||||
|
->exists();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function hasPendingInvitationForEmail(string $email): bool
|
||||||
|
{
|
||||||
|
return OrganizationInvitation::query()
|
||||||
|
->whereRaw('lower(email) = ?', [strtolower($email)])
|
||||||
|
->whereNull('accepted_at')
|
||||||
|
->exists();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws UserIsAlreadyMemberOfOrganizationApiException|InvitationForTheEmailAlreadyExistsApiException
|
* @throws UserIsAlreadyMemberOfOrganizationApiException|InvitationForTheEmailAlreadyExistsApiException
|
||||||
*/
|
*/
|
||||||
public function inviteUser(Organization $organization, string $email, Role $role, User $inviter): OrganizationInvitation
|
public function inviteUser(Organization $organization, string $email, Role $role, User $inviter): OrganizationInvitation
|
||||||
{
|
{
|
||||||
|
// Normalize the email so it matches how user emails are stored (see UserService::createUser),
|
||||||
|
// otherwise a mixed-case invite silently fails to link on registration.
|
||||||
|
$email = strtolower($email);
|
||||||
|
|
||||||
if (app(MemberService::class)->isEmailAlreadyMember($organization, $email)) {
|
if (app(MemberService::class)->isEmailAlreadyMember($organization, $email)) {
|
||||||
throw new UserIsAlreadyMemberOfOrganizationApiException;
|
throw new UserIsAlreadyMemberOfOrganizationApiException;
|
||||||
}
|
}
|
||||||
@@ -55,7 +75,7 @@ class InvitationService
|
|||||||
$organizations = new Collection;
|
$organizations = new Collection;
|
||||||
|
|
||||||
$invitations = OrganizationInvitation::query()
|
$invitations = OrganizationInvitation::query()
|
||||||
->where('email', $user->email)
|
->whereRaw('lower(email) = ?', [strtolower($user->email)])
|
||||||
->whereNotNull('accepted_at')
|
->whereNotNull('accepted_at')
|
||||||
->get();
|
->get();
|
||||||
|
|
||||||
|
|||||||
@@ -8,12 +8,14 @@ use App\Enums\CurrencyFormat;
|
|||||||
use App\Enums\DateFormat;
|
use App\Enums\DateFormat;
|
||||||
use App\Enums\IntervalFormat;
|
use App\Enums\IntervalFormat;
|
||||||
use App\Enums\NumberFormat;
|
use App\Enums\NumberFormat;
|
||||||
|
use App\Enums\TimeEntryAggregationType;
|
||||||
use App\Enums\TimeFormat;
|
use App\Enums\TimeFormat;
|
||||||
use App\Models\Organization;
|
use App\Models\Organization;
|
||||||
use Brick\Math\BigDecimal;
|
use Brick\Math\BigDecimal;
|
||||||
use Brick\Money\Money;
|
use Brick\Money\Money;
|
||||||
use Carbon\CarbonInterface;
|
use Carbon\CarbonInterface;
|
||||||
use Carbon\CarbonInterval;
|
use Carbon\CarbonInterval;
|
||||||
|
use Illuminate\Support\Carbon;
|
||||||
|
|
||||||
class LocalizationService
|
class LocalizationService
|
||||||
{
|
{
|
||||||
@@ -152,6 +154,38 @@ class LocalizationService
|
|||||||
return $date->format($this->dateFormat->toCarbonFormat());
|
return $date->format($this->dateFormat->toCarbonFormat());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Time group types have no server-side descriptor; their keys are ISO dates and are
|
||||||
|
* formatted here instead. A Week key is the first day of that week, so it renders as the
|
||||||
|
* range it covers. A Year key is already a bare year, so it is returned unchanged - it must
|
||||||
|
* not be parsed, Carbon reads a four digit string as a time of day.
|
||||||
|
*/
|
||||||
|
public function formatTimeGroupKey(?string $key, TimeEntryAggregationType $groupType): ?string
|
||||||
|
{
|
||||||
|
if ($key === null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($groupType === TimeEntryAggregationType::Day) {
|
||||||
|
return $this->formatDate(Carbon::parse($key));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($groupType === TimeEntryAggregationType::Week) {
|
||||||
|
$weekStart = Carbon::parse($key);
|
||||||
|
|
||||||
|
return $this->formatDate($weekStart).' - '.$this->formatDate($weekStart->copy()->addDays(6));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($groupType === TimeEntryAggregationType::Month) {
|
||||||
|
// Note: the leading "!" resets all fields the format does not name. Without it the
|
||||||
|
// day of the month is taken from today, and a day that the parsed month does not
|
||||||
|
// have overflows the date into the next month.
|
||||||
|
return Carbon::createFromFormat('!Y-m', $key)->format('F Y');
|
||||||
|
}
|
||||||
|
|
||||||
|
return $key;
|
||||||
|
}
|
||||||
|
|
||||||
public function setDateFormat(DateFormat $dateFormat): void
|
public function setDateFormat(DateFormat $dateFormat): void
|
||||||
{
|
{
|
||||||
$this->dateFormat = $dateFormat;
|
$this->dateFormat = $dateFormat;
|
||||||
|
|||||||
@@ -218,7 +218,16 @@ class MemberService
|
|||||||
|
|
||||||
$placeholderUser = $user->replicate();
|
$placeholderUser = $user->replicate();
|
||||||
$placeholderUser->is_placeholder = true;
|
$placeholderUser->is_placeholder = true;
|
||||||
$placeholderUser->current_team_id = $member->organization_id;
|
// Reset authentication relevant properties on the placeholder user
|
||||||
|
$placeholderUser->password = null;
|
||||||
|
$placeholderUser->remember_token = null;
|
||||||
|
$placeholderUser->two_factor_secret = null;
|
||||||
|
$placeholderUser->two_factor_recovery_codes = null;
|
||||||
|
$placeholderUser->two_factor_confirmed_at = null;
|
||||||
|
$placeholderUser->email_verified_at = null;
|
||||||
|
$placeholderUser->pending_email = null;
|
||||||
|
$placeholderUser->current_team_id = null;
|
||||||
|
$placeholderUser->profile_photo_path = null;
|
||||||
$placeholderUser->save();
|
$placeholderUser->save();
|
||||||
|
|
||||||
$member->user()->associate($placeholderUser);
|
$member->user()->associate($placeholderUser);
|
||||||
|
|||||||
@@ -80,6 +80,10 @@ class PermissionStore
|
|||||||
'invoices:update',
|
'invoices:update',
|
||||||
'invoices:download',
|
'invoices:download',
|
||||||
'invoices:delete',
|
'invoices:delete',
|
||||||
|
'invoice-recipients:view',
|
||||||
|
'invoice-recipients:create',
|
||||||
|
'invoice-recipients:update',
|
||||||
|
'invoice-recipients:delete',
|
||||||
'invoice-settings:view',
|
'invoice-settings:view',
|
||||||
'invoice-settings:update',
|
'invoice-settings:update',
|
||||||
],
|
],
|
||||||
@@ -147,6 +151,10 @@ class PermissionStore
|
|||||||
'invoices:update',
|
'invoices:update',
|
||||||
'invoices:download',
|
'invoices:download',
|
||||||
'invoices:delete',
|
'invoices:delete',
|
||||||
|
'invoice-recipients:view',
|
||||||
|
'invoice-recipients:create',
|
||||||
|
'invoice-recipients:update',
|
||||||
|
'invoice-recipients:delete',
|
||||||
'invoice-settings:view',
|
'invoice-settings:view',
|
||||||
'invoice-settings:update',
|
'invoice-settings:update',
|
||||||
],
|
],
|
||||||
@@ -203,6 +211,10 @@ class PermissionStore
|
|||||||
'invoices:update',
|
'invoices:update',
|
||||||
'invoices:download',
|
'invoices:download',
|
||||||
'invoices:delete',
|
'invoices:delete',
|
||||||
|
'invoice-recipients:view',
|
||||||
|
'invoice-recipients:create',
|
||||||
|
'invoice-recipients:update',
|
||||||
|
'invoice-recipients:delete',
|
||||||
'invoice-settings:view',
|
'invoice-settings:view',
|
||||||
'invoice-settings:update',
|
'invoice-settings:update',
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace App\Service\ReportExport;
|
namespace App\Service\ReportExport;
|
||||||
|
|
||||||
|
use App\Enums\TimeEntryType;
|
||||||
use App\Models\TimeEntry;
|
use App\Models\TimeEntry;
|
||||||
use App\Service\IntervalService;
|
use App\Service\IntervalService;
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
@@ -25,6 +26,7 @@ class TimeEntriesDetailedCsvExport extends CsvExport
|
|||||||
'Duration',
|
'Duration',
|
||||||
'Duration (decimal)',
|
'Duration (decimal)',
|
||||||
'Billable',
|
'Billable',
|
||||||
|
'Break',
|
||||||
'Tags',
|
'Tags',
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -58,6 +60,7 @@ class TimeEntriesDetailedCsvExport extends CsvExport
|
|||||||
'Duration' => $duration !== null ? $interval->format($model->getDuration()) : null,
|
'Duration' => $duration !== null ? $interval->format($model->getDuration()) : null,
|
||||||
'Duration (decimal)' => $duration?->totalHours,
|
'Duration (decimal)' => $duration?->totalHours,
|
||||||
'Billable' => $model->billable ? 'Yes' : 'No',
|
'Billable' => $model->billable ? 'Yes' : 'No',
|
||||||
|
'Break' => $model->type === TimeEntryType::Break ? 'Yes' : 'No',
|
||||||
'Tags' => $model->tagsRelation->pluck('name')->implode(', '),
|
'Tags' => $model->tagsRelation->pluck('name')->implode(', '),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ declare(strict_types=1);
|
|||||||
namespace App\Service\ReportExport;
|
namespace App\Service\ReportExport;
|
||||||
|
|
||||||
use App\Enums\ExportFormat;
|
use App\Enums\ExportFormat;
|
||||||
|
use App\Enums\TimeEntryType;
|
||||||
use App\Models\TimeEntry;
|
use App\Models\TimeEntry;
|
||||||
use App\Service\LocalizationService;
|
use App\Service\LocalizationService;
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
@@ -106,6 +107,7 @@ class TimeEntriesDetailedExport implements FromQuery, ShouldAutoSize, WithColumn
|
|||||||
'Duration',
|
'Duration',
|
||||||
'Duration (decimal)',
|
'Duration (decimal)',
|
||||||
'Billable',
|
'Billable',
|
||||||
|
'Break',
|
||||||
'Tags',
|
'Tags',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@@ -130,6 +132,7 @@ class TimeEntriesDetailedExport implements FromQuery, ShouldAutoSize, WithColumn
|
|||||||
$duration !== null ? $this->localizationService->formatInterval($duration) : null,
|
$duration !== null ? $this->localizationService->formatInterval($duration) : null,
|
||||||
$duration?->totalHours,
|
$duration?->totalHours,
|
||||||
$model->billable ? 'Yes' : 'No',
|
$model->billable ? 'Yes' : 'No',
|
||||||
|
$model->type === TimeEntryType::Break ? 'Yes' : 'No',
|
||||||
$model->tagsRelation->pluck('name')->implode(', '),
|
$model->tagsRelation->pluck('name')->implode(', '),
|
||||||
];
|
];
|
||||||
} elseif ($this->exportFormat === ExportFormat::ODS) {
|
} elseif ($this->exportFormat === ExportFormat::ODS) {
|
||||||
@@ -144,6 +147,7 @@ class TimeEntriesDetailedExport implements FromQuery, ShouldAutoSize, WithColumn
|
|||||||
$duration !== null ? $this->localizationService->formatInterval($duration) : null,
|
$duration !== null ? $this->localizationService->formatInterval($duration) : null,
|
||||||
$duration?->totalHours,
|
$duration?->totalHours,
|
||||||
$model->billable ? 'Yes' : 'No',
|
$model->billable ? 'Yes' : 'No',
|
||||||
|
$model->type === TimeEntryType::Break ? 'Yes' : 'No',
|
||||||
$model->tagsRelation->pluck('name')->implode(', '),
|
$model->tagsRelation->pluck('name')->implode(', '),
|
||||||
];
|
];
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ namespace App\Service\ReportExport;
|
|||||||
|
|
||||||
use App\Enums\ExportFormat;
|
use App\Enums\ExportFormat;
|
||||||
use App\Enums\TimeEntryAggregationType;
|
use App\Enums\TimeEntryAggregationType;
|
||||||
|
use App\Service\LocalizationService;
|
||||||
use Illuminate\View\View;
|
use Illuminate\View\View;
|
||||||
use Maatwebsite\Excel\Concerns\Exportable;
|
use Maatwebsite\Excel\Concerns\Exportable;
|
||||||
use Maatwebsite\Excel\Concerns\FromView;
|
use Maatwebsite\Excel\Concerns\FromView;
|
||||||
@@ -48,6 +49,8 @@ class TimeEntriesReportExport implements FromView, ShouldAutoSize, WithCustomCsv
|
|||||||
|
|
||||||
private bool $showBillableRate;
|
private bool $showBillableRate;
|
||||||
|
|
||||||
|
private LocalizationService $localization;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array{
|
* @param array{
|
||||||
* grouped_type: string|null,
|
* grouped_type: string|null,
|
||||||
@@ -68,7 +71,7 @@ class TimeEntriesReportExport implements FromView, ShouldAutoSize, WithCustomCsv
|
|||||||
* cost: int|null
|
* cost: int|null
|
||||||
* } $data
|
* } $data
|
||||||
*/
|
*/
|
||||||
public function __construct(array $data, ExportFormat $exportFormat, string $currency, TimeEntryAggregationType $group, TimeEntryAggregationType $subGroup, bool $showBillableRate)
|
public function __construct(array $data, ExportFormat $exportFormat, string $currency, TimeEntryAggregationType $group, TimeEntryAggregationType $subGroup, bool $showBillableRate, LocalizationService $localization)
|
||||||
{
|
{
|
||||||
$this->data = $data;
|
$this->data = $data;
|
||||||
$this->exportFormat = $exportFormat;
|
$this->exportFormat = $exportFormat;
|
||||||
@@ -76,6 +79,7 @@ class TimeEntriesReportExport implements FromView, ShouldAutoSize, WithCustomCsv
|
|||||||
$this->group = $group;
|
$this->group = $group;
|
||||||
$this->subGroup = $subGroup;
|
$this->subGroup = $subGroup;
|
||||||
$this->showBillableRate = $showBillableRate;
|
$this->showBillableRate = $showBillableRate;
|
||||||
|
$this->localization = $localization;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function view(): View
|
public function view(): View
|
||||||
@@ -87,6 +91,7 @@ class TimeEntriesReportExport implements FromView, ShouldAutoSize, WithCustomCsv
|
|||||||
'subGroup' => $this->subGroup,
|
'subGroup' => $this->subGroup,
|
||||||
'exportFormat' => $this->exportFormat,
|
'exportFormat' => $this->exportFormat,
|
||||||
'showBillableRate' => $this->showBillableRate,
|
'showBillableRate' => $this->showBillableRate,
|
||||||
|
'localization' => $this->localization,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -353,6 +353,13 @@ class TimeEntryAggregationService
|
|||||||
'color' => null,
|
'color' => null,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
} elseif ($type === TimeEntryAggregationType::Type) {
|
||||||
|
foreach ($keys as $key) {
|
||||||
|
$descriptorMap[$key] = [
|
||||||
|
'description' => $key === 'break' ? 'Break' : 'Work time',
|
||||||
|
'color' => null,
|
||||||
|
];
|
||||||
|
}
|
||||||
} elseif ($type === TimeEntryAggregationType::Tag) {
|
} elseif ($type === TimeEntryAggregationType::Tag) {
|
||||||
$tags = Tag::query()
|
$tags = Tag::query()
|
||||||
->whereIn('id', $keys)
|
->whereIn('id', $keys)
|
||||||
@@ -504,6 +511,8 @@ class TimeEntryAggregationService
|
|||||||
return 'client_id';
|
return 'client_id';
|
||||||
} elseif ($group === TimeEntryAggregationType::Billable) {
|
} elseif ($group === TimeEntryAggregationType::Billable) {
|
||||||
return 'billable';
|
return 'billable';
|
||||||
|
} elseif ($group === TimeEntryAggregationType::Type) {
|
||||||
|
return 'type';
|
||||||
} elseif ($group === TimeEntryAggregationType::Description) {
|
} elseif ($group === TimeEntryAggregationType::Description) {
|
||||||
return 'description';
|
return 'description';
|
||||||
} elseif ($group === TimeEntryAggregationType::Tag) {
|
} elseif ($group === TimeEntryAggregationType::Tag) {
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ declare(strict_types=1);
|
|||||||
namespace App\Service;
|
namespace App\Service;
|
||||||
|
|
||||||
use App\Enums\TagMatchType;
|
use App\Enums\TagMatchType;
|
||||||
|
use App\Enums\TimeEntryType;
|
||||||
use App\Models\Member;
|
use App\Models\Member;
|
||||||
use App\Models\TimeEntry;
|
use App\Models\TimeEntry;
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
@@ -144,6 +145,32 @@ class TimeEntryFilter
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function addTypeFilter(?string $type): self
|
||||||
|
{
|
||||||
|
if ($type === null) {
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
$typeEnum = TimeEntryType::tryFrom($type);
|
||||||
|
if ($typeEnum === null) {
|
||||||
|
Log::warning('Invalid type filter value', ['value' => $type]);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
$this->addType($typeEnum);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addType(?TimeEntryType $type): self
|
||||||
|
{
|
||||||
|
if ($type === null) {
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
$this->builder->where('type', '=', $type->value);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array<string>|null $clientIds
|
* @param array<string>|null $clientIds
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -75,11 +75,32 @@ return [
|
|||||||
|
|
||||||
'url' => env('APP_URL', 'http://localhost'),
|
'url' => env('APP_URL', 'http://localhost'),
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Trusted Hosts
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Additional hostnames (besides the APP_URL host and its subdomains) that
|
||||||
|
| the application is allowed to respond on. This is needed for multi-host
|
||||||
|
| setups, e.g. reaching the instance over both a public domain and a
|
||||||
|
| Tailscale name. A request arriving on any host that is neither APP_URL
|
||||||
|
| (nor a subdomain of it) nor listed here is rejected, which prevents
|
||||||
|
| Host-header poisoning of password reset and other out-of-band links.
|
||||||
|
|
|
||||||
|
| See App\Http\Middleware\TrustHosts.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'trusted_hosts' => array_values(array_filter(array_map(
|
||||||
|
'trim',
|
||||||
|
explode(',', (string) env('TRUSTED_HOSTS', ''))
|
||||||
|
))),
|
||||||
|
|
||||||
'asset_url' => env('ASSET_URL'),
|
'asset_url' => env('ASSET_URL'),
|
||||||
|
|
||||||
'force_https' => (bool) env('APP_FORCE_HTTPS', false),
|
'force_https' => (bool) env('APP_FORCE_HTTPS', false),
|
||||||
|
|
||||||
'enable_registration' => (bool) env('APP_ENABLE_REGISTRATION', false),
|
'enable_registration' => env('APP_ENABLE_REGISTRATION', 'off'),
|
||||||
|
|
||||||
'local_email_verification' => (bool) env('APP_LOCAL_EMAIL_VERIFICATION', false),
|
'local_email_verification' => (bool) env('APP_LOCAL_EMAIL_VERIFICATION', false),
|
||||||
|
|
||||||
@@ -137,6 +158,21 @@ return [
|
|||||||
|
|
||||||
'pagination_per_page_default' => (int) env('PAGINATION_PER_PAGE_DEFAULT', 15),
|
'pagination_per_page_default' => (int) env('PAGINATION_PER_PAGE_DEFAULT', 15),
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| API Rate Limiting
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| The number of API requests allowed per minute, counted per user for
|
||||||
|
| authenticated requests and per IP address for guest requests. These
|
||||||
|
| limits are only enforced when the application runs in production.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'api_rate_limit_authenticated_per_minute' => (int) (env('API_RATE_LIMIT_AUTH_PER_MINUTE') ?: 200),
|
||||||
|
|
||||||
|
'api_rate_limit_guest_per_minute' => (int) (env('API_RATE_LIMIT_GUEST_PER_MINUTE') ?: 60),
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
| Encryption Key
|
| Encryption Key
|
||||||
|
|||||||
34
config/import.php
Normal file
34
config/import.php
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
return [
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Import payload limit
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Maximum length of the base64 encoded "data" field of an import request in
|
||||||
|
| bytes. Requests with a larger payload are rejected with a validation error.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'max_data_size' => (int) (env('IMPORT_MAX_DATA_SIZE') ?: 50 * 1024 * 1024),
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| ZIP extraction limits
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Limits applied to ZIP based importers before and during extraction to
|
||||||
|
| protect the instance against decompression bombs. The uncompressed size
|
||||||
|
| is the sum of all files in the archive in bytes.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
'zip_max_files' => (int) (env('IMPORT_ZIP_MAX_FILES') ?: 100),
|
||||||
|
|
||||||
|
'zip_max_uncompressed_size' => (int) (env('IMPORT_ZIP_MAX_UNCOMPRESSED_SIZE') ?: 500 * 1024 * 1024),
|
||||||
|
|
||||||
|
];
|
||||||
@@ -33,6 +33,7 @@ class OrganizationFactory extends Factory
|
|||||||
'user_id' => User::factory(),
|
'user_id' => User::factory(),
|
||||||
'personal_team' => true,
|
'personal_team' => true,
|
||||||
'employees_can_see_billable_rates' => false,
|
'employees_can_see_billable_rates' => false,
|
||||||
|
'breaks_enabled' => false,
|
||||||
'number_format' => $this->faker->randomElement(NumberFormat::values()),
|
'number_format' => $this->faker->randomElement(NumberFormat::values()),
|
||||||
'currency_format' => $this->faker->randomElement(CurrencyFormat::values()),
|
'currency_format' => $this->faker->randomElement(CurrencyFormat::values()),
|
||||||
'date_format' => $this->faker->randomElement(DateFormat::values()),
|
'date_format' => $this->faker->randomElement(DateFormat::values()),
|
||||||
@@ -55,6 +56,13 @@ class OrganizationFactory extends Factory
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function withBreaksEnabled(): self
|
||||||
|
{
|
||||||
|
return $this->state(fn (array $attributes) => [
|
||||||
|
'breaks_enabled' => true,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
public function withOwner(?User $owner = null): self
|
public function withOwner(?User $owner = null): self
|
||||||
{
|
{
|
||||||
return $this->state(fn (array $attributes) => [
|
return $this->state(fn (array $attributes) => [
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace Database\Factories;
|
namespace Database\Factories;
|
||||||
|
|
||||||
|
use App\Enums\TimeEntryType;
|
||||||
use App\Models\Member;
|
use App\Models\Member;
|
||||||
use App\Models\Organization;
|
use App\Models\Organization;
|
||||||
use App\Models\Project;
|
use App\Models\Project;
|
||||||
@@ -33,6 +34,7 @@ class TimeEntryFactory extends Factory
|
|||||||
'start' => $start,
|
'start' => $start,
|
||||||
'end' => $this->faker->dateTimeBetween($start, 'now'),
|
'end' => $this->faker->dateTimeBetween($start, 'now'),
|
||||||
'billable' => $this->faker->boolean(),
|
'billable' => $this->faker->boolean(),
|
||||||
|
'type' => TimeEntryType::Work,
|
||||||
'is_imported' => false,
|
'is_imported' => false,
|
||||||
'tags' => [],
|
'tags' => [],
|
||||||
'user_id' => User::factory(),
|
'user_id' => User::factory(),
|
||||||
@@ -44,6 +46,18 @@ class TimeEntryFactory extends Factory
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function isBreak(): self
|
||||||
|
{
|
||||||
|
return $this->state(function (array $attributes): array {
|
||||||
|
return [
|
||||||
|
'type' => TimeEntryType::Break,
|
||||||
|
'billable' => false,
|
||||||
|
'project_id' => null,
|
||||||
|
'task_id' => null,
|
||||||
|
];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public function notBillable(): self
|
public function notBillable(): self
|
||||||
{
|
{
|
||||||
return $this->state(function (array $attributes): array {
|
return $this->state(function (array $attributes): array {
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::table('time_entries', function (Blueprint $table): void {
|
||||||
|
$table->string('type')->default('work');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::table('time_entries', function (Blueprint $table): void {
|
||||||
|
$table->dropColumn('type');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::table('organizations', function (Blueprint $table): void {
|
||||||
|
$table->boolean('breaks_enabled')->default(false)->after('prevent_overlapping_time_entries');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::table('organizations', function (Blueprint $table): void {
|
||||||
|
$table->dropColumn('breaks_enabled');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,230 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
|
use function Laravel\Prompts\info as consoleInfo;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* PostgreSQL cannot build or drop an index concurrently inside a transaction.
|
||||||
|
* Keeping this migration non-transactional prevents long write locks in production.
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
public $withinTransaction = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
// Tenant-scoped client pagination ordered by newest first; also covers the organization FK.
|
||||||
|
$this->runIndexOperation('create', 'clients_organization_created_id_index', 'CREATE INDEX CONCURRENTLY clients_organization_created_id_index ON clients (organization_id, created_at DESC, id)');
|
||||||
|
|
||||||
|
// Tenant-scoped project pagination ordered by newest first; also covers the organization FK.
|
||||||
|
$this->runIndexOperation('create', 'projects_organization_created_id_index', 'CREATE INDEX CONCURRENTLY projects_organization_created_id_index ON projects (organization_id, created_at DESC, id)');
|
||||||
|
// Speeds client relationship loads and the FK check when a client is deleted or its ID changes.
|
||||||
|
$this->runIndexOperation('create', 'projects_client_id_index', 'CREATE INDEX CONCURRENTLY projects_client_id_index ON projects (client_id)');
|
||||||
|
|
||||||
|
// Tenant-scoped task pagination ordered by newest first; also covers the organization FK.
|
||||||
|
$this->runIndexOperation('create', 'tasks_organization_created_id_index', 'CREATE INDEX CONCURRENTLY tasks_organization_created_id_index ON tasks (organization_id, created_at DESC, id)');
|
||||||
|
// Speeds project task lists and the FK check when a project is deleted or its ID changes.
|
||||||
|
$this->runIndexOperation('create', 'tasks_project_id_index', 'CREATE INDEX CONCURRENTLY tasks_project_id_index ON tasks (project_id)');
|
||||||
|
|
||||||
|
// Tenant-scoped tag pagination ordered by newest first; also covers the organization FK.
|
||||||
|
$this->runIndexOperation('create', 'tags_organization_created_id_index', 'CREATE INDEX CONCURRENTLY tags_organization_created_id_index ON tags (organization_id, created_at DESC, id)');
|
||||||
|
|
||||||
|
// Tenant-scoped report pagination ordered by newest first; also covers the organization FK.
|
||||||
|
$this->runIndexOperation('create', 'reports_organization_created_id_index', 'CREATE INDEX CONCURRENTLY reports_organization_created_id_index ON reports (organization_id, created_at DESC, id)');
|
||||||
|
|
||||||
|
// Tenant-scoped member pagination; the existing (organization_id, user_id) unique index remains for membership lookup.
|
||||||
|
$this->runIndexOperation('create', 'members_organization_created_id_index', 'CREATE INDEX CONCURRENTLY members_organization_created_id_index ON members (organization_id, created_at DESC, id)');
|
||||||
|
// Supports reverse user-to-membership lookups and the FK check when a user is deleted or its ID changes.
|
||||||
|
$this->runIndexOperation('create', 'members_user_id_index', 'CREATE INDEX CONCURRENTLY members_user_id_index ON members (user_id)');
|
||||||
|
|
||||||
|
// The existing (project_id, user_id) unique index covers project_id, but member_id and legacy user_id need reverse indexes.
|
||||||
|
$this->runIndexOperation('create', 'project_members_member_id_index', 'CREATE INDEX CONCURRENTLY project_members_member_id_index ON project_members (member_id)');
|
||||||
|
$this->runIndexOperation('create', 'project_members_user_id_index', 'CREATE INDEX CONCURRENTLY project_members_user_id_index ON project_members (user_id)');
|
||||||
|
|
||||||
|
// Supports organization deletion/current-team cleanup and the FK check on users.current_team_id.
|
||||||
|
$this->runIndexOperation('create', 'users_current_team_id_index', 'CREATE INDEX CONCURRENTLY users_current_team_id_index ON users (current_team_id)');
|
||||||
|
|
||||||
|
// Filament loads the newest audits first; this avoids scanning and sorting the large append-only audit table.
|
||||||
|
$this->runIndexOperation('create', 'audits_created_at_index', 'CREATE INDEX CONCURRENTLY audits_created_at_index ON audits (created_at DESC)');
|
||||||
|
|
||||||
|
// Main tenant time-entry range/pagination path, including its start DESC, id ordering; also covers the organization FK.
|
||||||
|
$this->runIndexOperation('create', 'time_entries_organization_start_id_index', 'CREATE INDEX CONCURRENTLY time_entries_organization_start_id_index ON time_entries (organization_id, start DESC, id)');
|
||||||
|
// Filament lists time entries globally by creation time, so the tenant-prefixed index cannot provide this ordering.
|
||||||
|
$this->runIndexOperation('create', 'time_entries_created_at_index', 'CREATE INDEX CONCURRENTLY time_entries_created_at_index ON time_entries (created_at DESC)');
|
||||||
|
// Dashboard history is consistently filtered by user and organization, then bounded by start; user first also covers its FK.
|
||||||
|
$this->runIndexOperation('create', 'time_entries_user_organization_start_index', 'CREATE INDEX CONCURRENTLY time_entries_user_organization_start_index ON time_entries (user_id, organization_id, start)');
|
||||||
|
// Member timelines, overlap checks, and billable-rate updates start with member_id; also covers its FK.
|
||||||
|
$this->runIndexOperation('create', 'time_entries_member_start_index', 'CREATE INDEX CONCURRENTLY time_entries_member_start_index ON time_entries (member_id, start)');
|
||||||
|
// These relationship/filter indexes also prevent full scans for FK checks when parent rows change or are deleted.
|
||||||
|
$this->runIndexOperation('create', 'time_entries_project_id_index', 'CREATE INDEX CONCURRENTLY time_entries_project_id_index ON time_entries (project_id)');
|
||||||
|
$this->runIndexOperation('create', 'time_entries_task_id_index', 'CREATE INDEX CONCURRENTLY time_entries_task_id_index ON time_entries (task_id)');
|
||||||
|
$this->runIndexOperation('create', 'time_entries_client_id_index', 'CREATE INDEX CONCURRENTLY time_entries_client_id_index ON time_entries (client_id)');
|
||||||
|
// Active-timer checks touch only open entries, so a partial index stays small while serving the hot member_id lookup.
|
||||||
|
$this->runIndexOperation('create', 'time_entries_active_member_index', 'CREATE INDEX CONCURRENTLY time_entries_active_member_index ON time_entries (member_id) WHERE "end" IS NULL');
|
||||||
|
// whereJsonContains(tags, tag_id) compiles to JSONB containment, which is supported by a GIN index.
|
||||||
|
$this->runIndexOperation('create', 'time_entries_tags_gin_index', 'CREATE INDEX CONCURRENTLY time_entries_tags_gin_index ON time_entries USING GIN (tags)');
|
||||||
|
|
||||||
|
// Passport already indexes user_id; these indexes cover the other FK used during OAuth client deletion/update.
|
||||||
|
$this->runIndexOperation('create', 'oauth_access_tokens_client_id_index', 'CREATE INDEX CONCURRENTLY oauth_access_tokens_client_id_index ON oauth_access_tokens (client_id)');
|
||||||
|
$this->runIndexOperation('create', 'oauth_auth_codes_client_id_index', 'CREATE INDEX CONCURRENTLY oauth_auth_codes_client_id_index ON oauth_auth_codes (client_id)');
|
||||||
|
|
||||||
|
// owner_id is already the leading column of oauth_clients_owner_id_owner_type_index.
|
||||||
|
$this->runIndexOperation('drop', 'oauth_clients_user_id_index', 'DROP INDEX CONCURRENTLY oauth_clients_user_id_index');
|
||||||
|
// Public report lookup starts with the unique share_secret index; no query filters only by this boolean.
|
||||||
|
$this->runIndexOperation('drop', 'reports_is_public_index', 'DROP INDEX CONCURRENTLY reports_is_public_index');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
$indexes = [
|
||||||
|
'clients_organization_created_id_index',
|
||||||
|
'projects_organization_created_id_index',
|
||||||
|
'projects_client_id_index',
|
||||||
|
'tasks_organization_created_id_index',
|
||||||
|
'tasks_project_id_index',
|
||||||
|
'tags_organization_created_id_index',
|
||||||
|
'reports_organization_created_id_index',
|
||||||
|
'members_organization_created_id_index',
|
||||||
|
'members_user_id_index',
|
||||||
|
'project_members_member_id_index',
|
||||||
|
'project_members_user_id_index',
|
||||||
|
'users_current_team_id_index',
|
||||||
|
'audits_created_at_index',
|
||||||
|
'time_entries_organization_start_id_index',
|
||||||
|
'time_entries_created_at_index',
|
||||||
|
'time_entries_user_organization_start_index',
|
||||||
|
'time_entries_member_start_index',
|
||||||
|
'time_entries_project_id_index',
|
||||||
|
'time_entries_task_id_index',
|
||||||
|
'time_entries_client_id_index',
|
||||||
|
'time_entries_active_member_index',
|
||||||
|
'time_entries_tags_gin_index',
|
||||||
|
'oauth_access_tokens_client_id_index',
|
||||||
|
'oauth_auth_codes_client_id_index',
|
||||||
|
];
|
||||||
|
|
||||||
|
$concurrently = DB::transactionLevel() === 0 ? ' CONCURRENTLY' : '';
|
||||||
|
foreach ($indexes as $index) {
|
||||||
|
$this->runIndexOperation('drop', $index, 'DROP INDEX'.$concurrently.' IF EXISTS '.$index);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->runIndexOperation('create', 'oauth_clients_user_id_index', 'CREATE INDEX'.$concurrently.' oauth_clients_user_id_index ON oauth_clients (owner_id)');
|
||||||
|
$this->runIndexOperation('create', 'reports_is_public_index', 'CREATE INDEX'.$concurrently.' reports_is_public_index ON reports (is_public)');
|
||||||
|
}
|
||||||
|
|
||||||
|
private function runIndexOperation(string $operation, string $index, string $statement): void
|
||||||
|
{
|
||||||
|
$indexState = $this->indexState($index);
|
||||||
|
|
||||||
|
if ($operation === 'create' && $indexState === ['valid' => true, 'ready' => true]) {
|
||||||
|
$this->writeProgress(sprintf('Skipping index [%s] because it already exists and is valid', $index));
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($operation === 'drop' && $indexState === null) {
|
||||||
|
$this->writeProgress(sprintf('Skipping index [%s] because it does not exist', $index));
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($operation === 'create' && $indexState !== null) {
|
||||||
|
$this->writeProgress(sprintf(
|
||||||
|
'Index [%s] exists but is incomplete (valid=%s, ready=%s); dropping it before rebuilding',
|
||||||
|
$index,
|
||||||
|
$indexState['valid'] ? 'true' : 'false',
|
||||||
|
$indexState['ready'] ? 'true' : 'false',
|
||||||
|
));
|
||||||
|
$this->executeIndexStatement(
|
||||||
|
'drop incomplete',
|
||||||
|
$index,
|
||||||
|
(DB::transactionLevel() === 0 ? 'DROP INDEX CONCURRENTLY ' : 'DROP INDEX ').$this->quoteIdentifier($index),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->executeIndexStatement($operation, $index, $statement);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function executeIndexStatement(string $operation, string $index, string $statement): void
|
||||||
|
{
|
||||||
|
$startedAt = microtime(true);
|
||||||
|
$this->writeProgress(sprintf('Starting to %s index [%s]', $operation, $index));
|
||||||
|
|
||||||
|
try {
|
||||||
|
DB::statement($statement);
|
||||||
|
} catch (Throwable $exception) {
|
||||||
|
$this->writeProgress(sprintf(
|
||||||
|
'Failed to %s index [%s] after %.2f seconds: %s',
|
||||||
|
$operation,
|
||||||
|
$index,
|
||||||
|
microtime(true) - $startedAt,
|
||||||
|
$exception->getMessage(),
|
||||||
|
));
|
||||||
|
|
||||||
|
throw $exception;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->writeProgress(sprintf(
|
||||||
|
'Finished %s index [%s] in %.2f seconds',
|
||||||
|
$operation === 'create' ? 'creating' : 'dropping',
|
||||||
|
$index,
|
||||||
|
microtime(true) - $startedAt,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array{valid: bool, ready: bool}|null
|
||||||
|
*/
|
||||||
|
private function indexState(string $index): ?array
|
||||||
|
{
|
||||||
|
$state = DB::selectOne(
|
||||||
|
<<<'SQL'
|
||||||
|
SELECT pg_index.indisvalid::int AS valid, pg_index.indisready::int AS ready
|
||||||
|
FROM pg_index
|
||||||
|
JOIN pg_class ON pg_class.oid = pg_index.indexrelid
|
||||||
|
JOIN pg_namespace ON pg_namespace.oid = pg_class.relnamespace
|
||||||
|
WHERE pg_namespace.nspname = current_schema()
|
||||||
|
AND pg_class.relname = ?
|
||||||
|
SQL,
|
||||||
|
[$index],
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($state === null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
'valid' => (bool) $state->valid,
|
||||||
|
'ready' => (bool) $state->ready,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
private function quoteIdentifier(string $identifier): string
|
||||||
|
{
|
||||||
|
return DB::connection()->getQueryGrammar()->wrap($identifier);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function writeProgress(string $message): void
|
||||||
|
{
|
||||||
|
if (app()->runningUnitTests()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$message = sprintf('[%s] %s', date(DATE_ATOM), $message);
|
||||||
|
Log::info($message);
|
||||||
|
consoleInfo($message);
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::table('users', function (Blueprint $table): void {
|
||||||
|
$table->boolean('send_time_entry_still_running_email')->default(true)->after('week_start');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::table('users', function (Blueprint $table): void {
|
||||||
|
$table->dropColumn('send_time_entry_still_running_email');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Query\Builder;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Placeholder users used to be created as a full copy of the user they were made from,
|
||||||
|
* which included the credentials and the account state of that user. A placeholder is a
|
||||||
|
* stand-in for a person in one organization, not an account, and the row shares the email
|
||||||
|
* address with the real account, so these values are removed from the placeholders that
|
||||||
|
* already exist. The organization a placeholder belongs to is recorded on its member row.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
DB::table('users')
|
||||||
|
->where('is_placeholder', '=', true)
|
||||||
|
->where(function (Builder $builder): void {
|
||||||
|
$builder->whereNotNull('password')
|
||||||
|
->orWhereNotNull('remember_token')
|
||||||
|
->orWhereNotNull('two_factor_secret')
|
||||||
|
->orWhereNotNull('two_factor_recovery_codes')
|
||||||
|
->orWhereNotNull('two_factor_confirmed_at')
|
||||||
|
->orWhereNotNull('email_verified_at')
|
||||||
|
->orWhereNotNull('pending_email')
|
||||||
|
->orWhereNotNull('current_team_id')
|
||||||
|
->orWhereNotNull('profile_photo_path');
|
||||||
|
})
|
||||||
|
->update([
|
||||||
|
'password' => null,
|
||||||
|
'remember_token' => null,
|
||||||
|
'two_factor_secret' => null,
|
||||||
|
'two_factor_recovery_codes' => null,
|
||||||
|
'two_factor_confirmed_at' => null,
|
||||||
|
'email_verified_at' => null,
|
||||||
|
'pending_email' => null,
|
||||||
|
'current_team_id' => null,
|
||||||
|
'profile_photo_path' => null,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
};
|
||||||
278
e2e/breaks.spec.ts
Normal file
278
e2e/breaks.spec.ts
Normal file
@@ -0,0 +1,278 @@
|
|||||||
|
import { expect, test } from '../playwright/fixtures';
|
||||||
|
import { PLAYWRIGHT_BASE_URL } from '../playwright/config';
|
||||||
|
import type { Page } from '@playwright/test';
|
||||||
|
import {
|
||||||
|
assertThatTimerHasStarted,
|
||||||
|
assertThatTimerIsStopped,
|
||||||
|
newTimeEntryResponse,
|
||||||
|
startOrStopTimerWithButton,
|
||||||
|
stoppedTimeEntryResponse,
|
||||||
|
} from './utils/currentTimeEntry';
|
||||||
|
import { createTimeEntryViaApi, updateOrganizationSettingViaApi } from './utils/api';
|
||||||
|
|
||||||
|
async function goToDashboard(page: Page) {
|
||||||
|
await page.goto(PLAYWRIGHT_BASE_URL + '/dashboard');
|
||||||
|
}
|
||||||
|
|
||||||
|
function visibleBreakButton(page: Page) {
|
||||||
|
return page.getByRole('button', { name: 'Take a break' }).locator('visible=true').first();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Breaks are disabled by default for new organizations, so enable them for the break flows.
|
||||||
|
// The tests that assert the disabled behaviour turn them back off explicitly.
|
||||||
|
test.beforeEach(async ({ ctx }) => {
|
||||||
|
await updateOrganizationSettingViaApi(ctx, { breaks_enabled: true });
|
||||||
|
});
|
||||||
|
|
||||||
|
test('test that switching to a break stops the work timer and starts a break entry', async ({
|
||||||
|
page,
|
||||||
|
}) => {
|
||||||
|
await goToDashboard(page);
|
||||||
|
await expect(page.getByTestId('time_entry_description')).toBeEditable();
|
||||||
|
await page.getByTestId('time_entry_description').fill('Work before break');
|
||||||
|
await Promise.all([
|
||||||
|
newTimeEntryResponse(page, { description: 'Work before break', type: 'work' }),
|
||||||
|
page.getByTestId('time_entry_description').press('Enter'),
|
||||||
|
]);
|
||||||
|
await assertThatTimerHasStarted(page);
|
||||||
|
await page.waitForTimeout(1500);
|
||||||
|
|
||||||
|
// Switch to break: stops the work entry and starts a break entry
|
||||||
|
await Promise.all([
|
||||||
|
newTimeEntryResponse(page, { description: '', type: 'break' }),
|
||||||
|
visibleBreakButton(page).click(),
|
||||||
|
]);
|
||||||
|
await expect(page.getByText('On break')).toBeVisible();
|
||||||
|
|
||||||
|
// The break bar offers a one-click resume that stops the break and restores
|
||||||
|
// the interrupted work context
|
||||||
|
await page.waitForTimeout(1500);
|
||||||
|
const resumeButton = page.getByRole('button', { name: 'Resume "Work before break"' });
|
||||||
|
await expect(resumeButton).toBeVisible();
|
||||||
|
await Promise.all([
|
||||||
|
stoppedTimeEntryResponse(page, { type: 'break' }),
|
||||||
|
newTimeEntryResponse(page, { description: 'Work before break', type: 'work' }),
|
||||||
|
resumeButton.click(),
|
||||||
|
]);
|
||||||
|
await assertThatTimerHasStarted(page);
|
||||||
|
await expect(page.getByTestId('time_entry_description')).toHaveValue('Work before break');
|
||||||
|
|
||||||
|
// Cleanup: stop the running entry
|
||||||
|
await Promise.all([
|
||||||
|
stoppedTimeEntryResponse(page, { description: 'Work before break', type: 'work' }),
|
||||||
|
startOrStopTimerWithButton(page),
|
||||||
|
]);
|
||||||
|
await assertThatTimerIsStopped(page);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('test that stopping a break returns to an idle tracker where a fresh entry starts normally', async ({
|
||||||
|
page,
|
||||||
|
}) => {
|
||||||
|
await goToDashboard(page);
|
||||||
|
await expect(page.getByTestId('time_entry_description')).toBeEditable();
|
||||||
|
await page.getByTestId('time_entry_description').fill('Work before break');
|
||||||
|
await Promise.all([
|
||||||
|
newTimeEntryResponse(page, { description: 'Work before break', type: 'work' }),
|
||||||
|
page.getByTestId('time_entry_description').press('Enter'),
|
||||||
|
]);
|
||||||
|
await assertThatTimerHasStarted(page);
|
||||||
|
await page.waitForTimeout(1500);
|
||||||
|
|
||||||
|
// Switch to a break
|
||||||
|
await Promise.all([
|
||||||
|
newTimeEntryResponse(page, { description: '', type: 'break' }),
|
||||||
|
visibleBreakButton(page).click(),
|
||||||
|
]);
|
||||||
|
await expect(page.getByText('On break')).toBeVisible();
|
||||||
|
|
||||||
|
// Stopping the break just ends it — no modal, the tracker returns to the
|
||||||
|
// empty idle input with focus so typing starts a fresh entry
|
||||||
|
await page.waitForTimeout(1500);
|
||||||
|
await Promise.all([
|
||||||
|
stoppedTimeEntryResponse(page, { type: 'break' }),
|
||||||
|
startOrStopTimerWithButton(page),
|
||||||
|
]);
|
||||||
|
await assertThatTimerIsStopped(page);
|
||||||
|
await expect(page.getByTestId('time_entry_description')).toHaveValue('');
|
||||||
|
await expect(page.getByTestId('time_entry_description')).toBeFocused();
|
||||||
|
|
||||||
|
// A fresh entry is the normal start flow: type + Enter
|
||||||
|
await page.getByTestId('time_entry_description').fill('Fresh after break');
|
||||||
|
await Promise.all([
|
||||||
|
newTimeEntryResponse(page, { description: 'Fresh after break', type: 'work' }),
|
||||||
|
page.getByTestId('time_entry_description').press('Enter'),
|
||||||
|
]);
|
||||||
|
await assertThatTimerHasStarted(page);
|
||||||
|
|
||||||
|
// Cleanup: stop the running entry
|
||||||
|
await Promise.all([
|
||||||
|
stoppedTimeEntryResponse(page, { description: 'Fresh after break', type: 'work' }),
|
||||||
|
startOrStopTimerWithButton(page),
|
||||||
|
]);
|
||||||
|
await assertThatTimerIsStopped(page);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('test that the more options dropdown can start a break directly', async ({ page }) => {
|
||||||
|
await goToDashboard(page);
|
||||||
|
await expect(page.getByTestId('time_entry_description')).toBeEditable();
|
||||||
|
|
||||||
|
// Start a break straight from the more options dropdown (no create modal)
|
||||||
|
await page.getByRole('button', { name: 'Time entry actions' }).click();
|
||||||
|
await Promise.all([
|
||||||
|
newTimeEntryResponse(page, { description: '', type: 'break' }),
|
||||||
|
page.getByRole('menuitem', { name: 'Start Break' }).click(),
|
||||||
|
]);
|
||||||
|
await expect(page.getByText('On break')).toBeVisible();
|
||||||
|
|
||||||
|
// Without interrupted work there is nothing to resume, so no resume button is offered
|
||||||
|
await expect(page.getByRole('button', { name: /^Resume/ })).toHaveCount(0);
|
||||||
|
|
||||||
|
// Cleanup: stop the break
|
||||||
|
await page.waitForTimeout(1500);
|
||||||
|
await Promise.all([
|
||||||
|
stoppedTimeEntryResponse(page, { type: 'break' }),
|
||||||
|
startOrStopTimerWithButton(page),
|
||||||
|
]);
|
||||||
|
await assertThatTimerIsStopped(page);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('test that disabling breaks hides every break-creation entry point', async ({ page, ctx }) => {
|
||||||
|
// Breaks disabled for the organization (delivered to the client via the organization endpoint)
|
||||||
|
await updateOrganizationSettingViaApi(ctx, { breaks_enabled: false });
|
||||||
|
await createTimeEntryViaApi(ctx, { duration: '1h', description: 'Regular work' });
|
||||||
|
|
||||||
|
// Calendar: the empty-slot context menu offers "Create Time Entry" but no "Add Break",
|
||||||
|
// and the edit modal drops the work-time/break type selector
|
||||||
|
await page.goto(PLAYWRIGHT_BASE_URL + '/calendar');
|
||||||
|
await expect(page.locator('.fc')).toBeVisible();
|
||||||
|
const event = page.locator('.fc-event').filter({ hasText: 'Regular work' }).first();
|
||||||
|
await event.scrollIntoViewIfNeeded();
|
||||||
|
await expect(event).toBeVisible();
|
||||||
|
|
||||||
|
const box = await event.boundingBox();
|
||||||
|
expect(box).not.toBeNull();
|
||||||
|
await page.mouse.click(box!.x + box!.width / 2, box!.y + box!.height + 40, { button: 'right' });
|
||||||
|
await expect(page.getByRole('menu')).toBeVisible();
|
||||||
|
await expect(page.getByRole('menuitem', { name: 'Create Time Entry' })).toBeVisible();
|
||||||
|
await expect(page.getByRole('menuitem', { name: 'Add Break' })).toHaveCount(0);
|
||||||
|
await page.keyboard.press('Escape');
|
||||||
|
|
||||||
|
await event.click({ button: 'right' });
|
||||||
|
await expect(page.getByRole('menu')).toBeVisible();
|
||||||
|
await page.getByRole('menuitem', { name: 'Edit' }).click();
|
||||||
|
await expect(page.getByRole('dialog')).toBeVisible();
|
||||||
|
await expect(
|
||||||
|
page.getByRole('dialog').getByRole('combobox').filter({ hasText: 'Work time' })
|
||||||
|
).toHaveCount(0);
|
||||||
|
await page.keyboard.press('Escape');
|
||||||
|
|
||||||
|
// Timesheet: no break row is shown
|
||||||
|
await page.goto(PLAYWRIGHT_BASE_URL + '/timesheet');
|
||||||
|
await expect(page.getByRole('button', { name: 'Add row' }).first()).toBeVisible();
|
||||||
|
await expect(page.getByText('Break', { exact: true })).toHaveCount(0);
|
||||||
|
|
||||||
|
// Dashboard tracker: no "Start Break" in the more options dropdown
|
||||||
|
await goToDashboard(page);
|
||||||
|
await expect(page.getByTestId('time_entry_description')).toBeEditable();
|
||||||
|
await page.getByRole('button', { name: 'Time entry actions' }).click();
|
||||||
|
await expect(page.getByRole('menuitem', { name: 'Switch to simple mode' })).toBeVisible();
|
||||||
|
await expect(page.getByRole('menuitem', { name: 'Start Break' })).toHaveCount(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
// The employee fixture registers a second user and accepts an invitation via Mailpit,
|
||||||
|
// which does not fit into the default per-test timeout.
|
||||||
|
test.describe('Org-level breaks setting', () => {
|
||||||
|
test.describe.configure({ timeout: 60000 });
|
||||||
|
|
||||||
|
test('test that the org-level breaks setting is respected for employees', async ({
|
||||||
|
ctx,
|
||||||
|
employee,
|
||||||
|
}) => {
|
||||||
|
const employeePage = employee.page;
|
||||||
|
|
||||||
|
// Breaks enabled (via beforeEach): the employee sees "Start Break" in the more options dropdown
|
||||||
|
await employeePage.goto(PLAYWRIGHT_BASE_URL + '/dashboard');
|
||||||
|
await expect(employeePage.getByTestId('dashboard_view')).toBeVisible();
|
||||||
|
await employeePage.getByRole('button', { name: 'Time entry actions' }).click();
|
||||||
|
await expect(
|
||||||
|
employeePage.getByRole('menuitem', { name: 'Switch to simple mode' })
|
||||||
|
).toBeVisible();
|
||||||
|
await expect(employeePage.getByRole('menuitem', { name: 'Start Break' })).toBeVisible();
|
||||||
|
await employeePage.keyboard.press('Escape');
|
||||||
|
|
||||||
|
// The owner disables breaks for the whole organization
|
||||||
|
await updateOrganizationSettingViaApi(ctx, { breaks_enabled: false });
|
||||||
|
|
||||||
|
// The employee reloads: "Start Break" is gone from the dropdown
|
||||||
|
await employeePage.goto(PLAYWRIGHT_BASE_URL + '/dashboard');
|
||||||
|
await expect(employeePage.getByTestId('dashboard_view')).toBeVisible();
|
||||||
|
await employeePage.getByRole('button', { name: 'Time entry actions' }).click();
|
||||||
|
await expect(
|
||||||
|
employeePage.getByRole('menuitem', { name: 'Switch to simple mode' })
|
||||||
|
).toBeVisible();
|
||||||
|
await expect(employeePage.getByRole('menuitem', { name: 'Start Break' })).toHaveCount(0);
|
||||||
|
await employeePage.keyboard.press('Escape');
|
||||||
|
|
||||||
|
// With an active timer the break (coffee) button is not shown either
|
||||||
|
await employeePage.getByTestId('time_entry_description').fill('Employee work');
|
||||||
|
await Promise.all([
|
||||||
|
newTimeEntryResponse(employeePage, { description: 'Employee work', type: 'work' }),
|
||||||
|
employeePage.getByTestId('time_entry_description').press('Enter'),
|
||||||
|
]);
|
||||||
|
await assertThatTimerHasStarted(employeePage);
|
||||||
|
await expect(employeePage.getByRole('button', { name: 'Take a break' })).toHaveCount(0);
|
||||||
|
|
||||||
|
// Cleanup: stop the running entry
|
||||||
|
await Promise.all([
|
||||||
|
stoppedTimeEntryResponse(employeePage, { description: 'Employee work', type: 'work' }),
|
||||||
|
startOrStopTimerWithButton(employeePage),
|
||||||
|
]);
|
||||||
|
await assertThatTimerIsStopped(employeePage);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('test that mass update warns about selected breaks and reports skipped entries instead of success', async ({
|
||||||
|
page,
|
||||||
|
ctx,
|
||||||
|
}) => {
|
||||||
|
// One work entry and one break: a billable mass update applies to the work
|
||||||
|
// entry but the server skips the break entirely — the UI must say so.
|
||||||
|
await createTimeEntryViaApi(ctx, { duration: '1h', description: 'Mass update work entry' });
|
||||||
|
await createTimeEntryViaApi(ctx, { duration: '30min', type: 'break' });
|
||||||
|
|
||||||
|
await page.goto(PLAYWRIGHT_BASE_URL + '/time');
|
||||||
|
await expect(page.locator('[data-testid="time_entry_row"]')).toHaveCount(2);
|
||||||
|
await page.getByLabel('Select All').click();
|
||||||
|
await expect(page.getByText('2 selected')).toBeVisible();
|
||||||
|
await page.getByRole('button', { name: 'Edit' }).click();
|
||||||
|
await expect(page.getByRole('dialog')).toBeVisible();
|
||||||
|
|
||||||
|
// No warning while the changeset is compatible with breaks
|
||||||
|
await expect(page.getByTestId('mass_update_break_warning')).not.toBeVisible();
|
||||||
|
|
||||||
|
// Making the entries billable is break-incompatible → warning appears
|
||||||
|
await page
|
||||||
|
.getByRole('dialog')
|
||||||
|
.getByRole('combobox')
|
||||||
|
.filter({ hasText: 'Set billable status' })
|
||||||
|
.click();
|
||||||
|
await page.getByRole('option', { name: 'Billable', exact: true }).click();
|
||||||
|
await expect(page.getByTestId('mass_update_break_warning')).toBeVisible();
|
||||||
|
await expect(page.getByTestId('mass_update_break_warning')).toContainText('skipped entirely');
|
||||||
|
|
||||||
|
// Submit: the work entry updates, the break is skipped, and the toast
|
||||||
|
// reports the skip instead of claiming success for all entries
|
||||||
|
const [massUpdateResponse] = await Promise.all([
|
||||||
|
page.waitForResponse(
|
||||||
|
(response) =>
|
||||||
|
response.url().includes('/time-entries') &&
|
||||||
|
response.request().method() === 'PATCH' &&
|
||||||
|
response.status() === 200
|
||||||
|
),
|
||||||
|
page.getByRole('button', { name: 'Update Time Entries' }).click(),
|
||||||
|
]);
|
||||||
|
const massUpdateBody = await massUpdateResponse.json();
|
||||||
|
expect(massUpdateBody.success.length).toBe(1);
|
||||||
|
expect(massUpdateBody.error.length).toBe(1);
|
||||||
|
await expect(page.getByText('1 of 2 time entries was skipped')).toBeVisible();
|
||||||
|
});
|
||||||
@@ -2874,3 +2874,54 @@ test.describe('Daily Total After Create', () => {
|
|||||||
}).toPass({ timeout: 5000 });
|
}).toPass({ timeout: 5000 });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('test that calendar context menu can add a break that fills the gap between two entries', async ({
|
||||||
|
page,
|
||||||
|
ctx,
|
||||||
|
}) => {
|
||||||
|
await updateOrganizationSettingViaApi(ctx, { breaks_enabled: true });
|
||||||
|
// Two work entries today (09:00-10:00 and 11:00-12:00 UTC) with a one hour gap
|
||||||
|
const today = new Date().toISOString().slice(0, 10);
|
||||||
|
const gapStart = `${today}T10:00:00Z`;
|
||||||
|
const gapEnd = `${today}T11:00:00Z`;
|
||||||
|
await createTimeEntryWithTimestampsViaApi(ctx, {
|
||||||
|
start: `${today}T09:00:00Z`,
|
||||||
|
end: gapStart,
|
||||||
|
description: 'Gap work A',
|
||||||
|
});
|
||||||
|
await createTimeEntryWithTimestampsViaApi(ctx, {
|
||||||
|
start: gapEnd,
|
||||||
|
end: `${today}T12:00:00Z`,
|
||||||
|
description: 'Gap work B',
|
||||||
|
});
|
||||||
|
|
||||||
|
await goToCalendar(page);
|
||||||
|
const eventA = page.locator('.fc-event').filter({ hasText: 'Gap work A' }).first();
|
||||||
|
await eventA.scrollIntoViewIfNeeded();
|
||||||
|
await expect(eventA).toBeVisible();
|
||||||
|
|
||||||
|
// Right-click just below entry A (inside the gap, in the same day column)
|
||||||
|
const box = await eventA.boundingBox();
|
||||||
|
expect(box).not.toBeNull();
|
||||||
|
await page.mouse.click(box!.x + box!.width / 2, box!.y + box!.height + 15, {
|
||||||
|
button: 'right',
|
||||||
|
});
|
||||||
|
await expect(page.getByRole('menu')).toBeVisible();
|
||||||
|
await page.getByRole('menuitem', { name: 'Add Break' }).click();
|
||||||
|
await expect(page.getByRole('dialog')).toBeVisible();
|
||||||
|
|
||||||
|
// The break is prefilled to fill the gap exactly
|
||||||
|
const [createResponse] = await Promise.all([
|
||||||
|
page.waitForResponse(
|
||||||
|
async (response) =>
|
||||||
|
response.url().includes('/time-entries') &&
|
||||||
|
response.request().method() === 'POST' &&
|
||||||
|
response.status() === 201 &&
|
||||||
|
(await response.json()).data.type === 'break'
|
||||||
|
),
|
||||||
|
page.getByRole('button', { name: 'Add Break' }).click(),
|
||||||
|
]);
|
||||||
|
const body = await createResponse.json();
|
||||||
|
expect(body.data.start).toBe(gapStart);
|
||||||
|
expect(body.data.end).toBe(gapEnd);
|
||||||
|
});
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import {
|
|||||||
createProjectViaApi,
|
createProjectViaApi,
|
||||||
createPublicProjectViaApi,
|
createPublicProjectViaApi,
|
||||||
} from './utils/api';
|
} from './utils/api';
|
||||||
import { getTableRowNames } from './utils/table';
|
import { clearTableState, getTableRowNames } from './utils/table';
|
||||||
|
|
||||||
async function goToClientsOverview(page: Page) {
|
async function goToClientsOverview(page: Page) {
|
||||||
await page.goto(PLAYWRIGHT_BASE_URL + '/clients');
|
await page.goto(PLAYWRIGHT_BASE_URL + '/clients');
|
||||||
@@ -210,18 +210,12 @@ test('test that client context menu delete deletes the client', async ({ page, c
|
|||||||
// Sorting Tests
|
// Sorting Tests
|
||||||
// =============================================
|
// =============================================
|
||||||
|
|
||||||
async function clearClientTableState(page: Page) {
|
|
||||||
await page.evaluate(() => {
|
|
||||||
localStorage.removeItem('client-table-state');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
test('test that sorting clients by name and status works', async ({ page, ctx }) => {
|
test('test that sorting clients by name and status works', async ({ page, ctx }) => {
|
||||||
await createClientViaApi(ctx, { name: 'AAA SortClient' });
|
await createClientViaApi(ctx, { name: 'AAA SortClient' });
|
||||||
await createClientViaApi(ctx, { name: 'ZZZ SortClient' });
|
await createClientViaApi(ctx, { name: 'ZZZ SortClient' });
|
||||||
|
|
||||||
await goToClientsOverview(page);
|
await goToClientsOverview(page);
|
||||||
await clearClientTableState(page);
|
await clearTableState(page, 'client-table-state');
|
||||||
await page.reload();
|
await page.reload();
|
||||||
|
|
||||||
const table = page.getByTestId('client_table');
|
const table = page.getByTestId('client_table');
|
||||||
@@ -253,7 +247,7 @@ test('test that sorting clients by project count works', async ({ page, ctx }) =
|
|||||||
await createProjectViaApi(ctx, { name: 'Proj2', client_id: clientWithMany.id });
|
await createProjectViaApi(ctx, { name: 'Proj2', client_id: clientWithMany.id });
|
||||||
|
|
||||||
await goToClientsOverview(page);
|
await goToClientsOverview(page);
|
||||||
await clearClientTableState(page);
|
await clearTableState(page, 'client-table-state');
|
||||||
await page.reload();
|
await page.reload();
|
||||||
|
|
||||||
const table = page.getByTestId('client_table');
|
const table = page.getByTestId('client_table');
|
||||||
@@ -274,7 +268,7 @@ test('test that sorting clients by project count works', async ({ page, ctx }) =
|
|||||||
|
|
||||||
test('test that client sort state persists after page reload', async ({ page }) => {
|
test('test that client sort state persists after page reload', async ({ page }) => {
|
||||||
await goToClientsOverview(page);
|
await goToClientsOverview(page);
|
||||||
await clearClientTableState(page);
|
await clearTableState(page, 'client-table-state');
|
||||||
await page.reload();
|
await page.reload();
|
||||||
|
|
||||||
const table = page.getByTestId('client_table');
|
const table = page.getByTestId('client_table');
|
||||||
@@ -397,7 +391,7 @@ test.describe('Clients Pagination', () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
await goToClientsOverview(page);
|
await goToClientsOverview(page);
|
||||||
await clearClientTableState(page);
|
await clearTableState(page, 'client-table-state');
|
||||||
await page.reload();
|
await page.reload();
|
||||||
|
|
||||||
// Default sort is name asc; first 15 clients (00–14) on page 1.
|
// Default sort is name asc; first 15 clients (00–14) on page 1.
|
||||||
@@ -450,7 +444,7 @@ test.describe('Clients Pagination', () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
await goToClientsOverview(page);
|
await goToClientsOverview(page);
|
||||||
await clearClientTableState(page);
|
await clearTableState(page, 'client-table-state');
|
||||||
await page.reload();
|
await page.reload();
|
||||||
|
|
||||||
await expect(page.getByTestId('client_table')).toBeVisible();
|
await expect(page.getByTestId('client_table')).toBeVisible();
|
||||||
@@ -470,7 +464,7 @@ test.describe('Clients Pagination', () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
await goToClientsOverview(page);
|
await goToClientsOverview(page);
|
||||||
await clearClientTableState(page);
|
await clearTableState(page, 'client-table-state');
|
||||||
await page.reload();
|
await page.reload();
|
||||||
|
|
||||||
await expect(page.getByText(prefix + '00')).toBeVisible({ timeout: 10000 });
|
await expect(page.getByText(prefix + '00')).toBeVisible({ timeout: 10000 });
|
||||||
|
|||||||
32
e2e/invitation-registration-prefill.spec.ts
Normal file
32
e2e/invitation-registration-prefill.spec.ts
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
import { expect, test } from '../playwright/fixtures';
|
||||||
|
import { PLAYWRIGHT_BASE_URL } from '../playwright/config';
|
||||||
|
import { getInvitationAcceptUrl } from './utils/mailpit';
|
||||||
|
|
||||||
|
test('prefills the registration email after accepting an invitation', async ({ page, browser }) => {
|
||||||
|
const memberId = `${Date.now()}-${Math.floor(Math.random() * 100000)}`;
|
||||||
|
const memberEmail = `prefill-${memberId}@invitation.test`;
|
||||||
|
|
||||||
|
await page.goto(PLAYWRIGHT_BASE_URL + '/members');
|
||||||
|
await page.getByRole('button', { name: 'Invite Member' }).click();
|
||||||
|
await page.getByPlaceholder('Member Email').fill(memberEmail);
|
||||||
|
await page.getByRole('button', { name: 'Employee' }).click();
|
||||||
|
await Promise.all([
|
||||||
|
page.waitForResponse(
|
||||||
|
(response) =>
|
||||||
|
response.url().includes('/invitations') &&
|
||||||
|
response.request().method() === 'POST' &&
|
||||||
|
response.status() === 204
|
||||||
|
),
|
||||||
|
page.getByRole('button', { name: 'Invite Member', exact: true }).click(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
const inviteeContext = await browser.newContext();
|
||||||
|
const inviteePage = await inviteeContext.newPage();
|
||||||
|
const acceptUrl = await getInvitationAcceptUrl(inviteePage.request, memberEmail);
|
||||||
|
await inviteePage.goto(acceptUrl);
|
||||||
|
await inviteePage.waitForURL(/\/register$/);
|
||||||
|
|
||||||
|
await expect(inviteePage.getByLabel('Email')).toHaveValue(memberEmail);
|
||||||
|
|
||||||
|
await inviteeContext.close();
|
||||||
|
});
|
||||||
@@ -11,7 +11,7 @@ import {
|
|||||||
updateMemberBillableRateViaApi,
|
updateMemberBillableRateViaApi,
|
||||||
updateOrganizationSettingViaApi,
|
updateOrganizationSettingViaApi,
|
||||||
} from './utils/api';
|
} from './utils/api';
|
||||||
import { getTableRowNames } from './utils/table';
|
import { clearTableState, getTableRowNames } from './utils/table';
|
||||||
|
|
||||||
// Tests that invite + accept members need more time
|
// Tests that invite + accept members need more time
|
||||||
test.describe.configure({ timeout: 45000 });
|
test.describe.configure({ timeout: 45000 });
|
||||||
@@ -779,20 +779,18 @@ test('test that accepted invitation disappears from invitations tab', async ({ p
|
|||||||
// Sorting Tests
|
// Sorting Tests
|
||||||
// =============================================
|
// =============================================
|
||||||
|
|
||||||
// Helper to clear localStorage before tests that check sorting
|
|
||||||
async function clearMemberTableState(page: Page) {
|
|
||||||
await page.evaluate(() => {
|
|
||||||
localStorage.removeItem('member-table-state');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
test('test that sorting members by name, role, and status works', async ({ page, ctx }) => {
|
test('test that sorting members by name, role, and status works', async ({ page, ctx }) => {
|
||||||
// Create two placeholder members with names that sort predictably around "John Doe"
|
// Create two placeholder members with names that sort predictably around "John Doe".
|
||||||
|
// Seeded alphabetically a second apart: created_at only has second precision and
|
||||||
|
// same-second rows fall back to a random UUID order. The spacing is what makes the
|
||||||
|
// API order (created_at desc: ZZZ, AAA, John) deterministic, so the tie-break
|
||||||
|
// assertions below are testing the tie-break rather than a coin flip.
|
||||||
await createPlaceholderMemberViaImportApi(ctx, 'AAA SortFirst');
|
await createPlaceholderMemberViaImportApi(ctx, 'AAA SortFirst');
|
||||||
|
await page.waitForTimeout(1100);
|
||||||
await createPlaceholderMemberViaImportApi(ctx, 'ZZZ SortLast');
|
await createPlaceholderMemberViaImportApi(ctx, 'ZZZ SortLast');
|
||||||
|
|
||||||
await goToMembersPage(page);
|
await goToMembersPage(page);
|
||||||
await clearMemberTableState(page);
|
await clearTableState(page, 'member-table-state');
|
||||||
await page.reload();
|
await page.reload();
|
||||||
|
|
||||||
const table = page.getByTestId('member_table');
|
const table = page.getByTestId('member_table');
|
||||||
@@ -814,20 +812,24 @@ test('test that sorting members by name, role, and status works', async ({ page,
|
|||||||
const ownerIdx = names.indexOf('John Doe');
|
const ownerIdx = names.indexOf('John Doe');
|
||||||
const placeholderIdx = names.indexOf('AAA SortFirst');
|
const placeholderIdx = names.indexOf('AAA SortFirst');
|
||||||
expect(ownerIdx).toBeLessThan(placeholderIdx);
|
expect(ownerIdx).toBeLessThan(placeholderIdx);
|
||||||
|
expect(names.indexOf('AAA SortFirst')).toBeLessThan(names.indexOf('ZZZ SortLast'));
|
||||||
|
|
||||||
await roleHeader.click(); // desc: Placeholder first
|
await roleHeader.click(); // desc: Placeholder first
|
||||||
names = await getTableRowNames(table);
|
names = await getTableRowNames(table);
|
||||||
expect(names.indexOf('AAA SortFirst')).toBeLessThan(names.indexOf('John Doe'));
|
expect(names.indexOf('AAA SortFirst')).toBeLessThan(names.indexOf('John Doe'));
|
||||||
|
expect(names.indexOf('AAA SortFirst')).toBeLessThan(names.indexOf('ZZZ SortLast'));
|
||||||
|
|
||||||
// -- Status sorting --
|
// -- Status sorting --
|
||||||
const statusHeader = table.getByText('Status').first();
|
const statusHeader = table.getByText('Status').first();
|
||||||
await statusHeader.click(); // asc: Active(0) < Inactive(1)
|
await statusHeader.click(); // asc: Active(0) < Inactive(1)
|
||||||
names = await getTableRowNames(table);
|
names = await getTableRowNames(table);
|
||||||
expect(names.indexOf('John Doe')).toBeLessThan(names.indexOf('AAA SortFirst'));
|
expect(names.indexOf('John Doe')).toBeLessThan(names.indexOf('AAA SortFirst'));
|
||||||
|
expect(names.indexOf('AAA SortFirst')).toBeLessThan(names.indexOf('ZZZ SortLast'));
|
||||||
|
|
||||||
await statusHeader.click(); // desc: Inactive first
|
await statusHeader.click(); // desc: Inactive first
|
||||||
names = await getTableRowNames(table);
|
names = await getTableRowNames(table);
|
||||||
expect(names.indexOf('AAA SortFirst')).toBeLessThan(names.indexOf('John Doe'));
|
expect(names.indexOf('AAA SortFirst')).toBeLessThan(names.indexOf('John Doe'));
|
||||||
|
expect(names.indexOf('AAA SortFirst')).toBeLessThan(names.indexOf('ZZZ SortLast'));
|
||||||
|
|
||||||
// -- Email: just verify sort indicator appears --
|
// -- Email: just verify sort indicator appears --
|
||||||
const emailHeader = table.getByText('Email').first();
|
const emailHeader = table.getByText('Email').first();
|
||||||
@@ -837,7 +839,7 @@ test('test that sorting members by name, role, and status works', async ({ page,
|
|||||||
|
|
||||||
test('test that member sort state persists after page reload', async ({ page }) => {
|
test('test that member sort state persists after page reload', async ({ page }) => {
|
||||||
await goToMembersPage(page);
|
await goToMembersPage(page);
|
||||||
await clearMemberTableState(page);
|
await clearTableState(page, 'member-table-state');
|
||||||
await page.reload();
|
await page.reload();
|
||||||
|
|
||||||
const table = page.getByTestId('member_table');
|
const table = page.getByTestId('member_table');
|
||||||
@@ -875,7 +877,7 @@ test('test that sorting members by billable rate works', async ({ page, ctx }) =
|
|||||||
await updateMemberBillableRateViaApi(ctx, lowRateMember!.id, 5000);
|
await updateMemberBillableRateViaApi(ctx, lowRateMember!.id, 5000);
|
||||||
|
|
||||||
await goToMembersPage(page);
|
await goToMembersPage(page);
|
||||||
await clearMemberTableState(page);
|
await clearTableState(page, 'member-table-state');
|
||||||
await page.reload();
|
await page.reload();
|
||||||
|
|
||||||
const table = page.getByTestId('member_table');
|
const table = page.getByTestId('member_table');
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { PLAYWRIGHT_BASE_URL, TEST_USER_PASSWORD } from '../playwright/config';
|
|||||||
async function goToOrganizationSettings(page) {
|
async function goToOrganizationSettings(page) {
|
||||||
await page.goto(PLAYWRIGHT_BASE_URL + '/dashboard');
|
await page.goto(PLAYWRIGHT_BASE_URL + '/dashboard');
|
||||||
await page.locator('[data-testid="organization_switcher"]:visible').click();
|
await page.locator('[data-testid="organization_switcher"]:visible').click();
|
||||||
await page.getByText('Organization Settings').click();
|
await page.getByRole('menuitem', { name: 'Organization Settings' }).click();
|
||||||
}
|
}
|
||||||
|
|
||||||
async function createTimeEntry(page, duration: string) {
|
async function createTimeEntry(page, duration: string) {
|
||||||
|
|||||||
@@ -20,6 +20,12 @@ function profileInformationForm(page: Page) {
|
|||||||
.locator('xpath=ancestor::*[descendant::form][1]');
|
.locator('xpath=ancestor::*[descendant::form][1]');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function notificationSettingsForm(page: Page) {
|
||||||
|
return page
|
||||||
|
.getByRole('heading', { name: 'Notifications', exact: true })
|
||||||
|
.locator('xpath=ancestor::*[descendant::form][1]');
|
||||||
|
}
|
||||||
|
|
||||||
async function saveProfileForm(page: Page): Promise<void> {
|
async function saveProfileForm(page: Page): Promise<void> {
|
||||||
const form = profileInformationForm(page);
|
const form = profileInformationForm(page);
|
||||||
await form.getByRole('button', { name: 'Save' }).click();
|
await form.getByRole('button', { name: 'Save' }).click();
|
||||||
@@ -50,6 +56,22 @@ test('week-start change persists across reload', async ({ page }) => {
|
|||||||
await expect(page.getByLabel('Start of the week')).toHaveValue('sunday');
|
await expect(page.getByLabel('Start of the week')).toHaveValue('sunday');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('still-running email notification setting persists across reload', async ({ page }) => {
|
||||||
|
await goToProfilePage(page);
|
||||||
|
const form = notificationSettingsForm(page);
|
||||||
|
const checkbox = form.getByLabel('Still-running time entry reminders');
|
||||||
|
|
||||||
|
await expect(checkbox).toBeChecked();
|
||||||
|
await checkbox.uncheck();
|
||||||
|
await form.getByRole('button', { name: 'Save' }).click();
|
||||||
|
await expect(form.getByText('Saved.', { exact: true })).toBeVisible();
|
||||||
|
|
||||||
|
await page.reload();
|
||||||
|
await expect(
|
||||||
|
notificationSettingsForm(page).getByLabel('Still-running time entry reminders')
|
||||||
|
).not.toBeChecked();
|
||||||
|
});
|
||||||
|
|
||||||
test('profile photo can be uploaded, persists across reload, and can be removed', async ({
|
test('profile photo can be uploaded, persists across reload, and can be removed', async ({
|
||||||
page,
|
page,
|
||||||
}) => {
|
}) => {
|
||||||
|
|||||||
@@ -13,18 +13,12 @@ import {
|
|||||||
archiveProjectViaApi,
|
archiveProjectViaApi,
|
||||||
updateOrganizationSettingViaApi,
|
updateOrganizationSettingViaApi,
|
||||||
} from './utils/api';
|
} from './utils/api';
|
||||||
|
import { clearTableState, getSeededRowOrder } from './utils/table';
|
||||||
|
|
||||||
async function goToProjectsOverview(page: Page) {
|
async function goToProjectsOverview(page: Page) {
|
||||||
await page.goto(PLAYWRIGHT_BASE_URL + '/projects');
|
await page.goto(PLAYWRIGHT_BASE_URL + '/projects');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper to clear localStorage before tests that check persistence
|
|
||||||
async function clearProjectTableState(page: Page) {
|
|
||||||
await page.evaluate(() => {
|
|
||||||
localStorage.removeItem('project-table-state');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create new project via modal
|
// Create new project via modal
|
||||||
test('test that creating and deleting a new project via the modal works', async ({ page }) => {
|
test('test that creating and deleting a new project via the modal works', async ({ page }) => {
|
||||||
const newProjectName = 'New Project ' + Math.floor(1 + Math.random() * 10000);
|
const newProjectName = 'New Project ' + Math.floor(1 + Math.random() * 10000);
|
||||||
@@ -84,7 +78,7 @@ test('test that archiving and unarchiving projects works', async ({ page, ctx })
|
|||||||
await createProjectViaApi(ctx, { name: newProjectName });
|
await createProjectViaApi(ctx, { name: newProjectName });
|
||||||
|
|
||||||
await goToProjectsOverview(page);
|
await goToProjectsOverview(page);
|
||||||
await clearProjectTableState(page);
|
await clearTableState(page, 'project-table-state');
|
||||||
await page.reload();
|
await page.reload();
|
||||||
await expect(page.getByText(newProjectName)).toBeVisible({ timeout: 10000 });
|
await expect(page.getByText(newProjectName)).toBeVisible({ timeout: 10000 });
|
||||||
|
|
||||||
@@ -480,7 +474,7 @@ test('test that sorting projects by all columns works', async ({ page, ctx }) =>
|
|||||||
});
|
});
|
||||||
|
|
||||||
await goToProjectsOverview(page);
|
await goToProjectsOverview(page);
|
||||||
await clearProjectTableState(page);
|
await clearTableState(page, 'project-table-state');
|
||||||
await page.reload();
|
await page.reload();
|
||||||
await expect(page.getByTestId('project_table')).toBeVisible();
|
await expect(page.getByTestId('project_table')).toBeVisible();
|
||||||
await expect(page.getByText('AAA Project')).toBeVisible();
|
await expect(page.getByText('AAA Project')).toBeVisible();
|
||||||
@@ -609,7 +603,7 @@ test('test that filtering projects by status works', async ({ page, ctx }) => {
|
|||||||
await createProjectViaApi(ctx, { name: newProjectName });
|
await createProjectViaApi(ctx, { name: newProjectName });
|
||||||
|
|
||||||
await goToProjectsOverview(page);
|
await goToProjectsOverview(page);
|
||||||
await clearProjectTableState(page);
|
await clearTableState(page, 'project-table-state');
|
||||||
await page.reload();
|
await page.reload();
|
||||||
await expect(page.getByText(newProjectName)).toBeVisible({ timeout: 10000 });
|
await expect(page.getByText(newProjectName)).toBeVisible({ timeout: 10000 });
|
||||||
|
|
||||||
@@ -640,7 +634,7 @@ test('test that filtering projects by status works', async ({ page, ctx }) => {
|
|||||||
|
|
||||||
test('test that filter state persists after page reload', async ({ page }) => {
|
test('test that filter state persists after page reload', async ({ page }) => {
|
||||||
await goToProjectsOverview(page);
|
await goToProjectsOverview(page);
|
||||||
await clearProjectTableState(page);
|
await clearTableState(page, 'project-table-state');
|
||||||
await page.reload();
|
await page.reload();
|
||||||
|
|
||||||
// Apply Active status filter
|
// Apply Active status filter
|
||||||
@@ -656,9 +650,96 @@ test('test that filter state persists after page reload', async ({ page }) => {
|
|||||||
await expect(page.getByTestId('status-filter-badge')).toBeVisible();
|
await expect(page.getByTestId('status-filter-badge')).toBeVisible();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('test that projects without a client or estimate are ordered by name at the bottom', async ({
|
||||||
|
page,
|
||||||
|
ctx,
|
||||||
|
}) => {
|
||||||
|
// Seeded a second apart: created_at only has second precision and same-second rows
|
||||||
|
// fall back to a random UUID order. The spacing makes the API order of the clientless
|
||||||
|
// rows (created_at desc: ZZZ, AAA) deterministic and different from the alphabetical
|
||||||
|
// order the name tie-break should produce.
|
||||||
|
await createProjectViaApi(ctx, { name: 'AAA Tiebreak Project' });
|
||||||
|
await page.waitForTimeout(1100);
|
||||||
|
await createProjectViaApi(ctx, { name: 'ZZZ Tiebreak Project' });
|
||||||
|
|
||||||
|
const clientAardvark = await createClientViaApi(ctx, { name: 'Aardvark Co' });
|
||||||
|
const clientZulu = await createClientViaApi(ctx, { name: 'Zulu Co' });
|
||||||
|
const projectM = await createProjectViaApi(ctx, {
|
||||||
|
name: 'MMM Tiebreak Project',
|
||||||
|
client_id: clientAardvark.id,
|
||||||
|
estimated_time: 36000, // 10h, 1h tracked below = 10%
|
||||||
|
});
|
||||||
|
await createTimeEntryViaApi(ctx, { duration: '1h', projectId: projectM.id });
|
||||||
|
const projectN = await createProjectViaApi(ctx, {
|
||||||
|
name: 'NNN Tiebreak Project',
|
||||||
|
client_id: clientZulu.id,
|
||||||
|
estimated_time: 14400, // 4h, 2h tracked below = 50%
|
||||||
|
});
|
||||||
|
await createTimeEntryViaApi(ctx, { duration: '2h', projectId: projectN.id });
|
||||||
|
|
||||||
|
await goToProjectsOverview(page);
|
||||||
|
await clearTableState(page, 'project-table-state');
|
||||||
|
await page.reload();
|
||||||
|
|
||||||
|
const table = page.getByTestId('project_table');
|
||||||
|
await expect(table).toBeVisible();
|
||||||
|
|
||||||
|
const seeded = [
|
||||||
|
'AAA Tiebreak Project',
|
||||||
|
'MMM Tiebreak Project',
|
||||||
|
'NNN Tiebreak Project',
|
||||||
|
'ZZZ Tiebreak Project',
|
||||||
|
];
|
||||||
|
const getOrder = () => getSeededRowOrder(table, seeded);
|
||||||
|
|
||||||
|
// -- Client: empty rows last in both directions, alphabetical among themselves --
|
||||||
|
const clientHeader = table.locator('.select-none', { hasText: 'Client' }).first();
|
||||||
|
await clientHeader.click();
|
||||||
|
await expect
|
||||||
|
.poll(getOrder)
|
||||||
|
.toEqual([
|
||||||
|
'MMM Tiebreak Project',
|
||||||
|
'NNN Tiebreak Project',
|
||||||
|
'AAA Tiebreak Project',
|
||||||
|
'ZZZ Tiebreak Project',
|
||||||
|
]);
|
||||||
|
|
||||||
|
await clientHeader.click();
|
||||||
|
await expect
|
||||||
|
.poll(getOrder)
|
||||||
|
.toEqual([
|
||||||
|
'NNN Tiebreak Project',
|
||||||
|
'MMM Tiebreak Project',
|
||||||
|
'AAA Tiebreak Project',
|
||||||
|
'ZZZ Tiebreak Project',
|
||||||
|
]);
|
||||||
|
|
||||||
|
// -- Progress: same, and the first click sorts highest first --
|
||||||
|
const progressHeader = table.locator('.select-none', { hasText: 'Progress' }).first();
|
||||||
|
await progressHeader.click();
|
||||||
|
await expect
|
||||||
|
.poll(getOrder)
|
||||||
|
.toEqual([
|
||||||
|
'NNN Tiebreak Project',
|
||||||
|
'MMM Tiebreak Project',
|
||||||
|
'AAA Tiebreak Project',
|
||||||
|
'ZZZ Tiebreak Project',
|
||||||
|
]);
|
||||||
|
|
||||||
|
await progressHeader.click();
|
||||||
|
await expect
|
||||||
|
.poll(getOrder)
|
||||||
|
.toEqual([
|
||||||
|
'MMM Tiebreak Project',
|
||||||
|
'NNN Tiebreak Project',
|
||||||
|
'AAA Tiebreak Project',
|
||||||
|
'ZZZ Tiebreak Project',
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
test('test that sort state persists after page reload', async ({ page }) => {
|
test('test that sort state persists after page reload', async ({ page }) => {
|
||||||
await goToProjectsOverview(page);
|
await goToProjectsOverview(page);
|
||||||
await clearProjectTableState(page);
|
await clearTableState(page, 'project-table-state');
|
||||||
await page.reload();
|
await page.reload();
|
||||||
|
|
||||||
// Click on Name header twice to sort descending
|
// Click on Name header twice to sort descending
|
||||||
@@ -1114,7 +1195,7 @@ test.describe('Projects Pagination', () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
await goToProjectsOverview(page);
|
await goToProjectsOverview(page);
|
||||||
await clearProjectTableState(page);
|
await clearTableState(page, 'project-table-state');
|
||||||
await page.reload();
|
await page.reload();
|
||||||
|
|
||||||
// Default sort is name asc; first 15 projects (00–14) should be on page 1.
|
// Default sort is name asc; first 15 projects (00–14) should be on page 1.
|
||||||
@@ -1168,7 +1249,7 @@ test.describe('Projects Pagination', () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
await goToProjectsOverview(page);
|
await goToProjectsOverview(page);
|
||||||
await clearProjectTableState(page);
|
await clearTableState(page, 'project-table-state');
|
||||||
await page.reload();
|
await page.reload();
|
||||||
|
|
||||||
await expect(page.getByTestId('project_table')).toBeVisible();
|
await expect(page.getByTestId('project_table')).toBeVisible();
|
||||||
@@ -1185,7 +1266,7 @@ test.describe('Projects Pagination', () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
await goToProjectsOverview(page);
|
await goToProjectsOverview(page);
|
||||||
await clearProjectTableState(page);
|
await clearTableState(page, 'project-table-state');
|
||||||
await page.reload();
|
await page.reload();
|
||||||
|
|
||||||
await expect(page.getByText(prefix + '00')).toBeVisible({ timeout: 10000 });
|
await expect(page.getByText(prefix + '00')).toBeVisible({ timeout: 10000 });
|
||||||
@@ -1207,3 +1288,36 @@ test.describe('Projects Pagination', () => {
|
|||||||
await expect(page.getByText(prefix + '00')).not.toBeVisible();
|
await expect(page.getByText(prefix + '00')).not.toBeVisible();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('test that searching projects by name works', async ({ page, ctx }) => {
|
||||||
|
const suffix = Math.floor(1 + Math.random() * 10000);
|
||||||
|
const matchingProjectName = 'Searchable Project ' + suffix;
|
||||||
|
const otherProjectName = 'Unrelated Work ' + suffix;
|
||||||
|
await createProjectViaApi(ctx, { name: matchingProjectName });
|
||||||
|
await createProjectViaApi(ctx, { name: otherProjectName });
|
||||||
|
|
||||||
|
await goToProjectsOverview(page);
|
||||||
|
await clearTableState(page, 'project-table-state');
|
||||||
|
await page.reload();
|
||||||
|
await expect(page.getByText(matchingProjectName)).toBeVisible({ timeout: 10000 });
|
||||||
|
await expect(page.getByText(otherProjectName)).toBeVisible();
|
||||||
|
|
||||||
|
const searchInput = page.getByRole('searchbox', { name: 'Search projects' });
|
||||||
|
|
||||||
|
// Searching is case insensitive and matches part of the name
|
||||||
|
await searchInput.fill('SEARCHABLE');
|
||||||
|
await expect(page.getByText(matchingProjectName)).toBeVisible();
|
||||||
|
await expect(page.getByText(otherProjectName)).not.toBeVisible();
|
||||||
|
|
||||||
|
// A term that matches nothing empties the table
|
||||||
|
await searchInput.fill('no project has this name');
|
||||||
|
await expect(page.getByText(matchingProjectName)).not.toBeVisible();
|
||||||
|
await expect(page.getByText(otherProjectName)).not.toBeVisible();
|
||||||
|
await expect(page.getByText('No matching projects')).toBeVisible();
|
||||||
|
await expect(page.getByRole('button', { name: 'Create your First Project' })).not.toBeVisible();
|
||||||
|
|
||||||
|
// Clearing the search restores both projects
|
||||||
|
await searchInput.fill('');
|
||||||
|
await expect(page.getByText(matchingProjectName)).toBeVisible();
|
||||||
|
await expect(page.getByText(otherProjectName)).toBeVisible();
|
||||||
|
});
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import {
|
|||||||
createTimeEntryWithTagViaApi,
|
createTimeEntryWithTagViaApi,
|
||||||
createTimeEntryWithBillableStatusViaApi,
|
createTimeEntryWithBillableStatusViaApi,
|
||||||
createBareTimeEntryViaApi,
|
createBareTimeEntryViaApi,
|
||||||
|
createTimeEntryOnDateViaApi,
|
||||||
createPublicProjectViaApi,
|
createPublicProjectViaApi,
|
||||||
updateOrganizationSettingViaApi,
|
updateOrganizationSettingViaApi,
|
||||||
} from './utils/api';
|
} from './utils/api';
|
||||||
@@ -841,6 +842,127 @@ test('test that setting group by to current sub group triggers sub group fallbac
|
|||||||
await expect(groupBySelects.filter({ hasText: 'Members' }).first()).toBeVisible();
|
await expect(groupBySelects.filter({ hasText: 'Members' }).first()).toBeVisible();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('test that group by date groups the report by day and formats the date labels with organization settings', async ({
|
||||||
|
page,
|
||||||
|
ctx,
|
||||||
|
}) => {
|
||||||
|
await updateOrganizationSettingViaApi(ctx, { date_format: 'point-separated-d-m-yyyy' });
|
||||||
|
|
||||||
|
await createTimeEntryViaApi(ctx, {
|
||||||
|
description: 'Entry for group by date',
|
||||||
|
duration: '1h',
|
||||||
|
});
|
||||||
|
|
||||||
|
// Go to reporting page
|
||||||
|
await goToReporting(page);
|
||||||
|
await expect(page.getByRole('button', { name: 'Export' })).toBeVisible();
|
||||||
|
|
||||||
|
// Find the "Group by" selects within the reporting table
|
||||||
|
const groupBySelects = page.locator('[data-testid="reporting_view"]').getByRole('combobox');
|
||||||
|
|
||||||
|
// Default state: group=Project
|
||||||
|
await groupBySelects.filter({ hasText: 'Project' }).first().click();
|
||||||
|
|
||||||
|
const [aggregateResponse] = await Promise.all([
|
||||||
|
page.waitForResponse(
|
||||||
|
(response) =>
|
||||||
|
response.url().includes('/time-entries/aggregate') &&
|
||||||
|
response.url().includes('group=day') &&
|
||||||
|
response.status() === 200
|
||||||
|
),
|
||||||
|
page.getByRole('option', { name: 'Date', exact: true }).click(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
// Verify the API request contains the correct group parameter
|
||||||
|
const requestUrl = new URL(aggregateResponse.url());
|
||||||
|
expect(requestUrl.searchParams.get('group')).toBe('day');
|
||||||
|
|
||||||
|
// The row label is rendered in the organization date format (D.M.YYYY)
|
||||||
|
await expect(
|
||||||
|
page.getByTestId('reporting_view').getByText(/^\d{1,2}\.\d{1,2}\.\d{4}$/)
|
||||||
|
).toBeVisible();
|
||||||
|
await expect(page.getByTestId('reporting_view').getByText(/^\d{4}-\d{2}-\d{2}$/)).toHaveCount(
|
||||||
|
0
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('test that group by week requests week grouping and does not leak the raw group key', async ({
|
||||||
|
page,
|
||||||
|
ctx,
|
||||||
|
}) => {
|
||||||
|
await createTimeEntryViaApi(ctx, {
|
||||||
|
description: 'Entry for group by week',
|
||||||
|
duration: '1h',
|
||||||
|
});
|
||||||
|
|
||||||
|
await goToReporting(page);
|
||||||
|
await expect(page.getByRole('button', { name: 'Export' })).toBeVisible();
|
||||||
|
|
||||||
|
const groupBySelects = page.locator('[data-testid="reporting_view"]').getByRole('combobox');
|
||||||
|
await groupBySelects.filter({ hasText: 'Project' }).first().click();
|
||||||
|
|
||||||
|
const [aggregateResponse] = await Promise.all([
|
||||||
|
page.waitForResponse(
|
||||||
|
(response) =>
|
||||||
|
response.url().includes('/time-entries/aggregate') &&
|
||||||
|
response.url().includes('group=week') &&
|
||||||
|
response.status() === 200
|
||||||
|
),
|
||||||
|
page.getByRole('option', { name: 'Week', exact: true }).click(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
const requestUrl = new URL(aggregateResponse.url());
|
||||||
|
expect(requestUrl.searchParams.get('group')).toBe('week');
|
||||||
|
|
||||||
|
// The raw group key is the first day of the week and must not leak through.
|
||||||
|
await expect(page.getByTestId('reporting_view').getByText(/^\d{4}-\d{2}-\d{2}$/)).toHaveCount(
|
||||||
|
0
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('test that group by week labels a week spanning new year with a range crossing the year', async ({
|
||||||
|
page,
|
||||||
|
ctx,
|
||||||
|
}) => {
|
||||||
|
await updateOrganizationSettingViaApi(ctx, { date_format: 'slash-separated-dd-mm-yyyy' });
|
||||||
|
|
||||||
|
for (const day of ['2025-12-22', '2025-12-29', '2026-01-05']) {
|
||||||
|
await createTimeEntryOnDateViaApi(ctx, {
|
||||||
|
date: new Date(`${day}T09:00:00Z`),
|
||||||
|
duration: '1h',
|
||||||
|
description: `Entry for ${day}`,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// The reporting page keeps its range in session storage, so seed a range spanning new year
|
||||||
|
// rather than driving the date picker.
|
||||||
|
await page.addInitScript(() => {
|
||||||
|
window.sessionStorage.setItem('reporting-start-date', '2025-12-15');
|
||||||
|
window.sessionStorage.setItem('reporting-end-date', '2026-01-15');
|
||||||
|
});
|
||||||
|
|
||||||
|
await goToReporting(page);
|
||||||
|
await expect(page.getByRole('button', { name: 'Export' })).toBeVisible();
|
||||||
|
|
||||||
|
const groupBySelects = page.locator('[data-testid="reporting_view"]').getByRole('combobox');
|
||||||
|
await groupBySelects.filter({ hasText: 'Project' }).first().click();
|
||||||
|
await Promise.all([
|
||||||
|
page.waitForResponse(
|
||||||
|
(response) =>
|
||||||
|
response.url().includes('/time-entries/aggregate') &&
|
||||||
|
response.url().includes('group=week') &&
|
||||||
|
response.status() === 200
|
||||||
|
),
|
||||||
|
page.getByRole('option', { name: 'Week', exact: true }).click(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
const reportingView = page.getByTestId('reporting_view');
|
||||||
|
await expect(reportingView.getByText('22/12/2025 - 28/12/2025', { exact: true })).toBeVisible();
|
||||||
|
await expect(reportingView.getByText('29/12/2025 - 04/01/2026', { exact: true })).toBeVisible();
|
||||||
|
await expect(reportingView.getByText('05/01/2026 - 11/01/2026', { exact: true })).toBeVisible();
|
||||||
|
await expect(reportingView.getByText(/^\d{4}-\d{2}-\d{2}$/)).toHaveCount(0);
|
||||||
|
});
|
||||||
|
|
||||||
// ──────────────────────────────────────────────────
|
// ──────────────────────────────────────────────────
|
||||||
// Export Tests
|
// Export Tests
|
||||||
// ──────────────────────────────────────────────────
|
// ──────────────────────────────────────────────────
|
||||||
@@ -1019,3 +1141,24 @@ test.describe('Employee Reporting Restrictions', () => {
|
|||||||
await expect(employee.page.getByText('100,00 EUR').first()).toBeVisible();
|
await expect(employee.page.getByText('100,00 EUR').first()).toBeVisible();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('test that reporting has a type filter that can show only breaks', async ({ page, ctx }) => {
|
||||||
|
await updateOrganizationSettingViaApi(ctx, { breaks_enabled: true });
|
||||||
|
await createTimeEntryViaApi(ctx, { duration: '1h', description: 'Regular work entry' });
|
||||||
|
await createTimeEntryViaApi(ctx, { duration: '20min', type: 'break' });
|
||||||
|
|
||||||
|
await goToReporting(page);
|
||||||
|
// The type filter defaults to "Work time"; switching it to "Breaks" re-aggregates.
|
||||||
|
const typeFilter = page.getByRole('combobox').filter({ hasText: 'Work time' });
|
||||||
|
await expect(typeFilter).toBeVisible();
|
||||||
|
await typeFilter.click();
|
||||||
|
await Promise.all([
|
||||||
|
page.waitForResponse(
|
||||||
|
(response) =>
|
||||||
|
response.url().includes('/time-entries/aggregate') &&
|
||||||
|
response.url().includes('type=break') &&
|
||||||
|
response.status() === 200
|
||||||
|
),
|
||||||
|
page.getByRole('option', { name: 'Breaks' }).click(),
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import {
|
|||||||
createTimeEntryWithBillableStatusViaApi,
|
createTimeEntryWithBillableStatusViaApi,
|
||||||
createTagViaApi,
|
createTagViaApi,
|
||||||
createReportViaApi,
|
createReportViaApi,
|
||||||
|
updateOrganizationSettingViaApi,
|
||||||
} from './utils/api';
|
} from './utils/api';
|
||||||
import {
|
import {
|
||||||
goToReporting,
|
goToReporting,
|
||||||
@@ -68,6 +69,42 @@ test('test that saving a report creates a shared report and its shareable link s
|
|||||||
await expect(page.getByText('Total')).toBeVisible();
|
await expect(page.getByText('Total')).toBeVisible();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('test that a shared report grouped by date shows date labels formatted by the organization setting', async ({
|
||||||
|
page,
|
||||||
|
ctx,
|
||||||
|
}) => {
|
||||||
|
const reportName = 'DateGroupReport ' + Math.floor(Math.random() * 10000);
|
||||||
|
|
||||||
|
await updateOrganizationSettingViaApi(ctx, { date_format: 'point-separated-d-m-yyyy' });
|
||||||
|
await createTimeEntryViaApi(ctx, {
|
||||||
|
description: 'Entry for date grouping',
|
||||||
|
duration: '1h',
|
||||||
|
});
|
||||||
|
|
||||||
|
await goToReporting(page);
|
||||||
|
|
||||||
|
// Switch the grouping to "Date"
|
||||||
|
const groupBySelects = page.locator('[data-testid="reporting_view"]').getByRole('combobox');
|
||||||
|
await groupBySelects.filter({ hasText: 'Project' }).first().click();
|
||||||
|
await Promise.all([
|
||||||
|
page.waitForResponse(
|
||||||
|
(response) =>
|
||||||
|
response.url().includes('/time-entries/aggregate') &&
|
||||||
|
response.url().includes('group=day') &&
|
||||||
|
response.status() === 200
|
||||||
|
),
|
||||||
|
page.getByRole('option', { name: 'Date', exact: true }).click(),
|
||||||
|
]);
|
||||||
|
|
||||||
|
const { shareableLink } = await saveAsSharedReport(page, reportName);
|
||||||
|
|
||||||
|
// Verify row labels are formatted correctly
|
||||||
|
await page.goto(shareableLink);
|
||||||
|
await expect(page.getByText('Total')).toBeVisible();
|
||||||
|
await expect(page.getByText(/^\d{1,2}\.\d{1,2}\.\d{4}$/)).toBeVisible();
|
||||||
|
await expect(page.getByText(/^\d{4}-\d{2}-\d{2}$/)).toHaveCount(0);
|
||||||
|
});
|
||||||
|
|
||||||
test('test that shared report with invalid secret shows no data', async ({ page }) => {
|
test('test that shared report with invalid secret shows no data', async ({ page }) => {
|
||||||
await page.goto(PLAYWRIGHT_BASE_URL + '/shared-report#invalid-secret-value');
|
await page.goto(PLAYWRIGHT_BASE_URL + '/shared-report#invalid-secret-value');
|
||||||
await expect(page.getByText('No time entries found').first()).toBeVisible();
|
await expect(page.getByText('No time entries found').first()).toBeVisible();
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user