Added ability to require permissions use ReportWidgets
This commit is contained in:
parent
bb0a23f54c
commit
1fc8dc6fd4
|
|
@ -1,6 +1,7 @@
|
|||
<?php namespace Backend\Classes;
|
||||
|
||||
use Str;
|
||||
use BackendAuth;
|
||||
use System\Classes\PluginManager;
|
||||
use Event;
|
||||
|
||||
|
|
@ -206,6 +207,15 @@ class WidgetManager
|
|||
*/
|
||||
Event::fire('system.reportwidgets.extendItems', [$this]);
|
||||
|
||||
$user = BackendAuth::getUser();
|
||||
foreach ($this->reportWidgets as $widget => $config) {
|
||||
if (!empty($config['permissions'])) {
|
||||
if (!$user->hasAccess($config['permissions'], false)) {
|
||||
unset($this->reportWidgets[$widget]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this->reportWidgets;
|
||||
}
|
||||
|
||||
|
|
@ -247,5 +257,4 @@ class WidgetManager
|
|||
|
||||
unset($this->reportWidgets[$className]);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -229,7 +229,7 @@ class ReportContainer extends WidgetBase
|
|||
|
||||
$widgets = $this->getWidgetsFromUserPreferences();
|
||||
|
||||
$num = count($widgets);
|
||||
$num = count($widgets);
|
||||
do {
|
||||
$num++;
|
||||
$alias = 'report_container_'.$this->context.'_'.$num;
|
||||
|
|
@ -336,7 +336,8 @@ class ReportContainer extends WidgetBase
|
|||
$configuration['alias'] = $alias;
|
||||
|
||||
$className = $widgetInfo['class'];
|
||||
if (!class_exists($className)) {
|
||||
$availableReportWidgets = array_keys(WidgetManager::instance()->listReportWidgets());
|
||||
if (!class_exists($className) || !in_array($className, $availableReportWidgets)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -501,4 +502,4 @@ class ReportContainer extends WidgetBase
|
|||
{
|
||||
return 'backend::reportwidgets.default.'.$this->context;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue