Skip to content

Commit

Permalink
Only show confirmed domains in drop-down
Browse files Browse the repository at this point in the history
  • Loading branch information
inxilpro committed Nov 17, 2024
1 parent 988a1ce commit c49d274
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 0 deletions.
10 changes: 10 additions & 0 deletions app/Enums/DomainStatus.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace App\Enums;

enum DomainStatus: string
{
case Confirmed = 'confirmed';

case Pending = 'pending';
}
11 changes: 11 additions & 0 deletions app/Http/Middleware/SetGroupFromDomainMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Http\Middleware;

use App\Enums\DomainStatus;
use App\Enums\RootDomains;
use App\Models\Group;
use Closure;
Expand All @@ -25,6 +26,8 @@ public function handle(Request $request, Closure $next)
throw new NotFoundHttpException();
}

$this->updateDomainStatusIfNecessary($group);

Container::getInstance()->instance(Group::class, $group);
Container::getInstance()->instance("group:{$group->domain}", $group);
Context::add('group_id', $group->getKey());
Expand Down Expand Up @@ -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())
Expand Down
2 changes: 2 additions & 0 deletions app/Models/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Models;

use App\Enums\DomainStatus;
use App\Enums\GroupStatus;
use Glhd\Bits\Database\HasSnowflakes;
use Illuminate\Container\Container;
Expand Down Expand Up @@ -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',
];
Expand Down
2 changes: 2 additions & 0 deletions app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Providers;

use App\Enums\DomainStatus;
use App\Models\ExternalGroup;
use App\Models\Group;
use Illuminate\Contracts\View\Factory;
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

use App\Enums\DomainStatus;
use App\Models\Group;
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('groups', function(Blueprint $table) {
$table->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');
});
}
};

0 comments on commit c49d274

Please sign in to comment.