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

[ADVAPP-1206]: Remove the display of "Permissions" as a standalone model under user management #1320

Merged
merged 4 commits into from
Feb 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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

This file was deleted.

This file was deleted.

10 changes: 2 additions & 8 deletions app-modules/authorization/src/Policies/PermissionPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,12 @@ class PermissionPolicy
{
public function viewAny(Authenticatable $authenticatable): Response
{
return $authenticatable->canOrElse(
abilities: 'permission.view-any',
denyResponse: 'You do not have permission to view permissions.'
);
return Response::allow();
}

public function view(Authenticatable $authenticatable, Permission $permission): Response
{
return $authenticatable->canOrElse(
abilities: ["permission.{$permission->getKey()}.view"],
denyResponse: 'You do not have permission to view this permission.'
);
return Response::allow();
}

public function create(Authenticatable $authenticatable): Response
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,6 @@
it('Not allows user which has not sass global admin role to assign sass global admin role to other user', function () {
$user = User::factory()->create();
$user->givePermissionTo(
'permission.view-any',
'permission.*.view',
'role.view-any',
'role.*.view',
'user.view-any',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class DivisionResource extends Resource

protected static ?string $navigationGroup = 'User Management';

protected static ?int $navigationSort = 70;
protected static ?int $navigationSort = 50;

public static function getRelations(): array
{
Expand Down
2 changes: 1 addition & 1 deletion app/Filament/Resources/SystemUserResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class SystemUserResource extends Resource

protected static ?string $breadcrumb = 'Programmatic Users';

protected static ?int $navigationSort = 60;
protected static ?int $navigationSort = 40;

public static function getRelations(): array
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,29 +34,39 @@
</COPYRIGHT>
*/

namespace AdvisingApp\Authorization\Filament\Resources\PermissionResource\Pages;
use Database\Migrations\Concerns\CanModifyPermissions;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\DB;

use AdvisingApp\Authorization\Filament\Resources\PermissionResource;
use Filament\Resources\Components\Tab;
use Filament\Resources\Pages\ListRecords;
use Illuminate\Database\Eloquent\Builder;
return new class () extends Migration {
use CanModifyPermissions;

class ListPermissions extends ListRecords
{
protected static string $resource = PermissionResource::class;
private array $permissions = [
'permission.view-any' => 'Permission',
'permission.*.view' => 'Permission',
];

public function getTabs(): array
private array $guards = [
'web',
];

public function up(): void
{
return [
'web' => Tab::make('Web')
->modifyQueryUsing(fn (Builder $query) => $query->web()),
'api' => Tab::make('Api')
->modifyQueryUsing(fn (Builder $query) => $query->api()),
];
collect($this->guards)
->each(fn (string $guard) => $this->deletePermissions(array_keys($this->permissions), $guard));
}

protected function getHeaderActions(): array
public function down(): void
{
return [];
collect($this->guards)
->each(function (string $guard) {
$permissions = Arr::except($this->permissions, DB::table('permissions')
->where('guard_name', $guard)
->pluck('name')
->all());

$this->createPermissions($permissions, $guard);
});
}
}
};