Merge lp:~cjwatson/launchpad/close-account-hwsubmissiondevice into lp:launchpad

Proposed by Colin Watson
Status: Merged
Merged at revision: 18899
Proposed branch: lp:~cjwatson/launchpad/close-account-hwsubmissiondevice
Merge into: lp:launchpad
Diff against target: 99 lines (+34/-5)
3 files modified
database/schema/security.cfg (+1/-0)
lib/lp/registry/scripts/closeaccount.py (+12/-3)
lib/lp/registry/scripts/tests/test_closeaccount.py (+21/-2)
To merge this branch: bzr merge lp:~cjwatson/launchpad/close-account-hwsubmissiondevice
Reviewer Review Type Date Requested Status
Adam Collard (community) Approve
Launchpad code reviewers Pending
Review via email: mp+364260@code.launchpad.net

Commit message

Handle hardware submission devices in close-account.

Description of the change

William predicted in https://code.launchpad.net/~cjwatson/launchpad/close-account-more-2/+merge/363259 that I was going to need this, and lo and behold ...

To post a comment you must log in.
Revision history for this message
Adam Collard (adam-collard) wrote :

LGTM, +1

review: Approve
Revision history for this message
William Grant (wgrant) :
Revision history for this message
Colin Watson (cjwatson) :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'database/schema/security.cfg'
2--- database/schema/security.cfg 2019-02-21 12:53:12 +0000
3+++ database/schema/security.cfg 2019-03-11 15:13:32 +0000
4@@ -336,6 +336,7 @@
5 type=user
6 public.archivesubscriber = SELECT, INSERT, UPDATE, DELETE
7 public.hwsubmission = SELECT, INSERT, UPDATE, DELETE
8+public.hwsubmissiondevice = SELECT, DELETE
9 public.karma = SELECT, INSERT, UPDATE, DELETE
10 public.sharingjob = SELECT, INSERT, UPDATE, DELETE
11 public.signedcodeofconduct = SELECT, INSERT, UPDATE, DELETE
12
13=== modified file 'lib/lp/registry/scripts/closeaccount.py'
14--- lib/lp/registry/scripts/closeaccount.py 2019-03-08 14:30:24 +0000
15+++ lib/lp/registry/scripts/closeaccount.py 2019-03-11 15:13:32 +0000
16@@ -18,6 +18,7 @@
17 from lp.answers.model.question import Question
18 from lp.app.interfaces.launchpad import ILaunchpadCelebrities
19 from lp.bugs.model.bugtask import BugTask
20+from lp.hardwaredb.model.hwdb import HWSubmission
21 from lp.registry.interfaces.person import PersonCreationRationale
22 from lp.registry.model.person import (
23 Person,
24@@ -289,9 +290,6 @@
25
26 # "Affects me too" information
27 ('BugAffectsPerson', 'person'),
28-
29- # Hardware submissions
30- ('HWSubmission', 'owner'),
31 ]
32 for table, person_id_column in removals:
33 table_notification(table)
34@@ -332,6 +330,17 @@
35 skip.add(('archivesubscriber', 'subscriber'))
36 skip.add(('archiveauthtoken', 'person'))
37
38+ # Remove hardware submissions.
39+ table_notification('HWSubmissionDevice')
40+ store.execute("""
41+ DELETE FROM HWSubmissionDevice
42+ USING HWSubmission
43+ WHERE HWSubmission.id = HWSubmissionDevice.submission
44+ AND owner = ?
45+ """, (person.id,))
46+ table_notification('HWSubmission')
47+ store.find(HWSubmission, HWSubmission.ownerID == person.id).remove()
48+
49 # Closing the account will only work if all references have been handled
50 # by this point. If not, it's safer to bail out. It's OK if this
51 # doesn't work in all conceivable situations, since some of them may
52
53=== modified file 'lib/lp/registry/scripts/tests/test_closeaccount.py'
54--- lib/lp/registry/scripts/tests/test_closeaccount.py 2019-03-08 14:30:24 +0000
55+++ lib/lp/registry/scripts/tests/test_closeaccount.py 2019-03-11 15:13:32 +0000
56@@ -19,7 +19,11 @@
57
58 from lp.answers.enums import QuestionStatus
59 from lp.app.interfaces.launchpad import ILaunchpadCelebrities
60-from lp.hardwaredb.interfaces.hwdb import IHWSubmissionSet
61+from lp.hardwaredb.interfaces.hwdb import (
62+ HWBus,
63+ IHWDeviceSet,
64+ IHWSubmissionSet,
65+ )
66 from lp.registry.interfaces.person import IPersonSet
67 from lp.registry.scripts.closeaccount import CloseAccountScript
68 from lp.scripts.garbo import PopulateLatestPersonSourcePackageReleaseCache
69@@ -376,10 +380,21 @@
70 person = self.factory.makePerson()
71 submission = self.factory.makeHWSubmission(
72 emailaddress=person.preferredemail.email)
73+ other_submission = self.factory.makeHWSubmission()
74+ device = getUtility(IHWDeviceSet).getByDeviceID(
75+ HWBus.PCI, '0x10de', '0x0455')
76+ with dbuser('hwdb-submission-processor'):
77+ parent_submission_device = self.factory.makeHWSubmissionDevice(
78+ submission, device, None, None, 1)
79+ self.factory.makeHWSubmissionDevice(
80+ submission, device, None, parent_submission_device, 2)
81+ other_submission_device = self.factory.makeHWSubmissionDevice(
82+ other_submission, device, None, None, 1)
83 key = submission.submission_key
84+ other_key = other_submission.submission_key
85 hw_submission_set = getUtility(IHWSubmissionSet)
86 self.assertNotEqual([], list(hw_submission_set.getByOwner(person)))
87- self.assertIsNotNone(hw_submission_set.getBySubmissionKey(key))
88+ self.assertEqual(submission, hw_submission_set.getBySubmissionKey(key))
89 person_id = person.id
90 account_id = person.account.id
91 script = self.makeScript([six.ensure_str(person.name)])
92@@ -388,3 +403,7 @@
93 self.assertRemoved(account_id, person_id)
94 self.assertEqual([], list(hw_submission_set.getByOwner(person)))
95 self.assertIsNone(hw_submission_set.getBySubmissionKey(key))
96+ self.assertEqual(
97+ other_submission, hw_submission_set.getBySubmissionKey(other_key))
98+ self.assertEqual(
99+ [other_submission_device], list(other_submission.devices))