-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3388 from cisagov/bob/2711-domain-mgr-remove
#2711: Domain manager view - remove manager when only one manager
- Loading branch information
Showing
5 changed files
with
80 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -721,6 +721,7 @@ def tearDown(self): | |
"""Ensure that the user has its original permissions""" | ||
PortfolioInvitation.objects.all().delete() | ||
UserPortfolioPermission.objects.all().delete() | ||
UserDomainRole.objects.all().delete() | ||
User.objects.exclude(id=self.user.id).delete() | ||
super().tearDown() | ||
|
||
|
@@ -1258,8 +1259,8 @@ def test_domain_invitation_cancel_retrieved_invitation(self): | |
response = self.client.post(reverse("invitation-cancel", kwargs={"pk": invitation.id}), follow=True) | ||
# Assert that an error message is displayed to the user | ||
self.assertContains(response, f"Invitation to {email_address} has already been retrieved.") | ||
# Assert that the Cancel link is not displayed | ||
self.assertNotContains(response, "Cancel") | ||
# Assert that the Cancel link (form) is not displayed | ||
self.assertNotContains(response, f"/invitation/{invitation.id}/cancel") | ||
# Assert that the DomainInvitation is not deleted | ||
self.assertTrue(DomainInvitation.objects.filter(id=invitation.id).exists()) | ||
DomainInvitation.objects.filter(email=email_address).delete() | ||
|
@@ -1317,6 +1318,57 @@ def test_domain_invitation_flow(self): | |
home_page = self.app.get(reverse("home")) | ||
self.assertContains(home_page, self.domain.name) | ||
|
||
@less_console_noise_decorator | ||
def test_domain_user_role_delete(self): | ||
"""Posting to the delete view deletes a user domain role.""" | ||
# add two managers to the domain so that one can be successfully deleted | ||
email_address = "[email protected]" | ||
new_user = User.objects.create(email=email_address, username="mayor") | ||
email_address_2 = "[email protected]" | ||
new_user_2 = User.objects.create(email=email_address_2, username="secondmayor") | ||
user_domain_role = UserDomainRole.objects.create( | ||
user=new_user, domain=self.domain, role=UserDomainRole.Roles.MANAGER | ||
) | ||
UserDomainRole.objects.create(user=new_user_2, domain=self.domain, role=UserDomainRole.Roles.MANAGER) | ||
response = self.client.post( | ||
reverse("domain-user-delete", kwargs={"pk": self.domain.id, "user_pk": new_user.id}), follow=True | ||
) | ||
# Assert that a success message is displayed to the user | ||
self.assertContains(response, f"Removed {email_address} as a manager for this domain.") | ||
# Assert that the second user is displayed | ||
self.assertContains(response, f"{email_address_2}") | ||
# Assert that the UserDomainRole is deleted | ||
self.assertFalse(UserDomainRole.objects.filter(id=user_domain_role.id).exists()) | ||
|
||
@less_console_noise_decorator | ||
def test_domain_user_role_delete_only_manager(self): | ||
"""Posting to the delete view attempts to delete a user domain role when there is only one manager.""" | ||
# self.user is the only domain manager, so attempt to delete it | ||
response = self.client.post( | ||
reverse("domain-user-delete", kwargs={"pk": self.domain.id, "user_pk": self.user.id}), follow=True | ||
) | ||
# Assert that an error message is displayed to the user | ||
self.assertContains(response, "Domains must have at least one domain manager.") | ||
# Assert that the user is still displayed | ||
self.assertContains(response, f"{self.user.email}") | ||
# Assert that the UserDomainRole still exists | ||
self.assertTrue(UserDomainRole.objects.filter(user=self.user, domain=self.domain).exists()) | ||
|
||
@less_console_noise_decorator | ||
def test_domain_user_role_delete_self_delete(self): | ||
"""Posting to the delete view attempts to delete a user domain role when there is only one manager.""" | ||
# add one manager, so there are two and the logged in user, self.user, can be deleted | ||
email_address = "[email protected]" | ||
new_user = User.objects.create(email=email_address, username="mayor") | ||
UserDomainRole.objects.create(user=new_user, domain=self.domain, role=UserDomainRole.Roles.MANAGER) | ||
response = self.client.post( | ||
reverse("domain-user-delete", kwargs={"pk": self.domain.id, "user_pk": self.user.id}), follow=True | ||
) | ||
# Assert that a success message is displayed to the user | ||
self.assertContains(response, f"You are no longer managing the domain {self.domain}.") | ||
# Assert that the UserDomainRole no longer exists | ||
self.assertFalse(UserDomainRole.objects.filter(user=self.user, domain=self.domain).exists()) | ||
|
||
|
||
class TestDomainNameservers(TestDomainOverview, MockEppLib): | ||
@less_console_noise_decorator | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters