mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-08-11 20:19:38 +02:00
Merge branch 'main' into nl/2855-add-searchbar-visible-labels
This commit is contained in:
commit
ebdd9041b8
3 changed files with 36 additions and 14 deletions
|
@ -445,3 +445,28 @@ class PortfolioNewMemberForm(BasePortfolioMemberForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = PortfolioInvitation
|
model = PortfolioInvitation
|
||||||
fields = ["portfolio", "email", "roles", "additional_permissions"]
|
fields = ["portfolio", "email", "roles", "additional_permissions"]
|
||||||
|
|
||||||
|
def _post_clean(self):
|
||||||
|
"""
|
||||||
|
Override _post_clean to customize model validation errors.
|
||||||
|
This runs after form clean is complete, but before the errors are displayed.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
super()._post_clean()
|
||||||
|
self.instance.clean()
|
||||||
|
except forms.ValidationError as e:
|
||||||
|
override_error = False
|
||||||
|
if hasattr(e, "code"):
|
||||||
|
field = "email" if "email" in self.fields else None
|
||||||
|
if e.code == "has_existing_permissions":
|
||||||
|
self.add_error(field, f"{self.instance.email} is already a member of another .gov organization.")
|
||||||
|
override_error = True
|
||||||
|
elif e.code == "has_existing_invitations":
|
||||||
|
self.add_error(
|
||||||
|
field, f"{self.instance.email} has already been invited to another .gov organization."
|
||||||
|
)
|
||||||
|
override_error = True
|
||||||
|
|
||||||
|
# Errors denoted as "__all__" are special error types reserved for the model level clean function
|
||||||
|
if override_error and "__all__" in self._errors:
|
||||||
|
del self._errors["__all__"]
|
||||||
|
|
|
@ -292,7 +292,8 @@ def validate_user_portfolio_permission(user_portfolio_permission):
|
||||||
if existing_permissions.exists():
|
if existing_permissions.exists():
|
||||||
raise ValidationError(
|
raise ValidationError(
|
||||||
"This user is already assigned to a portfolio. "
|
"This user is already assigned to a portfolio. "
|
||||||
"Based on current waffle flag settings, users cannot be assigned to multiple portfolios."
|
"Based on current waffle flag settings, users cannot be assigned to multiple portfolios.",
|
||||||
|
code="has_existing_permissions",
|
||||||
)
|
)
|
||||||
|
|
||||||
existing_invitations = PortfolioInvitation.objects.filter(email=user_portfolio_permission.user.email).exclude(
|
existing_invitations = PortfolioInvitation.objects.filter(email=user_portfolio_permission.user.email).exclude(
|
||||||
|
@ -302,7 +303,8 @@ def validate_user_portfolio_permission(user_portfolio_permission):
|
||||||
if existing_invitations.exists():
|
if existing_invitations.exists():
|
||||||
raise ValidationError(
|
raise ValidationError(
|
||||||
"This user is already assigned to a portfolio invitation. "
|
"This user is already assigned to a portfolio invitation. "
|
||||||
"Based on current waffle flag settings, users cannot be assigned to multiple portfolios."
|
"Based on current waffle flag settings, users cannot be assigned to multiple portfolios.",
|
||||||
|
code="has_existing_invitations",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -350,6 +352,7 @@ def validate_portfolio_invitation(portfolio_invitation):
|
||||||
|
|
||||||
# == Validate the multiple_porfolios flag. == #
|
# == Validate the multiple_porfolios flag. == #
|
||||||
user = User.objects.filter(email=portfolio_invitation.email).first()
|
user = User.objects.filter(email=portfolio_invitation.email).first()
|
||||||
|
|
||||||
# If user returns None, then we check for global assignment of multiple_portfolios.
|
# If user returns None, then we check for global assignment of multiple_portfolios.
|
||||||
# Otherwise we just check on the user.
|
# Otherwise we just check on the user.
|
||||||
if not flag_is_active_for_user(user, "multiple_portfolios"):
|
if not flag_is_active_for_user(user, "multiple_portfolios"):
|
||||||
|
@ -362,13 +365,15 @@ def validate_portfolio_invitation(portfolio_invitation):
|
||||||
if existing_permissions.exists():
|
if existing_permissions.exists():
|
||||||
raise ValidationError(
|
raise ValidationError(
|
||||||
"This user is already assigned to a portfolio. "
|
"This user is already assigned to a portfolio. "
|
||||||
"Based on current waffle flag settings, users cannot be assigned to multiple portfolios."
|
"Based on current waffle flag settings, users cannot be assigned to multiple portfolios.",
|
||||||
|
code="has_existing_permissions",
|
||||||
)
|
)
|
||||||
|
|
||||||
if existing_invitations.exists():
|
if existing_invitations.exists():
|
||||||
raise ValidationError(
|
raise ValidationError(
|
||||||
"This user is already assigned to a portfolio invitation. "
|
"This user is already assigned to a portfolio invitation. "
|
||||||
"Based on current waffle flag settings, users cannot be assigned to multiple portfolios."
|
"Based on current waffle flag settings, users cannot be assigned to multiple portfolios.",
|
||||||
|
code="has_existing_invitations",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -3873,11 +3873,7 @@ class TestPortfolioInviteNewMemberView(MockEppLib, WebTest):
|
||||||
# verify messages
|
# verify messages
|
||||||
self.assertContains(
|
self.assertContains(
|
||||||
response,
|
response,
|
||||||
(
|
f"{self.invited_member_email} has already been invited to another .gov organization.",
|
||||||
"This user is already assigned to a portfolio invitation. "
|
|
||||||
"Based on current waffle flag settings, users cannot be assigned "
|
|
||||||
"to multiple portfolios."
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# Validate Database has not changed
|
# Validate Database has not changed
|
||||||
|
@ -3915,11 +3911,7 @@ class TestPortfolioInviteNewMemberView(MockEppLib, WebTest):
|
||||||
# Verify messages
|
# Verify messages
|
||||||
self.assertContains(
|
self.assertContains(
|
||||||
response,
|
response,
|
||||||
(
|
f"{self.user.email} is already a member of another .gov organization.",
|
||||||
"This user is already assigned to a portfolio. "
|
|
||||||
"Based on current waffle flag settings, users cannot be "
|
|
||||||
"assigned to multiple portfolios."
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# Validate Database has not changed
|
# Validate Database has not changed
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue