rename has_permission_to(_any) to can(Any)

This commit is contained in:
Xu 2024-04-18 14:29:56 +02:00 committed by xuwhite
parent e514685444
commit 3972998ba0
18 changed files with 46 additions and 46 deletions

View File

@ -22,7 +22,7 @@
}) }}
</div>
{% if has_permission_to('logs.all') %}
{% if can('logs.all') %}
<div class="col-md-4">
{{ f.select('search_user_id', __('general.user'), users, {
'default_option': __('form.user_select'),
@ -36,7 +36,7 @@
</form>
</div>
{% if not has_permission_to('logs.all') %}
{% if not can('logs.all') %}
<div class="mb-3">
{{ m.alert(__('log.only_own')) }}
</div>

View File

@ -13,9 +13,9 @@
{{ block('title') }}
{% if is_index|default(false) and has_permission_to('shifttypes.edit') %}
{% if is_index|default(false) and can('shifttypes.edit') %}
{{ m.button(m.icon('plus-lg'), url('/admin/shifttypes/edit'), 'secondary') }}
{% elseif is_view|default(false) and has_permission_to('shifttypes.edit') %}
{% elseif is_view|default(false) and can('shifttypes.edit') %}
{{ m.button(m.icon('pencil'), url('admin/shifttypes/edit/' ~ shifttype.id), null, 'sm', __('form.edit')) }}
{% endif %}
</h1>
@ -43,7 +43,7 @@
</td>
<td>
{% if has_permission_to('shifttypes.edit') %}
{% if can('shifttypes.edit') %}
<div class="d-flex ms-auto">
{{ m.button(m.icon('pencil'), url('admin/shifttypes/edit/' ~ shifttype.id), null, 'sm', __('form.edit')) }}

View File

@ -32,7 +32,7 @@
<div class="col-md-6">
{{ f.switch('arrived', __('user.arrived'), {
'checked': userdata.state.arrived,
'disabled': not has_permission_to('admin_arrive'),
'disabled': not can('admin_arrive'),
}) }}
{% if userdata.state.force_active and config('enable_force_active') %}

View File

@ -12,7 +12,7 @@
<link rel="stylesheet" type="text/css" href="{{ asset('assets/theme' ~ themeId ~ '.css') }}"/>
<script src="{{ asset('assets/vendor.js') }}"></script>
{% if page() in ['news', 'meetings'] and is_user() and has_permission_to('atom') -%}
{% if page() in ['news', 'meetings'] and is_user() and can('atom') -%}
{% set parameters = {'key': user.api_key} -%}
{% if page() == 'meetings' -%}
{% set parameters = {'meetings': 1}|merge(parameters) -%}

View File

@ -39,7 +39,7 @@
{% for name,opt in config('footer_items') %}
{% set url = opt is iterable ? opt[0] : opt %}
{% set permission = opt is iterable ? opt[1] : null %}
{% if not permission or has_permission_to(permission) %}
{% if not permission or can(permission) %}
<a href="
{%- if url starts with '/' %}
{{ url(url) }}

View File

@ -48,7 +48,7 @@
{% for name,opt in config('header_items', {}) %}
{% set url = opt is iterable ? opt[0] : opt %}
{% set permission = opt is iterable ? opt[1] : null %}
{% if not permission or has_permission_to(permission) %}
{% if not permission or can(permission) %}
<li class="nav-item">
<a class="nav-link" href="{{ url|replace({'%lang%': session_get('locale')|split('_')[0]})|escape('html_attr') }}">
{{ __(name) }}
@ -62,7 +62,7 @@
{% if is_guest() %}
{% include "layouts/parts/language_dropdown.twig" %}
{% if has_permission_to('register') and config('registration_enabled') %}
{% if can('register') and config('registration_enabled') %}
{{ _self.toolbar_item(
__('general.register'),
config('external_registration_url') ?: url('/register'),
@ -71,7 +71,7 @@
) }}
{% endif %}
{% if has_permission_to('login') %}
{% if can('login') %}
{{ _self.toolbar_item(__('general.login'), url('/login'), 'login', 'box-arrow-in-right') }}
{% endif %}
{% endif %}
@ -79,7 +79,7 @@
{% if is_user() %}
{{ _self.toolbar_item(menuUserShiftState(user), url('/shifts', {'action': 'next'}), '', 'clock', __('shift.next')) }}
{% if has_permission_to('user_messages') %}
{% if can('user_messages') %}
{{ _self.toolbar_item(
user_messages ? '<span class="badge bg-danger">' ~ user_messages ~ '</span>' : '',
url('/messages'),
@ -96,15 +96,15 @@
{{ m.angel() }} {{ user.displayName }}
</a>
<ul class="dropdown-menu dropdown-menu-end">
{% if has_permission_to('user_myshifts') %}
{% if can('user_myshifts') %}
{{ _self.dropdown_item(__('profile.my-shifts'), url('/users', {'action': 'view'}), 'users', m.icon('calendar-range')) }}
{% endif %}
{% if has_permission_to('user_settings') %}
{% if can('user_settings') %}
{{ _self.dropdown_item(__('settings.settings'), url('/settings/profile'), 'settings/profile', m.icon('person-fill-gear')) }}
{% endif %}
{% if has_permission_to('logout') %}
{% if can('logout') %}
{{ _self.dropdown_item(__('general.logout'), url('/logout'), 'logout', m.icon('box-arrow-left')) }}
{% endif %}
</ul>

View File

@ -14,7 +14,7 @@
{{ __('angeltypes.angeltypes') }}
</a>
{% else %}
{% if has_permission_to('register') and config('registration_enabled') %}
{% if can('register') and config('registration_enabled') %}
<a
href="{{ config('external_registration_url') ?: url('/register') }}"
class="btn btn-secondary back"

View File

@ -9,7 +9,7 @@
<h1>
{{ block('title') }}
{%- if has_permission_to('faq.edit') -%}
{%- if can('faq.edit') -%}
{{ m.button(m.icon('plus-lg'), url('/admin/faq'), 'secondary') }}
{%- endif %}
</h1>
@ -18,7 +18,7 @@
<div class="row">
{% block questions_text %}
{% if has_permission_to('question.add') %}
{% if can('question.add') %}
<p>{{ __('faq.questions_link', [url('/questions')]) | raw }}</p>
{% endif %}
{% endblock %}
@ -52,7 +52,7 @@
{{ m.icon('clock') }} {{ item.updated_at.format(__('general.datetime')) }}
</div>
{% if has_permission_to('faq.edit') %}
{% if can('faq.edit') %}
<span class="ms-auto">
{{ m.button(m.icon('pencil'), url('/admin/faq/' ~ item.id), 'secondary', 'sm', __('form.edit')) }}
</span>
@ -76,7 +76,7 @@
{% endblock %}
{% block ask_question %}
{% if has_permission_to('question.add') %}
{% if can('question.add') %}
<form action="{{ url('/questions/new') }}" enctype="multipart/form-data" method="post">
{{ csrf() }}
<div class="col-md-12">

View File

@ -105,7 +105,7 @@
<div class="col-sm-6 text-center">
<h2>{{ __('general.register') }}</h2>
{% if
(has_permission_to('register') and config('registration_enabled') and config('enable_password'))
(can('register') and config('registration_enabled') and config('enable_password'))
or config('external_registration_url') %}
<p>{{ __('login.registration') }}</p>

View File

@ -52,7 +52,7 @@
{{ f.checkbox('is_pinned', __('news.edit.is_pinned'), {
'checked': is_pinned,
}) }}
{% if has_permission_to('news.highlight') %}
{% if can('news.highlight') %}
{{ f.checkbox('is_highlighted', __('news.edit.is_highlighted'), {
'checked': is_highlighted,
}) }}

View File

@ -24,7 +24,7 @@
</div>
{{ m.user(comment.user, {'pronoun': true}) }}
{% if comment.user.id == user.id or has_permission_to('admin_news') or has_permission_to('comment.delete') %}
{% if comment.user.id == user.id or can('admin_news') or can('comment.delete') %}
<div class="ms-auto">
<form
action="{{ url('/news/comment/' ~ comment.id) }}" enctype="multipart/form-data"
@ -45,7 +45,7 @@
{% endblock %}
{% block write_comment %}
{% if has_permission_to('news_comments') %}
{% if can('news_comments') %}
<div class="col-md-12 mt-4">
<h3>{{ __('news.comments.new') }}</h3>

View File

@ -12,7 +12,7 @@
{{ m.button(m.icon('chevron-left'), url('/news'), null, 'sm', __('general.back')) }}
{% endif %}
{{ block('title') }}
{%- if has_permission_to('admin_news') and is_overview|default(false) -%}
{%- if can('admin_news') and is_overview|default(false) -%}
{{ m.button(m.icon('plus-lg'), url('/admin/news', only_meetings ? {'meeting': 1} : {}), 'secondary') }}
{%- endif %}
</h1>
@ -97,7 +97,7 @@
</div>
{% endif %}
{% if has_permission_to('admin_news') %}
{% if can('admin_news') %}
<div class="d-flex ms-auto">
{{ m.button(m.icon('pencil'), url('/admin/news/' ~ news.id), 'secondary', 'sm', __('form.edit')) }}

View File

@ -14,7 +14,7 @@
{% for name,opt in config('contact_options') %}
{% set url = opt is iterable ? opt[0] : opt %}
{% set permission = opt is iterable ? opt[1] : null %}
{% if not permission or has_permission_to(permission) %}
{% if not permission or can(permission) %}
<a href="
{%- if url starts with '/' %}
{{ url(url) }}
@ -50,7 +50,7 @@
<div class="col-md-12">
{% block questions %}
{% block faq_text %}
{% if has_permission_to('faq.view') %}
{% if can('faq.view') %}
{% if not is_admin | default(false) %}
<p>
{{ __('question.faq_link', [url('/faq')]) | raw }}
@ -79,16 +79,16 @@
{{ m.icon('clock') }} {{ question.created_at.format(__('general.datetime')) }}
</div>
{% if has_permission_to('question.edit') %}
{% if can('question.edit') %}
{{ m.user(question.user, {'pronoun': true}) }}
{% endif %}
<div class="d-flex ms-auto">
{% if has_permission_to('question.edit') %}
{% if can('question.edit') %}
{{ m.button(m.icon('pencil'), url('/admin/questions/' ~ question.id), null, 'sm', __('form.edit')) }}
{% endif %}
{% if question.user.id == user.id or has_permission_to('question.edit') %}
{% if question.user.id == user.id or can('question.edit') %}
<form class="ps-1" method="post" action="">
{{ csrf() }}
{{ f.hidden('id', question.id) }}

View File

@ -8,7 +8,7 @@
<div class="container">
<div class="mb-5">
<h1>
{{ has_permission_to('admin_user')
{{ can('admin_user')
? m.button(m.icon('chevron-left'), url('/users'), null, 'sm', __('general.back'))
: ''
}}

View File

@ -16,7 +16,7 @@
}}
) }}
{% if has_permission_to('shifts_json_export') %}
{% if can('shifts_json_export') %}
{{ f.button(
__('settings.api.shifts_json_show'),
{'size': 'sm', 'icon_left': 'braces', 'attr': {
@ -26,7 +26,7 @@
) }}
{% endif %}
{% if has_permission_to('ical') %}
{% if can('ical') %}
{{ f.button(
__('settings.api.ical_show'),
{'size': 'sm', 'icon_left': 'calendar-week', 'attr': {
@ -36,7 +36,7 @@
) }}
{% endif %}
{% if has_permission_to('atom') %}
{% if can('atom') %}
{{ f.button(
__('settings.api.news_show'),
{'size': 'sm', 'icon_left': 'calendar-week', 'attr': {
@ -65,26 +65,26 @@
<code>{{ user.api_key }}</code>
</p>
{% if has_permission_to('shifts_json_export') %}
{% if can('shifts_json_export') %}
<p id="shifts_json_hide" class="collapse" data-bs-parent="#exports_hide">
<code>{{ url('/shifts-json-export', {'key': user.api_key}) }}</code>
</p>
{% endif %}
{% if has_permission_to('ical') %}
{% if can('ical') %}
<p id="ical_hide" class="collapse" data-bs-parent="#exports_hide">
<code>{{ url('/ical', {'key': user.api_key}) }}</code>
</p>
{% endif %}
{% if has_permission_to('atom') %}
{% if can('atom') %}
<p id="news_hide" class="collapse" data-bs-parent="#exports_hide">
<code>{{ url('/atom', {'key': user.api_key}) }}</code>
{% if has_permission_to('user_meetings') %}
{% if can('user_meetings') %}
<br><code>{{ url('/atom', {'meetings': 1, 'key': user.api_key}) }}</code>
{% endif %}
<br><code>{{ url('/rss', {'key': user.api_key}) }}</code>
{% if has_permission_to('user_meetings') %}
{% if can('user_meetings') %}
<br><code>{{ url('/rss', {'meetings': 1, 'key': user.api_key}) }}</code>
{% endif %}
</p>
@ -95,7 +95,7 @@
<div class="row">
<div class="col-md-12">
{% if has_permission_to('api') %}
{% if can('api') %}
{{ __('settings.api.about', [
config('app_name'),
url('/api/v0-beta'),

View File

@ -21,7 +21,7 @@
<div class="col-md-3 settings-menu">
<ul class="nav nav-pills flex-column mt-3 user-settings">
{% for url,title in settings_menu %}
{% if not title.permission|default(false) or has_permission_to(title.permission) %}
{% if not title.permission|default(false) or can(title.permission) %}
<li class="nav-item{% if title.hidden|default(false) and url != request.url() %} d-none{% endif %}">
<a class="nav-link {% if url == request.url() %}active{% endif %}" href="{{ url }}">
{{ m.icon(title.icon ?? 'gear-fill') }}

View File

@ -22,8 +22,8 @@ class Authentication extends TwigExtension
return [
new TwigFunction('is_user', [$this, 'isAuthenticated']),
new TwigFunction('is_guest', [$this, 'isGuest']),
new TwigFunction('has_permission_to', [$this->auth, 'can']),
new TwigFunction('has_permission_to_any', [$this->auth, 'canAny']),
new TwigFunction('can', [$this->auth, 'can']),
new TwigFunction('canAny', [$this->auth, 'canAny']),
];
}

View File

@ -25,8 +25,8 @@ class AuthenticationTest extends ExtensionTest
$this->assertExtensionExists('is_user', [$extension, 'isAuthenticated'], $functions);
$this->assertExtensionExists('is_guest', [$extension, 'isGuest'], $functions);
$this->assertExtensionExists('has_permission_to', [$auth, 'can'], $functions);
$this->assertExtensionExists('has_permission_to_any', [$auth, 'canAny'], $functions);
$this->assertExtensionExists('can', [$auth, 'can'], $functions);
$this->assertExtensionExists('canAny', [$auth, 'canAny'], $functions);
}
/**