← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/launchpad:hwdb-disable-submissions into launchpad:master

 

Colin Watson has proposed merging ~cjwatson/launchpad:hwdb-disable-submissions into launchpad:master.

Commit message:
Add a feature flag to disable new hwdb submissions

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/383158

Since Ubuntu xenial, checkbox no longer uses Launchpad's hardware database, and the only new submissions are coming from older systems; the certification teams no longer pay attention to it.  Add a hardwaredb.submissions.disabled feature flag to refuse new submissions, with the intention of removing submission support in a month or two if no good reasons to the contrary turn up.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:hwdb-disable-submissions into launchpad:master.
diff --git a/lib/lp/hardwaredb/browser/configure.zcml b/lib/lp/hardwaredb/browser/configure.zcml
index 2b5dfe0..4d06052 100644
--- a/lib/lp/hardwaredb/browser/configure.zcml
+++ b/lib/lp/hardwaredb/browser/configure.zcml
@@ -18,6 +18,12 @@
         permission="zope.Public"
         name="+submit"
         template="../templates/hwdb-submit-hardware-data.pt"/>
+    <browser:page
+        for="lp.hardwaredb.interfaces.hwdb.HWSubmissionsDisabledError"
+        class="lp.hardwaredb.browser.hwdb.HWDBSubmissionsDisabledView"
+        name="index.html"
+        permission="zope.Public"
+        template="../templates/hwdb-submissions-disabled.pt"/>
     <browser:url
         for="lp.hardwaredb.interfaces.hwdb.IHWSystemFingerprint"
         path_expression="string:+fingerprint/${fingerprint}"
@@ -68,4 +74,4 @@
         for="lp.hardwaredb.interfaces.hwdb.IHWSubmissionDevice"
         path_expression="string:+submissiondevice/${id}"
         parent_utility="lp.hardwaredb.interfaces.hwdb.IHWDBApplication"/>
-</configure>
\ No newline at end of file
+</configure>
diff --git a/lib/lp/hardwaredb/browser/hwdb.py b/lib/lp/hardwaredb/browser/hwdb.py
index cbd1801..bbd1ee6 100644
--- a/lib/lp/hardwaredb/browser/hwdb.py
+++ b/lib/lp/hardwaredb/browser/hwdb.py
@@ -7,6 +7,7 @@ __all__ = [
     'HWDBApplicationNavigation',
     'HWDBFingerprintSetView',
     'HWDBPersonSubmissionsView',
+    'HWDBSubmissionsDisabledView',
     'HWDBSubmissionTextView',
     'HWDBUploadView',
     ]
@@ -41,6 +42,7 @@ from lp.services.webapp import (
     stepthrough,
     )
 from lp.services.webapp.batching import BatchNavigator
+from lp.services.webapp.error import GoneView
 from lp.services.webapp.interfaces import ILaunchBag
 
 
@@ -156,6 +158,12 @@ class HWDBUploadView(LaunchpadFormView):
             u'X-Launchpad-HWDB-Submission', value)
 
 
+class HWDBSubmissionsDisabledView(GoneView):
+    """View to indicate that new submissions are disabled."""
+
+    page_title = "Hardware database submissions disabled"
+
+
 class HWDBPersonSubmissionsView(LaunchpadView):
     """View class for preseting HWDB submissions by a person."""
 
diff --git a/lib/lp/hardwaredb/doc/hwdb.txt b/lib/lp/hardwaredb/doc/hwdb.txt
index 6fc2582..6a2a032 100644
--- a/lib/lp/hardwaredb/doc/hwdb.txt
+++ b/lib/lp/hardwaredb/doc/hwdb.txt
@@ -744,3 +744,19 @@ IPerson.hardware_submissions.
     >>> set(submission.owner.name for submission
     ...     in owner.hardware_submissions)
     set([u'name12'])
+
+== Feature flag ==
+
+Launchpad's hardware database is obsolescent.  We have a feature flag to
+stage the removal of support for new submissions.
+
+    >>> from lp.hardwaredb.interfaces.hwdb import (
+    ...     HWDB_SUBMISSIONS_DISABLED_FEATURE_FLAG,
+    ...     )
+    >>> from lp.services.features.testing import FeatureFixture
+
+    >>> with FeatureFixture({HWDB_SUBMISSIONS_DISABLED_FEATURE_FLAG: u'on'}):
+    ...     factory.makeHWSubmission()
+    Traceback (most recent call last):
+    ...
+    HWSubmissionsDisabledError: Launchpad's hardware database is obsolete ...
diff --git a/lib/lp/hardwaredb/interfaces/hwdb.py b/lib/lp/hardwaredb/interfaces/hwdb.py
index 082c742..ca76b86 100644
--- a/lib/lp/hardwaredb/interfaces/hwdb.py
+++ b/lib/lp/hardwaredb/interfaces/hwdb.py
@@ -7,9 +7,11 @@ __metaclass__ = type
 
 __all__ = [
     'HWBus',
+    'HWDB_SUBMISSIONS_DISABLED_FEATURE_FLAG',
     'HWSubmissionFormat',
     'HWSubmissionKeyNotUnique',
     'HWSubmissionProcessingStatus',
+    'HWSubmissionsDisabledError',
     'IHWDBApplication',
     'IHWDevice',
     'IHWDeviceClass',
@@ -96,6 +98,23 @@ from lp.services.webservice.apihelpers import (
 from lp.soyuz.interfaces.distroarchseries import IDistroArchSeries
 
 
+HWDB_SUBMISSIONS_DISABLED_FEATURE_FLAG = 'hardwaredb.submissions.disabled'
+
+
+@error_status(http_client.GONE)
+class HWSubmissionsDisabledError(Exception):
+    """An exception saying that hardware database submissions are disabled."""
+
+    def __init__(self, message=None):
+        if message is None:
+            message = (
+                "Launchpad's hardware database is obsolete and is no longer "
+                "accepting submissions.  Please use "
+                "https://answers.launchpad.net/launchpad/+addquestion to tell "
+                "us about your requirements if you still need it.")
+        super(HWSubmissionsDisabledError, self).__init__(message)
+
+
 def validate_new_submission_key(submission_key):
     """Check, if submission_key already exists in HWDBSubmission."""
     if not valid_name(submission_key):
diff --git a/lib/lp/hardwaredb/model/hwdb.py b/lib/lp/hardwaredb/model/hwdb.py
index e1a4460..4e73474 100644
--- a/lib/lp/hardwaredb/model/hwdb.py
+++ b/lib/lp/hardwaredb/model/hwdb.py
@@ -61,9 +61,11 @@ from lp.bugs.model.bug import (
 from lp.bugs.model.bugsubscription import BugSubscription
 from lp.hardwaredb.interfaces.hwdb import (
     HWBus,
+    HWDB_SUBMISSIONS_DISABLED_FEATURE_FLAG,
     HWSubmissionFormat,
     HWSubmissionKeyNotUnique,
     HWSubmissionProcessingStatus,
+    HWSubmissionsDisabledError,
     IHWDevice,
     IHWDeviceClass,
     IHWDeviceClassSet,
@@ -113,6 +115,7 @@ from lp.services.database.sqlbase import (
     SQLBase,
     sqlvalues,
     )
+from lp.services.features import getFeatureFlag
 from lp.services.librarian.interfaces import ILibraryFileAliasSet
 from lp.soyuz.interfaces.distroarchseries import IDistroArchSeries
 from lp.soyuz.model.distroarchseries import DistroArchSeries
@@ -161,6 +164,9 @@ class HWSubmissionSet:
                          raw_submission, filename, filesize,
                          system_fingerprint):
         """See `IHWSubmissionSet`."""
+        if getFeatureFlag(HWDB_SUBMISSIONS_DISABLED_FEATURE_FLAG):
+            raise HWSubmissionsDisabledError()
+
         assert valid_name(submission_key), "Invalid key %s" % submission_key
 
         submission_exists = HWSubmission.selectOneBy(
diff --git a/lib/lp/hardwaredb/stories/hwdb/xx-hwdb.txt b/lib/lp/hardwaredb/stories/hwdb/xx-hwdb.txt
index 98128d1..148f79b 100644
--- a/lib/lp/hardwaredb/stories/hwdb/xx-hwdb.txt
+++ b/lib/lp/hardwaredb/stories/hwdb/xx-hwdb.txt
@@ -59,6 +59,27 @@ Human users get a message too.
     ...     print(tag)
     <div class="informational message">Thank you for your submission.</div>
 
+If the feature flag to disable new submissions is set, then we return an
+appropriate HTTP error instead.
+
+    >>> from lp.hardwaredb.interfaces.hwdb import (
+    ...     HWDB_SUBMISSIONS_DISABLED_FEATURE_FLAG,
+    ...     )
+    >>> from lp.services.features.testing import FeatureFixture
+
+    >>> submit_data['Unique Submission Key:'] = 'unique-id-disabled'
+    >>> browser.handleErrors = True
+    >>> with FeatureFixture({HWDB_SUBMISSIONS_DISABLED_FEATURE_FLAG: u'on'}):
+    ...     browser.open('http://launchpad.test/+hwdb/+submit')
+    ...     fill_form(
+    ...         browser, submit_data, submit_data_checkboxes, submit_file,
+    ...         'test.txt')
+    ...     browser.getControl('Upload').click()
+    Traceback (most recent call last):
+    ...
+    HTTPError: HTTP Error 410: Gone
+    >>> browser.handleErrors = False
+
 If fields are not set, the response contains a header explaining this
 error.
 
diff --git a/lib/lp/hardwaredb/templates/hwdb-submissions-disabled.pt b/lib/lp/hardwaredb/templates/hwdb-submissions-disabled.pt
new file mode 100644
index 0000000..772f459
--- /dev/null
+++ b/lib/lp/hardwaredb/templates/hwdb-submissions-disabled.pt
@@ -0,0 +1,19 @@
+<html
+  xmlns="http://www.w3.org/1999/xhtml";
+  xmlns:tal="http://xml.zope.org/namespaces/tal";
+  xmlns:metal="http://xml.zope.org/namespaces/metal";
+  xmlns:i18n="http://xml.zope.org/namespaces/i18n";
+  metal:use-macro="view/macro:page/main_only"
+  i18n:domain="launchpad">
+  <body>
+    <div class="top-portlet" metal:fill-slot="main">
+      <h1>Hardware database submissions disabled</h1>
+
+      <p>
+        Launchpad's hardware database is obsolete and is no longer accepting
+        submissions.  Please <a href="/launchpad/+addquestion">tell us about
+        your requirements</a> if you still need it.
+      </p>
+    </div>
+  </body>
+</html>
diff --git a/lib/lp/services/webapp/error.py b/lib/lp/services/webapp/error.py
index dfb3067..1fbc2b2 100644
--- a/lib/lp/services/webapp/error.py
+++ b/lib/lp/services/webapp/error.py
@@ -3,6 +3,7 @@
 
 __metaclass__ = type
 __all__ = [
+    'GoneView',
     'InvalidBatchSizeView',
     'NotFoundView',
     'ProtocolErrorView',