← Back to team overview

launchpad-reviewers team mailing list archive

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

 

Colin Watson has proposed merging lp:~cjwatson/launchpad/close-account-hwsubmissiondevice into lp:launchpad.

Commit message:
Handle hardware submission devices in close-account.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/close-account-hwsubmissiondevice/+merge/364260

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 ...
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~cjwatson/launchpad/close-account-hwsubmissiondevice into lp:launchpad.
=== modified file 'database/schema/security.cfg'
--- database/schema/security.cfg	2019-02-21 12:53:12 +0000
+++ database/schema/security.cfg	2019-03-11 15:13:32 +0000
@@ -336,6 +336,7 @@
 type=user
 public.archivesubscriber                = SELECT, INSERT, UPDATE, DELETE
 public.hwsubmission                     = SELECT, INSERT, UPDATE, DELETE
+public.hwsubmissiondevice               = SELECT, DELETE
 public.karma                            = SELECT, INSERT, UPDATE, DELETE
 public.sharingjob                       = SELECT, INSERT, UPDATE, DELETE
 public.signedcodeofconduct              = SELECT, INSERT, UPDATE, DELETE

=== modified file 'lib/lp/registry/scripts/closeaccount.py'
--- lib/lp/registry/scripts/closeaccount.py	2019-03-08 14:30:24 +0000
+++ lib/lp/registry/scripts/closeaccount.py	2019-03-11 15:13:32 +0000
@@ -18,6 +18,7 @@
 from lp.answers.model.question import Question
 from lp.app.interfaces.launchpad import ILaunchpadCelebrities
 from lp.bugs.model.bugtask import BugTask
+from lp.hardwaredb.model.hwdb import HWSubmission
 from lp.registry.interfaces.person import PersonCreationRationale
 from lp.registry.model.person import (
     Person,
@@ -289,9 +290,6 @@
 
         # "Affects me too" information
         ('BugAffectsPerson', 'person'),
-
-        # Hardware submissions
-        ('HWSubmission', 'owner'),
         ]
     for table, person_id_column in removals:
         table_notification(table)
@@ -332,6 +330,17 @@
     skip.add(('archivesubscriber', 'subscriber'))
     skip.add(('archiveauthtoken', 'person'))
 
+    # Remove hardware submissions.
+    table_notification('HWSubmissionDevice')
+    store.execute("""
+        DELETE FROM HWSubmissionDevice
+        USING HWSubmission
+        WHERE HWSubmission.id = HWSubmissionDevice.submission
+            AND owner = ?
+        """, (person.id,))
+    table_notification('HWSubmission')
+    store.find(HWSubmission, HWSubmission.ownerID == person.id).remove()
+
     # Closing the account will only work if all references have been handled
     # by this point.  If not, it's safer to bail out.  It's OK if this
     # doesn't work in all conceivable situations, since some of them may

=== modified file 'lib/lp/registry/scripts/tests/test_closeaccount.py'
--- lib/lp/registry/scripts/tests/test_closeaccount.py	2019-03-08 14:30:24 +0000
+++ lib/lp/registry/scripts/tests/test_closeaccount.py	2019-03-11 15:13:32 +0000
@@ -19,7 +19,11 @@
 
 from lp.answers.enums import QuestionStatus
 from lp.app.interfaces.launchpad import ILaunchpadCelebrities
-from lp.hardwaredb.interfaces.hwdb import IHWSubmissionSet
+from lp.hardwaredb.interfaces.hwdb import (
+    HWBus,
+    IHWDeviceSet,
+    IHWSubmissionSet,
+    )
 from lp.registry.interfaces.person import IPersonSet
 from lp.registry.scripts.closeaccount import CloseAccountScript
 from lp.scripts.garbo import PopulateLatestPersonSourcePackageReleaseCache
@@ -376,10 +380,21 @@
         person = self.factory.makePerson()
         submission = self.factory.makeHWSubmission(
             emailaddress=person.preferredemail.email)
+        other_submission = self.factory.makeHWSubmission()
+        device = getUtility(IHWDeviceSet).getByDeviceID(
+            HWBus.PCI, '0x10de', '0x0455')
+        with dbuser('hwdb-submission-processor'):
+            parent_submission_device = self.factory.makeHWSubmissionDevice(
+                submission, device, None, None, 1)
+            self.factory.makeHWSubmissionDevice(
+                submission, device, None, parent_submission_device, 2)
+            other_submission_device = self.factory.makeHWSubmissionDevice(
+                other_submission, device, None, None, 1)
         key = submission.submission_key
+        other_key = other_submission.submission_key
         hw_submission_set = getUtility(IHWSubmissionSet)
         self.assertNotEqual([], list(hw_submission_set.getByOwner(person)))
-        self.assertIsNotNone(hw_submission_set.getBySubmissionKey(key))
+        self.assertEqual(submission, hw_submission_set.getBySubmissionKey(key))
         person_id = person.id
         account_id = person.account.id
         script = self.makeScript([six.ensure_str(person.name)])
@@ -388,3 +403,7 @@
         self.assertRemoved(account_id, person_id)
         self.assertEqual([], list(hw_submission_set.getByOwner(person)))
         self.assertIsNone(hw_submission_set.getBySubmissionKey(key))
+        self.assertEqual(
+            other_submission, hw_submission_set.getBySubmissionKey(other_key))
+        self.assertEqual(
+            [other_submission_device], list(other_submission.devices))


Follow ups