mirror of
https://github.com/vitodeploy/vito.git
synced 2025-04-19 09:51:37 +00:00
2.x - databases
This commit is contained in:
parent
32993025de
commit
e4fed24498
@ -52,7 +52,7 @@ private function validate(array $input): void
|
|||||||
Validator::make($input, [
|
Validator::make($input, [
|
||||||
'custom' => [
|
'custom' => [
|
||||||
'required',
|
'required',
|
||||||
new CronRule(),
|
new CronRule,
|
||||||
],
|
],
|
||||||
])->validate();
|
])->validate();
|
||||||
}
|
}
|
||||||
|
@ -5,36 +5,36 @@
|
|||||||
use App\Enums\DatabaseStatus;
|
use App\Enums\DatabaseStatus;
|
||||||
use App\Models\Database;
|
use App\Models\Database;
|
||||||
use App\Models\Server;
|
use App\Models\Server;
|
||||||
use Illuminate\Support\Facades\Validator;
|
|
||||||
use Illuminate\Validation\Rule;
|
use Illuminate\Validation\Rule;
|
||||||
use Illuminate\Validation\ValidationException;
|
use Illuminate\Validation\ValidationException;
|
||||||
|
|
||||||
class CreateDatabase
|
class CreateDatabase
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* @throws ValidationException
|
|
||||||
*/
|
|
||||||
public function create(Server $server, array $input): Database
|
public function create(Server $server, array $input): Database
|
||||||
{
|
{
|
||||||
$this->validate($server, $input);
|
|
||||||
|
|
||||||
$database = new Database([
|
$database = new Database([
|
||||||
'server_id' => $server->id,
|
'server_id' => $server->id,
|
||||||
'name' => $input['name'],
|
'name' => $input['name'],
|
||||||
]);
|
]);
|
||||||
/** @var \App\SSH\Services\Database\Database */
|
/** @var \App\SSH\Services\Database\Database $databaseHandler */
|
||||||
$databaseHandler = $server->database()->handler();
|
$databaseHandler = $server->database()->handler();
|
||||||
$databaseHandler->create($database->name);
|
$databaseHandler->create($database->name);
|
||||||
$database->status = DatabaseStatus::READY;
|
$database->status = DatabaseStatus::READY;
|
||||||
$database->save();
|
$database->save();
|
||||||
|
|
||||||
|
if (isset($input['user']) && $input['user']) {
|
||||||
|
$databaseUser = app(CreateDatabaseUser::class)->create($server, $input, [$database->name]);
|
||||||
|
|
||||||
|
app(LinkUser::class)->link($databaseUser, ['databases' => [$database->name]]);
|
||||||
|
}
|
||||||
|
|
||||||
return $database;
|
return $database;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws ValidationException
|
* @throws ValidationException
|
||||||
*/
|
*/
|
||||||
private function validate(Server $server, array $input): void
|
public static function rules(Server $server, array $input): array
|
||||||
{
|
{
|
||||||
$rules = [
|
$rules = [
|
||||||
'name' => [
|
'name' => [
|
||||||
@ -57,6 +57,7 @@ private function validate(Server $server, array $input): void
|
|||||||
if (isset($input['remote']) && $input['remote']) {
|
if (isset($input['remote']) && $input['remote']) {
|
||||||
$rules['host'] = 'required';
|
$rules['host'] = 'required';
|
||||||
}
|
}
|
||||||
Validator::make($input, $rules)->validate();
|
|
||||||
|
return $rules;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
use App\Enums\DatabaseUserStatus;
|
use App\Enums\DatabaseUserStatus;
|
||||||
use App\Models\DatabaseUser;
|
use App\Models\DatabaseUser;
|
||||||
use App\Models\Server;
|
use App\Models\Server;
|
||||||
use Illuminate\Support\Facades\Validator;
|
use App\SSH\Services\Database\Database;
|
||||||
use Illuminate\Validation\Rule;
|
use Illuminate\Validation\Rule;
|
||||||
use Illuminate\Validation\ValidationException;
|
use Illuminate\Validation\ValidationException;
|
||||||
|
|
||||||
@ -16,8 +16,6 @@ class CreateDatabaseUser
|
|||||||
*/
|
*/
|
||||||
public function create(Server $server, array $input, array $links = []): DatabaseUser
|
public function create(Server $server, array $input, array $links = []): DatabaseUser
|
||||||
{
|
{
|
||||||
$this->validate($server, $input);
|
|
||||||
|
|
||||||
$databaseUser = new DatabaseUser([
|
$databaseUser = new DatabaseUser([
|
||||||
'server_id' => $server->id,
|
'server_id' => $server->id,
|
||||||
'username' => $input['username'],
|
'username' => $input['username'],
|
||||||
@ -25,7 +23,9 @@ public function create(Server $server, array $input, array $links = []): Databas
|
|||||||
'host' => isset($input['remote']) && $input['remote'] ? $input['host'] : 'localhost',
|
'host' => isset($input['remote']) && $input['remote'] ? $input['host'] : 'localhost',
|
||||||
'databases' => $links,
|
'databases' => $links,
|
||||||
]);
|
]);
|
||||||
$server->database()->handler()->createUser(
|
/** @var Database $databaseHandler */
|
||||||
|
$databaseHandler = $server->database()->handler();
|
||||||
|
$databaseHandler->createUser(
|
||||||
$databaseUser->username,
|
$databaseUser->username,
|
||||||
$databaseUser->password,
|
$databaseUser->password,
|
||||||
$databaseUser->host
|
$databaseUser->host
|
||||||
@ -43,7 +43,7 @@ public function create(Server $server, array $input, array $links = []): Databas
|
|||||||
/**
|
/**
|
||||||
* @throws ValidationException
|
* @throws ValidationException
|
||||||
*/
|
*/
|
||||||
private function validate(Server $server, array $input): void
|
public static function rules(Server $server, array $input): array
|
||||||
{
|
{
|
||||||
$rules = [
|
$rules = [
|
||||||
'username' => [
|
'username' => [
|
||||||
@ -59,6 +59,7 @@ private function validate(Server $server, array $input): void
|
|||||||
if (isset($input['remote']) && $input['remote']) {
|
if (isset($input['remote']) && $input['remote']) {
|
||||||
$rules['host'] = 'required';
|
$rules['host'] = 'required';
|
||||||
}
|
}
|
||||||
Validator::make($input, $rules)->validate();
|
|
||||||
|
return $rules;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
use App\Models\Database;
|
use App\Models\Database;
|
||||||
use App\Models\DatabaseUser;
|
use App\Models\DatabaseUser;
|
||||||
use App\Models\Server;
|
use App\Models\Server;
|
||||||
use Illuminate\Support\Facades\Validator;
|
|
||||||
use Illuminate\Validation\Rule;
|
use Illuminate\Validation\Rule;
|
||||||
use Illuminate\Validation\ValidationException;
|
use Illuminate\Validation\ValidationException;
|
||||||
|
|
||||||
@ -20,8 +19,6 @@ public function link(DatabaseUser $databaseUser, array $input): void
|
|||||||
$input['databases'] = [];
|
$input['databases'] = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->validate($databaseUser->server, $input);
|
|
||||||
|
|
||||||
$dbs = Database::query()
|
$dbs = Database::query()
|
||||||
->where('server_id', $databaseUser->server_id)
|
->where('server_id', $databaseUser->server_id)
|
||||||
->whereIn('name', $input['databases'])
|
->whereIn('name', $input['databases'])
|
||||||
@ -48,15 +45,13 @@ public function link(DatabaseUser $databaseUser, array $input): void
|
|||||||
$databaseUser->save();
|
$databaseUser->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function validate(Server $server, array $input): void
|
public static function rules(Server $server, array $input): array
|
||||||
{
|
{
|
||||||
$rules = [
|
return [
|
||||||
'databases.*' => [
|
'databases.*' => [
|
||||||
'required',
|
'required',
|
||||||
Rule::exists('databases', 'name')->where('server_id', $server->id),
|
Rule::exists('databases', 'name')->where('server_id', $server->id),
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
Validator::make($input, $rules)->validate();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@ public function run(Site $site): Deployment
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (! $site->deploymentScript?->content) {
|
if (! $site->deploymentScript?->content) {
|
||||||
throw new DeploymentScriptIsEmptyException();
|
throw new DeploymentScriptIsEmptyException;
|
||||||
}
|
}
|
||||||
|
|
||||||
$deployment = new Deployment([
|
$deployment = new Deployment([
|
||||||
|
@ -26,7 +26,7 @@ private function validate(array $input): void
|
|||||||
{
|
{
|
||||||
Validator::make($input, [
|
Validator::make($input, [
|
||||||
'aliases.*' => [
|
'aliases.*' => [
|
||||||
new DomainRule(),
|
new DomainRule,
|
||||||
],
|
],
|
||||||
])->validate();
|
])->validate();
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ private function validate(array $input): void
|
|||||||
'name' => 'required',
|
'name' => 'required',
|
||||||
'public_key' => [
|
'public_key' => [
|
||||||
'required',
|
'required',
|
||||||
new SshKeyRule(),
|
new SshKeyRule,
|
||||||
],
|
],
|
||||||
])->validate();
|
])->validate();
|
||||||
}
|
}
|
||||||
|
@ -13,14 +13,14 @@ public function update(User $user, array $input): void
|
|||||||
$this->validate($input);
|
$this->validate($input);
|
||||||
$user->projects()->sync($input['projects']);
|
$user->projects()->sync($input['projects']);
|
||||||
|
|
||||||
if ($user->currentProject && !$user->projects->contains($user->currentProject)) {
|
if ($user->currentProject && ! $user->projects->contains($user->currentProject)) {
|
||||||
$user->current_project_id = null;
|
$user->current_project_id = null;
|
||||||
$user->save();
|
$user->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @var Project $firstProject */
|
/** @var Project $firstProject */
|
||||||
$firstProject = $user->projects->first();
|
$firstProject = $user->projects->first();
|
||||||
if (!$user->currentProject && $firstProject) {
|
if (! $user->currentProject && $firstProject) {
|
||||||
$user->current_project_id = $firstProject->id;
|
$user->current_project_id = $firstProject->id;
|
||||||
$user->save();
|
$user->save();
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,7 @@ public static function rules(User $user): array
|
|||||||
'email' => [
|
'email' => [
|
||||||
'required',
|
'required',
|
||||||
'email', 'max:255',
|
'email', 'max:255',
|
||||||
Rule::unique('users', 'email')->ignore($user->id)
|
Rule::unique('users', 'email')->ignore($user->id),
|
||||||
],
|
],
|
||||||
'timezone' => [
|
'timezone' => [
|
||||||
'required',
|
'required',
|
||||||
|
@ -23,7 +23,7 @@ protected static function getFacadeAccessor(): string
|
|||||||
|
|
||||||
public static function fake(): FTPFake
|
public static function fake(): FTPFake
|
||||||
{
|
{
|
||||||
static::swap($fake = new FTPFake());
|
static::swap($fake = new FTPFake);
|
||||||
|
|
||||||
return $fake;
|
return $fake;
|
||||||
}
|
}
|
||||||
|
@ -8,12 +8,10 @@
|
|||||||
use App\Facades\Toast;
|
use App\Facades\Toast;
|
||||||
use App\Helpers\HtmxResponse;
|
use App\Helpers\HtmxResponse;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Models\Project;
|
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use Illuminate\Contracts\View\View;
|
use Illuminate\Contracts\View\View;
|
||||||
use Illuminate\Http\RedirectResponse;
|
use Illuminate\Http\RedirectResponse;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Validation\Rule;
|
|
||||||
|
|
||||||
class UserController extends Controller
|
class UserController extends Controller
|
||||||
{
|
{
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
|
use App\Enums\BackupStatus;
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
@ -49,6 +50,13 @@ public static function boot(): void
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static array $statusColors = [
|
||||||
|
BackupStatus::READY => 'success',
|
||||||
|
BackupStatus::RUNNING => 'warning',
|
||||||
|
BackupStatus::DELETING => 'warning',
|
||||||
|
BackupStatus::FAILED => 'danger',
|
||||||
|
];
|
||||||
|
|
||||||
public function server(): BelongsTo
|
public function server(): BelongsTo
|
||||||
{
|
{
|
||||||
return $this->belongsTo(Server::class);
|
return $this->belongsTo(Server::class);
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
|
use App\Enums\BackupFileStatus;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
@ -60,6 +61,15 @@ protected static function booted(): void
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static array $statusColors = [
|
||||||
|
BackupFileStatus::CREATED => 'success',
|
||||||
|
BackupFileStatus::CREATING => 'warning',
|
||||||
|
BackupFileStatus::FAILED => 'danger',
|
||||||
|
BackupFileStatus::DELETING => 'warning',
|
||||||
|
BackupFileStatus::RESTORED => 'warning',
|
||||||
|
BackupFileStatus::RESTORE_FAILED => 'danger',
|
||||||
|
];
|
||||||
|
|
||||||
public function backup(): BelongsTo
|
public function backup(): BelongsTo
|
||||||
{
|
{
|
||||||
return $this->belongsTo(Backup::class);
|
return $this->belongsTo(Backup::class);
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
|
use App\Enums\DatabaseStatus;
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
@ -46,6 +47,13 @@ public static function boot(): void
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static array $statusColors = [
|
||||||
|
DatabaseStatus::READY => 'success',
|
||||||
|
DatabaseStatus::CREATING => 'warning',
|
||||||
|
DatabaseStatus::DELETING => 'warning',
|
||||||
|
DatabaseStatus::FAILED => 'danger',
|
||||||
|
];
|
||||||
|
|
||||||
public function server(): BelongsTo
|
public function server(): BelongsTo
|
||||||
{
|
{
|
||||||
return $this->belongsTo(Server::class);
|
return $this->belongsTo(Server::class);
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
|
use App\Enums\DatabaseUserStatus;
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
|
|
||||||
@ -41,4 +42,11 @@ public function server(): BelongsTo
|
|||||||
{
|
{
|
||||||
return $this->belongsTo(Server::class);
|
return $this->belongsTo(Server::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static array $statusColors = [
|
||||||
|
DatabaseUserStatus::READY => 'success',
|
||||||
|
DatabaseUserStatus::CREATING => 'warning',
|
||||||
|
DatabaseUserStatus::DELETING => 'warning',
|
||||||
|
DatabaseUserStatus::FAILED => 'danger',
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ public function via(object $notifiable): string
|
|||||||
|
|
||||||
public function toEmail(object $notifiable): MailMessage
|
public function toEmail(object $notifiable): MailMessage
|
||||||
{
|
{
|
||||||
return (new MailMessage())
|
return (new MailMessage)
|
||||||
->subject('Notification')
|
->subject('Notification')
|
||||||
->line($this->rawText());
|
->line($this->rawText());
|
||||||
}
|
}
|
||||||
|
41
app/Policies/BackupPolicy.php
Normal file
41
app/Policies/BackupPolicy.php
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Policies;
|
||||||
|
|
||||||
|
use App\Models\Backup;
|
||||||
|
use App\Models\Server;
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Auth\Access\HandlesAuthorization;
|
||||||
|
|
||||||
|
class BackupPolicy
|
||||||
|
{
|
||||||
|
use HandlesAuthorization;
|
||||||
|
|
||||||
|
public function viewAny(User $user, Server $server): bool
|
||||||
|
{
|
||||||
|
return ($user->isAdmin() || $server->project->users->contains($user)) && $server->isReady();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function view(User $user, Backup $backup): bool
|
||||||
|
{
|
||||||
|
return ($user->isAdmin() || $backup->server->project->users->contains($user)) &&
|
||||||
|
$backup->server->isReady();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function create(User $user, Server $server): bool
|
||||||
|
{
|
||||||
|
return ($user->isAdmin() || $server->project->users->contains($user)) && $server->isReady();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update(User $user, Backup $backup): bool
|
||||||
|
{
|
||||||
|
return ($user->isAdmin() || $backup->server->project->users->contains($user)) &&
|
||||||
|
$backup->server->isReady();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function delete(User $user, Backup $backup): bool
|
||||||
|
{
|
||||||
|
return ($user->isAdmin() || $backup->server->project->users->contains($user)) &&
|
||||||
|
$backup->server->isReady();
|
||||||
|
}
|
||||||
|
}
|
41
app/Policies/DatabasePolicy.php
Normal file
41
app/Policies/DatabasePolicy.php
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Policies;
|
||||||
|
|
||||||
|
use App\Models\Database;
|
||||||
|
use App\Models\Server;
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Auth\Access\HandlesAuthorization;
|
||||||
|
|
||||||
|
class DatabasePolicy
|
||||||
|
{
|
||||||
|
use HandlesAuthorization;
|
||||||
|
|
||||||
|
public function viewAny(User $user, Server $server): bool
|
||||||
|
{
|
||||||
|
return ($user->isAdmin() || $server->project->users->contains($user)) && $server->isReady();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function view(User $user, Database $database): bool
|
||||||
|
{
|
||||||
|
return ($user->isAdmin() || $database->server->project->users->contains($user)) &&
|
||||||
|
$database->server->isReady();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function create(User $user, Server $server): bool
|
||||||
|
{
|
||||||
|
return ($user->isAdmin() || $server->project->users->contains($user)) && $server->isReady();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update(User $user, Database $database): bool
|
||||||
|
{
|
||||||
|
return ($user->isAdmin() || $database->server->project->users->contains($user)) &&
|
||||||
|
$database->server->isReady();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function delete(User $user, Database $database): bool
|
||||||
|
{
|
||||||
|
return ($user->isAdmin() || $database->server->project->users->contains($user)) &&
|
||||||
|
$database->server->isReady();
|
||||||
|
}
|
||||||
|
}
|
41
app/Policies/DatabaseUserPolicy.php
Normal file
41
app/Policies/DatabaseUserPolicy.php
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Policies;
|
||||||
|
|
||||||
|
use App\Models\DatabaseUser;
|
||||||
|
use App\Models\Server;
|
||||||
|
use App\Models\User;
|
||||||
|
use Illuminate\Auth\Access\HandlesAuthorization;
|
||||||
|
|
||||||
|
class DatabaseUserPolicy
|
||||||
|
{
|
||||||
|
use HandlesAuthorization;
|
||||||
|
|
||||||
|
public function viewAny(User $user, Server $server): bool
|
||||||
|
{
|
||||||
|
return ($user->isAdmin() || $server->project->users->contains($user)) && $server->isReady();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function view(User $user, DatabaseUser $databaseUser): bool
|
||||||
|
{
|
||||||
|
return ($user->isAdmin() || $databaseUser->server->project->users->contains($user)) &&
|
||||||
|
$databaseUser->server->isReady();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function create(User $user, Server $server): bool
|
||||||
|
{
|
||||||
|
return ($user->isAdmin() || $server->project->users->contains($user)) && $server->isReady();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update(User $user, DatabaseUser $databaseUser): bool
|
||||||
|
{
|
||||||
|
return ($user->isAdmin() || $databaseUser->server->project->users->contains($user)) &&
|
||||||
|
$databaseUser->server->isReady();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function delete(User $user, DatabaseUser $databaseUser): bool
|
||||||
|
{
|
||||||
|
return ($user->isAdmin() || $databaseUser->server->project->users->contains($user)) &&
|
||||||
|
$databaseUser->server->isReady();
|
||||||
|
}
|
||||||
|
}
|
@ -13,26 +13,26 @@ class ServicePolicy
|
|||||||
|
|
||||||
public function viewAny(User $user, Server $server): bool
|
public function viewAny(User $user, Server $server): bool
|
||||||
{
|
{
|
||||||
return $user->isAdmin() || $server->project->users->contains($user);
|
return ($user->isAdmin() || $server->project->users->contains($user)) && $server->isReady();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function view(User $user, Service $service): bool
|
public function view(User $user, Service $service): bool
|
||||||
{
|
{
|
||||||
return $user->isAdmin() || $service->server->project->users->contains($user);
|
return ($user->isAdmin() || $service->server->project->users->contains($user)) && $service->server->isReady();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function create(User $user, Server $server): bool
|
public function create(User $user, Server $server): bool
|
||||||
{
|
{
|
||||||
return $user->isAdmin() || $server->project->users->contains($user);
|
return ($user->isAdmin() || $server->project->users->contains($user)) && $server->isReady();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function update(User $user, Service $service): bool
|
public function update(User $user, Service $service): bool
|
||||||
{
|
{
|
||||||
return $user->isAdmin() || $service->server->project->users->contains($user);
|
return ($user->isAdmin() || $service->server->project->users->contains($user)) && $service->server->isReady();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function delete(User $user, Service $service): bool
|
public function delete(User $user, Service $service): bool
|
||||||
{
|
{
|
||||||
return $user->isAdmin() || $service->server->project->users->contains($user);
|
return ($user->isAdmin() || $service->server->project->users->contains($user)) && $service->server->isReady();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -93,6 +93,7 @@ public function panel(Panel $panel): Panel
|
|||||||
->authMiddleware([
|
->authMiddleware([
|
||||||
Authenticate::class,
|
Authenticate::class,
|
||||||
])
|
])
|
||||||
|
->spa()
|
||||||
->globalSearchKeyBindings(['command+k', 'ctrl+k'])
|
->globalSearchKeyBindings(['command+k', 'ctrl+k'])
|
||||||
->globalSearchFieldKeyBindingSuffix();
|
->globalSearchFieldKeyBindingSuffix();
|
||||||
}
|
}
|
||||||
|
@ -129,7 +129,7 @@ public function editFile(string $path, ?string $content = null): void
|
|||||||
$path
|
$path
|
||||||
);
|
);
|
||||||
} catch (Throwable) {
|
} catch (Throwable) {
|
||||||
throw new SSHUploadFailed();
|
throw new SSHUploadFailed;
|
||||||
} finally {
|
} finally {
|
||||||
$this->deleteTempFile($tmpName);
|
$this->deleteTempFile($tmpName);
|
||||||
}
|
}
|
||||||
|
@ -142,7 +142,7 @@ public function setupSSL(Ssl $ssl): void
|
|||||||
$ssl->site_id
|
$ssl->site_id
|
||||||
);
|
);
|
||||||
if (! $ssl->validateSetup($result)) {
|
if (! $ssl->validateSetup($result)) {
|
||||||
throw new SSLCreationException();
|
throw new SSLCreationException;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->updateVHost($ssl->site);
|
$this->updateVHost($ssl->site);
|
||||||
|
13
app/Web/Components/Page.php
Normal file
13
app/Web/Components/Page.php
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Web\Components;
|
||||||
|
|
||||||
|
use App\Web\Traits\HasWidgets;
|
||||||
|
use Filament\Pages\Page as BasePage;
|
||||||
|
|
||||||
|
abstract class Page extends BasePage
|
||||||
|
{
|
||||||
|
use HasWidgets;
|
||||||
|
|
||||||
|
protected static string $view = 'web.components.page';
|
||||||
|
}
|
@ -3,14 +3,11 @@
|
|||||||
namespace App\Web\Pages\Servers;
|
namespace App\Web\Pages\Servers;
|
||||||
|
|
||||||
use App\Models\Server;
|
use App\Models\Server;
|
||||||
use App\Web\Traits\PageHasWidgets;
|
use App\Web\Components\Page;
|
||||||
use Filament\Actions\Action;
|
use Filament\Actions\Action;
|
||||||
use Filament\Pages\Page;
|
|
||||||
|
|
||||||
class Create extends Page
|
class Create extends Page
|
||||||
{
|
{
|
||||||
use PageHasWidgets;
|
|
||||||
|
|
||||||
protected static ?string $slug = 'servers/create';
|
protected static ?string $slug = 'servers/create';
|
||||||
|
|
||||||
protected static bool $shouldRegisterNavigation = false;
|
protected static bool $shouldRegisterNavigation = false;
|
||||||
|
34
app/Web/Pages/Servers/Databases/Backups.php
Normal file
34
app/Web/Pages/Servers/Databases/Backups.php
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Web\Pages\Servers\Databases;
|
||||||
|
|
||||||
|
use App\Models\Backup;
|
||||||
|
use App\Models\Server;
|
||||||
|
use App\Web\Components\Page;
|
||||||
|
use App\Web\Traits\PageHasServer;
|
||||||
|
|
||||||
|
class Backups extends Page
|
||||||
|
{
|
||||||
|
use PageHasServer;
|
||||||
|
use Traits\Navigation;
|
||||||
|
|
||||||
|
protected static ?string $slug = 'servers/{server}/databases/backups';
|
||||||
|
|
||||||
|
protected static bool $shouldRegisterNavigation = false;
|
||||||
|
|
||||||
|
protected static ?string $title = 'Backups';
|
||||||
|
|
||||||
|
public Server $server;
|
||||||
|
|
||||||
|
public static function canAccess(): bool
|
||||||
|
{
|
||||||
|
return auth()->user()?->can('viewAny', [Backup::class, static::getServerFromRoute()]) ?? false;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getHeaderActions(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
96
app/Web/Pages/Servers/Databases/Index.php
Normal file
96
app/Web/Pages/Servers/Databases/Index.php
Normal file
@ -0,0 +1,96 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Web\Pages\Servers\Databases;
|
||||||
|
|
||||||
|
use App\Actions\Database\CreateDatabase;
|
||||||
|
use App\Models\Database;
|
||||||
|
use App\Models\Server;
|
||||||
|
use App\Web\Components\Page;
|
||||||
|
use App\Web\Traits\PageHasServer;
|
||||||
|
use Exception;
|
||||||
|
use Filament\Actions\Action;
|
||||||
|
use Filament\Forms\Components\Checkbox;
|
||||||
|
use Filament\Forms\Components\TextInput;
|
||||||
|
use Filament\Notifications\Notification;
|
||||||
|
use Filament\Support\Enums\MaxWidth;
|
||||||
|
|
||||||
|
class Index extends Page
|
||||||
|
{
|
||||||
|
use PageHasServer;
|
||||||
|
use Traits\Navigation;
|
||||||
|
|
||||||
|
protected static ?string $slug = 'servers/{server}/databases';
|
||||||
|
|
||||||
|
protected static bool $shouldRegisterNavigation = false;
|
||||||
|
|
||||||
|
protected static ?string $title = 'Databases';
|
||||||
|
|
||||||
|
public Server $server;
|
||||||
|
|
||||||
|
public static function canAccess(): bool
|
||||||
|
{
|
||||||
|
return auth()->user()?->can('viewAny', [Database::class, static::getServerFromRoute()]) ?? false;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getHeaderActions(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
Action::make('Create Database')
|
||||||
|
->icon('heroicon-o-plus')
|
||||||
|
->modalWidth(MaxWidth::Large)
|
||||||
|
->authorize(fn () => auth()->user()?->can('create', [Database::class, $this->server]))
|
||||||
|
->form([
|
||||||
|
TextInput::make('name')
|
||||||
|
->rules(fn (callable $get) => CreateDatabase::rules($this->server, $get())['name']),
|
||||||
|
Checkbox::make('user')
|
||||||
|
->label('Create User')
|
||||||
|
->default(false)
|
||||||
|
->reactive(),
|
||||||
|
TextInput::make('username')
|
||||||
|
->label('Username')
|
||||||
|
->rules(fn (callable $get) => CreateDatabase::rules($this->server, $get())['username'])
|
||||||
|
->hidden(fn (callable $get) => $get('user') !== true),
|
||||||
|
TextInput::make('password')
|
||||||
|
->label('Password')
|
||||||
|
->rules(fn (callable $get) => CreateDatabase::rules($this->server, $get())['password'])
|
||||||
|
->hidden(fn (callable $get) => $get('user') !== true),
|
||||||
|
Checkbox::make('remote')
|
||||||
|
->label('Remote')
|
||||||
|
->default(false)
|
||||||
|
->hidden(fn (callable $get) => $get('user') !== true)
|
||||||
|
->reactive(),
|
||||||
|
TextInput::make('host')
|
||||||
|
->label('Host')
|
||||||
|
->rules(fn (callable $get) => CreateDatabase::rules($this->server, $get())['host'])
|
||||||
|
->hidden(fn (callable $get) => $get('remote') !== true),
|
||||||
|
])
|
||||||
|
->modalSubmitActionLabel('Create')
|
||||||
|
->action(function (array $data) {
|
||||||
|
try {
|
||||||
|
app(CreateDatabase::class)->create($this->server, $data);
|
||||||
|
|
||||||
|
$this->dispatch('$refresh');
|
||||||
|
|
||||||
|
Notification::make()
|
||||||
|
->success()
|
||||||
|
->title('Database Created!')
|
||||||
|
->send();
|
||||||
|
} catch (Exception $e) {
|
||||||
|
Notification::make()
|
||||||
|
->danger()
|
||||||
|
->title($e->getMessage())
|
||||||
|
->send();
|
||||||
|
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getWidgets(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
[Widgets\DatabasesList::class, ['server' => $this->server]],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
45
app/Web/Pages/Servers/Databases/Traits/Navigation.php
Normal file
45
app/Web/Pages/Servers/Databases/Traits/Navigation.php
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Web\Pages\Servers\Databases\Traits;
|
||||||
|
|
||||||
|
use App\Web\Pages\Servers\Databases\Backups as Backups;
|
||||||
|
use App\Web\Pages\Servers\Databases\Index as Databases;
|
||||||
|
use App\Web\Pages\Servers\Databases\Users as Users;
|
||||||
|
use Filament\Navigation\NavigationGroup;
|
||||||
|
use Filament\Navigation\NavigationItem;
|
||||||
|
|
||||||
|
trait Navigation
|
||||||
|
{
|
||||||
|
public bool $hasSecondSubNavigation = true;
|
||||||
|
|
||||||
|
public function getSecondSubNavigation(): array
|
||||||
|
{
|
||||||
|
$items = [];
|
||||||
|
|
||||||
|
if (Databases::canAccess()) {
|
||||||
|
$items[] = NavigationItem::make(Databases::getNavigationLabel())
|
||||||
|
->icon('heroicon-o-circle-stack')
|
||||||
|
->isActiveWhen(fn () => request()->routeIs(Databases::getRouteName()))
|
||||||
|
->url(Databases::getUrl(parameters: ['server' => $this->server]));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Users::canAccess()) {
|
||||||
|
$items[] = NavigationItem::make(Users::getNavigationLabel())
|
||||||
|
->icon('heroicon-o-users')
|
||||||
|
->isActiveWhen(fn () => request()->routeIs(Users::getRouteName()))
|
||||||
|
->url(Users::getUrl(parameters: ['server' => $this->server]));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Backups::canAccess()) {
|
||||||
|
$items[] = NavigationItem::make(Backups::getNavigationLabel())
|
||||||
|
->icon('heroicon-o-circle-stack')
|
||||||
|
->isActiveWhen(fn () => request()->routeIs(Backups::getRouteName()))
|
||||||
|
->url(Backups::getUrl(parameters: ['server' => $this->server]));
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
NavigationGroup::make()
|
||||||
|
->items($items),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
88
app/Web/Pages/Servers/Databases/Users.php
Normal file
88
app/Web/Pages/Servers/Databases/Users.php
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Web\Pages\Servers\Databases;
|
||||||
|
|
||||||
|
use App\Actions\Database\CreateDatabase;
|
||||||
|
use App\Actions\Database\CreateDatabaseUser;
|
||||||
|
use App\Models\DatabaseUser;
|
||||||
|
use App\Models\Server;
|
||||||
|
use App\Web\Components\Page;
|
||||||
|
use App\Web\Traits\PageHasServer;
|
||||||
|
use Exception;
|
||||||
|
use Filament\Actions\Action;
|
||||||
|
use Filament\Forms\Components\Checkbox;
|
||||||
|
use Filament\Forms\Components\TextInput;
|
||||||
|
use Filament\Notifications\Notification;
|
||||||
|
use Filament\Support\Enums\MaxWidth;
|
||||||
|
|
||||||
|
class Users extends Page
|
||||||
|
{
|
||||||
|
use PageHasServer;
|
||||||
|
use Traits\Navigation;
|
||||||
|
|
||||||
|
protected static ?string $slug = 'servers/{server}/databases/users';
|
||||||
|
|
||||||
|
protected static bool $shouldRegisterNavigation = false;
|
||||||
|
|
||||||
|
protected static ?string $title = 'Database Users';
|
||||||
|
|
||||||
|
public Server $server;
|
||||||
|
|
||||||
|
public static function canAccess(): bool
|
||||||
|
{
|
||||||
|
return auth()->user()?->can('viewAny', [DatabaseUser::class, static::getServerFromRoute()]) ?? false;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getHeaderActions(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
Action::make('Create User')
|
||||||
|
->icon('heroicon-o-plus')
|
||||||
|
->modalWidth(MaxWidth::Large)
|
||||||
|
->authorize(fn () => auth()->user()?->can('create', [DatabaseUser::class, $this->server]))
|
||||||
|
->form([
|
||||||
|
TextInput::make('username')
|
||||||
|
->label('Username')
|
||||||
|
->rules(fn (callable $get) => CreateDatabaseUser::rules($this->server, $get())['username']),
|
||||||
|
TextInput::make('password')
|
||||||
|
->label('Password')
|
||||||
|
->rules(fn (callable $get) => CreateDatabaseUser::rules($this->server, $get())['password']),
|
||||||
|
Checkbox::make('remote')
|
||||||
|
->label('Remote')
|
||||||
|
->default(false)
|
||||||
|
->reactive(),
|
||||||
|
TextInput::make('host')
|
||||||
|
->label('Host')
|
||||||
|
->rules(fn (callable $get) => CreateDatabase::rules($this->server, $get())['host'])
|
||||||
|
->hidden(fn (callable $get) => $get('remote') !== true),
|
||||||
|
])
|
||||||
|
->modalSubmitActionLabel('Create')
|
||||||
|
->action(function (array $data) {
|
||||||
|
try {
|
||||||
|
app(CreateDatabaseUser::class)->create($this->server, $data);
|
||||||
|
|
||||||
|
$this->dispatch('$refresh');
|
||||||
|
|
||||||
|
Notification::make()
|
||||||
|
->success()
|
||||||
|
->title('Database user created!')
|
||||||
|
->send();
|
||||||
|
} catch (Exception $e) {
|
||||||
|
Notification::make()
|
||||||
|
->danger()
|
||||||
|
->title($e->getMessage())
|
||||||
|
->send();
|
||||||
|
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getWidgets(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
[Widgets\DatabaseUsersList::class, ['server' => $this->server]],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
147
app/Web/Pages/Servers/Databases/Widgets/DatabaseUsersList.php
Normal file
147
app/Web/Pages/Servers/Databases/Widgets/DatabaseUsersList.php
Normal file
@ -0,0 +1,147 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Web\Pages\Servers\Databases\Widgets;
|
||||||
|
|
||||||
|
use App\Actions\Database\DeleteDatabaseUser;
|
||||||
|
use App\Actions\Database\LinkUser;
|
||||||
|
use App\Models\DatabaseUser;
|
||||||
|
use App\Models\Server;
|
||||||
|
use Exception;
|
||||||
|
use Filament\Forms\Components\CheckboxList;
|
||||||
|
use Filament\Forms\Components\TextInput;
|
||||||
|
use Filament\Notifications\Notification;
|
||||||
|
use Filament\Support\Enums\MaxWidth;
|
||||||
|
use Filament\Tables\Actions\Action;
|
||||||
|
use Filament\Tables\Columns\TextColumn;
|
||||||
|
use Filament\Tables\Table;
|
||||||
|
use Filament\Widgets\TableWidget as Widget;
|
||||||
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
|
|
||||||
|
class DatabaseUsersList extends Widget
|
||||||
|
{
|
||||||
|
public Server $server;
|
||||||
|
|
||||||
|
protected $listeners = ['$refresh'];
|
||||||
|
|
||||||
|
protected function getTableQuery(): Builder
|
||||||
|
{
|
||||||
|
return DatabaseUser::query()->where('server_id', $this->server->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static ?string $heading = '';
|
||||||
|
|
||||||
|
protected function getTableColumns(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
TextColumn::make('id')
|
||||||
|
->searchable()
|
||||||
|
->sortable(),
|
||||||
|
TextColumn::make('username')
|
||||||
|
->searchable(),
|
||||||
|
TextColumn::make('status')
|
||||||
|
->label('Status')
|
||||||
|
->badge()
|
||||||
|
->color(fn (DatabaseUser $databaseUser) => DatabaseUser::$statusColors[$databaseUser->status])
|
||||||
|
->sortable(),
|
||||||
|
TextColumn::make('created_at')
|
||||||
|
->label('Created At')
|
||||||
|
->formatStateUsing(fn ($record) => $record->created_at_by_timezone)
|
||||||
|
->sortable(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTable(): Table
|
||||||
|
{
|
||||||
|
return $this->table
|
||||||
|
->actions([
|
||||||
|
$this->passwordAction(),
|
||||||
|
$this->linkAction(),
|
||||||
|
$this->deleteAction(),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function passwordAction(): Action
|
||||||
|
{
|
||||||
|
return Action::make('password')
|
||||||
|
->hiddenLabel()
|
||||||
|
->icon('heroicon-o-key')
|
||||||
|
->color('secondary')
|
||||||
|
->modalHeading('Database user\'s password')
|
||||||
|
->modalWidth(MaxWidth::Large)
|
||||||
|
->tooltip('Show the password')
|
||||||
|
->authorize(fn ($record) => auth()->user()->can('view', $record))
|
||||||
|
->form([
|
||||||
|
TextInput::make('password')
|
||||||
|
->label('Password')
|
||||||
|
->default(fn (DatabaseUser $record) => $record->password)
|
||||||
|
->disabled(),
|
||||||
|
])
|
||||||
|
->action(function (DatabaseUser $record, array $data) {
|
||||||
|
//
|
||||||
|
})
|
||||||
|
->modalSubmitAction(false)
|
||||||
|
->modalCancelActionLabel('Close');
|
||||||
|
}
|
||||||
|
|
||||||
|
private function linkAction(): Action
|
||||||
|
{
|
||||||
|
return Action::make('link')
|
||||||
|
->hiddenLabel()
|
||||||
|
->icon('heroicon-o-link')
|
||||||
|
->modalHeading('Link user to databases')
|
||||||
|
->modalWidth(MaxWidth::Large)
|
||||||
|
->tooltip('Link user')
|
||||||
|
->modalSubmitActionLabel('Save')
|
||||||
|
->authorize(fn ($record) => auth()->user()->can('update', $record))
|
||||||
|
->form([
|
||||||
|
CheckboxList::make('databases')
|
||||||
|
->label('Databases')
|
||||||
|
->options($this->server->databases()->pluck('name', 'name')->toArray())
|
||||||
|
->rules(fn (callable $get) => LinkUser::rules($this->server, $get()))
|
||||||
|
->default(fn (DatabaseUser $record) => $record->databases),
|
||||||
|
])
|
||||||
|
->action(function (DatabaseUser $record, array $data) {
|
||||||
|
try {
|
||||||
|
app(LinkUser::class)->link($record, $data);
|
||||||
|
|
||||||
|
Notification::make()
|
||||||
|
->success()
|
||||||
|
->title('User linked to databases!')
|
||||||
|
->send();
|
||||||
|
} catch (Exception $e) {
|
||||||
|
Notification::make()
|
||||||
|
->danger()
|
||||||
|
->title($e->getMessage())
|
||||||
|
->send();
|
||||||
|
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private function deleteAction(): Action
|
||||||
|
{
|
||||||
|
return Action::make('delete')
|
||||||
|
->hiddenLabel()
|
||||||
|
->icon('heroicon-o-trash')
|
||||||
|
->modalHeading('Delete Database User')
|
||||||
|
->color('danger')
|
||||||
|
->tooltip('Delete')
|
||||||
|
->authorize(fn ($record) => auth()->user()->can('delete', $record))
|
||||||
|
->requiresConfirmation()
|
||||||
|
->action(function (DatabaseUser $record) {
|
||||||
|
try {
|
||||||
|
app(DeleteDatabaseUser::class)->delete($this->server, $record);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
Notification::make()
|
||||||
|
->danger()
|
||||||
|
->title($e->getMessage())
|
||||||
|
->send();
|
||||||
|
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->dispatch('$refresh');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
77
app/Web/Pages/Servers/Databases/Widgets/DatabasesList.php
Normal file
77
app/Web/Pages/Servers/Databases/Widgets/DatabasesList.php
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Web\Pages\Servers\Databases\Widgets;
|
||||||
|
|
||||||
|
use App\Actions\Database\DeleteDatabase;
|
||||||
|
use App\Models\Database;
|
||||||
|
use App\Models\Server;
|
||||||
|
use Exception;
|
||||||
|
use Filament\Notifications\Notification;
|
||||||
|
use Filament\Tables\Actions\Action;
|
||||||
|
use Filament\Tables\Columns\TextColumn;
|
||||||
|
use Filament\Tables\Table;
|
||||||
|
use Filament\Widgets\TableWidget as Widget;
|
||||||
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
|
|
||||||
|
class DatabasesList extends Widget
|
||||||
|
{
|
||||||
|
public Server $server;
|
||||||
|
|
||||||
|
protected $listeners = ['$refresh'];
|
||||||
|
|
||||||
|
protected function getTableQuery(): Builder
|
||||||
|
{
|
||||||
|
return Database::query()->where('server_id', $this->server->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static ?string $heading = '';
|
||||||
|
|
||||||
|
protected function getTableColumns(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
TextColumn::make('id')
|
||||||
|
->searchable()
|
||||||
|
->sortable(),
|
||||||
|
TextColumn::make('name')
|
||||||
|
->searchable(),
|
||||||
|
TextColumn::make('status')
|
||||||
|
->label('Status')
|
||||||
|
->badge()
|
||||||
|
->color(fn (Database $database) => Database::$statusColors[$database->status])
|
||||||
|
->sortable(),
|
||||||
|
TextColumn::make('created_at')
|
||||||
|
->label('Created At')
|
||||||
|
->formatStateUsing(fn ($record) => $record->created_at_by_timezone)
|
||||||
|
->sortable(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTable(): Table
|
||||||
|
{
|
||||||
|
return $this->table
|
||||||
|
->actions([
|
||||||
|
Action::make('delete')
|
||||||
|
->hiddenLabel()
|
||||||
|
->icon('heroicon-o-trash')
|
||||||
|
->modalHeading('Delete Database')
|
||||||
|
->color('danger')
|
||||||
|
->tooltip('Delete')
|
||||||
|
->authorize(fn ($record) => auth()->user()->can('delete', $record))
|
||||||
|
->requiresConfirmation()
|
||||||
|
->action(function (Database $record) {
|
||||||
|
try {
|
||||||
|
app(DeleteDatabase::class)->delete($this->server, $record);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
Notification::make()
|
||||||
|
->danger()
|
||||||
|
->title($e->getMessage())
|
||||||
|
->send();
|
||||||
|
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->dispatch('$refresh');
|
||||||
|
}),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
@ -3,14 +3,11 @@
|
|||||||
namespace App\Web\Pages\Servers;
|
namespace App\Web\Pages\Servers;
|
||||||
|
|
||||||
use App\Models\Server;
|
use App\Models\Server;
|
||||||
use App\Web\Traits\PageHasWidgets;
|
use App\Web\Components\Page;
|
||||||
use Filament\Actions\Action;
|
use Filament\Actions\Action;
|
||||||
use Filament\Pages\Page;
|
|
||||||
|
|
||||||
class Index extends Page
|
class Index extends Page
|
||||||
{
|
{
|
||||||
use PageHasWidgets;
|
|
||||||
|
|
||||||
protected static ?string $slug = 'servers';
|
protected static ?string $slug = 'servers';
|
||||||
|
|
||||||
protected static ?string $navigationIcon = 'heroicon-o-server-stack';
|
protected static ?string $navigationIcon = 'heroicon-o-server-stack';
|
||||||
|
@ -4,15 +4,13 @@
|
|||||||
|
|
||||||
use App\Models\Server;
|
use App\Models\Server;
|
||||||
use App\Models\ServerLog;
|
use App\Models\ServerLog;
|
||||||
|
use App\Web\Components\Page;
|
||||||
use App\Web\Pages\Servers\Logs\Widgets\LogsList;
|
use App\Web\Pages\Servers\Logs\Widgets\LogsList;
|
||||||
use App\Web\Traits\PageHasServer;
|
use App\Web\Traits\PageHasServer;
|
||||||
use App\Web\Traits\PageHasWidgets;
|
|
||||||
use Filament\Pages\Page;
|
|
||||||
|
|
||||||
class Index extends Page
|
class Index extends Page
|
||||||
{
|
{
|
||||||
use PageHasServer;
|
use PageHasServer;
|
||||||
use PageHasWidgets;
|
|
||||||
|
|
||||||
protected static ?string $slug = 'servers/{server}/logs';
|
protected static ?string $slug = 'servers/{server}/logs';
|
||||||
|
|
||||||
|
@ -23,16 +23,18 @@ protected function getTableQuery(): Builder
|
|||||||
return ServerLog::query()->where('server_id', $this->server->id);
|
return ServerLog::query()->where('server_id', $this->server->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static ?string $heading = 'Logs';
|
protected static ?string $heading = '';
|
||||||
|
|
||||||
protected function getTableColumns(): array
|
protected function getTableColumns(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
TextColumn::make('name')
|
TextColumn::make('name')
|
||||||
|
->label('Event')
|
||||||
->searchable()
|
->searchable()
|
||||||
->sortable(),
|
->sortable(),
|
||||||
TextColumn::make('created_at_by_timezone')
|
TextColumn::make('created_at')
|
||||||
->label('Created At')
|
->label('Created At')
|
||||||
|
->formatStateUsing(fn ($record) => $record->created_at_by_timezone)
|
||||||
->sortable(),
|
->sortable(),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@ -68,7 +70,8 @@ public function getTable(): Table
|
|||||||
])
|
])
|
||||||
->actions([
|
->actions([
|
||||||
Action::make('view')
|
Action::make('view')
|
||||||
->label('View')
|
->hiddenLabel()
|
||||||
|
->tooltip('View')
|
||||||
->icon('heroicon-o-eye')
|
->icon('heroicon-o-eye')
|
||||||
->authorize(fn ($record) => auth()->user()->can('view', $record))
|
->authorize(fn ($record) => auth()->user()->can('view', $record))
|
||||||
->modalHeading('View Log')
|
->modalHeading('View Log')
|
||||||
@ -81,7 +84,8 @@ public function getTable(): Table
|
|||||||
->modalSubmitAction(false)
|
->modalSubmitAction(false)
|
||||||
->modalCancelActionLabel('Close'),
|
->modalCancelActionLabel('Close'),
|
||||||
Action::make('download')
|
Action::make('download')
|
||||||
->label('Download')
|
->hiddenLabel()
|
||||||
|
->tooltip('Download')
|
||||||
->color('secondary')
|
->color('secondary')
|
||||||
->icon('heroicon-o-archive-box-arrow-down')
|
->icon('heroicon-o-archive-box-arrow-down')
|
||||||
->authorize(fn ($record) => auth()->user()->can('view', $record))
|
->authorize(fn ($record) => auth()->user()->can('view', $record))
|
||||||
|
@ -5,17 +5,15 @@
|
|||||||
use App\Actions\PHP\InstallNewPHP;
|
use App\Actions\PHP\InstallNewPHP;
|
||||||
use App\Models\Server;
|
use App\Models\Server;
|
||||||
use App\Models\Service;
|
use App\Models\Service;
|
||||||
|
use App\Web\Components\Page;
|
||||||
use App\Web\Pages\Servers\PHP\Widgets\PHPList;
|
use App\Web\Pages\Servers\PHP\Widgets\PHPList;
|
||||||
use App\Web\Traits\PageHasServer;
|
use App\Web\Traits\PageHasServer;
|
||||||
use App\Web\Traits\PageHasWidgets;
|
|
||||||
use Filament\Actions\Action;
|
use Filament\Actions\Action;
|
||||||
use Filament\Actions\ActionGroup;
|
use Filament\Actions\ActionGroup;
|
||||||
use Filament\Pages\Page;
|
|
||||||
|
|
||||||
class Index extends Page
|
class Index extends Page
|
||||||
{
|
{
|
||||||
use PageHasServer;
|
use PageHasServer;
|
||||||
use PageHasWidgets;
|
|
||||||
|
|
||||||
protected static ?string $slug = 'servers/{server}/php';
|
protected static ?string $slug = 'servers/{server}/php';
|
||||||
|
|
||||||
@ -23,11 +21,6 @@ class Index extends Page
|
|||||||
|
|
||||||
protected static ?string $title = 'PHP';
|
protected static ?string $title = 'PHP';
|
||||||
|
|
||||||
protected function getExtraAttributes(): array
|
|
||||||
{
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
public Server $server;
|
public Server $server;
|
||||||
|
|
||||||
public static function canAccess(): bool
|
public static function canAccess(): bool
|
||||||
|
@ -28,6 +28,8 @@ class PHPList extends Widget
|
|||||||
{
|
{
|
||||||
public Server $server;
|
public Server $server;
|
||||||
|
|
||||||
|
protected $listeners = ['$refresh'];
|
||||||
|
|
||||||
protected function getTableQuery(): Builder
|
protected function getTableQuery(): Builder
|
||||||
{
|
{
|
||||||
return Service::query()->where('type', 'php')->where('server_id', $this->server->id);
|
return Service::query()->where('type', 'php')->where('server_id', $this->server->id);
|
||||||
@ -51,8 +53,9 @@ protected function getTableColumns(): array
|
|||||||
->color(fn (Service $service) => $service->is_default ? 'primary' : 'gray')
|
->color(fn (Service $service) => $service->is_default ? 'primary' : 'gray')
|
||||||
->state(fn (Service $service) => $service->is_default ? 'Yes' : 'No')
|
->state(fn (Service $service) => $service->is_default ? 'Yes' : 'No')
|
||||||
->sortable(),
|
->sortable(),
|
||||||
TextColumn::make('created_at_by_timezone')
|
TextColumn::make('created_at')
|
||||||
->label('Installed At'),
|
->label('Installed At')
|
||||||
|
->formatStateUsing(fn ($record) => $record->created_at_by_timezone),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,7 +80,7 @@ public function getTable(): Table
|
|||||||
private function installExtensionAction(): Action
|
private function installExtensionAction(): Action
|
||||||
{
|
{
|
||||||
return Action::make('install-extension')
|
return Action::make('install-extension')
|
||||||
->authorize(fn (Service $php) => auth()->user()?->can('update', [$php, $this->server]))
|
->authorize(fn (Service $php) => auth()->user()?->can('update', $php))
|
||||||
->label('Install Extension')
|
->label('Install Extension')
|
||||||
->modalHeading('Install PHP Extension')
|
->modalHeading('Install PHP Extension')
|
||||||
->modalWidth(MaxWidth::Large)
|
->modalWidth(MaxWidth::Large)
|
||||||
@ -114,7 +117,7 @@ private function installExtensionAction(): Action
|
|||||||
private function defaultPHPCliAction(): Action
|
private function defaultPHPCliAction(): Action
|
||||||
{
|
{
|
||||||
return Action::make('default-php-cli')
|
return Action::make('default-php-cli')
|
||||||
->authorize(fn (Service $php) => auth()->user()?->can('update', [$php, $this->server]))
|
->authorize(fn (Service $php) => auth()->user()?->can('update', $php))
|
||||||
->label('Make Default CLI')
|
->label('Make Default CLI')
|
||||||
->hidden(fn (Service $service) => $service->is_default)
|
->hidden(fn (Service $service) => $service->is_default)
|
||||||
->action(function (Service $service) {
|
->action(function (Service $service) {
|
||||||
@ -141,7 +144,7 @@ private function defaultPHPCliAction(): Action
|
|||||||
private function editPHPIniAction(string $type): Action
|
private function editPHPIniAction(string $type): Action
|
||||||
{
|
{
|
||||||
return Action::make('php-ini-'.$type)
|
return Action::make('php-ini-'.$type)
|
||||||
->authorize(fn (Service $php) => auth()->user()?->can('update', [$php, $this->server]))
|
->authorize(fn (Service $php) => auth()->user()?->can('update', $php))
|
||||||
->label('Update PHP ini ('.$type.')')
|
->label('Update PHP ini ('.$type.')')
|
||||||
->modalWidth(MaxWidth::TwoExtraLarge)
|
->modalWidth(MaxWidth::TwoExtraLarge)
|
||||||
->modalSubmitActionLabel('Save')
|
->modalSubmitActionLabel('Save')
|
||||||
@ -188,7 +191,7 @@ private function editPHPIniAction(string $type): Action
|
|||||||
private function restartFPMAction(): Action
|
private function restartFPMAction(): Action
|
||||||
{
|
{
|
||||||
return Action::make('restart-fpm')
|
return Action::make('restart-fpm')
|
||||||
->authorize(fn (Service $php) => auth()->user()?->can('update', [$php, $this->server]))
|
->authorize(fn (Service $php) => auth()->user()?->can('update', $php))
|
||||||
->label('Restart PHP FPM')
|
->label('Restart PHP FPM')
|
||||||
->action(function (Service $service) {
|
->action(function (Service $service) {
|
||||||
try {
|
try {
|
||||||
@ -209,7 +212,7 @@ private function restartFPMAction(): Action
|
|||||||
private function uninstallAction(): Action
|
private function uninstallAction(): Action
|
||||||
{
|
{
|
||||||
return Action::make('uninstall')
|
return Action::make('uninstall')
|
||||||
->authorize(fn (Service $php) => auth()->user()?->can('delete', [$php, $this->server]))
|
->authorize(fn (Service $php) => auth()->user()?->can('update', $php))
|
||||||
->label('Uninstall')
|
->label('Uninstall')
|
||||||
->color('danger')
|
->color('danger')
|
||||||
->requiresConfirmation()
|
->requiresConfirmation()
|
||||||
|
@ -4,19 +4,17 @@
|
|||||||
|
|
||||||
use App\Actions\Server\RebootServer;
|
use App\Actions\Server\RebootServer;
|
||||||
use App\Models\Server;
|
use App\Models\Server;
|
||||||
|
use App\Web\Components\Page;
|
||||||
use App\Web\Pages\Servers\Widgets\ServerDetails;
|
use App\Web\Pages\Servers\Widgets\ServerDetails;
|
||||||
use App\Web\Pages\Servers\Widgets\UpdateServerInfo;
|
use App\Web\Pages\Servers\Widgets\UpdateServerInfo;
|
||||||
use App\Web\Traits\PageHasServer;
|
use App\Web\Traits\PageHasServer;
|
||||||
use App\Web\Traits\PageHasWidgets;
|
|
||||||
use Filament\Actions\Action;
|
use Filament\Actions\Action;
|
||||||
use Filament\Actions\DeleteAction;
|
use Filament\Actions\DeleteAction;
|
||||||
use Filament\Notifications\Notification;
|
use Filament\Notifications\Notification;
|
||||||
use Filament\Pages\Page;
|
|
||||||
|
|
||||||
class Settings extends Page
|
class Settings extends Page
|
||||||
{
|
{
|
||||||
use PageHasServer;
|
use PageHasServer;
|
||||||
use PageHasWidgets;
|
|
||||||
|
|
||||||
protected static ?string $slug = 'servers/{server}/settings';
|
protected static ?string $slug = 'servers/{server}/settings';
|
||||||
|
|
||||||
|
@ -4,16 +4,14 @@
|
|||||||
|
|
||||||
use App\Models\Server;
|
use App\Models\Server;
|
||||||
use App\Models\Site;
|
use App\Models\Site;
|
||||||
|
use App\Web\Components\Page;
|
||||||
use App\Web\Pages\Servers\Sites\Widgets\SitesList;
|
use App\Web\Pages\Servers\Sites\Widgets\SitesList;
|
||||||
use App\Web\Traits\PageHasServer;
|
use App\Web\Traits\PageHasServer;
|
||||||
use App\Web\Traits\PageHasWidgets;
|
|
||||||
use Filament\Actions\CreateAction;
|
use Filament\Actions\CreateAction;
|
||||||
use Filament\Pages\Page;
|
|
||||||
|
|
||||||
class Index extends Page
|
class Index extends Page
|
||||||
{
|
{
|
||||||
use PageHasServer;
|
use PageHasServer;
|
||||||
use PageHasWidgets;
|
|
||||||
|
|
||||||
protected static ?string $slug = 'servers/{server}/sites';
|
protected static ?string $slug = 'servers/{server}/sites';
|
||||||
|
|
||||||
|
@ -4,18 +4,16 @@
|
|||||||
|
|
||||||
use App\Models\Server;
|
use App\Models\Server;
|
||||||
use App\Models\ServerLog;
|
use App\Models\ServerLog;
|
||||||
|
use App\Web\Components\Page;
|
||||||
use App\Web\Pages\Servers\Logs\Widgets\LogsList;
|
use App\Web\Pages\Servers\Logs\Widgets\LogsList;
|
||||||
use App\Web\Pages\Servers\Widgets\Installing;
|
use App\Web\Pages\Servers\Widgets\Installing;
|
||||||
use App\Web\Pages\Servers\Widgets\ServerStats;
|
use App\Web\Pages\Servers\Widgets\ServerStats;
|
||||||
use App\Web\Traits\PageHasServer;
|
use App\Web\Traits\PageHasServer;
|
||||||
use App\Web\Traits\PageHasWidgets;
|
|
||||||
use Filament\Pages\Page;
|
|
||||||
use Livewire\Attributes\On;
|
use Livewire\Attributes\On;
|
||||||
|
|
||||||
class View extends Page
|
class View extends Page
|
||||||
{
|
{
|
||||||
use PageHasServer;
|
use PageHasServer;
|
||||||
use PageHasWidgets;
|
|
||||||
|
|
||||||
protected static ?string $slug = 'servers/{server}';
|
protected static ?string $slug = 'servers/{server}';
|
||||||
|
|
||||||
|
@ -42,8 +42,9 @@ public function infolist(Infolist $infolist): Infolist
|
|||||||
->inlineLabel()
|
->inlineLabel()
|
||||||
->hintIcon('heroicon-o-information-circle')
|
->hintIcon('heroicon-o-information-circle')
|
||||||
->hintIconTooltip('Server unique identifier to use in the API'),
|
->hintIconTooltip('Server unique identifier to use in the API'),
|
||||||
TextEntry::make('created_at_by_timezone')
|
TextEntry::make('created_at')
|
||||||
->label('Created At')
|
->label('Created At')
|
||||||
|
->formatStateUsing(fn ($record) => $record->created_at_by_timezone)
|
||||||
->inlineLabel(),
|
->inlineLabel(),
|
||||||
TextEntry::make('last_updated_check')
|
TextEntry::make('last_updated_check')
|
||||||
->label('Last Updated Check')
|
->label('Last Updated Check')
|
||||||
|
@ -55,8 +55,14 @@ public function infolist(Infolist $infolist): Infolist
|
|||||||
->icon('heroicon-o-arrow-path')
|
->icon('heroicon-o-arrow-path')
|
||||||
->tooltip('Check Connection')
|
->tooltip('Check Connection')
|
||||||
->action(function (Server $record) {
|
->action(function (Server $record) {
|
||||||
|
$previousStatus = $record->status;
|
||||||
|
|
||||||
$record = $record->checkConnection();
|
$record = $record->checkConnection();
|
||||||
|
|
||||||
|
if ($previousStatus !== $record->status) {
|
||||||
|
$this->redirect(url()->previous());
|
||||||
|
}
|
||||||
|
|
||||||
$this->dispatch('$refresh');
|
$this->dispatch('$refresh');
|
||||||
|
|
||||||
Notification::make()
|
Notification::make()
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
namespace App\Web\Pages\Servers\Widgets;
|
namespace App\Web\Pages\Servers\Widgets;
|
||||||
|
|
||||||
use App\Models\Server;
|
use App\Models\Server;
|
||||||
|
use App\Web\Pages\Servers\Settings;
|
||||||
use App\Web\Pages\Servers\View;
|
use App\Web\Pages\Servers\View;
|
||||||
use Filament\Tables\Actions\Action;
|
use Filament\Tables\Actions\Action;
|
||||||
use Filament\Tables\Columns\TextColumn;
|
use Filament\Tables\Columns\TextColumn;
|
||||||
@ -41,8 +42,9 @@ protected function getTableColumns(): array
|
|||||||
->color(fn (Server $server) => Server::$statusColors[$server->status])
|
->color(fn (Server $server) => Server::$statusColors[$server->status])
|
||||||
->searchable()
|
->searchable()
|
||||||
->sortable(),
|
->sortable(),
|
||||||
TextColumn::make('created_at_by_timezone')
|
TextColumn::make('created_at')
|
||||||
->label('Created At')
|
->label('Created At')
|
||||||
|
->formatStateUsing(fn ($record) => $record->created_at_by_timezone)
|
||||||
->searchable()
|
->searchable()
|
||||||
->sortable(),
|
->sortable(),
|
||||||
];
|
];
|
||||||
@ -57,7 +59,7 @@ public function getTable(): Table
|
|||||||
->label('Settings')
|
->label('Settings')
|
||||||
->icon('heroicon-o-cog-6-tooth')
|
->icon('heroicon-o-cog-6-tooth')
|
||||||
->authorize(fn ($record) => auth()->user()->can('update', $record))
|
->authorize(fn ($record) => auth()->user()->can('update', $record))
|
||||||
->url(fn (Server $record) => '/'),
|
->url(fn (Server $record) => Settings::getUrl(parameters: ['server' => $record])),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,16 +2,13 @@
|
|||||||
|
|
||||||
namespace App\Web\Pages\Settings\Profile;
|
namespace App\Web\Pages\Settings\Profile;
|
||||||
|
|
||||||
|
use App\Web\Components\Page;
|
||||||
use App\Web\Pages\Settings\Profile\Widgets\ProfileInformation;
|
use App\Web\Pages\Settings\Profile\Widgets\ProfileInformation;
|
||||||
use App\Web\Pages\Settings\Profile\Widgets\TwoFactor;
|
use App\Web\Pages\Settings\Profile\Widgets\TwoFactor;
|
||||||
use App\Web\Pages\Settings\Profile\Widgets\UpdatePassword;
|
use App\Web\Pages\Settings\Profile\Widgets\UpdatePassword;
|
||||||
use App\Web\Traits\PageHasWidgets;
|
|
||||||
use Filament\Pages\Page;
|
|
||||||
|
|
||||||
class Index extends Page
|
class Index extends Page
|
||||||
{
|
{
|
||||||
use PageHasWidgets;
|
|
||||||
|
|
||||||
protected static ?string $navigationGroup = 'Settings';
|
protected static ?string $navigationGroup = 'Settings';
|
||||||
|
|
||||||
protected static ?string $slug = 'settings/profile';
|
protected static ?string $slug = 'settings/profile';
|
||||||
|
@ -4,17 +4,14 @@
|
|||||||
|
|
||||||
use App\Actions\Projects\CreateProject;
|
use App\Actions\Projects\CreateProject;
|
||||||
use App\Models\Project;
|
use App\Models\Project;
|
||||||
use App\Web\Traits\PageHasWidgets;
|
use App\Web\Components\Page;
|
||||||
use Filament\Actions\CreateAction;
|
use Filament\Actions\CreateAction;
|
||||||
use Filament\Forms\Components\TextInput;
|
use Filament\Forms\Components\TextInput;
|
||||||
use Filament\Forms\Form;
|
use Filament\Forms\Form;
|
||||||
use Filament\Pages\Page;
|
|
||||||
use Filament\Support\Enums\MaxWidth;
|
use Filament\Support\Enums\MaxWidth;
|
||||||
|
|
||||||
class Index extends Page
|
class Index extends Page
|
||||||
{
|
{
|
||||||
use PageHasWidgets;
|
|
||||||
|
|
||||||
protected static ?string $navigationGroup = 'Settings';
|
protected static ?string $navigationGroup = 'Settings';
|
||||||
|
|
||||||
protected static ?string $slug = 'settings/projects';
|
protected static ?string $slug = 'settings/projects';
|
||||||
|
@ -4,20 +4,17 @@
|
|||||||
|
|
||||||
use App\Actions\Projects\DeleteProject;
|
use App\Actions\Projects\DeleteProject;
|
||||||
use App\Models\Project;
|
use App\Models\Project;
|
||||||
|
use App\Web\Components\Page;
|
||||||
use App\Web\Pages\Settings\Projects\Widgets\AddUser;
|
use App\Web\Pages\Settings\Projects\Widgets\AddUser;
|
||||||
use App\Web\Pages\Settings\Projects\Widgets\ProjectUsersList;
|
use App\Web\Pages\Settings\Projects\Widgets\ProjectUsersList;
|
||||||
use App\Web\Pages\Settings\Projects\Widgets\UpdateProject;
|
use App\Web\Pages\Settings\Projects\Widgets\UpdateProject;
|
||||||
use App\Web\Traits\PageHasWidgets;
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use Filament\Actions\DeleteAction;
|
use Filament\Actions\DeleteAction;
|
||||||
use Filament\Notifications\Notification;
|
use Filament\Notifications\Notification;
|
||||||
use Filament\Pages\Page;
|
|
||||||
use Illuminate\Contracts\Support\Htmlable;
|
use Illuminate\Contracts\Support\Htmlable;
|
||||||
|
|
||||||
class Settings extends Page
|
class Settings extends Page
|
||||||
{
|
{
|
||||||
use PageHasWidgets;
|
|
||||||
|
|
||||||
protected static ?string $slug = 'settings/projects/{project}';
|
protected static ?string $slug = 'settings/projects/{project}';
|
||||||
|
|
||||||
protected static ?string $title = 'Project Settings';
|
protected static ?string $title = 'Project Settings';
|
||||||
|
@ -25,8 +25,9 @@ protected function getTableColumns(): array
|
|||||||
TextColumn::make('name')
|
TextColumn::make('name')
|
||||||
->searchable()
|
->searchable()
|
||||||
->sortable(),
|
->sortable(),
|
||||||
TextColumn::make('created_at_by_timezone')
|
TextColumn::make('created_at')
|
||||||
->label('Created At')
|
->label('Created At')
|
||||||
|
->formatStateUsing(fn ($record) => $record->created_at_by_timezone)
|
||||||
->searchable()
|
->searchable()
|
||||||
->sortable(),
|
->sortable(),
|
||||||
];
|
];
|
||||||
|
@ -3,15 +3,12 @@
|
|||||||
namespace App\Web\Pages\Settings\ServerProviders;
|
namespace App\Web\Pages\Settings\ServerProviders;
|
||||||
|
|
||||||
use App\Enums\ServerProvider;
|
use App\Enums\ServerProvider;
|
||||||
use App\Web\Traits\PageHasWidgets;
|
use App\Web\Components\Page;
|
||||||
use Filament\Actions\CreateAction;
|
use Filament\Actions\CreateAction;
|
||||||
use Filament\Pages\Page;
|
|
||||||
use Filament\Support\Enums\MaxWidth;
|
use Filament\Support\Enums\MaxWidth;
|
||||||
|
|
||||||
class Index extends Page
|
class Index extends Page
|
||||||
{
|
{
|
||||||
use PageHasWidgets;
|
|
||||||
|
|
||||||
protected static ?string $navigationGroup = 'Settings';
|
protected static ?string $navigationGroup = 'Settings';
|
||||||
|
|
||||||
protected static ?string $slug = 'settings/server-providers';
|
protected static ?string $slug = 'settings/server-providers';
|
||||||
|
@ -41,8 +41,9 @@ protected function getTableColumns(): array
|
|||||||
->formatStateUsing(function (ServerProvider $record) {
|
->formatStateUsing(function (ServerProvider $record) {
|
||||||
return $record->project_id ? 'No' : 'Yes';
|
return $record->project_id ? 'No' : 'Yes';
|
||||||
}),
|
}),
|
||||||
TextColumn::make('created_at_by_timezone')
|
TextColumn::make('created_at')
|
||||||
->label('Created At')
|
->label('Created At')
|
||||||
|
->formatStateUsing(fn ($record) => $record->created_at_by_timezone)
|
||||||
->searchable()
|
->searchable()
|
||||||
->sortable(),
|
->sortable(),
|
||||||
];
|
];
|
||||||
|
@ -4,18 +4,15 @@
|
|||||||
|
|
||||||
use App\Actions\User\CreateUser;
|
use App\Actions\User\CreateUser;
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\Web\Traits\PageHasWidgets;
|
use App\Web\Components\Page;
|
||||||
use Filament\Actions\CreateAction;
|
use Filament\Actions\CreateAction;
|
||||||
use Filament\Forms\Components\Select;
|
use Filament\Forms\Components\Select;
|
||||||
use Filament\Forms\Components\TextInput;
|
use Filament\Forms\Components\TextInput;
|
||||||
use Filament\Forms\Form;
|
use Filament\Forms\Form;
|
||||||
use Filament\Pages\Page;
|
|
||||||
use Filament\Support\Enums\MaxWidth;
|
use Filament\Support\Enums\MaxWidth;
|
||||||
|
|
||||||
class Index extends Page
|
class Index extends Page
|
||||||
{
|
{
|
||||||
use PageHasWidgets;
|
|
||||||
|
|
||||||
protected static ?string $navigationGroup = 'Settings';
|
protected static ?string $navigationGroup = 'Settings';
|
||||||
|
|
||||||
protected static ?string $slug = 'users';
|
protected static ?string $slug = 'users';
|
||||||
|
@ -41,8 +41,9 @@ protected function getTableColumns(): array
|
|||||||
->searchable()
|
->searchable()
|
||||||
->sortable(),
|
->sortable(),
|
||||||
TextColumn::make('timezone'),
|
TextColumn::make('timezone'),
|
||||||
TextColumn::make('created_at_by_timezone')
|
TextColumn::make('created_at')
|
||||||
->label('Created At')
|
->label('Created At')
|
||||||
|
->formatStateUsing(fn ($record) => $record->created_at_by_timezone)
|
||||||
->searchable()
|
->searchable()
|
||||||
->sortable(),
|
->sortable(),
|
||||||
TextColumn::make('role'),
|
TextColumn::make('role'),
|
||||||
|
@ -1,72 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Web\Traits;
|
|
||||||
|
|
||||||
use App\Models\Server;
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
|
||||||
use Illuminate\Support\Facades\Gate;
|
|
||||||
use Illuminate\Support\Facades\Request;
|
|
||||||
use Illuminate\Support\Facades\Route;
|
|
||||||
|
|
||||||
trait BelongsToServers
|
|
||||||
{
|
|
||||||
public static function getUrl(string $name = 'index', array $parameters = [], bool $isAbsolute = true, ?string $panel = null, ?Model $tenant = null): string
|
|
||||||
{
|
|
||||||
if (! isset($parameters['server'])) {
|
|
||||||
$parameters['server'] = request()->route('server') ?? 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return parent::getUrl($name, $parameters, $isAbsolute, $panel, $tenant);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function getServerFromRoute(): Server
|
|
||||||
{
|
|
||||||
$server = request()->route('server');
|
|
||||||
|
|
||||||
if (! $server) {
|
|
||||||
$server = Route::getRoutes()->match(Request::create(url()->previous()))->parameter('server');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (! $server instanceof Server) {
|
|
||||||
$server = Server::query()->find($server);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (! $server) {
|
|
||||||
$server = new Server;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $server;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function canViewAny(): bool
|
|
||||||
{
|
|
||||||
return static::can('viewAny');
|
|
||||||
|
|
||||||
return auth()->user()->can('viewAny', [static::getModel(), static::getServerFromRoute()]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function canCreate(): bool
|
|
||||||
{
|
|
||||||
return auth()->user()->can('create', [static::getModel(), static::getServerFromRoute()]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function authorizeViewAny(): void
|
|
||||||
{
|
|
||||||
Gate::authorize('viewAny', [static::getModel(), static::getServerFromRoute()]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function authorizeCreate(): void
|
|
||||||
{
|
|
||||||
Gate::authorize('create', [static::getModel(), static::getServerFromRoute()]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function authorizeEdit(Model $record): void
|
|
||||||
{
|
|
||||||
Gate::authorize('update', [$record, static::getServerFromRoute()]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function authorizeView(Model $record): void
|
|
||||||
{
|
|
||||||
Gate::authorize('view', [$record, static::getServerFromRoute()]);
|
|
||||||
}
|
|
||||||
}
|
|
38
app/Web/Traits/HasWidgets.php
Normal file
38
app/Web/Traits/HasWidgets.php
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Web\Traits;
|
||||||
|
|
||||||
|
use Illuminate\View\ComponentAttributeBag;
|
||||||
|
|
||||||
|
trait HasWidgets
|
||||||
|
{
|
||||||
|
protected ?string $live = '5s';
|
||||||
|
|
||||||
|
protected array $extraAttributes = [];
|
||||||
|
|
||||||
|
protected function getExtraAttributes(): array
|
||||||
|
{
|
||||||
|
$attributes = $this->extraAttributes;
|
||||||
|
|
||||||
|
if ($this->getLive()) {
|
||||||
|
$attributes['wire:poll.'.$this->getLive()] = '$dispatch(\'$refresh\')';
|
||||||
|
}
|
||||||
|
|
||||||
|
return $attributes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getExtraAttributesBag(): ComponentAttributeBag
|
||||||
|
{
|
||||||
|
return new ComponentAttributeBag($this->getExtraAttributes());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getLive(): ?string
|
||||||
|
{
|
||||||
|
return $this->live;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getWidgets(): array
|
||||||
|
{
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
@ -1,20 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Web\Traits;
|
|
||||||
|
|
||||||
trait PageHasCluster
|
|
||||||
{
|
|
||||||
// public function getMaxContentWidth(): ?string
|
|
||||||
// {
|
|
||||||
// return 'full';
|
|
||||||
// }
|
|
||||||
|
|
||||||
public function getSubNavigation(): array
|
|
||||||
{
|
|
||||||
if (filled($cluster = static::getCluster())) {
|
|
||||||
return $this->generateNavigationItems($cluster::getClusteredComponents());
|
|
||||||
}
|
|
||||||
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
}
|
|
@ -3,6 +3,7 @@
|
|||||||
namespace App\Web\Traits;
|
namespace App\Web\Traits;
|
||||||
|
|
||||||
use App\Models\Server;
|
use App\Models\Server;
|
||||||
|
use App\Web\Pages\Servers\Databases\Index as DatabasesIndex;
|
||||||
use App\Web\Pages\Servers\Logs\Index as LogsIndex;
|
use App\Web\Pages\Servers\Logs\Index as LogsIndex;
|
||||||
use App\Web\Pages\Servers\PHP\Index as PHPIndex;
|
use App\Web\Pages\Servers\PHP\Index as PHPIndex;
|
||||||
use App\Web\Pages\Servers\Settings as ServerSettings;
|
use App\Web\Pages\Servers\Settings as ServerSettings;
|
||||||
@ -26,35 +27,42 @@ public function getSubNavigation(): array
|
|||||||
$items = [];
|
$items = [];
|
||||||
|
|
||||||
if (ServerView::canAccess()) {
|
if (ServerView::canAccess()) {
|
||||||
$items[] = NavigationItem::make('Overview')
|
$items[] = NavigationItem::make(ServerView::getNavigationLabel())
|
||||||
->icon('heroicon-o-chart-pie')
|
->icon('heroicon-o-chart-pie')
|
||||||
->isActiveWhen(fn () => request()->routeIs(ServerView::getRouteName()))
|
->isActiveWhen(fn () => request()->routeIs(ServerView::getRouteName()))
|
||||||
->url(ServerView::getUrl(parameters: ['server' => $this->server]));
|
->url(ServerView::getUrl(parameters: ['server' => $this->server]));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (SitesIndex::canAccess()) {
|
if (SitesIndex::canAccess()) {
|
||||||
$items[] = NavigationItem::make('Sites')
|
$items[] = NavigationItem::make(SitesIndex::getNavigationLabel())
|
||||||
->icon('heroicon-o-globe-alt')
|
->icon('heroicon-o-globe-alt')
|
||||||
->isActiveWhen(fn () => request()->routeIs(SitesIndex::getRouteName().'*'))
|
->isActiveWhen(fn () => request()->routeIs(SitesIndex::getRouteName().'*'))
|
||||||
->url(SitesIndex::getUrl(parameters: ['server' => $this->server]));
|
->url(SitesIndex::getUrl(parameters: ['server' => $this->server]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (DatabasesIndex::canAccess()) {
|
||||||
|
$items[] = NavigationItem::make(DatabasesIndex::getNavigationLabel())
|
||||||
|
->icon('heroicon-o-circle-stack')
|
||||||
|
->isActiveWhen(fn () => request()->routeIs(DatabasesIndex::getRouteName().'*'))
|
||||||
|
->url(DatabasesIndex::getUrl(parameters: ['server' => $this->server]));
|
||||||
|
}
|
||||||
|
|
||||||
if (PHPIndex::canAccess()) {
|
if (PHPIndex::canAccess()) {
|
||||||
$items[] = NavigationItem::make('PHP')
|
$items[] = NavigationItem::make(PHPIndex::getNavigationLabel())
|
||||||
->icon('heroicon-o-code-bracket')
|
->icon('heroicon-o-code-bracket')
|
||||||
->isActiveWhen(fn () => request()->routeIs(PHPIndex::getRouteName().'*'))
|
->isActiveWhen(fn () => request()->routeIs(PHPIndex::getRouteName().'*'))
|
||||||
->url(PHPIndex::getUrl(parameters: ['server' => $this->server]));
|
->url(PHPIndex::getUrl(parameters: ['server' => $this->server]));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (LogsIndex::canAccess()) {
|
if (LogsIndex::canAccess()) {
|
||||||
$items[] = NavigationItem::make('Logs')
|
$items[] = NavigationItem::make(LogsIndex::getNavigationLabel())
|
||||||
->icon('heroicon-o-square-3-stack-3d')
|
->icon('heroicon-o-square-3-stack-3d')
|
||||||
->isActiveWhen(fn () => request()->routeIs(LogsIndex::getRouteName().'*'))
|
->isActiveWhen(fn () => request()->routeIs(LogsIndex::getRouteName().'*'))
|
||||||
->url(LogsIndex::getUrl(parameters: ['server' => $this->server]));
|
->url(LogsIndex::getUrl(parameters: ['server' => $this->server]));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ServerSettings::canAccess()) {
|
if (ServerSettings::canAccess()) {
|
||||||
$items[] = NavigationItem::make('Settings')
|
$items[] = NavigationItem::make(ServerSettings::getNavigationLabel())
|
||||||
->icon('heroicon-o-cog-6-tooth')
|
->icon('heroicon-o-cog-6-tooth')
|
||||||
->isActiveWhen(fn () => request()->routeIs(ServerSettings::getRouteName().'*'))
|
->isActiveWhen(fn () => request()->routeIs(ServerSettings::getRouteName().'*'))
|
||||||
->url(ServerSettings::getUrl(parameters: ['server' => $this->server]));
|
->url(ServerSettings::getUrl(parameters: ['server' => $this->server]));
|
||||||
|
@ -1,29 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Web\Traits;
|
|
||||||
|
|
||||||
use Illuminate\View\ComponentAttributeBag;
|
|
||||||
|
|
||||||
trait PageHasWidgets
|
|
||||||
{
|
|
||||||
protected array $extraAttributes = [
|
|
||||||
'wire:poll.5s' => '$dispatch(\'$refresh\')',
|
|
||||||
];
|
|
||||||
|
|
||||||
protected function getExtraAttributes(): array
|
|
||||||
{
|
|
||||||
return $this->extraAttributes;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getView(): string
|
|
||||||
{
|
|
||||||
return 'web.components.page';
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getExtraAttributesBag(): ComponentAttributeBag
|
|
||||||
{
|
|
||||||
return new ComponentAttributeBag($this->getExtraAttributes());
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract public function getWidgets(): array;
|
|
||||||
}
|
|
@ -480,5 +480,5 @@
|
|||||||
'user_roles' => [
|
'user_roles' => [
|
||||||
\App\Enums\UserRole::USER,
|
\App\Enums\UserRole::USER,
|
||||||
\App\Enums\UserRole::ADMIN,
|
\App\Enums\UserRole::ADMIN,
|
||||||
]
|
],
|
||||||
];
|
];
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
<form class="fi-form">
|
<form>
|
||||||
{{ $this->form }}
|
{{ $this->form }}
|
||||||
</form>
|
</form>
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
<div {{ $this->getExtraAttributesBag() }}>
|
<div {{ $this->getExtraAttributesBag() }}>
|
||||||
<x-filament-panels::page>
|
<x-filament-panels::page>
|
||||||
|
@if (method_exists($this, "getSecondSubNavigation"))
|
||||||
|
<x-filament-panels::page.sub-navigation.tabs :navigation="$this->getSecondSubNavigation()" />
|
||||||
|
@endif
|
||||||
|
|
||||||
@foreach ($this->getWidgets() as $key => $widget)
|
@foreach ($this->getWidgets() as $key => $widget)
|
||||||
@livewire($widget[0], $widget[1] ?? [], key(class_basename($widget[0]) . "-" . $key))
|
@livewire($widget[0], $widget[1] ?? [], key(class_basename($widget[0]) . "-" . $key))
|
||||||
@endforeach
|
@endforeach
|
||||||
|
@ -78,7 +78,7 @@ public function test_send(): void
|
|||||||
|
|
||||||
Http::fake();
|
Http::fake();
|
||||||
|
|
||||||
$provider->send($channel, new TestNotification());
|
$provider->send($channel, new TestNotification);
|
||||||
|
|
||||||
Http::assertSent(function (Request $request) {
|
Http::assertSent(function (Request $request) {
|
||||||
return $request->body() === '{"content":"Hello"}';
|
return $request->body() === '{"content":"Hello"}';
|
||||||
|
@ -76,7 +76,7 @@ public function test_send(): void
|
|||||||
|
|
||||||
Mail::fake();
|
Mail::fake();
|
||||||
|
|
||||||
$provider->send($channel, new TestNotification());
|
$provider->send($channel, new TestNotification);
|
||||||
|
|
||||||
Mail::assertSent(NotificationMail::class);
|
Mail::assertSent(NotificationMail::class);
|
||||||
}
|
}
|
||||||
|
@ -78,7 +78,7 @@ public function test_send(): void
|
|||||||
|
|
||||||
Http::fake();
|
Http::fake();
|
||||||
|
|
||||||
$provider->send($channel, new TestNotification());
|
$provider->send($channel, new TestNotification);
|
||||||
|
|
||||||
Http::assertSent(function (Request $request) {
|
Http::assertSent(function (Request $request) {
|
||||||
return $request->body() === '{"text":"Hello"}';
|
return $request->body() === '{"text":"Hello"}';
|
||||||
|
@ -92,7 +92,7 @@ public function test_send(): void
|
|||||||
|
|
||||||
Http::fake();
|
Http::fake();
|
||||||
|
|
||||||
$provider->send($channel, new TestNotification());
|
$provider->send($channel, new TestNotification);
|
||||||
|
|
||||||
Http::assertSent(function (Request $request) {
|
Http::assertSent(function (Request $request) {
|
||||||
if ($request->url() === 'https://api.telegram.org/botxxxxx/sendMessage') {
|
if ($request->url() === 'https://api.telegram.org/botxxxxx/sendMessage') {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user