|
@@ -1,9 +1,9 @@
|
|
from django.contrib.auth.models import Group
|
|
from django.contrib.auth.models import Group
|
|
from django.dispatch import receiver
|
|
from django.dispatch import receiver
|
|
from django.db.models.signals import post_migrate
|
|
from django.db.models.signals import post_migrate
|
|
-from django.contrib.auth.decorators import user_passes_test
|
|
|
|
|
|
|
|
-#Создание групп
|
|
|
|
|
|
+
|
|
|
|
+# Создание групп
|
|
@receiver(post_migrate)
|
|
@receiver(post_migrate)
|
|
def create_groups(sender, **kwargs):
|
|
def create_groups(sender, **kwargs):
|
|
Group.objects.get_or_create(pk=21, name='METASERVICE-ADMIN')
|
|
Group.objects.get_or_create(pk=21, name='METASERVICE-ADMIN')
|
|
@@ -19,15 +19,5 @@ def create_groups(sender, **kwargs):
|
|
Group.objects.get_or_create(pk=41, name='PROVIDER')
|
|
Group.objects.get_or_create(pk=41, name='PROVIDER')
|
|
Group.objects.get_or_create(pk=51, name='CLIENT')
|
|
Group.objects.get_or_create(pk=51, name='CLIENT')
|
|
Group.objects.get_or_create(pk=61, name='GUEST')
|
|
Group.objects.get_or_create(pk=61, name='GUEST')
|
|
-
|
|
|
|
-
|
|
|
|
|
|
|
|
-# Функция позволяющая определить принадлежность к группе, перенаправляет на авторизацию
|
|
|
|
-def group_required(*group_names):
|
|
|
|
- def in_groups(u):
|
|
|
|
- if u.is_authenticated:
|
|
|
|
- if u.groups.filter(name=group_names).exists() or u.is_superuser:
|
|
|
|
- return True
|
|
|
|
- return False
|
|
|
|
|
|
|
|
- return user_passes_test(in_groups)
|
|
|