Merge ~cjwatson/launchpad:prevent-manual-activation into launchpad:master

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: 14872e224ea36ab62ba7d773c00dbe2560262bd4
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/launchpad:prevent-manual-activation
Merge into: launchpad:master
Diff against target: 60 lines (+31/-0)
2 files modified
lib/lp/registry/browser/person.py (+17/-0)
lib/lp/registry/browser/tests/person-admin-views.rst (+14/-0)
Reviewer Review Type Date Requested Status
Jürgen Gmach Approve
Review via email: mp+429959@code.launchpad.net

Commit message

Prevent activating accounts from +reviewaccount

Description of the change

This is otherwise a tempting mistake to make when dealing with account issues.

To post a comment you must log in.
Revision history for this message
Jürgen Gmach (jugmac00) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/lp/registry/browser/person.py b/lib/lp/registry/browser/person.py
2index be5908b..8145cc0 100644
3--- a/lib/lp/registry/browser/person.py
4+++ b/lib/lp/registry/browser/person.py
5@@ -1391,6 +1391,23 @@ class PersonAccountAdministerView(LaunchpadFormView):
6 """See `LaunchpadEditFormView`."""
7 return canonical_url(self.person)
8
9+ def validate(self, data):
10+ """See `LaunchpadFormView`."""
11+ new_status = data.get("status")
12+ if (
13+ new_status != self.context.status
14+ and new_status == AccountStatus.ACTIVE
15+ ):
16+ # This typically breaks, as it bypasses the code in
17+ # `PersonSet.getOrCreateByOpenIDIdentifier` that sets the user's
18+ # preferred email address. Activating an account should only be
19+ # done by the user themselves logging in from a Deactivated,
20+ # Unactivated, or Placeholder account status.
21+ self.setFieldError(
22+ "status",
23+ "Only the user themselves can activate their account.",
24+ )
25+
26 @action("Change", name="change")
27 def change_action(self, action, data):
28 """Update the IAccount."""
29diff --git a/lib/lp/registry/browser/tests/person-admin-views.rst b/lib/lp/registry/browser/tests/person-admin-views.rst
30index e711afb..4a2e30a 100644
31--- a/lib/lp/registry/browser/tests/person-admin-views.rst
32+++ b/lib/lp/registry/browser/tests/person-admin-views.rst
33@@ -160,6 +160,7 @@ user must log in to restore the email addresses using the reactivate step.
34 >>> view = create_initialized_view(user, "+reviewaccount", form=form)
35 >>> print(view.errors)
36 []
37+ >>> transaction.commit()
38 >>> user.account_status
39 <DBItem AccountStatus.DEACTIVATED, ...>
40 >>> user.account_status_history
41@@ -169,6 +170,19 @@ user must log in to restore the email addresses using the reactivate step.
42 None
43
44
45+An admin cannot manually activate an account. The user must do that
46+themselves by logging in.
47+
48+ >>> form = {
49+ ... "field.status": "ACTIVE",
50+ ... "field.comment": "Manually reactivating.",
51+ ... "field.actions.change": "Change",
52+ ... }
53+ >>> view = create_initialized_view(user, "+reviewaccount", form=form)
54+ >>> print(view.errors)
55+ ['Only the user themselves can activate their account.']
56+
57+
58 An admin can mark an account as belonging to a user who has died.
59
60 >>> form = {

Subscribers

People subscribed via source and target branches

to status/vote changes: