From c49d2741d19b8eb581cf9e1a4d1cf7bb1584b05c Mon Sep 17 00:00:00 2001 From: Chris Morrell Date: Sun, 17 Nov 2024 11:02:05 -0500 Subject: [PATCH] Only show confirmed domains in drop-down --- app/Enums/DomainStatus.php | 10 ++++++++ .../SetGroupFromDomainMiddleware.php | 11 ++++++++ app/Models/Group.php | 2 ++ app/Providers/AppServiceProvider.php | 2 ++ ..._17_155609_add_domain_status_to_groups.php | 25 +++++++++++++++++++ 5 files changed, 50 insertions(+) create mode 100644 app/Enums/DomainStatus.php create mode 100644 database/migrations/2024_11_17_155609_add_domain_status_to_groups.php diff --git a/app/Enums/DomainStatus.php b/app/Enums/DomainStatus.php new file mode 100644 index 0000000..8f2229a --- /dev/null +++ b/app/Enums/DomainStatus.php @@ -0,0 +1,10 @@ +updateDomainStatusIfNecessary($group); + Container::getInstance()->instance(Group::class, $group); Container::getInstance()->instance("group:{$group->domain}", $group); Context::add('group_id', $group->getKey()); @@ -55,6 +58,14 @@ protected function group(Request $request): ?Group : null; } + protected function updateDomainStatusIfNecessary(Group $group): void + { + if ($group->domain_status !== DomainStatus::Confirmed) { + $group->update(['domain_status' => DomainStatus::Confirmed]); + Cache::forget('phpx-network'); + } + } + protected function isRootDomain(Request $request): bool { return collect(RootDomains::cases()) diff --git a/app/Models/Group.php b/app/Models/Group.php index 3029e2e..38447b8 100644 --- a/app/Models/Group.php +++ b/app/Models/Group.php @@ -2,6 +2,7 @@ namespace App\Models; +use App\Enums\DomainStatus; use App\Enums\GroupStatus; use Glhd\Bits\Database\HasSnowflakes; use Illuminate\Container\Container; @@ -43,6 +44,7 @@ protected function casts(): array 'mailcoach_token' => 'encrypted', 'bsky_app_password' => 'encrypted', 'status' => GroupStatus::class, + 'domain_status' => DomainStatus::class, 'latitude' => 'float', 'longitude' => 'float', ]; diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 6601d34..158eab9 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -2,6 +2,7 @@ namespace App\Providers; +use App\Enums\DomainStatus; use App\Models\ExternalGroup; use App\Models\Group; use Illuminate\Contracts\View\Factory; @@ -37,6 +38,7 @@ protected function sharePhpxNetwork() try { return Group::query() ->select('domain', 'name', 'region') + ->where('domain_status', DomainStatus::Confirmed) ->get() ->mapWithKeys(fn(Group $group) => [$group->domain => $group->label()]) ->toArray(); diff --git a/database/migrations/2024_11_17_155609_add_domain_status_to_groups.php b/database/migrations/2024_11_17_155609_add_domain_status_to_groups.php new file mode 100644 index 0000000..cc37022 --- /dev/null +++ b/database/migrations/2024_11_17_155609_add_domain_status_to_groups.php @@ -0,0 +1,25 @@ +string('domain_status')->default(DomainStatus::Pending)->index()->after('domain'); + }); + + Group::query()->update(['domain_status' => DomainStatus::Confirmed]); + } + + public function down(): void + { + Schema::table('groups', function(Blueprint $table) { + $table->dropColumn('domain_status'); + }); + } +};