diff --git a/.env.example b/.env.example index 3e3af021..ababebfd 100644 --- a/.env.example +++ b/.env.example @@ -68,3 +68,6 @@ SANCTUM_STATEFUL_DOMAINS=toby.blumilk.localhost SOPS_AGE_BETA_SECRET_KEY= SOPS_AGE_PROD_SECRET_KEY= + +# 5 minutes (in miliseconds) +VITE_LAST_UPDATE_TIMEOUT=300000 diff --git a/app/Architecture/Providers/EventServiceProvider.php b/app/Architecture/Providers/EventServiceProvider.php index a1e9f46b..63beae0d 100644 --- a/app/Architecture/Providers/EventServiceProvider.php +++ b/app/Architecture/Providers/EventServiceProvider.php @@ -7,12 +7,14 @@ use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider; use Toby\Domain\Events\VacationRequestChanged; use Toby\Domain\Listeners\UpdateDailySummaries; +use Toby\Domain\Listeners\UpdateLastUpdateCache; class EventServiceProvider extends ServiceProvider { protected $listen = [ VacationRequestChanged::class => [ UpdateDailySummaries::class, + UpdateLastUpdateCache::class, ], ]; } diff --git a/app/Domain/Actions/VacationRequest/WaitForAdminApprovalAction.php b/app/Domain/Actions/VacationRequest/WaitForAdminApprovalAction.php index 32bc3932..3afa7e97 100644 --- a/app/Domain/Actions/VacationRequest/WaitForAdminApprovalAction.php +++ b/app/Domain/Actions/VacationRequest/WaitForAdminApprovalAction.php @@ -35,6 +35,7 @@ protected function notifyAuthorizedUsers(VacationRequest $vacationRequest): void { $users = Permission::findByName("receiveVacationRequestWaitsForApprovalNotification") ->users() + ->with("permissions") ->get(); $users = $users->filter(fn(User $user): bool => $user->can("acceptAsAdminApprover", $vacationRequest)); diff --git a/app/Domain/Listeners/UpdateLastUpdateCache.php b/app/Domain/Listeners/UpdateLastUpdateCache.php new file mode 100644 index 00000000..8581087c --- /dev/null +++ b/app/Domain/Listeners/UpdateLastUpdateCache.php @@ -0,0 +1,21 @@ +cacheManager->set("last_update", Carbon::now()->toIso8601String()); + } +} diff --git a/app/Infrastructure/Http/Controllers/Api/LastUpdateController.php b/app/Infrastructure/Http/Controllers/Api/LastUpdateController.php new file mode 100644 index 00000000..c31483c2 --- /dev/null +++ b/app/Infrastructure/Http/Controllers/Api/LastUpdateController.php @@ -0,0 +1,19 @@ + $cache->get("last_update", Carbon::now()->toIso8601String()), + ]); + } +} diff --git a/app/Infrastructure/Http/Middleware/HandleInertiaRequests.php b/app/Infrastructure/Http/Middleware/HandleInertiaRequests.php index a3ba9cd3..09ff3f22 100644 --- a/app/Infrastructure/Http/Middleware/HandleInertiaRequests.php +++ b/app/Infrastructure/Http/Middleware/HandleInertiaRequests.php @@ -4,7 +4,9 @@ namespace Toby\Infrastructure\Http\Middleware; +use Carbon\Carbon; use Closure; +use Illuminate\Cache\CacheManager; use Illuminate\Http\Request; use Inertia\Middleware; use Spatie\Permission\Models\Permission; @@ -17,6 +19,7 @@ class HandleInertiaRequests extends Middleware { public function __construct( protected YearPeriodRetriever $yearPeriodRetriever, + protected CacheManager $cache, ) {} public function share(Request $request): array @@ -27,6 +30,7 @@ public function share(Request $request): array "years" => $this->getYearsData($request), "vacationRequestsCount" => $this->getVacationRequestsCount($request), "deployInformation" => $this->getDeployInformation(), + "lastUpdate" => $this->cache->rememberForever("last_update", fn(): string => Carbon::now()->toIso8601String()), ]); } diff --git a/app/Infrastructure/Http/Resources/VacationRequestResource.php b/app/Infrastructure/Http/Resources/VacationRequestResource.php index a1414b52..a5a785a3 100644 --- a/app/Infrastructure/Http/Resources/VacationRequestResource.php +++ b/app/Infrastructure/Http/Resources/VacationRequestResource.php @@ -30,7 +30,7 @@ public function toArray($request): array return [ "id" => $this->id, "name" => $this->name, - "user" => new SimpleUserResource($user), + "user" => new SimpleUserResource($this->user), "type" => $this->type, "isVacation" => $this->configRetriever->isVacation($this->type), "state" => $this->state, diff --git a/docker-compose.yml b/docker-compose.yml index 5456e4a4..df62a59e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,5 +1,3 @@ -version: "3.8" - services: app: build: diff --git a/environment/prod/app/Dockerfile b/environment/prod/app/Dockerfile index 83e2c0b9..38a0d2e2 100644 --- a/environment/prod/app/Dockerfile +++ b/environment/prod/app/Dockerfile @@ -24,6 +24,7 @@ FROM node:21.6.2-bullseye-slim as frontend WORKDIR /app_frontend_dependencies COPY package.json package-lock.json postcss.config.js tailwind.config.js vite.config.js ./ +COPY ./environment/prod/app/vite.env .env RUN npm clean-install diff --git a/environment/prod/app/vite.env b/environment/prod/app/vite.env new file mode 100644 index 00000000..bd58f70c --- /dev/null +++ b/environment/prod/app/vite.env @@ -0,0 +1 @@ +VITE_LAST_UPDATE_TIMEOUT=300000 diff --git a/public/images/icon-alert.png b/public/images/icon-alert.png new file mode 100644 index 00000000..d8dab065 Binary files /dev/null and b/public/images/icon-alert.png differ diff --git a/resources/js/Shared/LastUpdate.vue b/resources/js/Shared/LastUpdate.vue new file mode 100644 index 00000000..82377be0 --- /dev/null +++ b/resources/js/Shared/LastUpdate.vue @@ -0,0 +1,28 @@ + diff --git a/resources/js/Shared/Layout/AppLayout.vue b/resources/js/Shared/Layout/AppLayout.vue index fbd506b1..b17e3095 100644 --- a/resources/js/Shared/Layout/AppLayout.vue +++ b/resources/js/Shared/Layout/AppLayout.vue @@ -1,8 +1,10 @@