From f3e06bb1256ea1591907e46a289132f55feb6625 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Jaussoin?= Date: Tue, 25 Nov 2025 11:39:15 +0000 Subject: [PATCH] Fix FLEXIAPI-412 Restrict the default messages statistics graph to the space... --- .../Http/Controllers/Admin/StatisticsController.php | 10 +++++++--- flexiapi/app/Http/Middleware/SpaceCheck.php | 6 +++--- flexiapi/app/Libraries/StatisticsGraphFactory.php | 4 ++-- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/flexiapi/app/Http/Controllers/Admin/StatisticsController.php b/flexiapi/app/Http/Controllers/Admin/StatisticsController.php index 9a45fa6..c18ad64 100644 --- a/flexiapi/app/Http/Controllers/Admin/StatisticsController.php +++ b/flexiapi/app/Http/Controllers/Admin/StatisticsController.php @@ -106,9 +106,13 @@ class StatisticsController extends Controller $fromQuery = StatisticsCall::query(); $toQuery = StatisticsCall::query(); - if ($request->get('domain')) { - $fromQuery->where('to_domain', $request->get('domain')); - $toQuery->where('from_domain', $request->get('domain')); + $domain = $request->user()->superAdmin + ? $request->get('domain') + : $request->user()->domain; + + if ($domain) { + $fromQuery->where('to_domain', $domain); + $toQuery->where('from_domain', $domain); } if ($request->get('to')) { diff --git a/flexiapi/app/Http/Middleware/SpaceCheck.php b/flexiapi/app/Http/Middleware/SpaceCheck.php index 2d28a34..2477bda 100644 --- a/flexiapi/app/Http/Middleware/SpaceCheck.php +++ b/flexiapi/app/Http/Middleware/SpaceCheck.php @@ -12,14 +12,14 @@ class SpaceCheck public function handle(Request $request, Closure $next): Response { if (empty(config('app.root_host'))) { - return abort(503, 'APP_ROOT_HOST is not configured'); + abort(503, 'APP_ROOT_HOST is not configured'); } $space = space(reload: true); if ($space != null) { if (!str_ends_with($space->host, config('app.root_host'))) { - return abort(503, 'The APP_ROOT_HOST configured does not match with the current root domain'); + abort(503, 'The APP_ROOT_HOST configured does not match with the current root domain'); } Config::set('app.url', '://' . $space->host); @@ -51,6 +51,6 @@ class SpaceCheck return $next($request); } - return abort(404, 'Host not configured'); + abort(404, 'Host not configured'); } } diff --git a/flexiapi/app/Libraries/StatisticsGraphFactory.php b/flexiapi/app/Libraries/StatisticsGraphFactory.php index 1a5e993..25224b4 100644 --- a/flexiapi/app/Libraries/StatisticsGraphFactory.php +++ b/flexiapi/app/Libraries/StatisticsGraphFactory.php @@ -57,9 +57,9 @@ class StatisticsGraphFactory $fromQuery = StatisticsMessage::query(); $toQuery = StatisticsMessage::query(); - if (!Auth::user()?->admin) { + if (!Auth::user()?->superAdmin) { $fromQuery->where('from_domain', space()->domain); - $toQuery->toDomain($this->domain); + $toQuery->toDomain(space()->domain); } elseif ($this->domain) { $fromQuery->where('from_domain', $this->domain); $toQuery->toDomain($this->domain);