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
=== modified file 'lib/lp/registry/scripts/closeaccount.py'
--- lib/lp/registry/scripts/closeaccount.py 2019-05-06 14:22:34 +0000
+++ lib/lp/registry/scripts/closeaccount.py 2019-07-23 12:42:58 +0000
@@ -63,7 +63,8 @@
63 ).find(63 ).find(
64 Person,64 Person,
65 Or(Person.name == username,65 Or(Person.name == username,
66 Lower(EmailAddress.email) == Lower(username))).one()66 Lower(EmailAddress.email) == Lower(username))
67 ).order_by(Person.id).config(distinct=True).one()
67 if person is None:68 if person is None:
68 raise LaunchpadScriptFailure("User %s does not exist" % username)69 raise LaunchpadScriptFailure("User %s does not exist" % username)
69 person_name = person.name70 person_name = person.name
7071
=== modified file 'lib/lp/registry/scripts/tests/test_closeaccount.py'
--- lib/lp/registry/scripts/tests/test_closeaccount.py 2019-05-06 14:22:34 +0000
+++ lib/lp/registry/scripts/tests/test_closeaccount.py 2019-07-23 12:42:58 +0000
@@ -216,6 +216,14 @@
216 self.assertRemoved(account_ids[1], person_ids[1])216 self.assertRemoved(account_ids[1], person_ids[1])
217 self.assertNotRemoved(account_ids[2], person_ids[2])217 self.assertNotRemoved(account_ids[2], person_ids[2])
218218
219 def test_multiple_email_addresses(self):
220 person, person_id, account_id = self.makePopulatedUser()
221 self.factory.makeEmail('%s@another-domain.test' % person.name, person)
222 script = self.makeScript([six.ensure_str(person.name)])
223 with dbuser('launchpad'):
224 self.runScript(script)
225 self.assertRemoved(account_id, person_id)
226
219 def test_unactivated(self):227 def test_unactivated(self):
220 person = self.factory.makePerson(228 person = self.factory.makePerson(
221 account_status=AccountStatus.NOACCOUNT)229 account_status=AccountStatus.NOACCOUNT)