Ce serveur Gitlab sera éteint le 30 juin 2020, pensez à migrer vos projets vers les serveurs gitlab-research.centralesupelec.fr et gitlab-student.centralesupelec.fr !

Commit 9f7d994c authored by Gabriel Detraz's avatar Gabriel Detraz Committed by root

Templates tags can_change class

parent f8428568
...@@ -149,10 +149,10 @@ class Facture(FieldPermissionModelMixin, models.Model): ...@@ -149,10 +149,10 @@ class Facture(FieldPermissionModelMixin, models.Model):
else: else:
return True, None return True, None
def can_change_control(self, user, *args, **kwargs): def can_change_control(user, *args, **kwargs):
return user.has_perms(('tresorier',)), "Vous ne pouvez pas éditer le controle sans droit trésorier" return user.has_perms(('tresorier',)), "Vous ne pouvez pas éditer le controle sans droit trésorier"
def can_change_pdf(self, user, *args, **kwargs): def can_change_pdf(user, *args, **kwargs):
return user.has_perms(('tresorier',)), "Vous ne pouvez pas éditer une facture sans droit trésorier" return user.has_perms(('tresorier',)), "Vous ne pouvez pas éditer une facture sans droit trésorier"
field_permissions = { field_permissions = {
......
...@@ -26,16 +26,16 @@ with this program; if not, write to the Free Software Foundation, Inc., ...@@ -26,16 +26,16 @@ with this program; if not, write to the Free Software Foundation, Inc.,
{% load acl %} {% load acl %}
{% block sidebar %} {% block sidebar %}
{% can_create Facture %} {% can_change Facture pdf %}
<a class="list-group-item list-group-item-success" href="{% url "cotisations:new-facture-pdf" %}"> <a class="list-group-item list-group-item-success" href="{% url "cotisations:new-facture-pdf" %}">
<i class="glyphicon glyphicon-plus"></i> <i class="glyphicon glyphicon-plus"></i>
Créer une facture Créer une facture
</a> </a>
{% acl_end %}
<a class="list-group-item list-group-item-warning" href="{% url "cotisations:control" %}"> <a class="list-group-item list-group-item-warning" href="{% url "cotisations:control" %}">
<i class="glyphicon glyphicon-eye-open"></i> <i class="glyphicon glyphicon-eye-open"></i>
Contrôler les factures Contrôler les factures
</a> </a>
{% acl_end %}
{% can_view_all Facture %} {% can_view_all Facture %}
<a class="list-group-item list-group-item-info" href="{% url "cotisations:index" %}"> <a class="list-group-item list-group-item-info" href="{% url "cotisations:index" %}">
<i class="glyphicon glyphicon-list"></i> <i class="glyphicon glyphicon-list"></i>
......
...@@ -17,9 +17,6 @@ class FieldPermissionModelMixin: ...@@ -17,9 +17,6 @@ class FieldPermissionModelMixin:
checks = self.field_permissions[field] checks = self.field_permissions[field]
if not isinstance(checks, (list, tuple)): if not isinstance(checks, (list, tuple)):
checks = [checks] checks = [checks]
for i, perm in enumerate(checks):
if callable(perm):
checks[i] = partial(perm, field=field)
else: else:
checks = [] checks = []
...@@ -45,7 +42,7 @@ class FieldPermissionModelMixin: ...@@ -45,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(self, user=user) result, reason = perm(user=user)
if result is not None: if result is not None:
return result return result
else: else:
......
...@@ -820,13 +820,13 @@ class User(FieldPermissionModelMixin, AbstractBaseUser): ...@@ -820,13 +820,13 @@ 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(self, user_request, *args, **kwargs): def can_change_state(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(self, user_request, *args, **kwargs): def can_change_shell(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 changer le shell"
def can_change_force(self, user_request, *args, **kwargs): def can_change_force(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):
......
...@@ -81,8 +81,10 @@ with this program; if not, write to the Free Software Foundation, Inc., ...@@ -81,8 +81,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<i class="glyphicon glyphicon-trash"></i> <i class="glyphicon glyphicon-trash"></i>
Retirer un droit Retirer un droit
</a> </a>
{% can_change User state %}
<a class="list-group-item list-group-item-danger" href="{% url "users:mass-archive" %}"> <a class="list-group-item list-group-item-danger" href="{% url "users:mass-archive" %}">
<i class="glyphicon glyphicon-book"></i> <i class="glyphicon glyphicon-book"></i>
Archiver en masse Archiver en masse
</a> </a>
{% acl_end %}
{% endblock %} {% endblock %}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment