Skip to content

Commit

Permalink
Add access_admin gate
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurpar06 committed Apr 5, 2024
1 parent 1c8b4be commit 1b13dfb
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
4 changes: 2 additions & 2 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ public function canAccessPanel(Panel $panel): bool
{
// For the admin panel
if ($panel->getId() === 'admin') {
return $this->hasRole(Utils::getSuperAdminName()) || $this->can('page_Dashboard');
return $this->hasAdminAccess();
}

// For modules panels
Expand All @@ -395,7 +395,7 @@ public function canAccessPanel(Panel $panel): bool

public function hasAdminAccess(): bool
{
return $this->hasRole(Utils::getSuperAdminName()) || $this->can('page_Dashboard');
return $this->hasRole(Utils::getSuperAdminName().'|admin') || $this->can('page_Dashboard');
}

public function getFilamentAvatarUrl(): ?string
Expand Down
9 changes: 8 additions & 1 deletion app/Providers/AuthServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

namespace App\Providers;

use App\Models\User;
use Illuminate\Auth\Access\Response;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Gate;

class AuthServiceProvider extends ServiceProvider
{
Expand All @@ -22,6 +25,10 @@ class AuthServiceProvider extends ServiceProvider
*/
public function boot()
{
//
Gate::define('access_admin', function (User $user): Response {
return $user->hasAdminAccess()
? Response::allow()
: Response::deny('You do not have permission to access this page.');
});
}
}
2 changes: 1 addition & 1 deletion app/Providers/RouteServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ protected function mapUpdaterRoutes()
Route::group([
'as' => 'update.',
'prefix' => 'update',
'middleware' => ['web', 'auth', 'role_or_permission:super_admin|page_Dashboard'],
'middleware' => ['web', 'auth', 'can:access_admin'],
'namespace' => 'App\Http\Controllers\System',
], function () {
Route::get('/', 'UpdateController@index')->name('index');
Expand Down

0 comments on commit 1b13dfb

Please sign in to comment.