Skip to content

Commit

Permalink
handle server with "conflict state"
Browse files Browse the repository at this point in the history
  • Loading branch information
Boy132 committed Nov 21, 2024
1 parent 834306f commit 79b51b7
Show file tree
Hide file tree
Showing 10 changed files with 128 additions and 12 deletions.
11 changes: 6 additions & 5 deletions app/Filament/Server/Pages/Console.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,16 @@ protected function getHeaderActions(): array
return [
Action::make('start')
->color('primary')
->action(fn () => $this->dispatch('setServerState', state: 'start')),

->action(fn () => $this->dispatch('setServerState', state: 'start'))
->disabled(fn () => Filament::getTenant()->isInConflictState()),
Action::make('restart')
->color('gray')
->action(fn () => $this->dispatch('setServerState', state: 'restart')),

->action(fn () => $this->dispatch('setServerState', state: 'restart'))
->disabled(fn () => Filament::getTenant()->isInConflictState()),
Action::make('stop')
->color('danger')
->action(fn () => $this->dispatch('setServerState', state: 'stop')),
->action(fn () => $this->dispatch('setServerState', state: 'stop'))
->disabled(fn () => Filament::getTenant()->isInConflictState()),
];
}
}
13 changes: 13 additions & 0 deletions app/Filament/Server/Pages/ServerFormPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,17 @@ public function getRecord(): Server

return $server;
}

// TODO: find better way handle server conflict state
public static function canAccess(): bool
{
/** @var Server $server */
$server = Filament::getTenant();

if ($server->isInConflictState()) {
return false;
}

return parent::canAccess();
}
}
15 changes: 15 additions & 0 deletions app/Filament/Server/Resources/ActivityResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use App\Filament\Server\Resources\ActivityResource\Pages;
use App\Models\ActivityLog;
use App\Models\Server;
use Filament\Facades\Filament;
use Filament\Resources\Resource;

class ActivityResource extends Resource
Expand All @@ -18,6 +20,19 @@ class ActivityResource extends Resource

protected static ?string $tenantRelationshipName = 'activity'; // TODO: not displaying anything

// TODO: find better way handle server conflict state
public static function canAccess(): bool
{
/** @var Server $server */
$server = Filament::getTenant();

if ($server->isInConflictState()) {
return false;
}

return parent::canAccess();
}

public static function getPages(): array
{
return [
Expand Down
15 changes: 15 additions & 0 deletions app/Filament/Server/Resources/AllocationResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use App\Filament\Server\Resources\AllocationResource\Pages;
use App\Models\Allocation;
use App\Models\Server;
use Filament\Facades\Filament;
use Filament\Resources\Resource;

class AllocationResource extends Resource
Expand All @@ -18,6 +20,19 @@ class AllocationResource extends Resource

protected static ?string $navigationIcon = 'tabler-network';

// TODO: find better way handle server conflict state
public static function canAccess(): bool
{
/** @var Server $server */
$server = Filament::getTenant();

if ($server->isInConflictState()) {
return false;
}

return parent::canAccess();
}

public static function getPages(): array
{
return [
Expand Down
15 changes: 15 additions & 0 deletions app/Filament/Server/Resources/BackupResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use App\Filament\Server\Resources\BackupResource\Pages;
use App\Models\Backup;
use App\Models\Server;
use Filament\Facades\Filament;
use Filament\Resources\Resource;

class BackupResource extends Resource
Expand All @@ -16,6 +18,19 @@ class BackupResource extends Resource

protected static ?string $navigationIcon = 'tabler-download';

// TODO: find better way handle server conflict state
public static function canAccess(): bool
{
/** @var Server $server */
$server = Filament::getTenant();

if ($server->isInConflictState()) {
return false;
}

return parent::canAccess();
}

public static function getPages(): array
{
return [
Expand Down
15 changes: 15 additions & 0 deletions app/Filament/Server/Resources/DatabaseResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use App\Filament\Server\Resources\DatabaseResource\Pages;
use App\Models\Database;
use App\Models\Server;
use Filament\Facades\Filament;
use Filament\Resources\Resource;

class DatabaseResource extends Resource
Expand All @@ -14,6 +16,19 @@ class DatabaseResource extends Resource

protected static ?string $navigationIcon = 'tabler-database';

// TODO: find better way handle server conflict state
public static function canAccess(): bool
{
/** @var Server $server */
$server = Filament::getTenant();

if ($server->isInConflictState()) {
return false;
}

return parent::canAccess();
}

public static function getPages(): array
{
return [
Expand Down
15 changes: 15 additions & 0 deletions app/Filament/Server/Resources/FileResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use App\Filament\Server\Resources\FileResource\Pages;
use App\Models\File;
use App\Models\Server;
use Filament\Facades\Filament;
use Filament\Resources\Resource;

class FileResource extends Resource
Expand All @@ -14,6 +16,19 @@ class FileResource extends Resource

protected static ?string $navigationIcon = 'tabler-files';

// TODO: find better way handle server conflict state
public static function canAccess(): bool
{
/** @var Server $server */
$server = Filament::getTenant();

if ($server->isInConflictState()) {
return false;
}

return parent::canAccess();
}

public static function getPages(): array
{
return [
Expand Down
15 changes: 15 additions & 0 deletions app/Filament/Server/Resources/ScheduleResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
use App\Filament\Server\Resources\ScheduleResource\Pages;
use App\Filament\Server\Resources\ScheduleResource\RelationManagers\TasksRelationManager;
use App\Models\Schedule;
use App\Models\Server;
use Filament\Facades\Filament;
use Filament\Forms\Components\Actions;
use Filament\Forms\Components\Actions\Action;
use Filament\Forms\Components\Section;
Expand All @@ -23,6 +25,19 @@ class ScheduleResource extends Resource

protected static ?string $navigationIcon = 'tabler-clock';

// TODO: find better way handle server conflict state
public static function canAccess(): bool
{
/** @var Server $server */
$server = Filament::getTenant();

if ($server->isInConflictState()) {
return false;
}

return parent::canAccess();
}

public static function form(Form $form): Form
{
return $form
Expand Down
13 changes: 13 additions & 0 deletions app/Filament/Server/Resources/UserResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,19 @@ class UserResource extends Resource

protected static ?string $tenantOwnershipRelationshipName = 'subServers';

// TODO: find better way handle server conflict state
public static function canAccess(): bool
{
/** @var Server $server */
$server = Filament::getTenant();

if ($server->isInConflictState()) {
return false;
}

return parent::canAccess();
}

public static function table(Table $table): Table
{
return $table
Expand Down
13 changes: 6 additions & 7 deletions app/Models/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,11 @@ public function resolveChildRouteBinding($childType, $value, $field)
};
}

public function isInConflictState(): bool
{
return $this->isSuspended() || $this->node->isUnderMaintenance() || !$this->isInstalled() || $this->status === ServerState::RestoringBackup || !is_null($this->transfer);
}

/**
* Checks if the server is currently in a user-accessible state. If not, an
* exception is raised. This should be called whenever something needs to make
Expand All @@ -375,13 +380,7 @@ public function resolveChildRouteBinding($childType, $value, $field)
*/
public function validateCurrentState(): void
{
if (
$this->isSuspended() ||
$this->node->isUnderMaintenance() ||
!$this->isInstalled() ||
$this->status === ServerState::RestoringBackup ||
!is_null($this->transfer)
) {
if ($this->isInConflictState()) {
throw new ServerStateConflictException($this);
}
}
Expand Down

0 comments on commit 79b51b7

Please sign in to comment.