Commit e39b0fc7 authored by hypsug0's avatar hypsug0
Browse files

refactor: Move CatchAuth to management.regulatory submodule

parent 1d99b1e3
......@@ -28,45 +28,3 @@ class ManagementAuthMixin:
return super(ManagementAuthMixin, self).dispatch(request, *args, **kwargs)
else:
return redirect("core:view_unauth")
class CatchAuthCreateAuthMixin:
"""
Permission de créer un arrêté d'autorisation dans les conditions suivantes:
L'utilisateur est superutilisateur,
L'utilisateur peut modifier Toutes les données,
L'utilisateur est responsable de territoire.
"""
def dispatch(self, request, *args, **kwargs):
if not request.user.is_authenticated:
return redirect("%s?next=%s" % (reverse("auth_login"), request.path))
else:
loggeduser = get_user_model().objects.get(id=request.user.id)
if loggeduser.is_superuser or loggeduser.edit_all_data or loggeduser.is_resp:
return super(CatchAuthCreateAuthMixin, self).dispatch(request, *args, **kwargs)
else:
return redirect("core:update_unauth")
class StudyAuthMixin:
"""
Classe mixin de vérification que l'utilisateur possède les droits de créer le compte
"""
def dispatch(self, request, *args, **kwargs):
if not request.user.is_authenticated:
return redirect("%s?next=%s" % (reverse("auth_login"), request.path))
else:
loggeduser = get_user_model().objects.get(id=request.user.id)
if (
loggeduser.edit_all_data
or loggeduser.access_all_data
or loggeduser.is_resp
or loggeduser.is_staff
or loggeduser.is_superuser
or self.obj.project_manager == loggeduser
):
return super(StudyAuthMixin, self).dispatch(request, *args, **kwargs)
else:
return redirect("core:view_unauth")
"""
Mixins
"""
from django.contrib.auth import get_user_model
from django.shortcuts import redirect
from django.urls import reverse
class CatchAuthCreateAuthMixin:
"""
Permission de créer un arrêté d'autorisation dans les conditions suivantes:
L'utilisateur est superutilisateur,
L'utilisateur peut modifier Toutes les données,
L'utilisateur est responsable de territoire.
"""
def dispatch(self, request, *args, **kwargs):
if not request.user.is_authenticated:
return redirect("%s?next=%s" % (reverse("auth_login"), request.path))
else:
loggeduser = get_user_model().objects.get(id=request.user.id)
if loggeduser.is_superuser or loggeduser.edit_all_data or loggeduser.is_resp:
return super(CatchAuthCreateAuthMixin, self).dispatch(request, *args, **kwargs)
else:
return redirect("core:update_unauth")
......@@ -13,10 +13,11 @@ from django_tables2 import SingleTableView
from core import js
from .forms import CatchAuthForm
from .mixins import CatchAuthCreateAuthMixin, ManagementAuthMixin
from .models import CatchAuth
from .tables import CatchAuthTable
from ..forms import CatchAuthForm
from ..mixins import ManagementAuthMixin
from ..models import CatchAuth
from ..tables import CatchAuthTable
from .mixins import CatchAuthCreateAuthMixin
class CatchAuthCreate(CatchAuthCreateAuthMixin, CreateView):
......
from django.urls import path
from .regulatory.views import CatchAuthCreate, CatchAuthDelete, CatchAuthList, CatchAuthUpdate
from .study.api import StudyDatasApi, StudyListApi
from .study.views import StudyCreate, StudyDelete, StudyDetail, StudyList, StudyUpdate
from .transmitter.api import TransmitterSearchApi
......@@ -9,7 +10,6 @@ from .transmitter.views import (
TransmitterList,
TransmitterUpdate,
)
from .views import CatchAuthCreate, CatchAuthDelete, CatchAuthList, CatchAuthUpdate
app_name = "management"
......
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