Merge lp:~edwin-grubbs/launchpad/bug-248518-setPreferredEmail into lp:launchpad

Proposed by Edwin Grubbs
Status: Merged
Approved by: Curtis Hovey
Approved revision: no longer in the source branch.
Merged at revision: not available
Proposed branch: lp:~edwin-grubbs/launchpad/bug-248518-setPreferredEmail
Merge into: lp:launchpad
Prerequisite: lp:~edwin-grubbs/launchpad/bug-553384-deactivated-project-oops
Diff against target: 120 lines (+23/-20)
5 files modified
lib/lp/bugs/browser/bugalsoaffects.py (+1/-1)
lib/lp/bugs/browser/tests/bugtask-adding-views.txt (+0/-1)
lib/lp/registry/doc/person.txt (+13/-5)
lib/lp/registry/model/person.py (+0/-11)
lib/lp/testing/factory.py (+9/-2)
To merge this branch: bzr merge lp:~edwin-grubbs/launchpad/bug-248518-setPreferredEmail
Reviewer Review Type Date Requested Status
Curtis Hovey (community) code Approve
Review via email: mp+24041@code.launchpad.net

Description of the change

Summary
-------

Person.setPreferredEmail() no longer activates the account automatically.

Implementation details
----------------------

Changed setPreferredEmail and fixed tests.
    lib/lp/registry/model/person.py
    lib/lp/registry/doc/person.txt
    lib/lp/testing/factory.py

Fixed lint errors.
    lib/lp/bugs/browser/bugalsoaffects.py
    lib/lp/bugs/browser/tests/bugtask-adding-views.txt

Tests
-----

./bin/test -vv -t 'doc/person.txt|bugtask-adding-views.txt'

Demo and Q/A
------------

This has no effect on the UI.

To post a comment you must log in.
Revision history for this message
Curtis Hovey (sinzui) wrote :

I am surprised there is not comparable test for account.activate() in doc/account. I think your test is the only documentation we have. My initial though was to move your test, but I think your decision was right. I think your tests tells other launchpad developer how to get a person's account activated.

I like your graceful solution in the factory.

review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/bugs/browser/bugalsoaffects.py'
2--- lib/lp/bugs/browser/bugalsoaffects.py 2010-04-23 20:24:36 +0000
3+++ lib/lp/bugs/browser/bugalsoaffects.py 2010-04-23 20:24:38 +0000
4@@ -593,7 +593,7 @@
5 elif link_upstream_how == LinkUpstreamHowOptions.EMAIL_UPSTREAM_DONE:
6 # Ensure there's a bug tracker for this email address.
7 bug_url = 'mailto:' + data['upstream_email_address_done']
8- bug_tracker = getUtility(IBugTrackerSet).ensureBugTracker(
9+ getUtility(IBugTrackerSet).ensureBugTracker(
10 bug_url, self.user, BugTrackerType.EMAILADDRESS)
11 data['bug_url'] = bug_url
12
13
14=== modified file 'lib/lp/bugs/browser/tests/bugtask-adding-views.txt'
15--- lib/lp/bugs/browser/tests/bugtask-adding-views.txt 2010-04-23 20:24:36 +0000
16+++ lib/lp/bugs/browser/tests/bugtask-adding-views.txt 2010-04-23 20:24:38 +0000
17@@ -12,7 +12,6 @@
18 >>> len(bug_four.bugtasks)
19 1
20 >>> firefox_task = bug_four.bugtasks[0]
21- >>> from canonical.launchpad.webapp.servers import LaunchpadTestRequest
22
23 The views registered at +choose-affected-product and +distrotask are in
24 fact meta views responsible for calling other views in order to guide the
25
26=== modified file 'lib/lp/registry/doc/person.txt'
27--- lib/lp/registry/doc/person.txt 2010-04-23 20:24:36 +0000
28+++ lib/lp/registry/doc/person.txt 2010-04-23 20:24:38 +0000
29@@ -119,11 +119,9 @@
30
31 By default, newly created Person entries will have
32 AccountStatus.NOACCOUNT as their account_status. This is only changed
33-if/when we turn that entry into an actual user account. (Currently, we
34-assume that a Person entry is turned into a user account when its first
35-email address is confirmed) Note that both the Person and the
36-EmailAddress have accounts when they are created using the
37-createPersonAndEmail() method.
38+if/when we turn that entry into an actual user account. Note that both
39+the Person and the EmailAddress have accounts when they are created
40+using the createPersonAndEmail() method.
41
42 >>> p.account_status
43 <DBItem AccountStatus.NOACCOUNT...
44@@ -136,6 +134,16 @@
45 <DBItem EmailAddressStatus.PREFERRED...
46
47 >>> p.account_status
48+ <DBItem AccountStatus.NOACCOUNT...
49+
50+ >>> from canonical.launchpad.interfaces.lpstorm import IMasterStore
51+ >>> from canonical.launchpad.database.account import Account
52+ >>> account = IMasterStore(Account).get(Account, p.accountID)
53+ >>> account.activate(
54+ ... "Activated by doc test.",
55+ ... password=p.password,
56+ ... preferred_email=email)
57+ >>> p.account_status
58 <DBItem AccountStatus.ACTIVE...
59
60 The user can add additional email addresses. The
61
62=== modified file 'lib/lp/registry/model/person.py'
63--- lib/lp/registry/model/person.py 2010-04-23 14:22:30 +0000
64+++ lib/lp/registry/model/person.py 2010-04-23 20:24:38 +0000
65@@ -2091,17 +2091,6 @@
66 if email is None:
67 self._unsetPreferredEmail()
68 return
69- if (self.preferredemail is None
70- and self.account_status != AccountStatus.ACTIVE):
71- # XXX sinzui 2008-07-14 bug=248518:
72- # This is a hack to preserve this function's behaviour before
73- # Account was split from Person. This can be removed when
74- # all the callsites ensure that the account is ACTIVE first.
75- account = IMasterStore(Account).get(Account, self.accountID)
76- account.activate(
77- "Activated when the preferred email was set.",
78- password=self.password,
79- preferred_email=email)
80 self._setPreferredEmail(email)
81
82 def _setPreferredEmail(self, email):
83
84=== modified file 'lib/lp/testing/factory.py'
85--- lib/lp/testing/factory.py 2010-04-23 02:35:47 +0000
86+++ lib/lp/testing/factory.py 2010-04-23 20:24:38 +0000
87@@ -400,10 +400,10 @@
88 # To make the person someone valid in Launchpad, validate the
89 # email.
90 if email_address_status == EmailAddressStatus.PREFERRED:
91- person.validateAndEnsurePreferredEmail(email)
92 account = IMasterStore(Account).get(
93 Account, person.accountID)
94 account.status = AccountStatus.ACTIVE
95+ person.validateAndEnsurePreferredEmail(email)
96
97 removeSecurityProxy(email).status = email_address_status
98
99@@ -448,6 +448,13 @@
100 PersonCreationRationale.OWNER_CREATED_LAUNCHPAD,
101 name=variable_name, displayname=full_name)
102 if set_preferred_email:
103+ # setPreferredEmail no longer activates the account
104+ # automatically.
105+ account = IMasterStore(Account).get(Account, person.accountID)
106+ account.activate(
107+ "Activated by factory.makePersonByName",
108+ password='foo',
109+ preferred_email=email)
110 person.setPreferredEmail(email)
111
112 if not use_default_autosubscribe_policy:
113@@ -1358,7 +1365,7 @@
114 def makePackageCodeImport(self, sourcepackage=None, **kwargs):
115 """Make a code import targetting a sourcepackage."""
116 if sourcepackage is None:
117- sourcepackage = self.makeSourcePackage()
118+ sourcepackage = self.makeSourcePackage()
119 target = IBranchTarget(sourcepackage)
120 return self.makeCodeImport(target=target, **kwargs)
121