-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The most-frequent actions exposed on this UI make no sense: - You can't make the only email primary (it already is) - You can't remove your only email - Re-sending email to a verified email does nothing Let's try to mediate this a bit by just controlling what buttons are available for end users. This is a simple display-only fix that doesn't require any changes to the `django-allauth` backend.
- Loading branch information
Showing
3 changed files
with
205 additions
and
4 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 |
---|---|---|
|
@@ -270,3 +270,163 @@ def test_attempt_changing_to_insecure_password(self): | |
form_group = soup.find(class_="has-error") | ||
self.assertTrue(form_group) | ||
self.assertTrue(form_group.find(string="This password is too common.")) | ||
|
||
|
||
class ManageEmailsTest(TestCase): | ||
maxDiff = None | ||
|
||
def _get_buttons(self, user): | ||
self.client.force_login(user) | ||
response = self.client.get("/accounts/email/") | ||
soup = BeautifulSoup(response.content, "html.parser") | ||
form = soup.find("form", action="/accounts/email/") | ||
return {btn.text.strip(): btn.attrs for btn in form.find_all("button")} | ||
|
||
def test_one_primary_email(self): | ||
"""Test the usual case -- just one verified primary email.""" | ||
user = factories.UserFactory( | ||
emailaddress__primary=True, | ||
emailaddress__verified=True, | ||
) | ||
|
||
self.assertEqual( | ||
self._get_buttons(user), | ||
{ | ||
"Make Primary": { | ||
"class": ["btn", "btn-default"], | ||
"type": "submit", | ||
"disabled": "", | ||
"title": "Email address is already primary.", | ||
"name": "action_primary", | ||
}, | ||
# Notably "Re-send Verification" is missing entirely | ||
"Remove": { | ||
"class": ["btn", "btn-default"], | ||
"type": "submit", | ||
"disabled": "", | ||
"title": "Cannot remove your only email address.", | ||
"name": "action_remove", | ||
}, | ||
}, | ||
) | ||
|
||
def test_one_unverified_email(self): | ||
user = factories.UserFactory(emailaddress__verified=False) | ||
|
||
self.assertEqual( | ||
self._get_buttons(user), | ||
{ | ||
"Make Primary": { | ||
"class": ["btn", "btn-default"], | ||
"type": "submit", | ||
"disabled": "", | ||
"title": "Email address is already primary.", | ||
"name": "action_primary", | ||
}, | ||
"Re-send Verification": { | ||
"class": ["btn", "btn-default"], | ||
"type": "submit", | ||
"name": "action_send", | ||
}, | ||
"Remove": { | ||
"class": ["btn", "btn-default"], | ||
"type": "submit", | ||
"disabled": "", | ||
"title": "Cannot remove your only email address.", | ||
"name": "action_remove", | ||
}, | ||
}, | ||
) | ||
|
||
def test_two_verified_emails(self): | ||
"""With two emails, we can remove either or make either primary.""" | ||
user = factories.UserFactory() | ||
factories.EmailAddressFactory( | ||
user=user, | ||
email="[email protected]", | ||
primary=False, | ||
verified=True, | ||
) | ||
|
||
self.assertEqual( | ||
self._get_buttons(user), | ||
{ | ||
"Make Primary": { | ||
"class": ["btn", "btn-default"], | ||
"type": "submit", | ||
"name": "action_primary", | ||
}, | ||
# Notably "Re-send Verification" is missing entirely -- both are verified! | ||
"Remove": { | ||
"class": ["btn", "btn-default"], | ||
"type": "submit", | ||
"name": "action_remove", | ||
}, | ||
}, | ||
) | ||
|
||
def test_two_emails_but_one_unverified(self): | ||
"""Test the case of a newly-added but still unverified email.""" | ||
user = factories.UserFactory( | ||
emailaddress__verified=True, | ||
) | ||
factories.EmailAddressFactory( | ||
user=user, | ||
email="[email protected]", | ||
primary=False, | ||
verified=False, | ||
) | ||
|
||
self.assertEqual( | ||
self._get_buttons(user), | ||
{ | ||
"Make Primary": { | ||
"class": ["btn", "btn-default"], | ||
"type": "submit", | ||
"name": "action_primary", | ||
}, | ||
# Because there's at least one unverified email, we allow re-sending | ||
"Re-send Verification": { | ||
"class": ["btn", "btn-default"], | ||
"type": "submit", | ||
"name": "action_send", | ||
}, | ||
"Remove": { | ||
"class": ["btn", "btn-default"], | ||
"type": "submit", | ||
"name": "action_remove", | ||
}, | ||
}, | ||
) | ||
|
||
def test_multiple_unverified(self): | ||
"""You can still add an email even if one is unverified!""" | ||
user = factories.UserFactory() | ||
factories.EmailAddressFactory( | ||
user=user, | ||
email="[email protected]", | ||
primary=False, | ||
verified=False, | ||
) | ||
|
||
self.assertEqual( | ||
self._get_buttons(user), | ||
{ | ||
"Make Primary": { | ||
"class": ["btn", "btn-default"], | ||
"type": "submit", | ||
"name": "action_primary", | ||
}, | ||
# Because there's at least one unverified email, we allow re-sending | ||
"Re-send Verification": { | ||
"class": ["btn", "btn-default"], | ||
"type": "submit", | ||
"name": "action_send", | ||
}, | ||
"Remove": { | ||
"class": ["btn", "btn-default"], | ||
"type": "submit", | ||
"name": "action_remove", | ||
}, | ||
}, | ||
) |