-
Notifications
You must be signed in to change notification settings - Fork 268
Rename the Backpack Admin middleware to BackpackAdmin #67
Rename the Backpack Admin middleware to BackpackAdmin #67
Conversation
…ollide with the `admin` middleware name, which is commonly used by projects to define what an admin is.
True. And people might actually want to overwrite this admin middleware to only include users with a certain permission/role. So I'm now wondering - wouldn't it make sense to publish the middleware in the application folder? Or would it only be confusing (middleware lives inside the application, but all controllers live inside the vendor folder). What do you think? |
If this is going to be something thats going to be worked on, I'd like to heavily suggest that we make sure its compatible with laravels $guard system. We had a massive issue that meant the admin and frontend shared user sessions, because they both used |
Another option might be a user model trait. Similar to what I did here: https://github.com/ChrisThompsonTLDR/impersonate The traitor package can be used to cleanly publish your trait into the user model of the application: https://github.com/kkszymanowski/traitor |
How about if we publish the middleware by default? This usually needs to be customized. It's part of my suggestion here: #101. Also, I've noticed Laravel is going for verbs&sentences in naming middleware: \App\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\App\Http\Middleware\VerifyCsrfToken::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class, So maybe we should name the admin middleware something like What do you guys think? Any better ideas for a name? |
@tabacitu I thiiiiiiiiinkkk...its silently addressed within -> https://github.com/Laravel-Backpack/Base/pull/87/files#diff-bf16878a4c2c226c376eb91300705856 :D |
a temp solution for any new users until this gets merged
'setup_dashboard_routes' => false,
Route::group(['prefix' => config('backpack.base.route_prefix')], function () {
Route::get('dashboard', 'AdminController@dashboard');
Route::get('/', 'AdminController@redirect');
});
'BackpackAdmin' => \App\Http\Middleware\BackpackAdmin::class,
<?php
namespace App\Http\Controllers;
use Backpack\Base\app\Http\Controllers\AdminController as Backpack;
class AdminController extends Backpack
{
public function __construct()
{
$this->middleware('BackpackAdmin');
}
} |
I think is important for every backpack package:
Out of the box, all users are capable of doing everything, and is kind of difficult to understand how to insert permission middleware when all routes and controllers are inside vendor folder. |
@tabacitu - is this still valid if/when all the routes get published? And assuming that happens, will this pull request apply cleanly? |
@lloy0076 this is a breaking change, we'll need to tell the users to change the "admin" middleware to "backpack"/"backpackadmin" wherever it's used. We'll also need to do that ourselves inside all packages... |
Update: I still agree But after implementing the guard system in PR #165, I think a more future-proof solution would be to allow the developer to use a custom name, if he so chooses. Or a different middleware, while we're at it. We can fetch the middleware using helpers, and those helpers could get the value from the config. Expanding on how @OwenMelbz did it in PR #87 . To rephrase, in // Fully qualified namespace of the User model
'user_model_fqn' => '\Backpack\Base\app\Models\BackpackUser',
+ // The class for the middleware that checks if the visitor is an admin
+ 'middleware_class' => \Backpack\Base\app\Middleware\Admin::class,
+
+ // Alias for that middleware
+ 'middleware_key' => 'admin',
+ // Note: It's recommended to use the backpack_middleware() helper everywhere, which pulls this key for you.
This way:
Other considerations:
Thoughts? |
Just pushed PR #258 with all of the above. Let's move the conversation there please. |
Admin
is a common middleware name. Backpack is forcing its middleware, named admin, into theAdmin
namespace.