Skip to content

Commit

Permalink
Merge branch 'release/0.3.71' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
erikvw committed Jan 25, 2024
2 parents f50bb83 + 3544ee1 commit 8f9d457
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 12 additions & 0 deletions edc_action_item/modelform_mixins/modelform_mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from typing import TYPE_CHECKING

from django import forms
from edc_sites.exceptions import InvalidSiteForSubjectError
from edc_sites.utils import valid_site_for_subject_or_raise

from ..exceptions import ActionError

Expand All @@ -14,6 +16,7 @@
class ActionItemModelFormMixin:
def clean(self):
cleaned_data = super().clean()
self.valididate_site_for_subject_or_raise()
action_cls = self._meta.model.get_action_cls()
if self.action_cls:
try:
Expand Down Expand Up @@ -44,3 +47,12 @@ def related_action_item(self) -> ActionItem:
return self.cleaned_data.get("related_action_item") or getattr(
self.instance, "related_action_item", None
)

def valididate_site_for_subject_or_raise(self):
if self.get_subject_identifier():
try:
valid_site_for_subject_or_raise(self.get_subject_identifier())
except InvalidSiteForSubjectError:
raise forms.ValidationError(
"Subject is not from this site. Please login to the correct site."
)
2 changes: 1 addition & 1 deletion edc_action_item/tests/tests/test_auths.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from importlib import import_module

from django.test import TestCase, override_settings
from edc_adverse_event.auth_objects import TMG_ROLE
from edc_adverse_event.constants import TMG_ROLE
from edc_auth.auth_updater import AuthUpdater
from edc_auth.site_auths import site_auths
from edc_data_manager.auth_objects import DATA_MANAGER_ROLE, SITE_DATA_MANAGER_ROLE
Expand Down

0 comments on commit 8f9d457

Please sign in to comment.