# Share view refactoring
* refactors share views for eiv, oek, ema (kom does not have any)
This commit is contained in:
parent
3a9c4e13f6
commit
554ade6794
@ -5,29 +5,15 @@ Contact: ksp-servicestelle@sgdnord.rlp.de
|
|||||||
Created on: 19.08.22
|
Created on: 19.08.22
|
||||||
|
|
||||||
"""
|
"""
|
||||||
from django.contrib.auth.decorators import login_required
|
|
||||||
from django.utils.decorators import method_decorator
|
|
||||||
|
|
||||||
from compensation.models import EcoAccount
|
from compensation.models import EcoAccount
|
||||||
from konova.decorators import shared_access_required, default_group_required, login_required_modal
|
|
||||||
from konova.views.share import AbstractShareByTokenView, AbstractShareFormView
|
from konova.views.share import AbstractShareByTokenView, AbstractShareFormView
|
||||||
|
|
||||||
|
|
||||||
class EcoAccountShareByTokenView(AbstractShareByTokenView):
|
class EcoAccountShareByTokenView(AbstractShareByTokenView):
|
||||||
model = EcoAccount
|
_MODEL_CLS = EcoAccount
|
||||||
redirect_url = "compensation:acc:detail"
|
_REDIRECT_URL = "compensation:acc:detail"
|
||||||
|
|
||||||
@method_decorator(login_required)
|
|
||||||
def dispatch(self, request, *args, **kwargs):
|
|
||||||
return super().dispatch(request, *args, **kwargs)
|
|
||||||
|
|
||||||
|
|
||||||
class EcoAccountShareFormView(AbstractShareFormView):
|
class EcoAccountShareFormView(AbstractShareFormView):
|
||||||
model = EcoAccount
|
_MODEL_CLS = EcoAccount
|
||||||
|
_REDIRECT_URL = "compensation:acc:detail"
|
||||||
@method_decorator(login_required_modal)
|
|
||||||
@method_decorator(login_required)
|
|
||||||
@method_decorator(default_group_required)
|
|
||||||
@method_decorator(shared_access_required(EcoAccount, "id"))
|
|
||||||
def dispatch(self, request, *args, **kwargs):
|
|
||||||
return super().dispatch(request, *args, **kwargs)
|
|
||||||
|
|||||||
@ -5,29 +5,17 @@ Contact: ksp-servicestelle@sgdnord.rlp.de
|
|||||||
Created on: 19.08.22
|
Created on: 19.08.22
|
||||||
|
|
||||||
"""
|
"""
|
||||||
from django.contrib.auth.decorators import login_required
|
|
||||||
from django.utils.decorators import method_decorator
|
|
||||||
|
|
||||||
from ema.models import Ema
|
from ema.models import Ema
|
||||||
from konova.decorators import conservation_office_group_required, shared_access_required, login_required_modal
|
|
||||||
from konova.views.share import AbstractShareByTokenView, AbstractShareFormView
|
from konova.views.share import AbstractShareByTokenView, AbstractShareFormView
|
||||||
|
|
||||||
|
|
||||||
class EmaShareByTokenView(AbstractShareByTokenView):
|
class EmaShareByTokenView(AbstractShareByTokenView):
|
||||||
model = Ema
|
_MODEL_CLS = Ema
|
||||||
redirect_url = "ema:detail"
|
_REDIRECT_URL = "ema:detail"
|
||||||
|
|
||||||
@method_decorator(login_required)
|
|
||||||
def dispatch(self, request, *args, **kwargs):
|
|
||||||
return super().dispatch(request, *args, **kwargs)
|
|
||||||
|
|
||||||
|
|
||||||
class EmaShareFormView(AbstractShareFormView):
|
class EmaShareFormView(AbstractShareFormView):
|
||||||
model = Ema
|
_MODEL_CLS = Ema
|
||||||
|
_REDIRECT_URL = "ema:detail"
|
||||||
|
|
||||||
@method_decorator(login_required_modal)
|
def _user_has_permission(self, user):
|
||||||
@method_decorator(login_required)
|
return user.is_ets_user()
|
||||||
@method_decorator(conservation_office_group_required)
|
|
||||||
@method_decorator(shared_access_required(Ema, "id"))
|
|
||||||
def dispatch(self, request, *args, **kwargs):
|
|
||||||
return super().dispatch(request, *args, **kwargs)
|
|
||||||
@ -5,29 +5,15 @@ Contact: ksp-servicestelle@sgdnord.rlp.de
|
|||||||
Created on: 19.08.22
|
Created on: 19.08.22
|
||||||
|
|
||||||
"""
|
"""
|
||||||
from django.contrib.auth.decorators import login_required
|
|
||||||
from django.utils.decorators import method_decorator
|
|
||||||
|
|
||||||
from intervention.models import Intervention
|
from intervention.models import Intervention
|
||||||
from konova.decorators import default_group_required, shared_access_required, login_required_modal
|
|
||||||
from konova.views.share import AbstractShareByTokenView, AbstractShareFormView
|
from konova.views.share import AbstractShareByTokenView, AbstractShareFormView
|
||||||
|
|
||||||
|
|
||||||
class InterventionShareByTokenView(AbstractShareByTokenView):
|
class InterventionShareByTokenView(AbstractShareByTokenView):
|
||||||
model = Intervention
|
_MODEL_CLS = Intervention
|
||||||
redirect_url = "intervention:detail"
|
_REDIRECT_URL = "intervention:detail"
|
||||||
|
|
||||||
@method_decorator(login_required)
|
|
||||||
def dispatch(self, request, *args, **kwargs):
|
|
||||||
return super().dispatch(request, *args, **kwargs)
|
|
||||||
|
|
||||||
|
|
||||||
class InterventionShareFormView(AbstractShareFormView):
|
class InterventionShareFormView(AbstractShareFormView):
|
||||||
model = Intervention
|
_MODEL_CLS = Intervention
|
||||||
|
_REDIRECT_URL = "intervention:detail"
|
||||||
@method_decorator(login_required_modal)
|
|
||||||
@method_decorator(login_required)
|
|
||||||
@method_decorator(default_group_required)
|
|
||||||
@method_decorator(shared_access_required(Intervention, "id"))
|
|
||||||
def dispatch(self, request, *args, **kwargs):
|
|
||||||
return super().dispatch(request, *args, **kwargs)
|
|
||||||
@ -6,24 +6,24 @@ Created on: 22.08.22
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
|
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||||
from django.shortcuts import get_object_or_404, redirect
|
from django.shortcuts import get_object_or_404, redirect
|
||||||
from django.views import View
|
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
from intervention.forms.modals.share import ShareModalForm
|
from intervention.forms.modals.share import ShareModalForm
|
||||||
from konova.utils.message_templates import DATA_SHARE_SET
|
from konova.utils.message_templates import DATA_SHARE_SET
|
||||||
|
from konova.views.base import BaseView, BaseModalFormView
|
||||||
|
|
||||||
|
|
||||||
class AbstractShareByTokenView(View):
|
class AbstractShareByTokenView(LoginRequiredMixin, BaseView):
|
||||||
model = None
|
_MODEL_CLS = None
|
||||||
redirect_url = None
|
_REDIRECT_URL = None
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
abstract = True
|
abstract = True
|
||||||
|
|
||||||
def get(self, request, id: str, token: str):
|
def get(self, request, id: str, token: str):
|
||||||
|
""" Performs sharing of an entry
|
||||||
""" Performs sharing of an intervention
|
|
||||||
|
|
||||||
If token given in url is not valid, the user will be redirected to the dashboard
|
If token given in url is not valid, the user will be redirected to the dashboard
|
||||||
|
|
||||||
@ -36,7 +36,7 @@ class AbstractShareByTokenView(View):
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
user = request.user
|
user = request.user
|
||||||
obj = get_object_or_404(self.model, id=id)
|
obj = get_object_or_404(self._MODEL_CLS, id=id)
|
||||||
# Check tokens
|
# Check tokens
|
||||||
if obj.access_token == token:
|
if obj.access_token == token:
|
||||||
# Send different messages in case user has already been added to list of sharing users
|
# Send different messages in case user has already been added to list of sharing users
|
||||||
@ -51,7 +51,7 @@ class AbstractShareByTokenView(View):
|
|||||||
_("{} has been shared with you").format(obj.identifier)
|
_("{} has been shared with you").format(obj.identifier)
|
||||||
)
|
)
|
||||||
obj.share_with_user(user)
|
obj.share_with_user(user)
|
||||||
return redirect(self.redirect_url, id=id)
|
return redirect(self._REDIRECT_URL, id=id)
|
||||||
else:
|
else:
|
||||||
messages.error(
|
messages.error(
|
||||||
request,
|
request,
|
||||||
@ -60,29 +60,21 @@ class AbstractShareByTokenView(View):
|
|||||||
)
|
)
|
||||||
return redirect("home")
|
return redirect("home")
|
||||||
|
|
||||||
|
def _user_has_permission(self, user):
|
||||||
|
return user.is_default_user()
|
||||||
|
|
||||||
class AbstractShareFormView(View):
|
def _user_has_shared_access(self, user, **kwargs):
|
||||||
model = None
|
# The user does not need to have shared access to call the endpoint which gives them shared access
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
class AbstractShareFormView(LoginRequiredMixin, BaseModalFormView):
|
||||||
|
_MODEL_CLS = None
|
||||||
|
_FORM_CLS = ShareModalForm
|
||||||
|
_MSG_SUCCESS = DATA_SHARE_SET
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
abstract = True
|
abstract = True
|
||||||
|
|
||||||
def get(self, request, id: str):
|
def _user_has_permission(self, user):
|
||||||
""" Renders sharing form
|
return user.is_default_user()
|
||||||
|
|
||||||
Args:
|
|
||||||
request (HttpRequest): The incoming request
|
|
||||||
id (str): Object's id
|
|
||||||
|
|
||||||
Returns:
|
|
||||||
|
|
||||||
"""
|
|
||||||
obj = get_object_or_404(self.model, id=id)
|
|
||||||
form = ShareModalForm(request.POST or None, instance=obj, request=request)
|
|
||||||
return form.process_request(
|
|
||||||
request,
|
|
||||||
msg_success=DATA_SHARE_SET
|
|
||||||
)
|
|
||||||
|
|
||||||
def post(self, request, id: str):
|
|
||||||
return self.get(request, id)
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user