Browse Source

Fix can_view_app

release-2.9
Hugo Levy-Falk 5 years ago
committed by Gabriel Detraz
parent
commit
652982941a
  1. 2
      api/acl.py
  2. 2
      cotisations/acl.py
  3. 7
      logs/acl.py
  4. 5
      machines/acl.py
  5. 5
      preferences/acl.py
  6. 21
      re2o/utils.py
  7. 2
      search/acl.py
  8. 2
      topologie/acl.py
  9. 2
      users/acl.py

2
api/acl.py

@ -56,7 +56,7 @@ def _create_api_permission():
_create_api_permission() _create_api_permission()
def can_view(user): def can_view(user, *args, **kwargs):
"""Check if an user can view the application. """Check if an user can view the application.
Args: Args:

2
cotisations/acl.py

@ -28,7 +28,7 @@ Here are defined some functions to check acl on the application.
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
def can_view(user): def can_view(user, *args, **kwargs):
"""Check if an user can view the application. """Check if an user can view the application.
Args: Args:

7
logs/acl.py

@ -28,7 +28,7 @@ Here are defined some functions to check acl on the application.
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
def can_view(user): def can_view(user, *args, **kwargs):
"""Check if an user can view the application. """Check if an user can view the application.
Args: Args:
@ -41,7 +41,6 @@ def can_view(user):
can = user.has_module_perms("admin") can = user.has_module_perms("admin")
return ( return (
can, can,
None if can else _("You don't have the right to view this" None if can else _("You don't have the right to view this" " application."),
" application."), ("logs",),
"admin",
) )

5
machines/acl.py

@ -28,7 +28,7 @@ Here are defined some functions to check acl on the application.
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
def can_view(user): def can_view(user, *args, **kwargs):
"""Check if an user can view the application. """Check if an user can view the application.
Args: Args:
@ -41,7 +41,6 @@ def can_view(user):
can = user.has_module_perms("machines") can = user.has_module_perms("machines")
return ( return (
can, can,
None if can else _("You don't have the right to view this" None if can else _("You don't have the right to view this" " application."),
" application."),
("machines",), ("machines",),
) )

5
preferences/acl.py

@ -28,7 +28,7 @@ Here are defined some functions to check acl on the application.
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
def can_view(user): def can_view(user, *args, **kwargs):
"""Check if an user can view the application. """Check if an user can view the application.
Args: Args:
@ -41,7 +41,6 @@ def can_view(user):
can = user.has_module_perms("preferences") can = user.has_module_perms("preferences")
return ( return (
can, can,
None if can else _("You don't have the right to view this" None if can else _("You don't have the right to view this" " application."),
" application."),
("preferences",), ("preferences",),
) )

21
re2o/utils.py

@ -38,7 +38,7 @@ from __future__ import unicode_literals
from django.utils import timezone from django.utils import timezone
from django.db.models import Q from django.db.models import Q
from django.contrib.auth.models import Permission from django.contrib.auth.models import Permission, Group
from cotisations.models import Cotisation, Facture, Vente from cotisations.models import Cotisation, Facture, Vente
from machines.models import Interface, Machine from machines.models import Interface, Machine
@ -58,11 +58,20 @@ def get_group_having_permission(*permission_name):
""" """
groups = set() groups = set()
for name in permission_name: for name in permission_name:
app_label, codename = name.split(".") if "." in name:
permission = Permission.objects.get( app_label, codename = name.split(".")
content_type__app_label=app_label, codename=codename permission = Permission.objects.get(
) content_type__app_label=app_label, codename=codename
groups = groups.union(permission.group_set.all()) )
groups = groups.union(permission.group_set.all())
else:
groups = groups.union(
Group.objects.filter(
permissions__in=Permission.objects.filter(
content_type__app_label="users"
)
).distinct()
)
return groups return groups

2
search/acl.py

@ -27,7 +27,7 @@ Here are defined some functions to check acl on the application.
""" """
def can_view(_user): def can_view(*args, **kwargs):
"""Check if an user can view the application. """Check if an user can view the application.
Args: Args:

2
topologie/acl.py

@ -28,7 +28,7 @@ Here are defined some functions to check acl on the application.
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
def can_view(user): def can_view(user, *args, **kwargs):
"""Check if an user can view the application. """Check if an user can view the application.
Args: Args:

2
users/acl.py

@ -28,7 +28,7 @@ Here are defined some functions to check acl on the application.
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
def can_view(user): def can_view(user, *args, **kwargs):
"""Check if an user can view the application. """Check if an user can view the application.
Args: Args:

Loading…
Cancel
Save