8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-12-27 01:13:46 +00:00

Templates tags can_change class

This commit is contained in:
Gabriel Detraz 2017-12-29 12:34:49 +01:00 committed by root
parent 0b4a6b2582
commit b087235087
5 changed files with 11 additions and 12 deletions

View file

@ -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 = {

View file

@ -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>

View file

@ -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:
# 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:

View file

@ -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):

View file

@ -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 %}