Merge lp:~cjwatson/launchpad/close-account-distinct-person into lp:launchpad

Proposed by Colin Watson
Status: Merged
Merged at revision: 19014
Proposed branch: lp:~cjwatson/launchpad/close-account-distinct-person
Merge into: lp:launchpad
Diff against target: 32 lines (+10/-1)
2 files modified
lib/lp/registry/scripts/closeaccount.py (+2/-1)
lib/lp/registry/scripts/tests/test_closeaccount.py (+8/-0)
To merge this branch: bzr merge lp:~cjwatson/launchpad/close-account-distinct-person
Reviewer Review Type Date Requested Status
Natalia Bidart (community) Approve
Launchpad code reviewers Pending
Review via email: mp+370483@code.launchpad.net

Commit message

Make close-account work for users with multiple email addresses.

Description of the change

The explicit order_by is needed because Person is sorted by a custom person_sort_key function by default, and that isn't interesting in this case.

To post a comment you must log in.
Revision history for this message
Natalia Bidart (nataliabidart) wrote :

lgtm

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/registry/scripts/closeaccount.py'
2--- lib/lp/registry/scripts/closeaccount.py 2019-05-06 14:22:34 +0000
3+++ lib/lp/registry/scripts/closeaccount.py 2019-07-23 12:42:58 +0000
4@@ -63,7 +63,8 @@
5 ).find(
6 Person,
7 Or(Person.name == username,
8- Lower(EmailAddress.email) == Lower(username))).one()
9+ Lower(EmailAddress.email) == Lower(username))
10+ ).order_by(Person.id).config(distinct=True).one()
11 if person is None:
12 raise LaunchpadScriptFailure("User %s does not exist" % username)
13 person_name = person.name
14
15=== modified file 'lib/lp/registry/scripts/tests/test_closeaccount.py'
16--- lib/lp/registry/scripts/tests/test_closeaccount.py 2019-05-06 14:22:34 +0000
17+++ lib/lp/registry/scripts/tests/test_closeaccount.py 2019-07-23 12:42:58 +0000
18@@ -216,6 +216,14 @@
19 self.assertRemoved(account_ids[1], person_ids[1])
20 self.assertNotRemoved(account_ids[2], person_ids[2])
21
22+ def test_multiple_email_addresses(self):
23+ person, person_id, account_id = self.makePopulatedUser()
24+ self.factory.makeEmail('%s@another-domain.test' % person.name, person)
25+ script = self.makeScript([six.ensure_str(person.name)])
26+ with dbuser('launchpad'):
27+ self.runScript(script)
28+ self.assertRemoved(account_id, person_id)
29+
30 def test_unactivated(self):
31 person = self.factory.makePerson(
32 account_status=AccountStatus.NOACCOUNT)