mirror of
https://github.com/pretix/pretix.git
synced 2026-05-08 15:44:02 +00:00
Navigation and dashboard: Hide useless items (#5995)
* Navigation and dashboard: Hide useless items If a user has access to *no organizer teams*, hide a number of things from navigation and dashboard. This happens e.g. if a user only has permissions in scope of the pretix-resellers or pretix-scheduling plugins. * New mechanism
This commit is contained in:
@@ -49,6 +49,7 @@ from django.core.exceptions import BadRequest, PermissionDenied
|
|||||||
from django.db import IntegrityError, models, transaction
|
from django.db import IntegrityError, models, transaction
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
from django.utils.crypto import get_random_string, salted_hmac
|
from django.utils.crypto import get_random_string, salted_hmac
|
||||||
|
from django.utils.functional import cached_property
|
||||||
from django.utils.timezone import now
|
from django.utils.timezone import now
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from django_otp.models import Device
|
from django_otp.models import Device
|
||||||
@@ -667,6 +668,11 @@ class User(AbstractBaseUser, PermissionsMixin, LoggingMixin):
|
|||||||
self.session_token = generate_session_token()
|
self.session_token = generate_session_token()
|
||||||
self.save(update_fields=['session_token'])
|
self.save(update_fields=['session_token'])
|
||||||
|
|
||||||
|
@cached_property
|
||||||
|
@scopes_disabled()
|
||||||
|
def is_in_any_teams(self):
|
||||||
|
return self.teams.exists()
|
||||||
|
|
||||||
|
|
||||||
class UserKnownLoginSource(models.Model):
|
class UserKnownLoginSource(models.Model):
|
||||||
user = models.ForeignKey('User', on_delete=models.CASCADE, related_name="known_login_sources")
|
user = models.ForeignKey('User', on_delete=models.CASCADE, related_name="known_login_sources")
|
||||||
|
|||||||
@@ -340,38 +340,43 @@ def get_global_navigation(request):
|
|||||||
'active': (url.url_name == 'index'),
|
'active': (url.url_name == 'index'),
|
||||||
'icon': 'dashboard',
|
'icon': 'dashboard',
|
||||||
},
|
},
|
||||||
{
|
]
|
||||||
'label': _('Events'),
|
if request.user.is_in_any_teams:
|
||||||
'url': reverse('control:events'),
|
nav += [
|
||||||
'active': 'events' in url.url_name,
|
{
|
||||||
'icon': 'calendar',
|
'label': _('Events'),
|
||||||
},
|
'url': reverse('control:events'),
|
||||||
{
|
'active': 'events' in url.url_name,
|
||||||
'label': _('Organizers'),
|
'icon': 'calendar',
|
||||||
'url': reverse('control:organizers'),
|
},
|
||||||
'active': 'organizers' in url.url_name,
|
{
|
||||||
'icon': 'group',
|
'label': _('Organizers'),
|
||||||
},
|
'url': reverse('control:organizers'),
|
||||||
{
|
'active': 'organizers' in url.url_name,
|
||||||
'label': _('Search'),
|
'icon': 'group',
|
||||||
'url': reverse('control:search.orders'),
|
},
|
||||||
'active': False,
|
{
|
||||||
'icon': 'search',
|
'label': _('Search'),
|
||||||
'children': [
|
'url': reverse('control:search.orders'),
|
||||||
{
|
'active': False,
|
||||||
'label': _('Orders'),
|
'icon': 'search',
|
||||||
'url': reverse('control:search.orders'),
|
'children': [
|
||||||
'active': 'search.orders' in url.url_name,
|
{
|
||||||
'icon': 'search',
|
'label': _('Orders'),
|
||||||
},
|
'url': reverse('control:search.orders'),
|
||||||
{
|
'active': 'search.orders' in url.url_name,
|
||||||
'label': _('Payments'),
|
'icon': 'search',
|
||||||
'url': reverse('control:search.payments'),
|
},
|
||||||
'active': 'search.payments' in url.url_name,
|
{
|
||||||
'icon': 'search',
|
'label': _('Payments'),
|
||||||
},
|
'url': reverse('control:search.payments'),
|
||||||
]
|
'active': 'search.payments' in url.url_name,
|
||||||
},
|
'icon': 'search',
|
||||||
|
},
|
||||||
|
]
|
||||||
|
},
|
||||||
|
]
|
||||||
|
nav += [
|
||||||
{
|
{
|
||||||
'label': _('User settings'),
|
'label': _('User settings'),
|
||||||
'url': reverse('control:user.settings'),
|
'url': reverse('control:user.settings'),
|
||||||
|
|||||||
@@ -12,27 +12,29 @@
|
|||||||
class="event-dropdown dropdown-menu">
|
class="event-dropdown dropdown-menu">
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<h2>{% trans "Your upcoming events" %}</h2>
|
{% if upcoming or can_create_event %}
|
||||||
<div class="dashboard">
|
<h2>{% trans "Your upcoming events" %}</h2>
|
||||||
{% if can_create_event %}
|
<div class="dashboard">
|
||||||
<div class="widget-small widget-container">
|
{% if can_create_event %}
|
||||||
<a href="{% url "control:events.add" %}" class="widget">
|
<div class="widget-small widget-container">
|
||||||
<div class="newevent"><span class="fa fa-plus-circle"></span>{% trans "Create a new event" %}</div>
|
<a href="{% url "control:events.add" %}" class="widget">
|
||||||
</a>
|
<div class="newevent"><span class="fa fa-plus-circle"></span>{% trans "Create a new event" %}</div>
|
||||||
</div>
|
</a>
|
||||||
{% endif %}
|
|
||||||
{% for w in upcoming %}
|
|
||||||
<div class="widget-{{ w.display_size|default:"small" }} {{ w.container_class|default:"widget-container" }} {% if w.lazy %}widget-lazy-loading{% endif %}" data-lazy-id="{{ w.lazy }}">
|
|
||||||
<div class="widget">
|
|
||||||
{% if w.lazy %}
|
|
||||||
<span class="fa fa-cog fa-4x"></span>
|
|
||||||
{% else %}
|
|
||||||
{{ w.content|safe }}
|
|
||||||
{% endif %}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
{% endif %}
|
||||||
{% endfor %}
|
{% for w in upcoming %}
|
||||||
</div>
|
<div class="widget-{{ w.display_size|default:"small" }} {{ w.container_class|default:"widget-container" }} {% if w.lazy %}widget-lazy-loading{% endif %}" data-lazy-id="{{ w.lazy }}">
|
||||||
|
<div class="widget">
|
||||||
|
{% if w.lazy %}
|
||||||
|
<span class="fa fa-cog fa-4x"></span>
|
||||||
|
{% else %}
|
||||||
|
{{ w.content|safe }}
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
{% if upcoming %}
|
{% if upcoming %}
|
||||||
<p class="">
|
<p class="">
|
||||||
<a href="{% url "control:events" %}?ordering=date_from&status=date_future" class="">
|
<a href="{% url "control:events" %}?ordering=date_from&status=date_future" class="">
|
||||||
|
|||||||
Reference in New Issue
Block a user