diff --git a/app/Filament/App/Resources/ActivityResource.php b/app/Filament/App/Resources/ActivityResource.php index c3db101bc5..8b7661ba88 100644 --- a/app/Filament/App/Resources/ActivityResource.php +++ b/app/Filament/App/Resources/ActivityResource.php @@ -3,16 +3,11 @@ namespace App\Filament\App\Resources; use App\Filament\App\Resources\ActivityResource\Pages; -use App\Filament\App\Resources\ActivityResource\RelationManagers; -use App\Models\Activity; use App\Models\ActivityLog; -use Filament\Forms; use Filament\Forms\Form; use Filament\Resources\Resource; use Filament\Tables; use Filament\Tables\Table; -use Illuminate\Database\Eloquent\Builder; -use Illuminate\Database\Eloquent\SoftDeletingScope; class ActivityResource extends Resource { diff --git a/app/Filament/App/Resources/ActivityResource/Pages/ListActivities.php b/app/Filament/App/Resources/ActivityResource/Pages/ListActivities.php index bbb68c4912..7c9ab806b8 100644 --- a/app/Filament/App/Resources/ActivityResource/Pages/ListActivities.php +++ b/app/Filament/App/Resources/ActivityResource/Pages/ListActivities.php @@ -3,17 +3,9 @@ namespace App\Filament\App\Resources\ActivityResource\Pages; use App\Filament\App\Resources\ActivityResource; -use Filament\Actions; use Filament\Resources\Pages\ListRecords; class ListActivities extends ListRecords { protected static string $resource = ActivityResource::class; - - protected function getHeaderActions(): array - { - return [ - Actions\CreateAction::make(), - ]; - } } diff --git a/app/Filament/App/Resources/BackupResource.php b/app/Filament/App/Resources/BackupResource.php index 1afc241ca7..45c6ae057b 100644 --- a/app/Filament/App/Resources/BackupResource.php +++ b/app/Filament/App/Resources/BackupResource.php @@ -3,15 +3,12 @@ namespace App\Filament\App\Resources; use App\Filament\App\Resources\BackupResource\Pages; -use App\Filament\App\Resources\BackupResource\RelationManagers; use App\Models\Backup; use Filament\Forms; use Filament\Forms\Form; use Filament\Resources\Resource; use Filament\Tables; use Filament\Tables\Table; -use Illuminate\Database\Eloquent\Builder; -use Illuminate\Database\Eloquent\SoftDeletingScope; class BackupResource extends Resource { diff --git a/app/Filament/App/Resources/BackupResource/Pages/CreateBackup.php b/app/Filament/App/Resources/BackupResource/Pages/CreateBackup.php index 403a19ca20..c6f9ec7bca 100644 --- a/app/Filament/App/Resources/BackupResource/Pages/CreateBackup.php +++ b/app/Filament/App/Resources/BackupResource/Pages/CreateBackup.php @@ -3,7 +3,6 @@ namespace App\Filament\App\Resources\BackupResource\Pages; use App\Filament\App\Resources\BackupResource; -use Filament\Actions; use Filament\Resources\Pages\CreateRecord; class CreateBackup extends CreateRecord diff --git a/app/Filament/App/Resources/DatabaseResource.php b/app/Filament/App/Resources/DatabaseResource.php index 1e3576f321..92fdd0b0fb 100644 --- a/app/Filament/App/Resources/DatabaseResource.php +++ b/app/Filament/App/Resources/DatabaseResource.php @@ -3,15 +3,12 @@ namespace App\Filament\App\Resources; use App\Filament\App\Resources\DatabaseResource\Pages; -use App\Filament\App\Resources\DatabaseResource\RelationManagers; use App\Models\Database; use Filament\Forms; use Filament\Forms\Form; use Filament\Resources\Resource; use Filament\Tables; use Filament\Tables\Table; -use Illuminate\Database\Eloquent\Builder; -use Illuminate\Database\Eloquent\SoftDeletingScope; class DatabaseResource extends Resource { diff --git a/app/Filament/App/Resources/DatabaseResource/Pages/CreateDatabase.php b/app/Filament/App/Resources/DatabaseResource/Pages/CreateDatabase.php index 4d5bbc6e6b..d6238b3632 100644 --- a/app/Filament/App/Resources/DatabaseResource/Pages/CreateDatabase.php +++ b/app/Filament/App/Resources/DatabaseResource/Pages/CreateDatabase.php @@ -3,7 +3,6 @@ namespace App\Filament\App\Resources\DatabaseResource\Pages; use App\Filament\App\Resources\DatabaseResource; -use Filament\Actions; use Filament\Resources\Pages\CreateRecord; class CreateDatabase extends CreateRecord diff --git a/app/Filament/App/Resources/ScheduleResource.php b/app/Filament/App/Resources/ScheduleResource.php index 440babf5f2..a8554a988a 100644 --- a/app/Filament/App/Resources/ScheduleResource.php +++ b/app/Filament/App/Resources/ScheduleResource.php @@ -3,15 +3,12 @@ namespace App\Filament\App\Resources; use App\Filament\App\Resources\ScheduleResource\Pages; -use App\Filament\App\Resources\ScheduleResource\RelationManagers; use App\Models\Schedule; use Filament\Forms; use Filament\Forms\Form; use Filament\Resources\Resource; use Filament\Tables; use Filament\Tables\Table; -use Illuminate\Database\Eloquent\Builder; -use Illuminate\Database\Eloquent\SoftDeletingScope; class ScheduleResource extends Resource { diff --git a/app/Filament/App/Resources/ScheduleResource/Pages/CreateSchedule.php b/app/Filament/App/Resources/ScheduleResource/Pages/CreateSchedule.php index c249ab01bf..a95e6be06d 100644 --- a/app/Filament/App/Resources/ScheduleResource/Pages/CreateSchedule.php +++ b/app/Filament/App/Resources/ScheduleResource/Pages/CreateSchedule.php @@ -3,7 +3,6 @@ namespace App\Filament\App\Resources\ScheduleResource\Pages; use App\Filament\App\Resources\ScheduleResource; -use Filament\Actions; use Filament\Resources\Pages\CreateRecord; class CreateSchedule extends CreateRecord diff --git a/app/Filament/App/Resources/UserResource.php b/app/Filament/App/Resources/UserResource.php index 1908bcf753..de147123a3 100644 --- a/app/Filament/App/Resources/UserResource.php +++ b/app/Filament/App/Resources/UserResource.php @@ -3,15 +3,10 @@ namespace App\Filament\App\Resources; use App\Filament\App\Resources\UserResource\Pages; -use App\Filament\App\Resources\UserResource\RelationManagers; use App\Models\User; -use Filament\Forms; -use Filament\Forms\Form; use Filament\Resources\Resource; use Filament\Tables; use Filament\Tables\Table; -use Illuminate\Database\Eloquent\Builder; -use Illuminate\Database\Eloquent\SoftDeletingScope; class UserResource extends Resource { diff --git a/app/Filament/App/Resources/UserResource/Pages/ListUsers.php b/app/Filament/App/Resources/UserResource/Pages/ListUsers.php index 5a5a3d8378..340f734c8c 100644 --- a/app/Filament/App/Resources/UserResource/Pages/ListUsers.php +++ b/app/Filament/App/Resources/UserResource/Pages/ListUsers.php @@ -3,7 +3,15 @@ namespace App\Filament\App\Resources\UserResource\Pages; use App\Filament\App\Resources\UserResource; +use App\Models\Server; +use App\Services\Subusers\SubuserCreationService; use Filament\Actions; +use Filament\Forms\Components\CheckboxList; +use Filament\Forms\Components\Grid; +use Filament\Forms\Components\Section; +use Filament\Forms\Components\Tabs; +use Filament\Forms\Components\TextInput; +use Filament\Notifications\Notification; use Filament\Resources\Pages\ListRecords; class ListUsers extends ListRecords @@ -13,8 +21,256 @@ class ListUsers extends ListRecords protected function getHeaderActions(): array { return [ - Actions\CreateAction::make(), - // TODO: Invite User instead of Create + Actions\CreateAction::make('invite') + ->label('Invite User') + ->createAnother(false) + ->form([ + Grid::make() + ->columnSpanFull() + ->schema([ + TextInput::make('email') + ->email() + ->columnSpanFull() + ->required() + ->unique(), + Tabs::make() + ->columnSpanFull() + ->schema([ + Tabs\Tab::make('Console') + ->schema([ + Section::make() + ->description(trans('server/users.permissions.control_desc')) + ->icon('tabler-terminal-2') + ->schema([ + CheckboxList::make('console') + ->bulkToggleable() + ->label('') + ->columns(2) + ->options([ + 'console' => 'Console', + 'start' => 'Start', + 'stop' => 'Stop', + 'restart' => 'Restart', + 'kill' => 'Kill', + ]) + ->descriptions([ + 'console' => trans('server/users.permissions.control_console'), + 'start' => trans('server/users.permissions.control_start'), + 'stop' => trans('server/users.permissions.control_stop'), + 'restart' => trans('server/users.permissions.control_restart'), + 'kill' => trans('server/users.permissions.control_kill'), + ]), + ]), + ]), + Tabs\Tab::make('User') + ->schema([ + Section::make() + ->description(trans('server/users.permissions.user_desc')) + ->icon('tabler-users') + ->schema([ + CheckboxList::make('user') + ->bulkToggleable() + ->label('') + ->columns(2) + ->options([ + 'read' => 'Read', + 'create' => 'Create', + 'update' => 'Update', + 'delete' => 'Delete', + ]) + ->descriptions([ + 'create' => trans('server/users.permissions.user_create'), + 'read' => trans('server/users.permissions.user_read'), + 'update' => trans('server/users.permissions.user_update'), + 'delete' => trans('server/users.permissions.user_delete'), + ]), + ]), + ]), + Tabs\Tab::make('File') + ->schema([ + Section::make() + ->description(trans('server/users.permissions.file_desc')) + ->icon('tabler-folders') + ->schema([ + CheckboxList::make('file') + ->bulkToggleable() + ->label('') + ->columns(2) + ->options([ + 'read' => 'Read', + 'read-content' => 'Read Content', + 'create' => 'Create', + 'update' => 'Update', + 'delete' => 'Delete', + 'archive' => 'Archive', + 'sftp' => 'SFTP', + ]) + ->descriptions([ + 'create' => trans('server/users.permissions.file_create'), + 'read' => trans('server/users.permissions.file_read'), + 'read-content' => trans('server/users.permissions.file_read_content'), + 'update' => trans('server/users.permissions.file_update'), + 'delete' => trans('server/users.permissions.file_delete'), + 'archive' => trans('server/users.permissions.file_archive'), + 'sftp' => trans('server/users.permissions.file_sftp'), + ]), + ]), + ]), + Tabs\Tab::make('Backup') + ->schema([ + Section::make() + ->description(trans('server/users.permissions.backup_desc')) + ->icon('tabler-download') + ->schema([ + CheckboxList::make('backup') + ->bulkToggleable() + ->label('') + ->columns(2) + ->options([ + 'read' => 'Read', + 'create' => 'Create', + 'delete' => 'Delete', + 'download' => 'Download', + 'restore' => 'Restore', + ]) + ->descriptions([ + 'create' => trans('server/users.permissions.backup_create'), + 'read' => trans('server/users.permissions.backup_read'), + 'delete' => trans('server/users.permissions.backup_delete'), + 'download' => trans('server/users.permissions.backup_download'), + 'restore' => trans('server/users.permissions.backup_restore'), + ]), + ]), + ]), + Tabs\Tab::make('Allocation') + ->schema([ + Section::make() + ->description(trans('server/users.permissions.allocation_desc')) + ->icon('tabler-network') + ->schema([ + CheckboxList::make('allocation') + ->bulkToggleable() + ->label('') + ->columns(2) + ->options([ + 'read' => 'Read', + 'create' => 'Create', + 'update' => 'Update', + 'delete' => 'Delete', + ]) + ->descriptions([ + 'read' => trans('server/users.permissions.allocation_read'), + 'create' => trans('server/users.permissions.allocation_create'), + 'update' => trans('server/users.permissions.allocation_update'), + 'delete' => trans('server/users.permissions.allocation_delete'), + ]), + ]), + ]), + Tabs\Tab::make('Startup') + ->schema([ + Section::make() + ->description(trans('server/users.permissions.startup_desc')) + ->icon('tabler-question-mark') + ->schema([ + CheckboxList::make('startup') + ->bulkToggleable() + ->label('') + ->columns(2) + ->options([ + 'read' => 'Read', + 'update' => 'Update', + 'docker-image' => 'Docker Image', + ]) + ->descriptions([ + 'read' => trans('server/users.permissions.startup_read'), + 'update' => trans('server/users.permissions.startup_update'), + 'docker-image' => trans('server/users.permissions.startup_docker_image'), + ]), + ]), + ]), + Tabs\Tab::make('Database') + ->schema([ + Section::make() + ->description(trans('server/users.permissions.database_desc')) + ->icon('tabler-database') + ->schema([ + CheckboxList::make('database') + ->bulkToggleable() + ->label('') + ->columns(2) + ->options([ + 'read' => 'Read', + 'create' => 'Create', + 'update' => 'Update', + 'delete' => 'Delete', + 'view-password' => 'View Password', + ]) + ->descriptions([ + 'read' => trans('server/users.permissions.database_read'), + 'create' => trans('server/users.permissions.database_create'), + 'update' => trans('server/users.permissions.database_update'), + 'delete' => trans('server/users.permissions.database_delete'), + 'view-password' => trans('server/users.permissions.database_view_password'), + ]), + ]), + ]), + Tabs\Tab::make('Schedule') + ->schema([ + Section::make() + ->description(trans('server/users.permissions.schedule_desc')) + ->icon('tabler-clock') + ->schema([ + CheckboxList::make('schedule') + ->bulkToggleable() + ->label('') + ->columns(2) + ->options([ + 'read' => 'Read', + 'create' => 'Create', + 'update' => 'Update', + 'delete' => 'Delete', + ]) + ->descriptions([ + 'read' => trans('server/users.permissions.schedule_read'), + 'create' => trans('server/users.permissions.schedule_create'), + 'update' => trans('server/users.permissions.schedule_update'), + 'delete' => trans('server/users.permissions.schedule_delete'), + ]), + ]), + ]), + Tabs\Tab::make('Settings') + ->schema([ + Section::make() + ->description(trans('server/users.permissions.settings_desc')) + ->icon('tabler-settings') + ->schema([ + CheckboxList::make('settings') + ->bulkToggleable() + ->label('') + ->columns(2) + ->options([ + 'rename' => 'Rename', + 'reinstall' => 'Reinstall', + 'activity' => 'Activity', + ]) + ->descriptions([ + 'rename' => trans('server/users.permissions.setting_rename'), + 'reinstall' => trans('server/users.permissions.setting_reinstall'), + 'activity' => trans('server/users.permissions.setting_activity'), + ]), + ]), + ]), + ]), + + ]), + ]) + ->modalHeading('Invite User') + ->action(function (Server $server, array $data) { + resolve(SubuserCreationService::class)->handle($server, $data['email'], []); //TODO: The Logic <3 + Notification::make()->title('User Invited!')->success()->send(); + + return redirect()->route('filament.app.resources.users.index'); + }), ]; } } diff --git a/app/Services/Subusers/SubuserCreationService.php b/app/Services/Subusers/SubuserCreationService.php index 0f9508ba72..a449f371ed 100644 --- a/app/Services/Subusers/SubuserCreationService.php +++ b/app/Services/Subusers/SubuserCreationService.php @@ -44,8 +44,6 @@ public function handle(Server $server, string $email, array $permissions): Subus $user = $this->userCreationService->handle([ 'email' => $email, 'username' => $username, - 'name_first' => 'Server', - 'name_last' => 'Subuser', 'root_admin' => false, ]); } diff --git a/lang/en/server/users.php b/lang/en/server/users.php index ce77c41010..c449e710cd 100644 --- a/lang/en/server/users.php +++ b/lang/en/server/users.php @@ -2,26 +2,44 @@ return [ 'permissions' => [ - 'websocket_*' => 'Allows access to the websocket for this server.', - 'control_console' => 'Allows the user to send data to the server console.', - 'control_start' => 'Allows the user to start the server instance.', - 'control_stop' => 'Allows the user to stop the server instance.', - 'control_restart' => 'Allows the user to restart the server instance.', - 'control_kill' => 'Allows the user to kill the server instance.', - 'user_create' => 'Allows the user to create new user accounts for the server.', - 'user_read' => 'Allows the user permission to view users associated with this server.', - 'user_update' => 'Allows the user to modify other users associated with this server.', - 'user_delete' => 'Allows the user to delete other users associated with this server.', - 'file_create' => 'Allows the user permission to create new files and directories.', - 'file_read' => 'Allows the user to see files and folders associated with this server instance, as well as view their contents.', - 'file_update' => 'Allows the user to update files and folders associated with the server.', - 'file_delete' => 'Allows the user to delete files and directories.', - 'file_archive' => 'Allows the user to create file archives and decompress existing archives.', - 'file_sftp' => 'Allows the user to perform the above file actions using a SFTP client.', - 'allocation_read' => 'Allows access to the server allocation management pages.', - 'allocation_update' => 'Allows user permission to make modifications to the server\'s allocations.', - 'database_create' => 'Allows user permission to create a new database for the server.', - 'database_read' => 'Allows user permission to view the server databases.', + 'startup_desc' => 'Permissions that control a user\'s ability to view this server\'s startup parameters.', + 'settings_desc' => 'Permissions that control a user\'s access to the schedule management for this server.', + 'control_desc' => 'Permissions that control a user\'s ability to control the power state of a server, or send commands.', + 'user_desc' => 'Permissions that allow a user to manage other subusers on a server. They will never be able to edit their own account, or assign permissions they do not have themselves.', + 'file_desc' => 'Permissions that control a user\'s ability to modify the filesystem for this server.', + 'allocation_desc' => 'Permissions that control a user\'s ability to modify the port allocations for this server.', + 'database_desc' => 'Permissions that control a user\'s access to the database management for this server.', + 'backup_desc' => 'Permissions that control a user\'s ability to generate and manage server backups.', + 'schedule_desc' => 'Permissions that control a user\'s access to the schedule management for this server.', + 'startup_read' => 'Allows a user to view the startup variables for a server.', + 'startup_update' => 'Allows a user to modify the startup variables for the server.', + 'startup_docker_image' => 'Allows a user to modify the Docker image used when running the server.', + 'setting_reinstall' => 'Allows a user to trigger a reinstall of this server.', + 'setting_rename' => 'Allows a user to rename this server and change the description of it.', + 'setting_activity' => 'Allows a user to view the activity logs for the server.', + 'websocket_*' => 'Allows a user access to the websocket for this server.', + 'control_console' => 'Allows a user to send data to the server console.', + 'control_start' => 'Allows a user to start the server instance.', + 'control_stop' => 'Allows a user to stop the server instance.', + 'control_restart' => 'Allows a user to restart the server instance.', + 'control_kill' => 'Allows a user to kill the server instance.', + 'user_create' => 'Allows a user to create new user accounts for the server.', + 'user_read' => 'Allows a user permission to view users associated with this server.', + 'user_update' => 'Allows a user to modify other users associated with this server.', + 'user_delete' => 'Allows a user to delete other users associated with this server.', + 'file_create' => 'Allows a user permission to create new files and directories.', + 'file_read' => 'Allows a user to view the contents of a directory, but not view the contents of or download files.', + 'file_read_content' => 'Allows a user to view the contents of a given file. This will also allow the user to download files.', + 'file_update' => 'Allows a user to update files and folders associated with the server.', + 'file_delete' => 'Allows a user to delete files and directories.', + 'file_archive' => 'Allows a user to create file archives and decompress existing archives.', + 'file_sftp' => 'Allows a user to perform the above file actions using a SFTP client.', + 'allocation_read' => 'Allows a user to view all allocations currently assigned to this server. Users with any level of access to this server can always view the primary allocation.', + 'allocation_update' => 'Allows a user to change the primary server allocation and attach notes to each allocation.', + 'allocation_delete' => 'Allows a user to delete an allocation from the server.', + 'allocation_create' => 'Allows a user to assign additional allocations to the server.', + 'database_create' => 'Allows a user permission to create a new database for the server.', + 'database_read' => 'Allows a user permission to view the server databases.', 'database_update' => 'Allows a user permission to make modifications to a database. If the user does not have the "View Password" permission as well they will not be able to modify the password.', 'database_delete' => 'Allows a user permission to delete a database instance.', 'database_view_password' => 'Allows a user permission to view a database password in the system.', @@ -29,5 +47,10 @@ 'schedule_read' => 'Allows a user permission to view schedules for a server.', 'schedule_update' => 'Allows a user permission to make modifications to an existing server schedule.', 'schedule_delete' => 'Allows a user to delete a schedule for the server.', + 'backup_create' => 'Allows a user to create new backups for this server.', + 'backup_read' => 'Allows a user to view all backups that exist for this server.', + 'backup_delete' => 'Allows a user to remove backups from the system.', + 'backup_download' => 'Allows a user to download a backup for the server. Danger: this allows a user to access all files for the server in the backup.', + 'backup_restore' => 'Allows a user to restore a backup for the server. Danger: this allows the user to delete all of the server files in the process.', ], ];