mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-30 00:22:25 +00:00
Fix can_view_app
This commit is contained in:
parent
f4c5101b35
commit
652982941a
9 changed files with 27 additions and 21 deletions
|
@ -56,7 +56,7 @@ def _create_api_permission():
|
|||
_create_api_permission()
|
||||
|
||||
|
||||
def can_view(user):
|
||||
def can_view(user, *args, **kwargs):
|
||||
"""Check if an user can view the application.
|
||||
|
||||
Args:
|
||||
|
|
|
@ -28,7 +28,7 @@ Here are defined some functions to check acl on the application.
|
|||
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.
|
||||
|
||||
Args:
|
||||
|
|
|
@ -28,7 +28,7 @@ Here are defined some functions to check acl on the application.
|
|||
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.
|
||||
|
||||
Args:
|
||||
|
@ -41,7 +41,6 @@ def can_view(user):
|
|||
can = user.has_module_perms("admin")
|
||||
return (
|
||||
can,
|
||||
None if can else _("You don't have the right to view this"
|
||||
" application."),
|
||||
"admin",
|
||||
None if can else _("You don't have the right to view this" " application."),
|
||||
("logs",),
|
||||
)
|
||||
|
|
|
@ -28,7 +28,7 @@ Here are defined some functions to check acl on the application.
|
|||
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.
|
||||
|
||||
Args:
|
||||
|
@ -41,7 +41,6 @@ def can_view(user):
|
|||
can = user.has_module_perms("machines")
|
||||
return (
|
||||
can,
|
||||
None if can else _("You don't have the right to view this"
|
||||
" application."),
|
||||
None if can else _("You don't have the right to view this" " application."),
|
||||
("machines",),
|
||||
)
|
||||
|
|
|
@ -28,7 +28,7 @@ Here are defined some functions to check acl on the application.
|
|||
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.
|
||||
|
||||
Args:
|
||||
|
@ -41,7 +41,6 @@ def can_view(user):
|
|||
can = user.has_module_perms("preferences")
|
||||
return (
|
||||
can,
|
||||
None if can else _("You don't have the right to view this"
|
||||
" application."),
|
||||
None if can else _("You don't have the right to view this" " application."),
|
||||
("preferences",),
|
||||
)
|
||||
|
|
|
@ -38,7 +38,7 @@ from __future__ import unicode_literals
|
|||
|
||||
from django.utils import timezone
|
||||
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 machines.models import Interface, Machine
|
||||
|
@ -58,11 +58,20 @@ def get_group_having_permission(*permission_name):
|
|||
"""
|
||||
groups = set()
|
||||
for name in permission_name:
|
||||
app_label, codename = name.split(".")
|
||||
permission = Permission.objects.get(
|
||||
content_type__app_label=app_label, codename=codename
|
||||
)
|
||||
groups = groups.union(permission.group_set.all())
|
||||
if "." in name:
|
||||
app_label, codename = name.split(".")
|
||||
permission = Permission.objects.get(
|
||||
content_type__app_label=app_label, codename=codename
|
||||
)
|
||||
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
|
||||
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
||||
Args:
|
||||
|
|
|
@ -28,7 +28,7 @@ Here are defined some functions to check acl on the application.
|
|||
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.
|
||||
|
||||
Args:
|
||||
|
|
|
@ -28,7 +28,7 @@ Here are defined some functions to check acl on the application.
|
|||
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.
|
||||
|
||||
Args:
|
||||
|
|
Loading…
Reference in a new issue