mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-08-02 16:02:15 +02:00
linted + comments
This commit is contained in:
parent
f0b0e9d246
commit
f1be3fafeb
2 changed files with 14 additions and 5 deletions
|
@ -110,8 +110,14 @@ class UserPortfolioPermission(TimeStampedModel):
|
|||
# Check if a user is set without accessing the related object.
|
||||
has_user = bool(self.user_id)
|
||||
if has_user:
|
||||
existing_permission_pks = UserPortfolioPermission.objects.filter(user=self.user).values_list("pk", flat=True)
|
||||
if not flag_is_active_for_user(self.user, "multiple_portfolios") and existing_permission_pks.exists() and not self.pk in existing_permission_pks:
|
||||
existing_permission_pks = UserPortfolioPermission.objects.filter(user=self.user).values_list(
|
||||
"pk", flat=True
|
||||
)
|
||||
if (
|
||||
not flag_is_active_for_user(self.user, "multiple_portfolios")
|
||||
and existing_permission_pks.exists()
|
||||
and self.pk not in existing_permission_pks
|
||||
):
|
||||
raise ValidationError(
|
||||
"This user is already assigned to a portfolio. "
|
||||
"Based on current waffle flag settings, users cannot be assigned to multiple portfolios."
|
||||
|
|
|
@ -34,6 +34,7 @@ from waffle.testutils import override_flag
|
|||
|
||||
from api.tests.common import less_console_noise_decorator
|
||||
|
||||
|
||||
class TestDomainInformation(TestCase):
|
||||
"""Test the DomainInformation model, when approved or otherwise"""
|
||||
|
||||
|
@ -282,7 +283,7 @@ class TestUserPortfolioPermission(TestCase):
|
|||
portfolio_permission_2.clean()
|
||||
except ValidationError as error:
|
||||
self.fail(f"Raised ValidationError unexpectedly: {error}")
|
||||
|
||||
|
||||
@less_console_noise_decorator
|
||||
@override_flag("multiple_portfolios", active=False)
|
||||
def test_clean_on_creates_multiple_portfolios(self):
|
||||
|
@ -310,7 +311,7 @@ class TestUserPortfolioPermission(TestCase):
|
|||
"Based on current waffle flag settings, users cannot be assigned to multiple portfolios."
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
@less_console_noise_decorator
|
||||
@override_flag("multiple_portfolios", active=False)
|
||||
def test_multiple_portfolio_reassignment(self):
|
||||
|
@ -328,7 +329,9 @@ class TestUserPortfolioPermission(TestCase):
|
|||
# This should work as intended
|
||||
portfolio_permission.clean()
|
||||
portfolio_permission_2.clean()
|
||||
|
||||
|
||||
# Reassign the portfolio of "user2" to "user" (this should throw an error
|
||||
# preventing "user" from having multiple portfolios)
|
||||
with self.assertRaises(ValidationError) as cm:
|
||||
portfolio_permission_2.user = self.user
|
||||
portfolio_permission_2.clean()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue