diff --git a/compensation/views/eco_account.py b/compensation/views/eco_account.py index 2c5340ab..ea058bf5 100644 --- a/compensation/views/eco_account.py +++ b/compensation/views/eco_account.py @@ -19,7 +19,7 @@ from compensation.forms.modalForms import NewStateModalForm, NewActionModalForm, NewEcoAccountDocumentForm from compensation.models import EcoAccount, EcoAccountDocument, CompensationState, CompensationAction from compensation.tables import EcoAccountTable -from intervention.forms.modalForms import NewDeductionModalForm, ShareInterventionModalForm +from intervention.forms.modalForms import NewDeductionModalForm, ShareModalForm from konova.contexts import BaseContext from konova.decorators import any_group_check, default_group_required, conservation_office_group_required, \ shared_access_required @@ -642,7 +642,7 @@ def create_share_view(request: HttpRequest, id: str): """ obj = get_object_or_404(EcoAccount, id=id) - form = ShareInterventionModalForm(request.POST or None, instance=obj, request=request) + form = ShareModalForm(request.POST or None, instance=obj, request=request) return form.process_request( request, msg_success=_("Share settings updated") diff --git a/ema/views.py b/ema/views.py index 783dc7c7..22f6e651 100644 --- a/ema/views.py +++ b/ema/views.py @@ -10,11 +10,11 @@ from compensation.forms.modalForms import NewStateModalForm, NewActionModalForm, from compensation.models import CompensationAction, CompensationState from ema.forms import NewEmaForm, EditEmaForm, NewEmaDocumentForm from ema.tables import EmaTable -from intervention.forms.modalForms import ShareInterventionModalForm +from intervention.forms.modalForms import ShareModalForm from konova.contexts import BaseContext from konova.decorators import conservation_office_group_required, shared_access_required from ema.models import Ema, EmaDocument -from konova.forms import RemoveModalForm, NewDocumentForm, SimpleGeomForm, RecordModalForm +from konova.forms import RemoveModalForm, SimpleGeomForm, RecordModalForm from konova.settings import DEFAULT_GROUP, ZB_GROUP, ETS_GROUP from konova.utils.documents import get_document, remove_document from konova.utils.generators import generate_qr_code @@ -546,7 +546,7 @@ def create_share_view(request: HttpRequest, id: str): """ obj = get_object_or_404(Ema, id=id) - form = ShareInterventionModalForm(request.POST or None, instance=obj, request=request) + form = ShareModalForm(request.POST or None, instance=obj, request=request) return form.process_request( request, msg_success=_("Share settings updated") diff --git a/intervention/forms/modalForms.py b/intervention/forms/modalForms.py index 4d9abec4..26aaa6b0 100644 --- a/intervention/forms/modalForms.py +++ b/intervention/forms/modalForms.py @@ -20,7 +20,7 @@ from konova.utils.general import format_german_float from konova.utils.user_checks import is_default_group_only -class ShareInterventionModalForm(BaseModalForm): +class ShareModalForm(BaseModalForm): url = forms.CharField( label=_("Share link"), label_suffix="", diff --git a/intervention/models/intervention.py b/intervention/models/intervention.py index e75c215f..64949559 100644 --- a/intervention/models/intervention.py +++ b/intervention/models/intervention.py @@ -284,25 +284,6 @@ class Intervention(BaseObject, ShareableObjectMixin, RecordableObjectMixin, Chec ) return deduction - def update_sharing_user(self, form): - """ Adds a new user with shared access to the intervention - - Args: - form (ShareInterventionModalForm): The form holding the data - - Returns: - - """ - form_data = form.cleaned_data - - keep_accessing_users = form_data["users"] - new_accessing_users = list(form_data["user_select"].values_list("id", flat=True)) - accessing_users = keep_accessing_users + new_accessing_users - users = User.objects.filter( - id__in=accessing_users - ) - self.share_with_list(users) - class InterventionDocument(AbstractDocument): """ diff --git a/intervention/views.py b/intervention/views.py index f79ae5f4..512285be 100644 --- a/intervention/views.py +++ b/intervention/views.py @@ -4,7 +4,7 @@ from django.http import HttpRequest, JsonResponse from django.shortcuts import render from intervention.forms.forms import NewInterventionForm, EditInterventionForm -from intervention.forms.modalForms import ShareInterventionModalForm, NewRevocationModalForm, \ +from intervention.forms.modalForms import ShareModalForm, NewRevocationModalForm, \ CheckModalForm, NewDeductionModalForm, NewInterventionDocumentForm from intervention.models import Intervention, Revocation, InterventionDocument, RevocationDocument from intervention.tables import InterventionTable @@ -402,7 +402,7 @@ def create_share_view(request: HttpRequest, id: str): """ intervention = get_object_or_404(Intervention, id=id) - form = ShareInterventionModalForm(request.POST or None, instance=intervention, request=request, user=request.user) + form = ShareModalForm(request.POST or None, instance=intervention, request=request, user=request.user) return form.process_request( request, msg_success=_("Share settings updated") diff --git a/konova/models/object.py b/konova/models/object.py index d62130cc..fce4d1bc 100644 --- a/konova/models/object.py +++ b/konova/models/object.py @@ -396,3 +396,22 @@ class ShareableObjectMixin(models.Model): """ self.users.set(user_list) + + def update_sharing_user(self, form): + """ Adds a new user with shared access to the object + + Args: + form (ShareModalForm): The form holding the data + + Returns: + + """ + form_data = form.cleaned_data + + keep_accessing_users = form_data["users"] + new_accessing_users = list(form_data["user_select"].values_list("id", flat=True)) + accessing_users = keep_accessing_users + new_accessing_users + users = User.objects.filter( + id__in=accessing_users + ) + self.share_with_list(users)