8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-27 15:12:25 +00:00

Les can_change deviennent des class method

This commit is contained in:
Gabriel Detraz 2017-12-29 18:32:57 +01:00 committed by root
parent 9f7d994c4a
commit 20be7fdb63
5 changed files with 56 additions and 51 deletions

View file

@ -149,11 +149,13 @@ class Facture(FieldPermissionModelMixin, models.Model):
else: else:
return True, None return True, None
def can_change_control(user, *args, **kwargs): @classmethod
return user.has_perms(('tresorier',)), "Vous ne pouvez pas éditer le controle sans droit trésorier" def can_change_control(cls, user_request, *args, **kwargs):
return user_request.has_perms(('tresorier',)), "Vous ne pouvez pas éditer le controle sans droit trésorier"
def can_change_pdf(user, *args, **kwargs): @classmethod
return user.has_perms(('tresorier',)), "Vous ne pouvez pas éditer une facture sans droit trésorier" def can_change_pdf(cls, user_request, *args, **kwargs):
return user_request.has_perms(('tresorier',)), "Vous ne pouvez pas éditer une facture sans droit trésorier"
field_permissions = { field_permissions = {
'control': can_change_control, 'control': can_change_control,

View file

@ -42,7 +42,7 @@ class FieldPermissionModelMixin:
# Try to find a user setting that qualifies them for permission. # Try to find a user setting that qualifies them for permission.
for perm in checks: for perm in checks:
if callable(perm): if callable(perm):
result, reason = perm(user=user) result, reason = perm(user_request=user)
if result is not None: if result is not None:
return result return result
else: else:

View file

@ -820,13 +820,16 @@ class User(FieldPermissionModelMixin, AbstractBaseUser):
else: else:
return False, u"Vous ne pouvez éditer un autre utilisateur que vous même" return False, u"Vous ne pouvez éditer un autre utilisateur que vous même"
def can_change_state(user_request, *args, **kwargs): @classmethod
def can_change_state(cls, user_request, *args, **kwargs):
return user_request.has_perms(('bureau',)), "Droit bureau requis pour changer l'état" return user_request.has_perms(('bureau',)), "Droit bureau requis pour changer l'état"
def can_change_shell(user_request, *args, **kwargs): @classmethod
def can_change_shell(cls, user_request, *args, **kwargs):
return user_request.has_perms(('cableur',)), "Droit requis pour changer le shell" return user_request.has_perms(('cableur',)), "Droit requis pour changer le shell"
def can_change_force(user_request, *args, **kwargs): @classmethod
def can_change_force(cls, user_request, *args, **kwargs):
return user_request.has_perms(('cableur',)), "Droit requis pour forcer le déménagement" return user_request.has_perms(('cableur',)), "Droit requis pour forcer le déménagement"
def can_delete(self, user_request, *args, **kwargs): def can_delete(self, user_request, *args, **kwargs):

View file

@ -28,25 +28,25 @@ with this program; if not, write to the Free Software Foundation, Inc.,
{% block title %}Profil{% endblock %} {% block title %}Profil{% endblock %}
{% block content %} {% block content %}
<h2>{{ user.class_name }}</h2> <h2>{{ users.class_name }}</h2>
<div> <div>
<a class="btn btn-primary btn-sm" role="button" href="{% url 'users:edit-info' user.id %}"> <a class="btn btn-primary btn-sm" role="button" href="{% url 'users:edit-info' users.id %}">
<i class="glyphicon glyphicon-edit"></i> <i class="glyphicon glyphicon-edit"></i>
Editer Editer
</a> </a>
<a class="btn btn-primary btn-sm" role="button" href="{% url 'users:password' user.id %}"> <a class="btn btn-primary btn-sm" role="button" href="{% url 'users:password' users.id %}">
<i class="glyphicon glyphicon-lock"></i> <i class="glyphicon glyphicon-lock"></i>
Changer le mot de passe Changer le mot de passe
</a> </a>
<a class="btn btn-primary btn-sm" role="button" href="{% url 'users:state' user.id %}"> <a class="btn btn-primary btn-sm" role="button" href="{% url 'users:state' users.id %}">
<i class="glyphicon glyphicon-flash"></i> <i class="glyphicon glyphicon-flash"></i>
Changer le statut Changer le statut
</a> </a>
<a class="btn btn-primary btn-sm" role="button" href="{% url 'users:add-right' user.id %}"> <a class="btn btn-primary btn-sm" role="button" href="{% url 'users:add-right' users.id %}">
<i class="glyphicon glyphicon-ok"></i> <i class="glyphicon glyphicon-ok"></i>
Ajouter un droit Ajouter un droit
</a> </a>
<a class="btn btn-info btn-sm" role="button" href="{% url 'users:history' 'user' user.id %}"> <a class="btn btn-info btn-sm" role="button" href="{% url 'users:history' 'user' users.id %}">
<i class="glyphicon glyphicon-time"></i> <i class="glyphicon glyphicon-time"></i>
Historique Historique
</a> </a>
@ -57,58 +57,58 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<table class="table table-striped"> <table class="table table-striped">
<tr> <tr>
<th>Prénom</th> <th>Prénom</th>
<td>{{ user.name }}</td> <td>{{ users.name }}</td>
<th>Nom</th> <th>Nom</th>
<td>{{ user.surname }}</td> <td>{{ users.surname }}</td>
</tr> </tr>
<tr> <tr>
<th>Pseudo</th> <th>Pseudo</th>
<td>{{ user.pseudo }}</td> <td>{{ users.pseudo }}</td>
<th>E-mail</th> <th>E-mail</th>
<td>{{ user.email }}</td> <td>{{ users.email }}</td>
</tr> </tr>
<tr> <tr>
<th>Chambre</th> <th>Chambre</th>
<td>{{ user.room }}</td> <td>{{ users.room }}</td>
<th>Téléphone</th> <th>Téléphone</th>
<td>{{ user.telephone }}</td> <td>{{ users.telephone }}</td>
</tr> </tr>
<tr> <tr>
<th>École</th> <th>École</th>
<td>{{ user.school }}</td> <td>{{ users.school }}</td>
<th>Commentaire</th> <th>Commentaire</th>
<td>{{ user.comment }}</td> <td>{{ users.comment }}</td>
</tr> </tr>
<tr> <tr>
<th>Date d'inscription</th> <th>Date d'inscription</th>
<td>{{ user.registered }}</td> <td>{{ users.registered }}</td>
<th>Dernière connexion</th> <th>Dernière connexion</th>
<td>{{ user.last_login }}</td> <td>{{ users.last_login }}</td>
</tr> </tr>
<tr> <tr>
<th>Fin d'adhésion</th> <th>Fin d'adhésion</th>
{% if user.end_adhesion != None %} {% if users.end_adhesion != None %}
<td><i class="text-success">{{ user.end_adhesion }}</i></td> <td><i class="text-success">{{ users.end_adhesion }}</i></td>
{% else %} {% else %}
<td><i class="text-danger">Non adhérent</i></td> <td><i class="text-danger">Non adhérent</i></td>
{% endif %} {% endif %}
<th>Accès gracieux</th> <th>Accès gracieux</th>
{% if user.end_whitelist != None %} {% if users.end_whitelist != None %}
<td><i class="text-success">{{ user.end_whitelist }}</i></td> <td><i class="text-success">{{ users.end_whitelist }}</i></td>
{% else %} {% else %}
<td><i class="text-warning">Aucun</i></td> <td><i class="text-warning">Aucun</i></td>
{% endif %} {% endif %}
<tr> <tr>
<th>Bannissement</th> <th>Bannissement</th>
{% if user.end_ban != None %} {% if users.end_ban != None %}
<td><i class="text-danger">{{ user.end_ban }}</i></td> <td><i class="text-danger">{{ users.end_ban }}</i></td>
{% else %} {% else %}
<td><i class="text-success">Non banni</i></td> <td><i class="text-success">Non banni</i></td>
{% endif %} {% endif %}
<th>Statut</th> <th>Statut</th>
{% if user.state == 0 %} {% if users.state == 0 %}
<td><i class="text-success">Actif</i></td> <td><i class="text-success">Actif</i></td>
{% elif user.state == 1 %} {% elif users.state == 1 %}
<td><i class="text-danger">Désactivé</i></td> <td><i class="text-danger">Désactivé</i></td>
{% else %} {% else %}
<td><i class="text-warning">Archivé</i></td> <td><i class="text-warning">Archivé</i></td>
@ -116,8 +116,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
</tr> </tr>
<tr> <tr>
<th>Accès internet</th> <th>Accès internet</th>
{% if user.has_access == True %} {% if users.has_access == True %}
<td><i class="text-success">Actif (jusqu'au {{ user.end_access }})</i></td> <td><i class="text-success">Actif (jusqu'au {{ users.end_access }})</i></td>
{% else %} {% else %}
<td><i class="text-danger">Désactivé</i></td> <td><i class="text-danger">Désactivé</i></td>
{% endif %} {% endif %}
@ -131,16 +131,16 @@ with this program; if not, write to the Free Software Foundation, Inc.,
{% if user_solde %} {% if user_solde %}
<tr> <tr>
<th>Solde</th> <th>Solde</th>
<td>{{ user.solde }} €</td> <td>{{ users.solde }} €</td>
</tr> </tr>
{% endif %} {% endif %}
{% if user.shell %} {% if users.shell %}
<th>Shell</th> <th>Shell</th>
<td>{{ user.shell }}</td> <td>{{ users.shell }}</td>
{% endif %} {% endif %}
</table> </table>
{% if user.is_class_club %} {% if users.is_class_club %}
<a class="btn btn-primary btn-sm" role="button" href="{% url 'users:edit-club-admin-members' user.club.id %}"> <a class="btn btn-primary btn-sm" role="button" href="{% url 'users:edit-club-admin-members' users.club.id %}">
<i class="glyphicon glyphicon-lock"></i> <i class="glyphicon glyphicon-lock"></i>
Gérer admin et membres Gérer admin et membres
</a> </a>
@ -153,7 +153,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<th>Pseudo</th> <th>Pseudo</th>
</tr> </tr>
</thead> </thead>
{% for admin in user.club.administrators.all %} {% for admin in users.club.administrators.all %}
<tr> <tr>
<td>{{ admin.surname }}</td> <td>{{ admin.surname }}</td>
<td>{{ admin.name }}</td> <td>{{ admin.name }}</td>
@ -170,7 +170,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<th>Pseudo</th> <th>Pseudo</th>
</tr> </tr>
</thead> </thead>
{% for admin in user.club.members.all %} {% for admin in users.club.members.all %}
<tr> <tr>
<td>{{ admin.surname }}</td> <td>{{ admin.surname }}</td>
<td>{{ admin.name }}</td> <td>{{ admin.name }}</td>
@ -180,28 +180,28 @@ with this program; if not, write to the Free Software Foundation, Inc.,
</table> </table>
{% endif %} {% endif %}
<h2>Machines</h2> <h2>Machines</h2>
<h4><a class="btn btn-primary btn-sm" role="button" href="{% url 'machines:new-machine' user.id %}"><i class="glyphicon glyphicon-phone"></i> Ajouter une machine</a></h4> <h4><a class="btn btn-primary btn-sm" role="button" href="{% url 'machines:new-machine' users.id %}"><i class="glyphicon glyphicon-phone"></i> Ajouter une machine</a></h4>
{% if machines_list %} {% if machines_list %}
{% include "machines/aff_machines.html" with machines_list=machines_list %} {% include "machines/aff_machines.html" with machines_list=machines_list %}
{% else %} {% else %}
<p>Aucune machine</p> <p>Aucune machine</p>
{% endif %} {% endif %}
<h2>Cotisations</h2> <h2>Cotisations</h2>
<h4>{% can_create Facture %}<a class="btn btn-primary btn-sm" role="button" href="{% url 'cotisations:new-facture' user.id %}"><i class="glyphicon glyphicon-piggy-bank"></i> Ajouter une cotisation</a>{% acl_end %} {% if user_solde %}<a class="btn btn-primary btn-sm" role="button" href="{% url 'cotisations:credit-solde' user.id %}"><i class="glyphicon glyphicon-piggy-bank"></i> Modifier le solde</a>{% endif%}</h4> <h4>{% can_create Facture %}<a class="btn btn-primary btn-sm" role="button" href="{% url 'cotisations:new-facture' users.id %}"><i class="glyphicon glyphicon-piggy-bank"></i> Ajouter une cotisation</a>{% acl_end %} {% if user_solde %}<a class="btn btn-primary btn-sm" role="button" href="{% url 'cotisations:credit-solde' users.id %}"><i class="glyphicon glyphicon-piggy-bank"></i> Modifier le solde</a>{% endif%}</h4>
{% if facture_list %} {% if facture_list %}
{% include "cotisations/aff_cotisations.html" with facture_list=facture_list %} {% include "cotisations/aff_cotisations.html" with facture_list=facture_list %}
{% else %} {% else %}
<p>Aucune facture</p> <p>Aucune facture</p>
{% endif %} {% endif %}
<h2>Bannissements</h2> <h2>Bannissements</h2>
{% can_create Ban %}<h4><a class="btn btn-primary btn-sm" role="button" href="{% url 'users:add-ban' user.id %}"><i class="glyphicon glyphicon-pushpin"></i> Ajouter un bannissement</a></h4>{% acl_end %} {% can_create Ban %}<h4><a class="btn btn-primary btn-sm" role="button" href="{% url 'users:add-ban' users.id %}"><i class="glyphicon glyphicon-pushpin"></i> Ajouter un bannissement</a></h4>{% acl_end %}
{% if ban_list %} {% if ban_list %}
{% include "users/aff_bans.html" with ban_list=ban_list %} {% include "users/aff_bans.html" with ban_list=ban_list %}
{% else %} {% else %}
<p>Aucun bannissement</p> <p>Aucun bannissement</p>
{% endif %} {% endif %}
<h2>Accès à titre gracieux :</h2> <h2>Accès à titre gracieux :</h2>
{% can_create Whitelist %}<h4><a class="btn btn-primary btn-sm" role="button" href="{% url 'users:add-whitelist' user.id %}"><i class="glyphicon glyphicon-flag"></i> Accorder un accès à titre gracieux</a></h4>{% acl_end %} {% can_create Whitelist %}<h4><a class="btn btn-primary btn-sm" role="button" href="{% url 'users:add-whitelist' users.id %}"><i class="glyphicon glyphicon-flag"></i> Accorder un accès à titre gracieux</a></h4>{% acl_end %}
{% if white_list %} {% if white_list %}
{% include "users/aff_whitelists.html" with white_list=white_list %} {% include "users/aff_whitelists.html" with white_list=white_list %}
{% else %} {% else %}

View file

@ -124,7 +124,7 @@ def password_change_action(u_form, user, request, req=False):
def new_user(request): def new_user(request):
""" Vue de création d'un nouvel utilisateur, """ Vue de création d'un nouvel utilisateur,
envoie un mail pour le mot de passe""" envoie un mail pour le mot de passe"""
user = AdherentForm(request.POST or None) user = AdherentForm(request.POST or None, user=request.user)
if user.is_valid(): if user.is_valid():
user = user.save(commit=False) user = user.save(commit=False)
with transaction.atomic(), reversion.create_revision(): with transaction.atomic(), reversion.create_revision():
@ -146,7 +146,7 @@ def new_user(request):
def new_club(request): def new_club(request):
""" Vue de création d'un nouveau club, """ Vue de création d'un nouveau club,
envoie un mail pour le mot de passe""" envoie un mail pour le mot de passe"""
club = ClubForm(request.POST or None) club = ClubForm(request.POST or None, user=request.user)
if club.is_valid(): if club.is_valid():
club = club.save(commit=False) club = club.save(commit=False)
with transaction.atomic(), reversion.create_revision(): with transaction.atomic(), reversion.create_revision():
@ -803,7 +803,7 @@ def profil(request, users, userid):
request, request,
'users/profil.html', 'users/profil.html',
{ {
'user': users, 'users': users,
'machines_list': machines, 'machines_list': machines,
'facture_list': factures, 'facture_list': factures,
'ban_list': bans, 'ban_list': bans,