From a13497df5f1c1aa7f72fabb097106c6dae8b6396 Mon Sep 17 00:00:00 2001 From: Deon George Date: Sat, 25 Nov 2023 00:10:21 +1100 Subject: [PATCH] Update domain::public() to only show public domains to admins, update status to be consistent with domain::public() --- app/Http/Controllers/HomeController.php | 1 + app/Models/Domain.php | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index ba327f6..4726c25 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -292,6 +292,7 @@ class HomeController extends Controller ->where('addresses.active',TRUE) ->where('zones.active',TRUE) ->where('domains.active',TRUE) + ->when(! ($x=Auth::user()) || (! $x->isAdmin()),function($query) { return $query->where('domains.public',TRUE); }) ->join('addresses',['addresses.id'=>'a.id']) ->join('zones',['zones.id'=>'addresses.zone_id']) ->join('domains',['domains.id'=>'zones.domain_id']) diff --git a/app/Models/Domain.php b/app/Models/Domain.php index 5bc2f1e..f673e08 100644 --- a/app/Models/Domain.php +++ b/app/Models/Domain.php @@ -7,6 +7,7 @@ use Carbon\Carbon; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Collection; +use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\DB; use App\Casts\CompressedString; @@ -30,7 +31,10 @@ class Domain extends Model */ public function scopePublic($query) { - return $query->where('public',TRUE); + $user = Auth::user(); + + return $query + ->when(((! $user) || (! $user->isAdmin())),function($query) { return $query->where('public',TRUE)->active(); }); } /* RELATIONS */