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

Admin Roles #502

Merged
merged 54 commits into from
Sep 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
d81df34
add spatie/permissions
Boy132 Jul 19, 2024
091e87a
add policies
Boy132 Jul 22, 2024
91682e5
add role resource
Boy132 Jul 22, 2024
aa34d6c
add root admin role handling
Boy132 Jul 22, 2024
86b1978
replace some "root_admin" with function
Boy132 Jul 22, 2024
e16bbe3
add model specific permissions
Boy132 Jul 22, 2024
18249e5
make permission selection nicer
Boy132 Jul 22, 2024
18d52f3
fix user creation
Boy132 Jul 22, 2024
f3d6c0a
fix tests
Boy132 Jul 22, 2024
7806182
add back subuser checks in server policy
Boy132 Jul 22, 2024
27880d5
add custom model for role
Boy132 Jul 22, 2024
8da88c6
assign new users to role if root_admin is set
Boy132 Jul 22, 2024
da85e51
add api for roles
Boy132 Jul 22, 2024
4d809cd
fix phpstan
Boy132 Jul 22, 2024
dee8366
Merge branch 'pelican-dev:main' into feature/admin-roles
Boy132 Jul 23, 2024
19e47b3
Merge branch 'refs/heads/main' into feature/admin-roles
Boy132 Jul 30, 2024
466670f
Merge branch 'pelican-dev:main' into feature/admin-roles
Boy132 Jul 31, 2024
434ffa7
add permissions for settings page
Boy132 Jul 31, 2024
de717a3
remove "restore" and "forceDelete" permissions
Boy132 Aug 1, 2024
2fdd62e
add user count to list
Boy132 Aug 1, 2024
231ed5a
prevent deletion if role has users
Boy132 Aug 1, 2024
98733e9
update user list
Boy132 Aug 1, 2024
ac8e184
fix server policy
Boy132 Aug 1, 2024
ebd63d8
remove old `root_admin` column
Boy132 Aug 2, 2024
409c90a
small refactor
Boy132 Aug 2, 2024
1e1e02c
fix tests
Boy132 Aug 2, 2024
8d6e358
forgot can checks here
Boy132 Aug 2, 2024
507048e
forgot use
Boy132 Aug 2, 2024
74bc5e4
Merge branch 'refs/heads/main' into feature/admin-roles
Boy132 Aug 9, 2024
c8f42f8
Merge branch 'pelican-dev:main' into feature/admin-roles
Boy132 Aug 19, 2024
7af4db0
disable editing own roles & disable assigning root admin
Boy132 Aug 19, 2024
38a3f43
don't allow to rename root admin role
Boy132 Aug 19, 2024
6067076
remove php bombing exception handler
Boy132 Aug 19, 2024
f3efe7a
fix role assignment when creating a user
Boy132 Aug 19, 2024
f3a1ae8
fix disableOptionWhen
Boy132 Aug 19, 2024
8de90f2
fix missing `root_admin` attribute on react frontend
Boy132 Aug 20, 2024
8daac73
Merge branch 'pelican-dev:main' into feature/admin-roles
Boy132 Sep 1, 2024
46cbaa0
add permission check for bulk delete
Boy132 Sep 1, 2024
9b80665
rename viewAny to viewList
Boy132 Sep 5, 2024
db7db97
improve canAccessPanel check
Boy132 Sep 5, 2024
5481b5b
fix admin not displaying for non-root admins
Boy132 Sep 5, 2024
f71b0b2
make sure non root admins can't edit root admins
Boy132 Sep 6, 2024
08abba4
fix import
Boy132 Sep 6, 2024
d709509
fix settings page permission check
Boy132 Sep 6, 2024
72c8f0b
Merge branch 'pelican-dev:main' into feature/admin-roles
Boy132 Sep 9, 2024
20aab5a
fix server permissions for non-subusers
Boy132 Sep 18, 2024
22442cb
fix settings page permission check v2
Boy132 Sep 18, 2024
4f63cda
small cleanup
Boy132 Sep 18, 2024
16dbb53
cleanup config file
Boy132 Sep 19, 2024
6ff4083
move consts from resouce into enum & model
Boy132 Sep 19, 2024
5a17393
Update database/migrations/2024_08_01_114538_remove_root_admin_column…
Boy132 Sep 19, 2024
a7b8b34
fix config
Boy132 Sep 19, 2024
ea66fc7
fix phpstan
Boy132 Sep 19, 2024
2bc7c27
fix phpstan 2.0
Boy132 Sep 19, 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
2 changes: 1 addition & 1 deletion app/Console/Commands/User/MakeUserCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function handle(): int
['UUID', $user->uuid],
['Email', $user->email],
['Username', $user->username],
['Admin', $user->root_admin ? 'Yes' : 'No'],
['Admin', $user->isRootAdmin() ? 'Yes' : 'No'],
]);

return 0;
Expand Down
16 changes: 16 additions & 0 deletions app/Enums/RolePermissionModels.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace App\Enums;

enum RolePermissionModels: string
{
case ApiKey = 'apikey';
case DatabaseHost = 'databasehost';
case Database = 'database';
case Egg = 'egg';
case Mount = 'mount';
case Node = 'node';
case Role = 'role';
case Server = 'server';
case User = 'user';
}
12 changes: 12 additions & 0 deletions app/Enums/RolePermissionPrefixes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace App\Enums;

enum RolePermissionPrefixes: string
{
case ViewAny = 'viewList';
case View = 'view';
case Create = 'create';
case Update = 'update';
case Delete = 'delete';
}
14 changes: 10 additions & 4 deletions app/Filament/Pages/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,18 @@ public function mount(): void
$this->form->fill();
}

public static function canAccess(): bool
{
return auth()->user()->can('view settings');
}

protected function getFormSchema(): array
{
return [
Tabs::make('Tabs')
->columns()
->persistTabInQueryString()
->disabled(fn () => !auth()->user()->can('update settings'))
->tabs([
Tab::make('general')
->label('General')
Expand Down Expand Up @@ -147,10 +153,12 @@ private function generalSettings(): array
->color('danger')
->icon('tabler-trash')
->requiresConfirmation()
->authorize(fn () => auth()->user()->can('update settings'))
->action(fn (Set $set) => $set('TRUSTED_PROXIES', [])),
FormAction::make('cloudflare')
->label('Set to Cloudflare IPs')
->icon('tabler-brand-cloudflare')
->authorize(fn () => auth()->user()->can('update settings'))
->action(fn (Set $set) => $set('TRUSTED_PROXIES', [
'173.245.48.0/20',
'103.21.244.0/22',
Expand Down Expand Up @@ -226,6 +234,7 @@ private function mailSettings(): array
->label('Send Test Mail')
->icon('tabler-send')
->hidden(fn (Get $get) => $get('MAIL_MAILER') === 'log')
->authorize(fn () => auth()->user()->can('update settings'))
->action(function () {
try {
MailNotification::route('mail', auth()->user()->email)
Expand Down Expand Up @@ -561,12 +570,9 @@ protected function getHeaderActions(): array
return [
Action::make('save')
->action('save')
->authorize(fn () => auth()->user()->can('update settings'))
->keyBindings(['mod+s']),
];

}
protected function getFormActions(): array
{
return [];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ public function table(Table $table): Table
])
->bulkActions([
BulkActionGroup::make([
DeleteBulkAction::make(),
DeleteBulkAction::make()
->authorize(fn () => auth()->user()->can('delete databasehost')),
]),
]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

use App\Filament\Resources\DatabaseResource;
use Filament\Actions;
use Filament\Tables\Actions\EditAction;
use Filament\Resources\Pages\ListRecords;
use Filament\Tables\Actions\BulkActionGroup;
use Filament\Tables\Actions\DeleteBulkAction;
use Filament\Tables\Actions\EditAction;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;

Expand Down Expand Up @@ -48,7 +48,8 @@ public function table(Table $table): Table
])
->bulkActions([
BulkActionGroup::make([
DeleteBulkAction::make(),
DeleteBulkAction::make()
->authorize(fn () => auth()->user()->can('delete database')),
]),
]);
}
Expand Down
17 changes: 8 additions & 9 deletions app/Filament/Resources/EggResource/Pages/EditEgg.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

namespace App\Filament\Resources\EggResource\Pages;

use AbdelhamidErrahmouni\FilamentMonacoEditor\MonacoEditor;
use App\Filament\Resources\EggResource;
use App\Filament\Resources\EggResource\RelationManagers\ServersRelationManager;
use App\Models\Egg;
use App\Services\Eggs\Sharing\EggExporterService;
use App\Services\Eggs\Sharing\EggImporterService;
use Exception;
use Filament\Actions;
use Filament\Forms;
use Filament\Forms\Components\Checkbox;
use Filament\Forms\Components\Fieldset;
use Filament\Forms\Components\FileUpload;
Expand All @@ -22,12 +25,9 @@
use Filament\Forms\Components\Textarea;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\Toggle;
use Filament\Forms\Form;
use Filament\Notifications\Notification;
use Filament\Resources\Pages\EditRecord;
use AbdelhamidErrahmouni\FilamentMonacoEditor\MonacoEditor;
use App\Services\Eggs\Sharing\EggExporterService;
use Filament\Forms;
use Filament\Forms\Form;

class EditEgg extends EditRecord
{
Expand Down Expand Up @@ -245,14 +245,13 @@ protected function getHeaderActions(): array
Actions\DeleteAction::make('deleteEgg')
->disabled(fn (Egg $egg): bool => $egg->servers()->count() > 0)
->label(fn (Egg $egg): string => $egg->servers()->count() <= 0 ? 'Delete' : 'In Use'),

Actions\Action::make('exportEgg')
->label('Export')
->color('primary')
->action(fn (EggExporterService $service, Egg $egg) => response()->streamDownload(function () use ($service, $egg) {
echo $service->handle($egg->id);
}, 'egg-' . $egg->getKebabName() . '.json')),

}, 'egg-' . $egg->getKebabName() . '.json'))
->authorize(fn () => auth()->user()->can('export egg')),
Actions\Action::make('importEgg')
->label('Import')
->form([
Expand Down Expand Up @@ -321,8 +320,8 @@ protected function getHeaderActions(): array
->title('Import Success')
->success()
->send();
}),

})
->authorize(fn () => auth()->user()->can('import egg')),
$this->getSaveFormAction()->formId('form'),
];
}
Expand Down
11 changes: 7 additions & 4 deletions app/Filament/Resources/EggResource/Pages/ListEggs.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
use Filament\Forms\Components\TextInput;
use Filament\Notifications\Notification;
use Filament\Resources\Pages\ListRecords;
use Filament\Tables;
use Filament\Tables\Actions\BulkActionGroup;
use Filament\Tables\Actions\DeleteBulkAction;
use Filament\Tables\Actions\EditAction;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;
use Livewire\Features\SupportFileUploads\TemporaryUploadedFile;
use Filament\Tables;

class ListEggs extends ListRecords
{
Expand Down Expand Up @@ -55,11 +55,13 @@ public function table(Table $table): Table
->color('primary')
->action(fn (EggExporterService $service, Egg $egg) => response()->streamDownload(function () use ($service, $egg) {
echo $service->handle($egg->id);
}, 'egg-' . $egg->getKebabName() . '.json')),
}, 'egg-' . $egg->getKebabName() . '.json'))
->authorize(fn () => auth()->user()->can('export egg')),
])
->bulkActions([
BulkActionGroup::make([
DeleteBulkAction::make(),
DeleteBulkAction::make()
->authorize(fn () => auth()->user()->can('delete egg')),
]),
]);
}
Expand Down Expand Up @@ -138,7 +140,8 @@ protected function getHeaderActions(): array
->title('Import Success')
->success()
->send();
}),
})
->authorize(fn () => auth()->user()->can('import egg')),
];
}
}
3 changes: 2 additions & 1 deletion app/Filament/Resources/MountResource/Pages/ListMounts.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ public function table(Table $table): Table
])
->bulkActions([
BulkActionGroup::make([
DeleteBulkAction::make(),
DeleteBulkAction::make()
->authorize(fn () => auth()->user()->can('delete mount')),
]),
])
->emptyStateIcon('tabler-layers-linked')
Expand Down
3 changes: 2 additions & 1 deletion app/Filament/Resources/NodeResource/Pages/ListNodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ public function table(Table $table): Table
])
->bulkActions([
BulkActionGroup::make([
DeleteBulkAction::make(),
DeleteBulkAction::make()
->authorize(fn () => auth()->user()->can('delete node')),
]),
])
->emptyStateIcon('tabler-server-2')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
use App\Services\Allocations\AssignmentService;
use Filament\Forms\Components\TagsInput;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Set;
use Filament\Tables\Actions\BulkActionGroup;
use Filament\Tables\Actions\DeleteBulkAction;
use Filament\Forms\Form;
use Filament\Forms\Set;
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Tables;
use Filament\Tables\Actions\BulkActionGroup;
use Filament\Tables\Actions\DeleteBulkAction;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Columns\TextInputColumn;
use Filament\Tables\Table;
Expand Down Expand Up @@ -152,7 +152,8 @@ public function table(Table $table): Table
])
->bulkActions([
BulkActionGroup::make([
DeleteBulkAction::make(),
DeleteBulkAction::make()
->authorize(fn () => auth()->user()->can('delete allocation')),
]),
]);
}
Expand Down
Loading
Loading