reportWidget permissions and default reportWidget

Widget Permissions:

Is there a way to define widget permissions for backend user groups?

for example: I want to show some widgets to a user group but not to all. the adminstrator can see everything but publisher should not see system status

Default widgets:

is there a way to define default widgets for new users?

UPDATE:

i can see these two files:

modules/backend/controllers/Index.php
/**
 * initReportContainer prepares the report widget used by the dashboard
 * @param Model $model
 * @return void
 */
protected function initReportContainer()
{
    $widgetConfig = $this->makeConfig('config_dashboard.yaml');
    $widgetConfig->showConfigure = BackendAuth::userHasAccess('dashboard.manage');
    $widgetConfig->showAddRemove = BackendAuth::userHasAccess('dashboard.manage');
    $widgetConfig->showReorder = $widgetConfig->showConfigure || $widgetConfig->showAddRemove;
    $widgetConfig->showMakeDefault = BackendAuth::userHasAccess('dashboard.manage');

    $reportWidget = $this->makeWidget(\Backend\Widgets\ReportContainer::class, $widgetConfig);
    $reportWidget->bindToController();
}```

and

modules/backend/controllers/index/config_dashboard.yaml

question is how can i Overwrite the action in that controller?

SOLUTION:

for those who might run into the same problem

public function boot(){

    Index::extend(function($controller) {
        if ($controller->getAction() === 'index') {

            $user = BackendAuth::getUser();

            if($user){
                $widgetConfig = $controller->makeConfig('$/custom/settings/config_dashboard.yaml');
                $widgetConfig->showConfigure = BackendAuth::userHasAccess('custom.settings.manage_widgets');
                $widgetConfig->showAddRemove = BackendAuth::userHasAccess('custom.settings.manage_widgets');
                $widgetConfig->showReorder = BackendAuth::userHasAccess('custom.settings.manage_widgets');
                $widgetConfig->showMakeDefault = BackendAuth::userHasAccess('custom.settings.manage_widgets');
                $reportWidget = $controller->makeWidget(\Backend\Widgets\ReportContainer::class, $widgetConfig);
                $reportWidget->bindToController();
            }
        }

    });

}   
1 Like