refactored permissions for simpler customizations (#808)
This commit is contained in:
@@ -4,22 +4,6 @@
|
||||
{% block page_subtitle %}{{ 'about.subtitle'|trans({}, 'about') }}{% endblock %}
|
||||
|
||||
{% block about_box %}
|
||||
{% if is_granted('system_actions') %}
|
||||
{% embed '@AdminLTE/Widgets/box-widget.html.twig' with {'boxtype': 'warning'} %}
|
||||
{% block box_title %}{{ 'label.actions'|trans }}{% endblock %}
|
||||
{% block box_body %}
|
||||
{% if content_action is defined and content_action is not empty %}
|
||||
<pre>
|
||||
{{ content_action }}
|
||||
</pre>
|
||||
{% endif %}
|
||||
|
||||
<p>
|
||||
<a href="{{ path('system_flush_cache') }}" class="btn btn-primary" onclick="$(this).html('Clear cache <i class=\'fas fa-spinner fa-spin\'></i>')">Clear cache</a>
|
||||
</p>
|
||||
{% endblock %}
|
||||
{% endembed %}
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
{% block about %}
|
||||
|
||||
@@ -131,6 +131,9 @@
|
||||
}
|
||||
|
||||
ALERT.question(message, function(value) {
|
||||
if (!value) {
|
||||
return;
|
||||
}
|
||||
var btn = $(button);
|
||||
var exportButtons = $('.exportBtn');
|
||||
// disabling does not yet work...
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
{% import "macros/widgets.html.twig" as widgets %}
|
||||
{% import "macros/toolbar.html.twig" as toolbar %}
|
||||
{% import "macros/datatables.html.twig" as tables %}
|
||||
{% import "macros/actions.html.twig" as actions %}
|
||||
|
||||
{% set columns = {
|
||||
'date': 'alwaysVisible',
|
||||
@@ -16,16 +17,7 @@
|
||||
|
||||
{% block page_title %}{{ 'invoice.title'|trans }}{% endblock %}
|
||||
{% block page_subtitle %}{{ 'invoice.subtitle'|trans }}{% endblock %}
|
||||
{% block page_actions %}
|
||||
{% set actions = {'filter': '#collapseInvoice', 'visibility': '#modal_invoice'} %}
|
||||
{% if is_granted('create_invoice_template') %}
|
||||
{% set actions = actions|merge({'create': path('admin_invoice_template_create')}) %}
|
||||
{% endif %}
|
||||
{% if is_granted('view_invoice_template') %}
|
||||
{% set actions = actions|merge({'list': path('admin_invoice_template')}) %}
|
||||
{% endif %}
|
||||
{{ widgets.page_actions(actions) }}
|
||||
{% endblock %}
|
||||
{% block page_actions %}{{ actions.invoices('index') }}{% endblock %}
|
||||
|
||||
{% block main_before %}
|
||||
{{ toolbar.toolbar(form, 'collapseInvoice', true) }}
|
||||
|
||||
@@ -1,21 +1,11 @@
|
||||
{% extends 'base.html.twig' %}
|
||||
{% import "macros/widgets.html.twig" as widgets %}
|
||||
{% import "macros/datatables.html.twig" as tables %}
|
||||
{% import "macros/actions.html.twig" as actions %}
|
||||
|
||||
{% block page_title %}{{ 'admin_invoice_template.title'|trans }}{% endblock %}
|
||||
{% block page_subtitle %}{{ 'admin_invoice_template.subtitle'|trans }}{% endblock %}
|
||||
{% block page_actions %}
|
||||
{# TODO move me to actions macro #}
|
||||
{% set actions = {} %}
|
||||
{% if is_granted('create_invoice_template') %}
|
||||
{% set actions = actions|merge({'create': path('admin_invoice_template_create')}) %}
|
||||
{% endif %}
|
||||
{% if is_granted('view_invoice') %}
|
||||
{% set actions = actions|merge({'invoice': path('invoice')}) %}
|
||||
{% endif %}
|
||||
{% set event = trigger('actions.invoice_templates', {'actions': actions, 'view': 'index'}) %}
|
||||
{{ widgets.page_actions(actions) }}
|
||||
{% endblock %}
|
||||
{% block page_actions %}{{ actions.invoice_templates('index') }}{% endblock %}
|
||||
|
||||
{% block main %}
|
||||
{% if entries.count == 0 %}
|
||||
|
||||
@@ -48,16 +48,43 @@
|
||||
|
||||
{% macro users(view) %}
|
||||
{% import "macros/widgets.html.twig" as widgets %}
|
||||
{% set actions = {'filter': '#collapseUserAdmin', 'visibility': '#modal_user_admin'} %}
|
||||
{% set actions = {} %}
|
||||
|
||||
{% if view == 'index' %}
|
||||
{% set actions = actions|merge({'filter': '#collapseUserAdmin', 'visibility': '#modal_user_admin'}) %}
|
||||
{% else %}
|
||||
{% set actions = actions|merge({'back': path('admin_user')}) %}
|
||||
{% endif %}
|
||||
|
||||
{% if view != 'permissions' and is_granted('role_permissions') %}
|
||||
{% set actions = actions|merge({'permissions': path('admin_user_permissions')}) %}
|
||||
{% endif %}
|
||||
|
||||
{% if is_granted('create_user') %}
|
||||
{% set actions = actions|merge({'create': path('admin_user_create')}) %}
|
||||
{% endif %}
|
||||
|
||||
{% if view == 'index' %}
|
||||
{% set actions = actions|merge({'help': {'url': 'users.html'|docu_link, 'target': '_blank'}}) %}
|
||||
{% elseif view == 'permissions' %}
|
||||
{% set actions = actions|merge({'help': {'url': 'permissions.html'|docu_link, 'target': '_blank'}}) %}
|
||||
{% endif %}
|
||||
|
||||
{% set event = trigger('actions.users', {'actions': actions, 'view': view}) %}
|
||||
{{ widgets.page_actions(event.payload.actions) }}
|
||||
{% endmacro %}
|
||||
|
||||
{% macro user_permissions(view) %}
|
||||
{% import "macros/widgets.html.twig" as widgets %}
|
||||
{% set actions = {} %}
|
||||
|
||||
{% set actions = actions|merge({'back': path('admin_user')}) %}
|
||||
{% set actions = actions|merge({'help': {'url': 'permissions.html'|docu_link, 'target': '_blank'}}) %}
|
||||
|
||||
{% set event = trigger('actions.user_permissions', {'actions': actions, 'view': view}) %}
|
||||
{{ widgets.page_actions(event.payload.actions) }}
|
||||
{% endmacro %}
|
||||
|
||||
{% macro user(user, view) %}
|
||||
{% import "macros/widgets.html.twig" as widgets %}
|
||||
{% set actions = {} %}
|
||||
@@ -371,3 +398,39 @@
|
||||
{% set event = trigger('actions.tag', {'actions': actions, 'view': view, 'tag': tag}) %}
|
||||
{{ widgets.table_actions(event.payload.actions) }}
|
||||
{% endmacro %}
|
||||
|
||||
{% macro invoices(view) %}
|
||||
{% import "macros/widgets.html.twig" as widgets %}
|
||||
|
||||
{% set actions = {'filter': '#collapseInvoice', 'visibility': '#modal_invoice'} %}
|
||||
{% if is_granted('create_invoice_template') %}
|
||||
{% set actions = actions|merge({'create': path('admin_invoice_template_create')}) %}
|
||||
{% endif %}
|
||||
{% if is_granted('view_invoice_template') %}
|
||||
{% set actions = actions|merge({'list': path('admin_invoice_template')}) %}
|
||||
{% endif %}
|
||||
|
||||
{% set actions = actions|merge({'help': {'url': 'invoices.html'|docu_link, 'target': '_blank'}}) %}
|
||||
|
||||
{% set event = trigger('actions.invoices', {'actions': actions, 'view': view}) %}
|
||||
{{ widgets.page_actions(event.payload.actions) }}
|
||||
{% endmacro %}
|
||||
|
||||
{% macro invoice_templates(view) %}
|
||||
{% import "macros/widgets.html.twig" as widgets %}
|
||||
|
||||
{% set actions = {} %}
|
||||
{% if is_granted('view_invoice') %}
|
||||
{% set actions = actions|merge({'back': path('invoice')}) %}
|
||||
{% endif %}
|
||||
|
||||
{% if is_granted('create_invoice_template') %}
|
||||
{% set actions = actions|merge({'create': path('admin_invoice_template_create')}) %}
|
||||
{% endif %}
|
||||
|
||||
{% set actions = actions|merge({'help': {'url': 'invoices.html'|docu_link, 'target': '_blank'}}) %}
|
||||
|
||||
{% set event = trigger('actions.invoice_templates', {'actions': actions, 'view': 'index'}) %}
|
||||
{{ widgets.page_actions(actions) }}
|
||||
{% endmacro %}
|
||||
|
||||
|
||||
@@ -70,22 +70,36 @@
|
||||
{% endspaceless %}
|
||||
{% endmacro %}
|
||||
|
||||
{% macro data_table_header_options(name, columns, options) %}
|
||||
{% set skipStripped = options.skipStripped|default(false) %}
|
||||
{% set reloadEvent = options.reloadEvent|default('') %}
|
||||
{% set translationDomain = options.translationDomain|default('messages') %}
|
||||
{# |default does not work here, as the prefix might be an empty string #}
|
||||
{% set translationPrefix = 'label.' %}
|
||||
{% if options.translationPrefix is defined %}
|
||||
{% set translationPrefix = options.translationPrefix %}
|
||||
{% endif %}
|
||||
|
||||
{% import _self as macro %}
|
||||
<div class="box box-{{ admin_lte_context.widget.type }} data_table" id="datatable_{{ name }}">
|
||||
<div class="box-body no-padding">
|
||||
<div class="dataTables_wrapper form-inline dt-bootstrap">
|
||||
<div class="row">
|
||||
<div class="col-sm-12">
|
||||
<table class="table {% if not skipStripped %}table-striped {% endif %}table-hover dataTable" role="grid" data-reload-event="{{ reloadEvent }}">
|
||||
<thead>
|
||||
<tr>
|
||||
{%- for title, class in columns -%}
|
||||
<th data-field="{{ title }}" class="{{ macro.data_table_column_class(name, columns, title) }}">{% if title is not empty and title != 'actions' %}{{ (translationPrefix ~ title)|trans({}, translationDomain) }}{% endif %}</th>
|
||||
{%- endfor -%}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% endmacro %}
|
||||
|
||||
{% macro data_table_header(name, columns, skipStripped, reloadEvent) %}
|
||||
{% import _self as macro %}
|
||||
<div class="box box-{{ admin_lte_context.widget.type }} data_table" id="datatable_{{ name }}">
|
||||
<div class="box-body no-padding">
|
||||
<div class="dataTables_wrapper form-inline dt-bootstrap">
|
||||
<div class="row">
|
||||
<div class="col-sm-12">
|
||||
<table class="table {% if not skipStripped %}table-striped {% endif %}table-hover dataTable" role="grid" data-reload-event="{{ reloadEvent }}">
|
||||
<thead>
|
||||
<tr>
|
||||
{%- for title, class in columns -%}
|
||||
<th data-field="{{ title }}" class="{{ macro.data_table_column_class(name, columns, title) }}">{% if title is not empty and title != 'actions' %}{{ ('label.' ~ title)|trans }}{% endif %}</th>
|
||||
{%- endfor -%}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% import _self as macro %}
|
||||
{{ macro.data_table_header_options(name, columns, {'skipStripped': skipStripped, 'reloadEvent': reloadEvent}) }}
|
||||
{% endmacro %}
|
||||
|
||||
{% macro data_table_footer(entries, route) %}
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
<h2 class="page-header">{{ title|trans }}</h2>
|
||||
{% endmacro %}
|
||||
|
||||
{% macro label_visible(visible) %}
|
||||
{% macro label_boolean(visible) %}
|
||||
{% import _self as macro %}
|
||||
{% if visible %}
|
||||
{{ macro.label('yes', 'success') }}
|
||||
@@ -33,6 +33,11 @@
|
||||
{% endif %}
|
||||
{% endmacro %}
|
||||
|
||||
{% macro label_visible(visible) %}
|
||||
{% import _self as macro %}
|
||||
{{ macro.label_boolean(visible) }}
|
||||
{% endmacro %}
|
||||
|
||||
{% macro label_role(role) %}
|
||||
{% import _self as macro %}
|
||||
{% if role == 'ROLE_SUPER_ADMIN' %}
|
||||
|
||||
40
templates/user/permissions.html.twig
Normal file
40
templates/user/permissions.html.twig
Normal file
@@ -0,0 +1,40 @@
|
||||
{% extends 'base.html.twig' %}
|
||||
{% import "macros/datatables.html.twig" as tables %}
|
||||
{% import "macros/widgets.html.twig" as widgets %}
|
||||
{% import "macros/toolbar.html.twig" as toolbar %}
|
||||
{% import "macros/actions.html.twig" as actions %}
|
||||
|
||||
{% set columns = {
|
||||
'label.name': 'alwaysVisible',
|
||||
} %}
|
||||
|
||||
{% for role in roles %}
|
||||
{% set columns = columns|merge({
|
||||
(role): 'alwaysVisible text-center',
|
||||
}) %}
|
||||
{% endfor %}
|
||||
|
||||
{% set tableName = 'user_admin_permissions' %}
|
||||
|
||||
{% block page_title %}{{ 'admin_user.title'|trans }}{% endblock %}
|
||||
{% block page_subtitle %}{{ 'admin_user.subtitle'|trans }}{% endblock %}
|
||||
{% block page_actions %}{{ actions.user_permissions('index') }}{% endblock %}
|
||||
|
||||
{% block main %}
|
||||
|
||||
{{ tables.data_table_header_options(tableName, columns, {'translationPrefix': ''}) }}
|
||||
|
||||
{% for permission in permissions|sort %}
|
||||
<tr>
|
||||
<td>{{ permission }}</td>
|
||||
{% for role in roles %}
|
||||
<td class="text-center">
|
||||
{{ widgets.label_boolean(manager.permission(role, permission)) }}
|
||||
</td>
|
||||
{% endfor %}
|
||||
</tr>
|
||||
{% endfor %}
|
||||
|
||||
{{ tables.data_table_footer(permissions) }}
|
||||
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user