You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
With pretty URLs, it is now possible to easily have multiple dashboard controllers. But the issue is that under the hood, EA tries to apply ALL CRUD controllers to ALL Dashboards when generating URLs. For example, if we have AdminDashboard and CustomerDashboard controllers in different namespaces, EA will link ALL available CRUDs to both dashboards making customer CRUDs available for admins and admin CRUDs available customers!
The suggestion is to implement a basic dynamic CRUD controllers filtering. I'm using the following patch:
--- a/src/Router/AdminRouteGenerator.php+++ b/src/Router/AdminRouteGenerator.php@@ -131,6 +131,9 @@
// then, create the routes of the CRUD controllers associated with the dashboard
foreach ($this->crudControllers as $crudController) {
$crudControllerFqcn = $crudController::class;
+ if (method_exists($dashboardController, 'isCrudControllerAllowed') && !$dashboardController::isCrudControllerAllowed($crudControllerFqcn)) {+ continue;+ }
if (null !== $allowedCrudControllers && !\in_array($crudControllerFqcn, $allowedCrudControllers, true)) {
continue;
It adds the support of the isCrudControllerAllowed method to dashboard controllers so I can do the following filtering:
namespaceApp\Controller\Admin; // All Admin controllers are in this namespaceclass DashboardController extends AbstractDashboardController
{
/** * Allow only CRUD controllers from the current namespace. */publicstaticfunctionisCrudControllerAllowed(string$controllerFqcn): bool
{
returnstr_starts_with($controllerFqcn, __NAMESPACE__ . '\\');
}
}
Which easily and effectively removes all useless CRUD controllers from the dashboard routes.
The current method of removing CRUDs by adding them to the AdminDashboard attribute is inconvenient in this case because we have many CRUD controllers and manual list management is hard and ineffective - someone may forget to add an exclusion without any errors/warnings/hints potentially exposing unneeded functionality to users that should not have access to.
The above is an example of the idea implementation and it can be implemented in many ways. It's up to the authors to choose one.
I could imagine another option like this:
namespaceApp\Controller\Admin;
#[AdminDashboard('/admin/dashboard', 'admin_dashboard', crudFilterTag: 'admin')]
class DashboardController extends AbstractDashboardController
This way, all controllers in these two namespaces will have the corresponding ea.crud_filter tag value so AdminRouteGenerator will match it to the AdminDashboard::$crudFilterTag value and decide whether to add the CRUD to the dashboard or not.
The text was updated successfully, but these errors were encountered:
With pretty URLs, it is now possible to easily have multiple dashboard controllers. But the issue is that under the hood, EA tries to apply ALL CRUD controllers to ALL Dashboards when generating URLs. For example, if we have AdminDashboard and CustomerDashboard controllers in different namespaces, EA will link ALL available CRUDs to both dashboards making customer CRUDs available for admins and admin CRUDs available customers!
The suggestion is to implement a basic dynamic CRUD controllers filtering. I'm using the following patch:
It adds the support of the
isCrudControllerAllowed
method to dashboard controllers so I can do the following filtering:Which easily and effectively removes all useless CRUD controllers from the dashboard routes.
The current method of removing CRUDs by adding them to the
AdminDashboard
attribute is inconvenient in this case because we have many CRUD controllers and manual list management is hard and ineffective - someone may forget to add an exclusion without any errors/warnings/hints potentially exposing unneeded functionality to users that should not have access to.The above is an example of the idea implementation and it can be implemented in many ways. It's up to the authors to choose one.
I could imagine another option like this:
And then in the Symfony config:
This way, all controllers in these two namespaces will have the corresponding
ea.crud_filter
tag value soAdminRouteGenerator
will match it to theAdminDashboard::$crudFilterTag
value and decide whether to add the CRUD to the dashboard or not.The text was updated successfully, but these errors were encountered: