Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Create Database btn on admin side #721

Merged
merged 24 commits into from
Dec 1, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
7160fc9
Add Create Database btn on admin side
notAreYouScared Nov 20, 2024
6363b74
Remove unused function
notAreYouScared Nov 20, 2024
aba55ef
readd function
notAreYouScared Nov 20, 2024
01d7456
replace refreshform function
notAreYouScared Nov 20, 2024
96275e0
add authorize, remove database limit check
notAreYouScared Nov 20, 2024
1aeb017
add random words, use proper name function, catch exceptions on creation
notAreYouScared Nov 20, 2024
f18adda
add validation, match old client area more
notAreYouScared Nov 20, 2024
af3b87f
Merge remote-tracking branch 'origin/main' into feature/create-db
notAreYouScared Nov 22, 2024
ff2d059
Add more authorize to Database tab
notAreYouScared Nov 22, 2024
4592fde
Add confirmation to delete
notAreYouScared Nov 22, 2024
eb79fad
make password hidden / revealable
notAreYouScared Nov 22, 2024
c5e4488
better clarification
notAreYouScared Nov 22, 2024
9324da0
Set default and remove placeholder.
notAreYouScared Nov 22, 2024
203956b
Remove server import, add database model to auth
notAreYouScared Nov 22, 2024
f3c0e02
Make same changes for the database host page
notAreYouScared Nov 22, 2024
c55657f
Update app/Filament/Resources/ServerResource/Pages/EditServer.php
notAreYouScared Nov 23, 2024
0cf715e
Update app/Filament/Resources/DatabaseHostResource/RelationManagers/D…
notAreYouScared Nov 23, 2024
89955cc
Update app/Filament/Resources/DatabaseHostResource/RelationManagers/D…
notAreYouScared Nov 23, 2024
cca1999
Remove each hidden
notAreYouScared Nov 24, 2024
246c90a
Return nothing if user has no perms
notAreYouScared Nov 24, 2024
a9a5a2b
This is the way... Im done messing with it...
notAreYouScared Nov 26, 2024
fb9900c
Fix view permission for relationship manager
notAreYouScared Dec 1, 2024
3821837
Update app/Filament/Resources/DatabaseHostResource/RelationManagers/D…
RMartinOscar Dec 1, 2024
ea88a4a
Pint
RMartinOscar Dec 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 55 additions & 2 deletions app/Filament/Resources/ServerResource/Pages/EditServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use App\Filament\Resources\ServerResource;
use App\Filament\Resources\ServerResource\RelationManagers\AllocationsRelationManager;
use App\Models\Database;
use App\Models\DatabaseHost;
use App\Models\Egg;
use App\Models\Mount;
use App\Models\Server;
Expand Down Expand Up @@ -609,6 +610,7 @@ public function form(Form $form): Form
]),
Tab::make('Databases')
->icon('tabler-database')
->columns(4)
->schema([
Repeater::make('databases')
->grid()
Expand All @@ -624,7 +626,10 @@ public function form(Form $form): Form
Action::make('Delete')
->color('danger')
->icon('tabler-trash')
notAreYouScared marked this conversation as resolved.
Show resolved Hide resolved
->action(fn (DatabaseManagementService $databaseManagementService, $record) => $databaseManagementService->delete($record))
->action(function (DatabaseManagementService $databaseManagementService, $record) {
$databaseManagementService->delete($record);
$this->fillForm();
})
),
TextInput::make('username')
->disabled()
Expand Down Expand Up @@ -659,7 +664,55 @@ public function form(Form $form): Form
->deletable(false)
->addable(false)
->columnSpan(4),
])->columns(4),
Forms\Components\Actions::make([
Action::make('createDatabase')
notAreYouScared marked this conversation as resolved.
Show resolved Hide resolved
Boy132 marked this conversation as resolved.
Show resolved Hide resolved
->authorize(fn (Server $server) => auth()->user()->can('create database'))
->disabled(fn (Server $server) => DatabaseHost::query()->count() < 1)
->label(fn (Server $server) => DatabaseHost::query()->count() < 1 ? 'No Database Hosts' : 'Create Database')
->color(fn (Server $server) => DatabaseHost::query()->count() < 1 ? 'danger' : 'primary')
->modalSubmitActionLabel('Create')
->action(function (array $data, DatabaseManagementService $service, Server $server, RandomWordService $randomWordService) {
if (empty($data['database'])) {
$data['database'] = $randomWordService->word() . random_int(1, 420);
}
if (empty($data['remote'])) {
$data['remote'] = '%';
}

$data['database'] = $service->generateUniqueDatabaseName($data['database'], $server->id);

try {
$service->setValidateDatabaseLimit(false)->create($server, $data);
} catch (Exception $e) {
Notification::make()
->title('Failed to Create Database')
->body($e->getMessage())
->danger()
->persistent()->send();
}
$this->fillForm();
})
->form([
Select::make('database_host_id')
->label('Database Host')
->required()
->placeholder('Select Database Host')
->relationship('node.databaseHosts', 'name'),
TextInput::make('database')
->label('Database Name')
->alphaDash()
->prefix(fn (Server $server) => 's' . $server->id . '_')
->hintIcon('tabler-question-mark')
->hintIconTooltip('Leaving this blank will auto generate a random name'),
TextInput::make('remote')
->columnSpan(1)
->regex('/^[\w\-\/.%:]+$/')
->label('Connections From')
->hintIcon('tabler-question-mark')
->hintIconTooltip('Where connections should be allowed from. Leave blank to allow connections from anywhere.'),
]),
])->alignCenter()->columnSpanFull(),
]),
Tab::make('Actions')
->icon('tabler-settings')
->schema([
Expand Down
5 changes: 5 additions & 0 deletions app/Models/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,11 @@ public function allocations(): HasMany
return $this->hasMany(Allocation::class);
}

public function databaseHosts(): HasMany
{
return $this->hasMany(DatabaseHost::class);
}

/**
* Returns a boolean if the node is viable for an additional server to be placed on it.
*/
Expand Down
Loading