mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-08-13 04:59:59 +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.
|
# Check if a user is set without accessing the related object.
|
||||||
has_user = bool(self.user_id)
|
has_user = bool(self.user_id)
|
||||||
if has_user:
|
if has_user:
|
||||||
existing_permission_pks = UserPortfolioPermission.objects.filter(user=self.user).values_list("pk", flat=True)
|
existing_permission_pks = UserPortfolioPermission.objects.filter(user=self.user).values_list(
|
||||||
if not flag_is_active_for_user(self.user, "multiple_portfolios") and existing_permission_pks.exists() and not self.pk in existing_permission_pks:
|
"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(
|
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."
|
||||||
|
|
|
@ -34,6 +34,7 @@ from waffle.testutils import override_flag
|
||||||
|
|
||||||
from api.tests.common import less_console_noise_decorator
|
from api.tests.common import less_console_noise_decorator
|
||||||
|
|
||||||
|
|
||||||
class TestDomainInformation(TestCase):
|
class TestDomainInformation(TestCase):
|
||||||
"""Test the DomainInformation model, when approved or otherwise"""
|
"""Test the DomainInformation model, when approved or otherwise"""
|
||||||
|
|
||||||
|
@ -329,6 +330,8 @@ class TestUserPortfolioPermission(TestCase):
|
||||||
portfolio_permission.clean()
|
portfolio_permission.clean()
|
||||||
portfolio_permission_2.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:
|
with self.assertRaises(ValidationError) as cm:
|
||||||
portfolio_permission_2.user = self.user
|
portfolio_permission_2.user = self.user
|
||||||
portfolio_permission_2.clean()
|
portfolio_permission_2.clean()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue