link to the control panel in account view
This commit is contained in:
parent
e2a0efd24f
commit
2b02138e39
6 changed files with 43 additions and 3 deletions
12
src/c3nav/control/middleware.py
Normal file
12
src/c3nav/control/middleware.py
Normal file
|
@ -0,0 +1,12 @@
|
|||
from django.utils.functional import SimpleLazyObject
|
||||
|
||||
from c3nav.control.models import UserPermissions
|
||||
|
||||
|
||||
class UserPermissionsMiddleware:
|
||||
def __init__(self, get_response):
|
||||
self.get_response = get_response
|
||||
|
||||
def __call__(self, request):
|
||||
request.user_permissions = SimpleLazyObject(lambda: UserPermissions.get_for_user(request.user))
|
||||
return self.get_response(request)
|
|
@ -1,6 +1,7 @@
|
|||
from django.conf import settings
|
||||
from django.core.cache import cache
|
||||
from django.db import models
|
||||
from django.utils.functional import lazy
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
|
||||
|
@ -36,10 +37,17 @@ class UserPermissions(models.Model):
|
|||
break
|
||||
if result:
|
||||
return result
|
||||
result = user.permissions
|
||||
try:
|
||||
result = user.permissions
|
||||
except AttributeError:
|
||||
result = cls()
|
||||
cache.set(cache_key, result, 900)
|
||||
return result
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
super().save(*args, **kwargs)
|
||||
cache_key = self.get_cache_key(self.pk)
|
||||
cache.set(cache_key, self, 900)
|
||||
|
||||
|
||||
get_permissions_for_user_lazy = lazy(UserPermissions.get_for_user, UserPermissions)
|
||||
|
|
|
@ -42,7 +42,7 @@ def no_language(keep_content_language=False):
|
|||
return decorator
|
||||
|
||||
|
||||
class GetUserDataMiddleware:
|
||||
class UserDataMiddleware:
|
||||
def __init__(self, get_response):
|
||||
self.get_response = get_response
|
||||
|
||||
|
|
|
@ -49,6 +49,10 @@ input {
|
|||
user-select: none;
|
||||
}
|
||||
|
||||
hr {
|
||||
margin: 1.5rem 0;
|
||||
}
|
||||
|
||||
main {
|
||||
flex-grow: 1;
|
||||
border: 0 solid #CCCCCC;
|
||||
|
|
|
@ -736,10 +736,15 @@ c3nav = {
|
|||
}
|
||||
},
|
||||
_modal_link_click: function(e) {
|
||||
var location = $(this).attr('href');
|
||||
if (location.startsWith('/control/')) {
|
||||
$(this).attr('target', '_blank');
|
||||
return;
|
||||
}
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
c3nav.open_modal();
|
||||
$.get($(this).attr('href'), c3nav._modal_loaded).fail(c3nav._modal_error);
|
||||
$.get(location, c3nav._modal_loaded).fail(c3nav._modal_error);
|
||||
},
|
||||
_modal_submit: function(e) {
|
||||
e.preventDefault();
|
||||
|
|
|
@ -13,6 +13,17 @@
|
|||
{% endwith %}
|
||||
</p>
|
||||
|
||||
{% if request.user_permissions.control_panel %}
|
||||
<hr>
|
||||
<p>
|
||||
{% trans 'You can access the control panel.' %}
|
||||
</p>
|
||||
<p>
|
||||
<a class="button" href="{% url 'control.index' %}">{% trans 'c3nav control panel' %}</a>
|
||||
</p>
|
||||
{% endif %}
|
||||
|
||||
<hr>
|
||||
<p>
|
||||
<a class="button" href="{% url 'site.logout' %}">{% trans 'Log out' %}</a>
|
||||
<a class="button" href="{% url 'site.account.change_password' %}">{% trans 'Change password' %}</a>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue