Merge lp:~jcsackett/launchpad/no-canonical-urls-628247 into lp:launchpad
Status: | Merged | ||||
---|---|---|---|---|---|
Approved by: | Aaron Bentley | ||||
Approved revision: | no longer in the source branch. | ||||
Merged at revision: | 11561 | ||||
Proposed branch: | lp:~jcsackett/launchpad/no-canonical-urls-628247 | ||||
Merge into: | lp:launchpad | ||||
Diff against target: |
193 lines (+91/-13) 3 files modified
lib/canonical/launchpad/interfaces/emailaddress.py (+1/-2) lib/canonical/launchpad/interfaces/validation.py (+32/-10) lib/lp/registry/browser/tests/test_person_view.py (+58/-1) |
||||
To merge this branch: | bzr merge lp:~jcsackett/launchpad/no-canonical-urls-628247 | ||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Aaron Bentley (community) | Approve | ||
Review via email: mp+35301@code.launchpad.net |
Commit message
Fixes a bad condition in canonical validation of team email addresses; now instead of assuming that if an email is taken in LP there must be a team, it finds all associations with that email before returning errors.
Description of the change
Summary
=======
Fixes a condition which raised an OOPS on team creation when emails were taken.
Proposed Fix
============
Create or improve a checker for email addresses so that the condition can't happen.
Pre-implementation notes
=======
Spoke with Curtis Hovey (sinzui) who proposed that the error wasn't actually where the OOPS was raised, but earlier in checking the availability of the email address entered.
Implementation details
=======
Adds a function to get the highest order association of an email (Person/Team, then Account, then the Email model instance itself, then None). This is used to craft an appropriate error message. Previously the checker assumed that if an email was already in the LP db, then a person must exist--it was in crafting the error message with this assumed person that NoCanonicalURL would be raised.
Tests
=====
bin/test -t TestTeamCreation
Demo and Q/A
============
If you create an Account without a Person in the database for launchpad.dev, then try to add a team via the web interface with that email address, it should inform you in an error on contactemail that an account uses that email address. Previously it would OOPS.
Lint
====
Checking for conflicts and issues in changed files.
Linting changed files:
lib/canonical
lib/canonical
lib/canonical
lib/lp/
./lib/canonical
65: E302 expected 2 blank lines, found 1
Error in validation.py is from the linter getting confused about whitespace around comments.
Diff from the last change:
=== modified file 'lib/canonical/ launchpad/ database/ emailaddress. py' launchpad/ database/ emailaddress. py 2010-09-13 16:17:51 +0000 launchpad/ database/ emailaddress. py 2010-09-13 19:29:21 +0000
personID= personID,
account= account)
--- lib/canonical/
+++ lib/canonical/
@@ -145,22 +145,6 @@
- def getEmailAssocia tion(self, email): t`.""" (email) person is not None: person account is not None: account
- """See IEmailAddressSe
- # First check if the email address is in use.
- email_address = self.getByEmail
- if email_address is None:
- # If the email address doesn't exist in the system, it is
- # available.
- return
-
- # The email already exists; determine what has it.
- if email_address.
- return email_address.
- if email_address.
- return email_address.
- return email_address
-
class UndeletableEmai lAddress( Exception) :
"""User attempted to delete an email address which can't be deleted."""
=== modified file 'lib/canonical/ launchpad/ interfaces/ emailaddress. py' launchpad/ interfaces/ emailaddress. py 2010-09-13 16:17:51 +0000 launchpad/ interfaces/ emailaddress. py 2010-09-13 19:29:21 +0000
--- lib/canonical/
+++ lib/canonical/
@@ -153,12 +153,3 @@
Return None if there is no such email address. tion(email) :
"""
-
- def getEmailAssocia
- """Return the entity associated with the email.
-
- Returns the person or team with the email, if one exists. If not,
- returns the account with the email, if it exists. If it doesn't,
- return the email model instance, if it exists. If it doesn't, return
- None.
- """
=== modified file 'lib/canonical/ launchpad/ interfaces/ validation. py' launchpad/ interfaces/ validation. py 2010-09-13 16:17:51 +0000 launchpad/ interfaces/ validation. py 2010-09-13 19:29:21 +0000 launchpad. interfaces. launchpad import ILaunchBag launchpad. interfaces. account import IAccount launchpad. interfaces. emailaddress import IEmailAddress launchpad. interfaces. emailaddress import ( launchpad. validators import LaunchpadValida tionError launchpad. validators. cve import valid_cve launchpad. validators. email import valid_email launchpad. validators. url import valid_absolute_url launchpad. webapp. menu import structured
--- lib/canonical/
+++ lib/canonical/
@@ -32,13 +32,15 @@
from canonical.launchpad import _
from canonical.
from canonical.
-from canonical.
+from canonical.
+ IEmailAddress,
+ IEmailAddressSet,
+ )
from canonical.
from canonical.
from canonical.
from canonical.
from canonical.
-
from lp.app.errors import NotFoundError
@@ -192,6 +194,28 @@
" ${email} isn't a valid email address.",
mapping= {'email' : email}))
+def _check_ email_availabil ity(email) : IEmailAddressSe t).getByEmail( email) person is not None: person
+ email_address = getUtility(
+ if email_address is not None:
+ # The email already exists; determine what has it.
+ if email_address.
+ person = email_address.
+ message = _('${email} is already registered in Launchpad and is '
+ ...