diff --git a/src/Providers/EventsServiceProvider.php b/src/Providers/EventsServiceProvider.php index b0aaab8..86021f8 100644 --- a/src/Providers/EventsServiceProvider.php +++ b/src/Providers/EventsServiceProvider.php @@ -45,8 +45,8 @@ public function boot(DispatcherContract $events) }); $events->listen('view.page.edit', function ($page) { - if (acl_check('widgets.index') and $page->hasLayout()) { - echo view('widgets::widgets.page.iframe')->with('page', $page)->render(); + if (acl_check('widgets::list') and $page->hasLayout()) { + echo view('widgets::widgets.page.iframe', compact('page'))->render(); } }); @@ -58,7 +58,7 @@ public function boot(DispatcherContract $events) echo view('widgets::widgets.partials.renderable', compact('widget', 'commentKeys', 'snippets'))->render(); } - if ($widget->isCacheable() and acl_check('widgets.cache')) { + if ($widget->isCacheable() and acl_check('widget_settings::cache')) { echo view('widgets::widgets.partials.cacheable', compact('widget'))->render(); } }); @@ -71,7 +71,7 @@ public function boot(DispatcherContract $events) echo view('widgets::widgets.partials.renderable_buttons', compact('widget', 'commentKeys', 'snippets', 'assetsPackages', 'widgetList'))->render(); } - if (acl_check('widgets.roles') and ! $widget->isHandler()) { + if (acl_check('widget_settings::roles') and ! $widget->isHandler()) { $usersRoles = Role::pluck('name', 'id')->all(); echo view('widgets::widgets.partials.permissions', compact('widget', 'usersRoles'))->render(); } diff --git a/src/Providers/ModuleServiceProvider.php b/src/Providers/ModuleServiceProvider.php index 00737b0..a1302ae 100644 --- a/src/Providers/ModuleServiceProvider.php +++ b/src/Providers/ModuleServiceProvider.php @@ -3,6 +3,7 @@ namespace KodiCMS\Widgets\Providers; use KodiCMS\Support\ServiceProvider; +use KodiCMS\Users\Model\Permission; use KodiCMS\Widgets\Contracts\WidgetManager; use KodiCMS\Widgets\Manager\WidgetManagerDatabase; @@ -15,7 +16,6 @@ public function boot() }); $this->app->alias('widget.manager', WidgetManager::class); - $this->app['view']->addNamespace('snippets', snippets_path()); } @@ -25,6 +25,27 @@ public function register() BladeServiceProvider::class, EventsServiceProvider::class, ]); + + Permission::register('widgets', 'widget', [ + 'list', + 'add', + 'delete', + 'edit', + ]); + + Permission::register('widgets', 'widget_settings', [ + 'cache', + 'roles', + 'location', + ]); + + Permission::register('widgets', 'snippet', [ + 'add', + 'edit', + 'list', + 'view', + 'delete' + ]); } public function contextBackend() @@ -35,7 +56,7 @@ public function contextBackend() 'id' => 'snippets', 'title' => 'widgets::snippet.title.list', 'url' => route('backend.snippet.list'), - 'permissions' => 'snippet.index', + 'permissions' => 'snippet::list', 'priority' => 200, 'icon' => 'cutlery', ], @@ -43,7 +64,7 @@ public function contextBackend() 'id' => 'widgets', 'title' => 'widgets::core.title.list', 'url' => route('backend.widget.list'), - 'permissions' => 'widgets.index', + 'permissions' => 'widget::list', 'priority' => 300, 'icon' => 'cubes', ], diff --git a/src/resources/lang/ru/permissions.php b/src/resources/lang/ru/permissions.php new file mode 100644 index 0000000..3f33d93 --- /dev/null +++ b/src/resources/lang/ru/permissions.php @@ -0,0 +1,28 @@ + [ + 'module' => 'Виджеты', + 'widget' => '', + 'snippet' => 'Сниппеты', + 'widget_settings' => 'Настройки виджета', + ], + 'widget' => [ + 'list' => 'Просмотр списка', + 'add' => 'Создание', + 'delete' => 'Удаление', + 'edit' => 'Редактирование', + ], + 'snippet' => [ + 'list' => 'Просмотр списка', + 'add' => 'Создание', + 'delete' => 'Удаление', + 'edit' => 'Редактирование', + 'view' => 'Просмотр кода', + ], + 'widget_settings' => [ + 'cache' => 'Кеш', + 'roles' => 'Роли', + 'location' => 'Размещение', + ], +]; \ No newline at end of file diff --git a/src/resources/views/snippet/form.blade.php b/src/resources/views/snippet/form.blade.php index 9fbff7a..0d3315d 100644 --- a/src/resources/views/snippet/form.blade.php +++ b/src/resources/views/snippet/form.blade.php @@ -11,7 +11,7 @@ -@if (!$snippet->isReadOnly() or $snippet->isNew()) +@if ((!$snippet->isReadOnly() or $snippet->isNew()) and acl_check('snippet::edit'))
{!! UI::icon('chevron-down panel-toggler-icon') !!} @lang('widgets::snippet.label.settings')
@@ -61,7 +61,7 @@
@lang('widgets::snippet.messages.snippet_not_writeable')
-@elseif (acl_check('snippet.edit')) +@elseif (acl_check('snippet::edit')) diff --git a/src/resources/views/snippet/list.blade.php b/src/resources/views/snippet/list.blade.php index 6c23556..e1f9ba2 100644 --- a/src/resources/views/snippet/list.blade.php +++ b/src/resources/views/snippet/list.blade.php @@ -1,7 +1,7 @@
@if (!$collection->isReadOnly())
- @if (acl_check('snippet.add')) + @if (acl_check('snippet::add')) {!! link_to_route('backend.snippet.create', trans('widgets::snippet.button.add'), [], [ 'class' => 'btn btn-default btn-labeled', 'data-icon' => 'plus', 'data-hotkeys' => 'ctrl+a' ]) !!} @@ -40,11 +40,12 @@ @lang('widgets::snippet.label.readonly') @endif - @if (acl_check('snippet.edit') or acl_check('snippet.view')) + @if (acl_check('snippet::edit') or acl_check('snippet::view')) {!! link_to_route('backend.snippet.edit', $snippet->getName(), [$snippet->getName()], [ 'class' => $snippet->isReadOnly() ? 'popup' : '' ]) !!} @else + {{ $snippet->getName() }} @endif @@ -57,7 +58,7 @@ {!! UI::label($snippet->getRelativePath()) !!} - @if (acl_check('snippet.delete')) + @if (acl_check('snippet::delete')) {!! Form::open(['route' => ['backend.snippet.delete', $snippet->getName()]]) !!} {!! Form::button('', [ 'type' => 'submit', diff --git a/src/resources/views/snippet/snippet_select.blade.php b/src/resources/views/snippet/snippet_select.blade.php index 4d37007..e0c21ac 100644 --- a/src/resources/views/snippet/snippet_select.blade.php +++ b/src/resources/views/snippet/snippet_select.blade.php @@ -60,14 +60,14 @@ function update_snippets_list(e, response) { ]) !!}
- @if (acl_check('snippet.edit')) + @if (acl_check('snippet::edit')) {!! link_to_route('backend.snippet.edit', '', [$template], [ 'data-icon' => 'edit', 'class' => 'btn popup btn-primary '.$hidden, 'id' => 'EditTemplateButton' ]) !!} @endif - @if (acl_check('snippet.add')) + @if (acl_check('snippet::add')) {!! link_to_route('backend.snippet.create', '', [], [ 'data-icon' => 'plus', 'class' => 'btn popup btn-success', 'id' => 'AddTemplateButton' diff --git a/src/resources/views/widgets/edit.blade.php b/src/resources/views/widgets/edit.blade.php index a662db1..2e61a35 100644 --- a/src/resources/views/widgets/edit.blade.php +++ b/src/resources/views/widgets/edit.blade.php @@ -45,7 +45,7 @@
- @if (acl_check('widgets.location') and !$widget->isHandler()) + @if (acl_check('widget_settings::location') and !$widget->isHandler()) {!! link_to_route('backend.widget.location', trans('widgets::core.button.location'), [$widget], [ 'data-icon' => 'sitemap', 'class' => 'btn btn-sm btn-primary btn-labeled' ]) !!} diff --git a/src/resources/views/widgets/list.blade.php b/src/resources/views/widgets/list.blade.php index 806ecab..f080b0b 100644 --- a/src/resources/views/widgets/list.blade.php +++ b/src/resources/views/widgets/list.blade.php @@ -44,7 +44,7 @@ @lang('widgets::core.messages.corrupted') - @if (acl_check('widgets.delete')) + @if (acl_check('widget::delete')) {!! link_to_route('backend.widget.delete', '', [$widget], [ 'data-icon' => 'times fa-inverse', 'class' => 'btn btn-xs btn-confirm' ]) !!} @@ -52,7 +52,7 @@ @else - @if (acl_check('widgets.edit')) + @if (acl_check('widget::edit')) {!! link_to_route('backend.widget.edit', $widget->name, [$widget]) !!} @else {{ $widget->name }} @@ -96,12 +96,12 @@ @endif - @if (acl_check('widgets.location') and !$widget->isHandler()) + @if (acl_check('widget_settings::location') and !$widget->isHandler()) {!! link_to_route('backend.widget.location', '', [$widget], [ 'data-icon' => 'sitemap', 'class' => 'btn btn-xs btn-primary popup' ]) !!} @endif - @if (acl_check('widgets.delete')) + @if (acl_check('widget::delete')) {!! Form::open(['route' => ['backend.widget.delete', $widget], 'style' => 'display: inline-block']) !!} {!! Form::button('', [ 'type' => 'submit', diff --git a/src/resources/views/widgets/location.blade.php b/src/resources/views/widgets/location.blade.php index 2021e73..71f7a2d 100644 --- a/src/resources/views/widgets/location.blade.php +++ b/src/resources/views/widgets/location.blade.php @@ -32,7 +32,7 @@
- @if (acl_check('layout.rebuild')) + @if (acl_check('layout::rebuild')) {!! Form::button(trans('widgets::core.button.rebuild_blocks'), [ 'data-icon' => 'refresh', 'class' => 'btn btn-xs btn-info btn-labeled', @@ -88,7 +88,7 @@ function recurse_pages($pages, $spaces = 0, $layoutsBlocks = [], $pageWidgets = $data .= Form::text('blocks[' . $page['id'] . '][position]', (int) $currentPosition, ['maxlength' => 4, 'size' => 4, 'class' => 'form-control text-right widget-position']); $data .= ''; - if (acl_check('page.edit')) + if (acl_check('page::edit')) { $data .= '' . str_repeat("- ", $spaces) . link_to_route('backend.page.edit', $page['title'], [$page['id']]) . ''; } diff --git a/src/resources/views/widgets/page/list.blade.php b/src/resources/views/widgets/page/list.blade.php index 69777d7..0c38a36 100644 --- a/src/resources/views/widgets/page/list.blade.php +++ b/src/resources/views/widgets/page/list.blade.php @@ -13,13 +13,13 @@ @else - @if (acl_check('widgets.location')) + @if (acl_check('widget_settings::location')) @lang('widgets::core.button.add_to_page') - @if (acl_check('layout.rebuild')) + @if (acl_check('layout::rebuild')) {!! Form::button(trans('pages::layout.button.rebuild'), [ 'data-icon' => 'refresh', 'class' => 'btn btn-inverse btn-xs', diff --git a/src/resources/views/widgets/page/row.blade.php b/src/resources/views/widgets/page/row.blade.php index 9aca80c..e219581 100644 --- a/src/resources/views/widgets/page/row.blade.php +++ b/src/resources/views/widgets/page/row.blade.php @@ -1,6 +1,6 @@ - @if (acl_check('widgets.edit')) + @if (acl_check('widgets::edit')) {!! link_to_route('backend.widget.edit', $widget->getName(), [$widget->getId()]) !!} @else {!! UI::icon('lock') !!} {{ $widget->getName() }} @@ -11,14 +11,14 @@ @endif - @if(acl_check('widgets.location')) + @if(acl_check('widget_settings::location')) {!! Form::text('widget[' . $widget->getId() . '][position]', (int) $position, ['maxlength' => 4, 'size' => 4, 'class' => 'form-control text-right']) !!} @else {{ __('Position: :position', [':block_name' => $block]) }} @endif - @if(acl_check('widgets.location') and $page->hasLayout()) + @if(acl_check('widget_settings::location') and $page->hasLayout())
{!! Form::hidden('widget[' . $widget->getId() . '][block]', ! empty($block) ? $block : 0, ['class' => 'widget-blocks', 'data-layout' => $page->layout]) !!}