Improved permissions field to add support for displaying calculated permissions

This commit is contained in:
Matias Griese
2019-11-13 11:46:53 +02:00
parent 30d5382d49
commit f7e8a4f076
3 changed files with 30 additions and 5 deletions

View File

@@ -1,6 +1,8 @@
# v1.10.0-rc.2
## mm/dd/2019
1. [](#improved)
* Improved `permissions` field to add support for displaying calculated permissions
1. [](#bugfix)
* Fixed `permissions` field with nested permissions

View File

@@ -851,3 +851,11 @@ PLUGIN_ADMIN:
SANITIZE_SVG: "Sanitize SVG"
SANITIZE_SVG_HELP: "Removes any XSS code from SVG"
ACCOUNTS: "Accounts"
USER_ACCOUNTS: "User Accounts"
USER_GROUPS: "User Groups"
GROUP_NAME: "Group Name"
DISPLAY_NAME: "Display Name"
ICON: "Icon"
ACCESS: "Access"
NO_ACCESS: "No Access"
SUPER_USER: "Super User"

View File

@@ -20,19 +20,24 @@
{% set permissions = permissions|merge({(existing_key): 'boolean'}) %}
{% endif %}
{% endfor %}
{% set super = object.authorize('admin.super', 'test') %}
<div class="permissions-container">
{% for permission, type in permissions %}
<div class="permission-container">
{% set permission_value = value[permission] ?? null %}
{% if permission_value in ['on', 'true', 1] %}
{% set permission_value = 'true' %}
{% set permission_value = value[permission] ?? '' %}
{% if permission_value is not same as('') %}
{% if permission_value in ['yes', 'on', 'true', 1, true] %}
{% set permission_value = 'true' %}
{% else %}
{% set permission_value = 'false' %}
{% endif %}
{% endif %}
<input type="text" class="medium permission-value" value="{{ permission }}" />
<div class="switch-toggle switch-grav medium switch-3">
{% set options = { true: 'PLUGIN_ADMIN.YES', false: 'PLUGIN_ADMIN.NO', '': 'PLUGIN_ADMIN.NOT_SET' } %}
{% set options = { 'true': 'PLUGIN_ADMIN.YES', 'false': 'PLUGIN_ADMIN.NO', '': 'PLUGIN_ADMIN.NOT_SET' } %}
{% set maxLen = 0 %}
{% for value, text in options %}
@@ -52,13 +57,23 @@
{% if key|fieldName == '' ~ permission_value|fieldName %}
checked="checked"
{% endif %}
{% if field.validate.required in ['on', 'true', 1] %}required="required"{% endif %}
{% if field.validate.required in ['yes', 'on', 'true', 1, true] %}required="required"{% endif %}
/>
<label for="{{ id }}">{{ (macro.spanToggle(translation, maxLen)|trim)|raw }}</label>
{% endfor %}
<a></a>
</div>
{% if object %}
{% set auth = object.authorize(permission, 'test') ?? super %}
{% if super and auth %}
<span class="badge badge-green">{{ 'PLUGIN_ADMIN.SUPER_USER'|tu }}</span>
{% elseif auth %}
<span class="badge badge-green">{{ 'PLUGIN_ADMIN.ACCESS'|tu }}</span>
{% else %}
<span class="badge badge-red">{{ 'PLUGIN_ADMIN.NO_ACCESS'|tu }}</span>
{% endif %}
{% endif %}
</div>
{% endfor %}
</div>