mirror of
https://gitlab.crans.org/bde/nk20
synced 2024-11-26 18:37:12 +00:00
Better index page: non-Kfet members will be redirected to their profile page, the account note (when it will be managed) will see the consumption page
This commit is contained in:
parent
b5fa428bad
commit
65a2e8c08c
@ -245,7 +245,7 @@ REST_FRAMEWORK = {
|
|||||||
FORM_RENDERER = 'django.forms.renderers.TemplatesSetting'
|
FORM_RENDERER = 'django.forms.renderers.TemplatesSetting'
|
||||||
|
|
||||||
# After login redirect user to transfer page
|
# After login redirect user to transfer page
|
||||||
LOGIN_REDIRECT_URL = '/note/transfer/'
|
LOGIN_REDIRECT_URL = '/'
|
||||||
|
|
||||||
# An user session will expired after 3 hours
|
# An user session will expired after 3 hours
|
||||||
SESSION_COOKIE_AGE = 60 * 60 * 3
|
SESSION_COOKIE_AGE = 60 * 60 * 3
|
||||||
|
@ -64,7 +64,8 @@ SPDX-License-Identifier: GPL-3.0-or-later
|
|||||||
<a class="nav-link {% if request.path_info == url %}active{% endif %}" href="{{ url }}"><i class="fa fa-coffee"></i> {% trans 'Consumptions' %}</a>
|
<a class="nav-link {% if request.path_info == url %}active{% endif %}" href="{{ url }}"><i class="fa fa-coffee"></i> {% trans 'Consumptions' %}</a>
|
||||||
</li>
|
</li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if "note.transaction"|not_empty_model_list %}
|
{# FIXME Find a better solution to check if a user has the right to see the transfer page #}
|
||||||
|
{% if "note.alias"|model_list_length >= 2 %}
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
{% url 'note:transfer' as url %}
|
{% url 'note:transfer' as url %}
|
||||||
<a class="nav-link {% if request.path_info == url %}active{% endif %}" href="{{ url }}"><i class="fa fa-exchange"></i> {% trans 'Transfer' %} </a>
|
<a class="nav-link {% if request.path_info == url %}active{% endif %}" href="{{ url }}"><i class="fa fa-exchange"></i> {% trans 'Transfer' %} </a>
|
||||||
|
@ -5,15 +5,14 @@ from django.conf import settings
|
|||||||
from django.conf.urls.static import static
|
from django.conf.urls.static import static
|
||||||
from django.urls import path, include
|
from django.urls import path, include
|
||||||
from django.views.defaults import bad_request, permission_denied, page_not_found, server_error
|
from django.views.defaults import bad_request, permission_denied, page_not_found, server_error
|
||||||
from django.views.generic import RedirectView
|
|
||||||
|
|
||||||
from member.views import CustomLoginView
|
from member.views import CustomLoginView
|
||||||
|
|
||||||
from .admin import admin_site
|
from .admin import admin_site
|
||||||
|
from .views import IndexView
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
# Dev so redirect to something random
|
# Dev so redirect to something random
|
||||||
path('', RedirectView.as_view(pattern_name='note:transfer'), name='index'),
|
path('', IndexView.as_view(), name='index'),
|
||||||
|
|
||||||
# Include project routers
|
# Include project routers
|
||||||
path('note/', include('note.urls')),
|
path('note/', include('note.urls')),
|
||||||
|
30
note_kfet/views.py
Normal file
30
note_kfet/views.py
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
|
||||||
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||||
|
from django.urls import reverse
|
||||||
|
from django.views.generic import RedirectView
|
||||||
|
from note.models import Alias
|
||||||
|
from permission.backends import PermissionBackend
|
||||||
|
|
||||||
|
|
||||||
|
class IndexView(LoginRequiredMixin, RedirectView):
|
||||||
|
def get_redirect_url(self, *args, **kwargs):
|
||||||
|
"""
|
||||||
|
Calculate the index page according to the roles.
|
||||||
|
A normal user will have access to the transfer page.
|
||||||
|
A non-Kfet member will have access to its user detail page.
|
||||||
|
The user "note" will display the consumption interface.
|
||||||
|
"""
|
||||||
|
user = self.request.user
|
||||||
|
|
||||||
|
# The account note will have the consumption page as default page
|
||||||
|
if not PermissionBackend.check_perm(user, "auth.view_user", user):
|
||||||
|
return reverse("note:consos")
|
||||||
|
|
||||||
|
# People that can see the alias BDE are Kfet members
|
||||||
|
if PermissionBackend.check_perm(user, "alias.view_alias", Alias.objects.get(name="BDE")):
|
||||||
|
return reverse("note:transfer")
|
||||||
|
|
||||||
|
# Non-Kfet members will don't see the transfer page, but their profile page
|
||||||
|
return reverse("member:user_detail", args=(user.pk,))
|
Loading…
Reference in New Issue
Block a user