FEATURE #2048: add missing policies
This commit is contained in:
@@ -5,7 +5,7 @@ namespace App\CMS\Handlers;
|
||||
use App\CMS\Contracts\Modules\BaseModuleHandler;
|
||||
use App\CMS\Enumerations\TemplatePathsHumanReadableRootOnly;
|
||||
use App\CMS\Enumerations\WidgetTypes;
|
||||
use App\Models\ActionLog\ActionLogType;
|
||||
use App\Models\ActionLog\ActionLog;
|
||||
use App\Models\Content\Content;
|
||||
use App\Models\FileManager\File;
|
||||
use App\Models\Settings;
|
||||
@@ -60,7 +60,7 @@ abstract class BaseHandler implements BaseModuleHandler
|
||||
// create list of all widget types
|
||||
$widgets = WidgetTypes::getWithTranslations();
|
||||
|
||||
if (!empty($widgets) && $user->can('create-widgets', Widget::class)) {
|
||||
if (!empty($widgets) && $user->can('create', Widget::class)) {
|
||||
$sub->dropdown(trans('admin/mainMenu.newWidget'), function ($sub) use ($widgets) {
|
||||
$i = 1;
|
||||
foreach ($widgets as $type => $name) {
|
||||
@@ -117,7 +117,7 @@ abstract class BaseHandler implements BaseModuleHandler
|
||||
}
|
||||
}
|
||||
|
||||
if ($user->can('manage', ActionLogType::class)) {
|
||||
if ($user->can('manage', ActionLog::class)) {
|
||||
$sub->route('log.overview', trans('admin/mainMenu.actionLog'), [], 70, ['icon' => 'fa fa-fw fa-history']);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Policies;
|
||||
|
||||
use Illuminate\Auth\Access\HandlesAuthorization;
|
||||
|
||||
class ActionLogPolicy extends BasicPolicy
|
||||
{
|
||||
use HandlesAuthorization;
|
||||
protected $entity = 'actions';
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Models\FileManager\Directory;
|
||||
use App\Models\User;
|
||||
use Illuminate\Auth\Access\HandlesAuthorization;
|
||||
|
||||
class DirectoriesPolicy extends BasicPolicy
|
||||
{
|
||||
use HandlesAuthorization;
|
||||
protected $entity = 'directories';
|
||||
|
||||
/**
|
||||
* Determine whether the user can create directories.
|
||||
*
|
||||
* @param \App\Models\User $user
|
||||
* @return mixed
|
||||
*/
|
||||
public function create(User $user)
|
||||
{
|
||||
return $user->hasAbility('create-directories');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can update the directory.
|
||||
*
|
||||
* @param \App\Models\User $user
|
||||
* @param \App\Directory $directory
|
||||
* @return mixed
|
||||
*/
|
||||
public function update(User $user, Directory $directory)
|
||||
{
|
||||
return $user->hasAbility('update-directories');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Policies;
|
||||
|
||||
use Illuminate\Auth\Access\HandlesAuthorization;
|
||||
|
||||
class SettingsPolicy extends BasicPolicy
|
||||
{
|
||||
use HandlesAuthorization;
|
||||
protected $entity = 'settings';
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Models\Templates\Template;
|
||||
use App\Models\User;
|
||||
use Illuminate\Auth\Access\HandlesAuthorization;
|
||||
|
||||
class TemplatePolicy extends BasicPolicy
|
||||
{
|
||||
use HandlesAuthorization;
|
||||
|
||||
protected $entity = 'templates';
|
||||
|
||||
/**
|
||||
* Determine whether the user can view the template.
|
||||
*
|
||||
* @param \App\Models\User $user
|
||||
* @param \App\Template $template
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function copy(User $user, Template $template)
|
||||
{
|
||||
return $user->hasAbility('copy-templates');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can update the template.
|
||||
*
|
||||
* @param \App\Models\User $user
|
||||
* @param \App\Template $template
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function update(User $user, Template $template)
|
||||
{
|
||||
return $user->hasAbility('edit-templates');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Models\Widgets\WidgetArea;
|
||||
use Illuminate\Auth\Access\HandlesAuthorization;
|
||||
|
||||
class WidgetAreaPolicy extends BasicPolicy
|
||||
{
|
||||
use HandlesAuthorization;
|
||||
protected $entity = 'widgetareas';
|
||||
|
||||
/**
|
||||
* Determine whether the user can create widgetAreas.
|
||||
*
|
||||
* @param \App\Models\User $user
|
||||
* @return mixed
|
||||
*/
|
||||
public function create(User $user)
|
||||
{
|
||||
return $user->hasAbility('create-widgetareas');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can update the widgetArea.
|
||||
*
|
||||
* @param \App\Models\User $user
|
||||
* @param \App\WidgetArea $widgetArea
|
||||
* @return mixed
|
||||
*/
|
||||
public function update(User $user, WidgetArea $widgetArea)
|
||||
{
|
||||
return $user->hasAbility('edit-widgetareas');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Models\Widgets\Widget;
|
||||
use Illuminate\Auth\Access\HandlesAuthorization;
|
||||
|
||||
class WidgetsPolicy extends BasicPolicy
|
||||
{
|
||||
use HandlesAuthorization;
|
||||
protected $entity = 'widgets';
|
||||
|
||||
/**
|
||||
* Determine whether the user can create widgets.
|
||||
*
|
||||
* @param \App\Models\User $user
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function create(User $user)
|
||||
{
|
||||
return $user->hasAbility('create-widgets');
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can update the widget.
|
||||
*
|
||||
* @param \App\Models\User $user
|
||||
* @param \App\Widget $widget
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function update(User $user, Widget $widget)
|
||||
{
|
||||
return $user->id == $widget->user_id || $user->hasAbility('edit-widgets');
|
||||
}
|
||||
|
||||
public function assign(User $user, Widget $widget)
|
||||
{
|
||||
return $user->hasAbility('assign-widgets');
|
||||
}
|
||||
|
||||
public function unassign(User $user, Widget $widget)
|
||||
{
|
||||
return $user->hasAbility('unassign-widgets');
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,7 @@ use App\CMS\Repositories\Module as ModuleRepository;
|
||||
use App\CMS\Repositories\Templates\Template as TemplateRepository;
|
||||
use App\CMS\Widgets\HtmlCode\HtmlCode;
|
||||
use App\CMS\Widgets\Menu\Menu;
|
||||
use App\CMS\Widgets\SocialButtons\SocialButtons;
|
||||
use Barryvdh\Debugbar\ServiceProvider as DebugBarServiceProvider;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
@@ -106,6 +107,7 @@ class AppServiceProvider extends ServiceProvider
|
||||
// register all available widgets
|
||||
$registrator->register(HtmlCode::class);
|
||||
$registrator->register(Menu::class);
|
||||
$registrator->register(SocialButtons::class);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,14 +2,26 @@
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use App\Models\ActionLog\ActionLog;
|
||||
use App\Models\Content\Content;
|
||||
use App\Models\FileManager\Directory;
|
||||
use App\Models\FileManager\File;
|
||||
use App\Models\Module;
|
||||
use App\Models\Settings;
|
||||
use App\Models\Templates\Template;
|
||||
use App\Models\User;
|
||||
use App\Models\Widgets\Widget;
|
||||
use App\Models\Widgets\WidgetArea;
|
||||
use App\Policies\ActionLogPolicy;
|
||||
use App\Policies\ContentPolicy;
|
||||
use App\Policies\DirectoriesPolicy;
|
||||
use App\Policies\FilesPolicy;
|
||||
use App\Policies\ModulePolicy;
|
||||
use App\Policies\SettingsPolicy;
|
||||
use App\Policies\TemplatePolicy;
|
||||
use App\Policies\UserPolicy;
|
||||
use App\Policies\WidgetAreaPolicy;
|
||||
use App\Policies\WidgetsPolicy;
|
||||
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as IlluminateAuthServiceProvider;
|
||||
|
||||
class AuthServiceProvider extends IlluminateAuthServiceProvider
|
||||
@@ -23,6 +35,13 @@ class AuthServiceProvider extends IlluminateAuthServiceProvider
|
||||
User::class => UserPolicy::class,
|
||||
Module::class => ModulePolicy::class,
|
||||
File::class => FilesPolicy::class,
|
||||
ActionLog::class => ActionLogPolicy::class,
|
||||
Template::class => TemplatePolicy::class,
|
||||
Directory::class => DirectoriesPolicy::class,
|
||||
Settings::class => SettingsPolicy::class,
|
||||
Widget::class => WidgetsPolicy::class,
|
||||
WidgetArea::class => WidgetAreaPolicy::class,
|
||||
ActionLog::class => ActionLogPolicy::class,
|
||||
];
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
<?php
|
||||
return [
|
||||
"code" => "Dodatečný HTML/JS kód pro slider",
|
||||
"containerClass" => "HTML třída pro obalový element tohoto widgetu",
|
||||
"createNew" => "Vytvořit nový",
|
||||
"description" => "Popis",
|
||||
"displayBullets" => "Zobrazit odrážky?",
|
||||
"edit" => "Upravit :name",
|
||||
"editExisting" => "Uložit",
|
||||
"extraSettings" => "Další nastavení",
|
||||
"fullscreen" => "Zobrazit slider na celou obrazovku",
|
||||
"imagesPerSlide" => "Obrázků na slide",
|
||||
"name" => "Jméno slideru",
|
||||
"new" => "Vytvořit nový slider",
|
||||
"preview" => "Náhled",
|
||||
"showInFullscreen" => "Zobrazit na celou obrazovku",
|
||||
"slideContainerClass" => "HTML třída pro každý obrázek ve slideru",
|
||||
"upload" => "Přidat obrázky do slideru",
|
||||
"widgetDescription" => "Slider pro obrázky. Tento widget používá Foundation framework a jeho vlastní slider zvaný Orbit. (Nebude fungovat bez Foundation 6!)",
|
||||
"widgetName" => "Orbit slider",
|
||||
];
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
return [
|
||||
"code" => "HTML kod",
|
||||
"containerClass" => "HTML třída pro obalový element tohoto widgetu",
|
||||
"createNew" => "Vytvořit nový widget",
|
||||
"description" => "Popis",
|
||||
"edit" => "Edituji widget :name",
|
||||
"editExisting" => "Upravit widget",
|
||||
"name" => "Jméno",
|
||||
"new" => "Vytvořit nový widget",
|
||||
"preview" => "Náhled",
|
||||
"save" => "Uložit",
|
||||
"successfullyEdited" => "Widget úspěšně upraven",
|
||||
"widgetDescription" => "Jednoduchý widget pro vkládání sociálních tlačítek.",
|
||||
"widgetName" => "Sociální tlačítka",
|
||||
];
|
||||
@@ -8,6 +8,7 @@
|
||||
{{str_limit($template->description, 150)}}
|
||||
</div>
|
||||
|
||||
@can('copy', $template)
|
||||
@if($isWritable)
|
||||
<a data-template-id="{{$template->id}}" data-template-name="{{$template->template_name}}"
|
||||
class="btn btn-pill-left btn-secondary col-lg-6 copy-template" data-toggle="tooltip"
|
||||
@@ -20,6 +21,13 @@
|
||||
<i class="fa fa-copy"></i>
|
||||
</a>
|
||||
@endif
|
||||
@else
|
||||
<a href="#" class="btn btn-pill-left btn-secondary disabled col-lg-6" data-toggle="tooltip"
|
||||
title="@lang('admin/templates.cannotCopy')">
|
||||
<i class="fa fa-copy"></i>
|
||||
</a>
|
||||
@endcan
|
||||
@can('update', $template)
|
||||
<a href="{{route('templates.edit', ['id' => $template->id])}}"
|
||||
class="btn btn-primary btn-pill-right col-lg-6" data-toggle="tooltip"
|
||||
title="@lang('admin/templates.edit', ['name' => $template->name])">
|
||||
@@ -30,6 +38,7 @@
|
||||
@endif
|
||||
|
||||
</a>
|
||||
@endcan
|
||||
</div>
|
||||
@empty
|
||||
<div class="alert alert-info">
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
href="{{route('widgetareas.edit', ['id' => $area->id])}}"><i
|
||||
class="fa fa-pencil"></i></a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="{{route('widgets.associate', ['widgetArea' => $area->id])}}"
|
||||
data-toggle="tooltip"
|
||||
@@ -66,6 +67,7 @@
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
@can('create', \App\Models\Widgets\WidgetArea::class)
|
||||
<div class="col-lg-4">
|
||||
<div class="card items">
|
||||
<div class="card-header">
|
||||
@@ -78,6 +80,7 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endcan
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
@@ -23,12 +23,19 @@
|
||||
</tr>
|
||||
@foreach($widgets as $widget)
|
||||
<tr>
|
||||
<td><a href="{{route('widgets.edit', ['id' => $widget->id])}}">{{$widget->name}}</a></td>
|
||||
<td>
|
||||
@can('update', $widget)
|
||||
<a href="{{route('widgets.edit', ['id' => $widget->id])}}">{{$widget->name}}</a>
|
||||
@else
|
||||
{{$widget->name}}
|
||||
@endcan
|
||||
</td>
|
||||
<td>{{trans(call_user_func([$widget->widget_type_handler, 'getName']))}}</td>
|
||||
<td>{{$widget->description}}</td>
|
||||
<td class="text-center">
|
||||
|
||||
|
||||
@if(\Auth::user()->can('update', $widget) || $widget->deletable)
|
||||
<div class="item-actions-dropdown">
|
||||
<a class="item-actions-toggle-btn">
|
||||
<span class="inactive"><i class="fa fa-cog"></i></span>
|
||||
@@ -36,12 +43,14 @@
|
||||
</a>
|
||||
<div class="item-actions-block">
|
||||
<ul class="item-actions-list">
|
||||
@can('update', $widget)
|
||||
<li>
|
||||
<a class="edit" data-toggle="tooltip"
|
||||
title="@lang('admin/widgets.editTooltip')"
|
||||
href="{{route('widgets.edit', ['id' => $widget->id])}}"><i
|
||||
class="fa fa-pencil"></i></a>
|
||||
</li>
|
||||
@endcan
|
||||
|
||||
@if($widget->deletable)
|
||||
<li>
|
||||
@@ -55,6 +64,7 @@
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
@@ -5,7 +5,7 @@ Route::group(['namespace' => 'Widgets'], function () {
|
||||
// list of all installed widget types
|
||||
Route::get('widgets', 'WidgetsOverview@index')
|
||||
->name('widgets.overview')
|
||||
->middleware('can:update,' . \App\Models\Widgets\Widget::class);
|
||||
->middleware('can:manage,' . \App\Models\Widgets\Widget::class);
|
||||
|
||||
// create new instance of widget of given type
|
||||
Route::get('widgets/new/{widgetType}', 'CreateNewWidget@getNew')
|
||||
@@ -14,7 +14,7 @@ Route::group(['namespace' => 'Widgets'], function () {
|
||||
|
||||
Route::post('widgets/new/{widgetType}', 'CreateNewWidget@postNew')
|
||||
->name('widgets.postNew')
|
||||
->middleware('can:createf,' . \App\Models\Widgets\Widget::class);
|
||||
->middleware('can:create,' . \App\Models\Widgets\Widget::class);
|
||||
|
||||
// edit widget settings
|
||||
Route::get('widgets/edit/{widget}', 'EditWidget@getEdit')
|
||||
|
||||
Reference in New Issue
Block a user