mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-22 03:13:12 +00:00
Modification de la navbar
This commit is contained in:
parent
6b8b576452
commit
0e282037d5
2 changed files with 77 additions and 55 deletions
87
re2o/acl.py
87
re2o/acl.py
|
@ -33,7 +33,13 @@ from django.contrib import messages
|
||||||
from django.shortcuts import redirect
|
from django.shortcuts import redirect
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
|
|
||||||
import cotisations, logs, machines, preferences, search, topologie, users
|
import cotisations
|
||||||
|
import logs
|
||||||
|
import machines
|
||||||
|
import preferences
|
||||||
|
import search
|
||||||
|
import topologie
|
||||||
|
import users
|
||||||
|
|
||||||
|
|
||||||
def can_create(model):
|
def can_create(model):
|
||||||
|
@ -46,7 +52,8 @@ def can_create(model):
|
||||||
def wrapper(request, *args, **kwargs):
|
def wrapper(request, *args, **kwargs):
|
||||||
can, msg = model.can_create(request.user, *args, **kwargs)
|
can, msg = model.can_create(request.user, *args, **kwargs)
|
||||||
if not can:
|
if not can:
|
||||||
messages.error(request, msg or "Vous ne pouvez pas accéder à ce menu")
|
messages.error(
|
||||||
|
request, msg or "Vous ne pouvez pas accéder à ce menu")
|
||||||
return redirect(reverse('index'))
|
return redirect(reverse('index'))
|
||||||
return view(request, *args, **kwargs)
|
return view(request, *args, **kwargs)
|
||||||
return wrapper
|
return wrapper
|
||||||
|
@ -67,22 +74,25 @@ def can_edit(model, *field_list):
|
||||||
except model.DoesNotExist:
|
except model.DoesNotExist:
|
||||||
messages.error(request, u"Entrée inexistante")
|
messages.error(request, u"Entrée inexistante")
|
||||||
return redirect(reverse('users:profil',
|
return redirect(reverse('users:profil',
|
||||||
kwargs={'userid':str(request.user.id)}
|
kwargs={'userid': str(request.user.id)}
|
||||||
))
|
))
|
||||||
can, msg = instance.can_edit(request.user)
|
can, msg = instance.can_edit(request.user)
|
||||||
if not can:
|
if not can:
|
||||||
messages.error(request, msg or "Vous ne pouvez pas accéder à ce menu")
|
messages.error(
|
||||||
|
request, msg or "Vous ne pouvez pas accéder à ce menu")
|
||||||
return redirect(reverse('users:profil',
|
return redirect(reverse('users:profil',
|
||||||
kwargs={'userid':str(request.user.id)}
|
kwargs={'userid': str(request.user.id)}
|
||||||
))
|
))
|
||||||
for field in field_list:
|
for field in field_list:
|
||||||
can_change = getattr(instance, 'can_change_' + field)
|
can_change = getattr(instance, 'can_change_' + field)
|
||||||
can, msg = can_change(request.user, *args, **kwargs)
|
can, msg = can_change(request.user, *args, **kwargs)
|
||||||
if not can:
|
if not can:
|
||||||
messages.error(request, msg or "Vous ne pouvez pas accéder à ce menu")
|
messages.error(
|
||||||
|
request, msg or "Vous ne pouvez pas accéder à ce menu")
|
||||||
return redirect(reverse('users:profil',
|
return redirect(reverse('users:profil',
|
||||||
kwargs={'userid':str(request.user.id)}
|
kwargs={'userid': str(
|
||||||
))
|
request.user.id)}
|
||||||
|
))
|
||||||
return view(request, instance, *args, **kwargs)
|
return view(request, instance, *args, **kwargs)
|
||||||
return wrapper
|
return wrapper
|
||||||
return decorator
|
return decorator
|
||||||
|
@ -98,10 +108,12 @@ def can_change(model, *field_list):
|
||||||
can_change = getattr(model, 'can_change_' + field)
|
can_change = getattr(model, 'can_change_' + field)
|
||||||
can, msg = can_change(request.user, *args, **kwargs)
|
can, msg = can_change(request.user, *args, **kwargs)
|
||||||
if not can:
|
if not can:
|
||||||
messages.error(request, msg or "Vous ne pouvez pas accéder à ce menu")
|
messages.error(
|
||||||
|
request, msg or "Vous ne pouvez pas accéder à ce menu")
|
||||||
return redirect(reverse('users:profil',
|
return redirect(reverse('users:profil',
|
||||||
kwargs={'userid':str(request.user.id)}
|
kwargs={'userid': str(
|
||||||
))
|
request.user.id)}
|
||||||
|
))
|
||||||
return view(request, *args, **kwargs)
|
return view(request, *args, **kwargs)
|
||||||
return wrapper
|
return wrapper
|
||||||
return decorator
|
return decorator
|
||||||
|
@ -121,14 +133,15 @@ def can_delete(model):
|
||||||
except model.DoesNotExist:
|
except model.DoesNotExist:
|
||||||
messages.error(request, u"Entrée inexistante")
|
messages.error(request, u"Entrée inexistante")
|
||||||
return redirect(reverse('users:profil',
|
return redirect(reverse('users:profil',
|
||||||
kwargs={'userid':str(request.user.id)}
|
kwargs={'userid': str(request.user.id)}
|
||||||
))
|
))
|
||||||
can, msg = instance.can_delete(request.user)
|
can, msg = instance.can_delete(request.user)
|
||||||
if not can:
|
if not can:
|
||||||
messages.error(request, msg or "Vous ne pouvez pas accéder à ce menu")
|
messages.error(
|
||||||
|
request, msg or "Vous ne pouvez pas accéder à ce menu")
|
||||||
return redirect(reverse('users:profil',
|
return redirect(reverse('users:profil',
|
||||||
kwargs={'userid':str(request.user.id)}
|
kwargs={'userid': str(request.user.id)}
|
||||||
))
|
))
|
||||||
return view(request, instance, *args, **kwargs)
|
return view(request, instance, *args, **kwargs)
|
||||||
return wrapper
|
return wrapper
|
||||||
return decorator
|
return decorator
|
||||||
|
@ -149,8 +162,8 @@ def can_delete_set(model):
|
||||||
if not instances:
|
if not instances:
|
||||||
messages.error(request, "Vous ne pouvez pas accéder à ce menu")
|
messages.error(request, "Vous ne pouvez pas accéder à ce menu")
|
||||||
return redirect(reverse('users:profil',
|
return redirect(reverse('users:profil',
|
||||||
kwargs={'userid':str(request.user.id)}
|
kwargs={'userid': str(request.user.id)}
|
||||||
))
|
))
|
||||||
return view(request, instances, *args, **kwargs)
|
return view(request, instances, *args, **kwargs)
|
||||||
return wrapper
|
return wrapper
|
||||||
return decorator
|
return decorator
|
||||||
|
@ -170,14 +183,15 @@ def can_view(model):
|
||||||
except model.DoesNotExist:
|
except model.DoesNotExist:
|
||||||
messages.error(request, u"Entrée inexistante")
|
messages.error(request, u"Entrée inexistante")
|
||||||
return redirect(reverse('users:profil',
|
return redirect(reverse('users:profil',
|
||||||
kwargs={'userid':str(request.user.id)}
|
kwargs={'userid': str(request.user.id)}
|
||||||
))
|
))
|
||||||
can, msg = instance.can_view(request.user)
|
can, msg = instance.can_view(request.user)
|
||||||
if not can:
|
if not can:
|
||||||
messages.error(request, msg or "Vous ne pouvez pas accéder à ce menu")
|
messages.error(
|
||||||
|
request, msg or "Vous ne pouvez pas accéder à ce menu")
|
||||||
return redirect(reverse('users:profil',
|
return redirect(reverse('users:profil',
|
||||||
kwargs={'userid':str(request.user.id)}
|
kwargs={'userid': str(request.user.id)}
|
||||||
))
|
))
|
||||||
return view(request, instance, *args, **kwargs)
|
return view(request, instance, *args, **kwargs)
|
||||||
return wrapper
|
return wrapper
|
||||||
return decorator
|
return decorator
|
||||||
|
@ -190,10 +204,11 @@ def can_view_all(model):
|
||||||
def wrapper(request, *args, **kwargs):
|
def wrapper(request, *args, **kwargs):
|
||||||
can, msg = model.can_view_all(request.user)
|
can, msg = model.can_view_all(request.user)
|
||||||
if not can:
|
if not can:
|
||||||
messages.error(request, msg or "Vous ne pouvez pas accéder à ce menu")
|
messages.error(
|
||||||
|
request, msg or "Vous ne pouvez pas accéder à ce menu")
|
||||||
return redirect(reverse('users:profil',
|
return redirect(reverse('users:profil',
|
||||||
kwargs={'userid':str(request.user.id)}
|
kwargs={'userid': str(request.user.id)}
|
||||||
))
|
))
|
||||||
return view(request, *args, **kwargs)
|
return view(request, *args, **kwargs)
|
||||||
return wrapper
|
return wrapper
|
||||||
return decorator
|
return decorator
|
||||||
|
@ -203,16 +218,17 @@ def can_view_app(app_name):
|
||||||
"""Decorator to check if an user can view an application.
|
"""Decorator to check if an user can view an application.
|
||||||
"""
|
"""
|
||||||
assert app_name in sys.modules.keys()
|
assert app_name in sys.modules.keys()
|
||||||
|
|
||||||
def decorator(view):
|
def decorator(view):
|
||||||
def wrapper(request, *args, **kwargs):
|
def wrapper(request, *args, **kwargs):
|
||||||
app = sys.modules[app_name]
|
app = sys.modules[app_name]
|
||||||
can,msg = app.can_view(request.user)
|
can, msg = app.can_view(request.user)
|
||||||
if can:
|
if can:
|
||||||
return view(request, *args, **kwargs)
|
return view(request, *args, **kwargs)
|
||||||
messages.error(request, msg)
|
messages.error(request, msg)
|
||||||
return redirect(reverse('users:profil',
|
return redirect(reverse('users:profil',
|
||||||
kwargs={'userid':str(request.user.id)}
|
kwargs={'userid': str(request.user.id)}
|
||||||
))
|
))
|
||||||
return wrapper
|
return wrapper
|
||||||
return decorator
|
return decorator
|
||||||
|
|
||||||
|
@ -223,11 +239,10 @@ def can_edit_history(view):
|
||||||
if request.user.has_perm('admin.change_logentry'):
|
if request.user.has_perm('admin.change_logentry'):
|
||||||
return view(request, *args, **kwargs)
|
return view(request, *args, **kwargs)
|
||||||
messages.error(
|
messages.error(
|
||||||
request,
|
request,
|
||||||
"Vous ne pouvez pas éditer l'historique."
|
"Vous ne pouvez pas éditer l'historique."
|
||||||
)
|
)
|
||||||
return redirect(reverse('users:profil',
|
return redirect(reverse('users:profil',
|
||||||
kwargs={'userid':str(request.user.id)}
|
kwargs={'userid': str(request.user.id)}
|
||||||
))
|
))
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
|
|
|
@ -36,6 +36,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
<meta property="og:url" content="\\{{request.get_host}}" />
|
<meta property="og:url" content="\\{{request.get_host}}" />
|
||||||
<meta property="og:image" content="\\{{request.get_host}}/static/logo/re2o.png"/>
|
<meta property="og:image" content="\\{{request.get_host}}/static/logo/re2o.png"/>
|
||||||
<meta property="og:description" content="Site de gestion de réseau supporté par FedeRez." />
|
<meta property="og:description" content="Site de gestion de réseau supporté par FedeRez." />
|
||||||
|
<script defer src="https://use.fontawesome.com/releases/v5.0.8/js/all.js"></script>
|
||||||
{# Load CSS and JavaScript #}
|
{# Load CSS and JavaScript #}
|
||||||
{% bootstrap_css %}
|
{% bootstrap_css %}
|
||||||
<link href="/static/css/typeaheadjs.css" rel="stylesheet">
|
<link href="/static/css/typeaheadjs.css" rel="stylesheet">
|
||||||
|
@ -69,22 +70,28 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
</div>
|
</div>
|
||||||
<div class="collapse navbar-collapse" id="myNavbar">
|
<div class="collapse navbar-collapse" id="myNavbar">
|
||||||
<ul class="nav navbar-nav">
|
<ul class="nav navbar-nav">
|
||||||
<li><a href="{% url "users:mon-profil" %}">Mon profil</a></li>
|
<li><a href="{% url "users:mon-profil" %}"><i class="fa fa-user"></i> Mon profil</a></li>
|
||||||
{% can_view_app users %}
|
{% can_view_any_app users machines cotisations %}
|
||||||
|
<li class="dropdown">
|
||||||
<li><a href="{% url "users:index" %}">Adhérents</a></li>
|
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><i class="fa fa-users"></i> Adhérents<span class="caret"></span></a>
|
||||||
{% acl_end %}
|
<ul class="dropdown-menu">
|
||||||
{% can_view_app machines %}
|
{% can_view_app users %}
|
||||||
<li><a href="{% url "machines:index" %}">Machines</a></li>
|
<li><a href="{% url 'users:index' %}"><i class="fa fa-users"></i> Voir les adhérents</a></li>
|
||||||
{% acl_end %}
|
{% acl_end %}
|
||||||
{% can_view_app cotisations %}
|
{% can_view_app machines %}
|
||||||
<li><a href="{% url "cotisations:index" %}">Cotisations</a></li>
|
<li><a href="{% url 'machines:index' %}"><i class="fa fa-desktop"></i> Voir les machines</a></li>
|
||||||
|
{% acl_end %}
|
||||||
|
{% can_view_app cotisations %}
|
||||||
|
<li><a href="{% url 'cotisations:index' %}"><i class="fa fa-dollar-sign"></i> Voir les cotisations</a></li>
|
||||||
|
{% acl_end %}
|
||||||
|
</ul>
|
||||||
|
</li>
|
||||||
{% acl_end %}
|
{% acl_end %}
|
||||||
{% can_view_app topologie %}
|
{% can_view_app topologie %}
|
||||||
<li><a href="{% url "topologie:index" %}">Topologie</a></li>
|
<li><a href="{% url "topologie:index" %}"><i class="fa fa-sitemap"></i> Topologie</a></li>
|
||||||
{% acl_end %}
|
{% acl_end %}
|
||||||
{% can_view_app logs %}
|
{% can_view_app logs %}
|
||||||
<li><a href="{% url "logs:index" %}">Statistiques</a></li>
|
<li><a href="{% url "logs:index" %}"><i class="fa fa-chart-area"></i> Statistiques</a></li>
|
||||||
{% acl_end %}
|
{% acl_end %}
|
||||||
</ul>
|
</ul>
|
||||||
<div class="col-sm-3 col-md-3 navbar-right">
|
<div class="col-sm-3 col-md-3 navbar-right">
|
||||||
|
@ -92,8 +99,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
<div class="input-group">
|
<div class="input-group">
|
||||||
<input type="text" class="form-control" placeholder="Search" name="q" id="search-term" {% if search_term %}value="{{ search_term }}"{% endif %}>
|
<input type="text" class="form-control" placeholder="Search" name="q" id="search-term" {% if search_term %}value="{{ search_term }}"{% endif %}>
|
||||||
<div class="input-group-btn">
|
<div class="input-group-btn">
|
||||||
<button class="btn btn-default" type="submit"><i class="glyphicon glyphicon-search"></i></button>
|
<button class="btn btn-default" type="submit"><i class="fa fa-search"></i></button>
|
||||||
<a href="{% url "search:searchp" %}" class="btn btn-default" role="button"><i class="glyphicon glyphicon-plus"></i></a>
|
<a href="{% url "search:searchp" %}" class="btn btn-default" role="button"><i class="fa fa-plus"></i></a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
@ -102,20 +109,20 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
{% if request.user.is_authenticated %}
|
{% if request.user.is_authenticated %}
|
||||||
<li>
|
<li>
|
||||||
<a href="{% url 'logout' %}">
|
<a href="{% url 'logout' %}">
|
||||||
<span class="glyphicon glyphicon-log-out"></span> Logout
|
<i class="fa fa-sign-out-alt"></i> Logout
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
{% else %}
|
{% else %}
|
||||||
{% if var_sa %}
|
{% if var_sa %}
|
||||||
<li>
|
<li>
|
||||||
<a href="{% url 'users:new-user' %}">
|
<a href="{% url 'users:new-user' %}">
|
||||||
<span class="glyphicon glyphicon-user"></span> Créer un compte
|
<i class="fa fa-user-plus"></i> Créer un compte
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<li>
|
<li>
|
||||||
<a href="{% url 'login' %}">
|
<a href="{% url 'login' %}">
|
||||||
<span class="glyphicon glyphicon-log-in"></span> Login
|
<i class="fa fa-sign-in-alt"></i> Login
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -124,7 +131,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
<ul class="nav navbar-nav navbar-right">
|
<ul class="nav navbar-nav navbar-right">
|
||||||
<li>
|
<li>
|
||||||
<a href="{% url 'preferences:display-options' %}">
|
<a href="{% url 'preferences:display-options' %}">
|
||||||
<span class="glyphicon glyphicon-cog"></span> Preferences
|
<i class="fa fa-cogs"></i> Preferences
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
@ -187,7 +194,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
</table>
|
</table>
|
||||||
<div class="list-group">
|
<div class="list-group">
|
||||||
<a class="list-group-item list-group-item-info" role="button"href="{% url "users:mon-profil" %}">
|
<a class="list-group-item list-group-item-info" role="button"href="{% url "users:mon-profil" %}">
|
||||||
<i class="glyphicon glyphicon-user"></i>
|
<i class="fa fa-user-circle"></i>
|
||||||
Voir mon profil
|
Voir mon profil
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in a new issue