← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/launchpad:maintenance-feature-rule into launchpad:master

 

Colin Watson has proposed merging ~cjwatson/launchpad:maintenance-feature-rule into launchpad:master.

Commit message:
Allow setting maintenance messages using feature rules

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

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

We use the new feature rule 'app.maintenance_message'.

This lets us display custom maintenance messages only on certain pages, by using the existing scoping system for feature rules.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:maintenance-feature-rule into launchpad:master.
diff --git a/lib/lp/app/browser/launchpad.py b/lib/lp/app/browser/launchpad.py
index eb4b9bb..4c1eb59 100644
--- a/lib/lp/app/browser/launchpad.py
+++ b/lib/lp/app/browser/launchpad.py
@@ -123,6 +123,7 @@ from lp.registry.interfaces.projectgroup import IProjectGroupSet
 from lp.registry.interfaces.role import IPersonRoles
 from lp.registry.interfaces.sourcepackagename import ISourcePackageNameSet
 from lp.services.config import config
+from lp.services.features import getFeatureFlag
 from lp.services.helpers import intOrZero
 from lp.services.identity.interfaces.account import AccountStatus
 from lp.services.propertycache import cachedproperty
@@ -537,6 +538,7 @@ class MaintenanceMessage:
     """
 
     timelefttext = None
+    featuretext = None
 
     notmuchtime = timedelta(seconds=30)
     toomuchtime = timedelta(seconds=1800)  # 30 minutes
@@ -558,6 +560,8 @@ class MaintenanceMessage:
             else:
                 self.timelefttext = 'in %s' % (
                     DurationFormatterAPI(timeleft).approximateduration())
+        self.featuretext = getFeatureFlag('app.maintenance_message')
+        if self.timelefttext or self.featuretext:
             return self.index()
         return ''
 
diff --git a/lib/lp/app/stories/basics/xx-maintenance-message.txt b/lib/lp/app/stories/basics/xx-maintenance-message.txt
index 75a9c04..5f66dca 100644
--- a/lib/lp/app/stories/basics/xx-maintenance-message.txt
+++ b/lib/lp/app/stories/basics/xx-maintenance-message.txt
@@ -94,3 +94,22 @@ Remove +maintenancetime.txt to clean up.
 
     >>> os.remove('+maintenancetime.txt')
 
+
+== Per-page maintenance messages ==
+
+Alternatively, a maintenance message can be set in the
+app.maintenance_message feature flag, which can be scoped to particular
+pages.
+
+    >>> from lp.services.features.testing import FeatureFixture
+    >>> maintenance_text = (
+    ...     'This page will be <a href="https://example.com/";>broken</a> '
+    ...     'for a while.')
+    >>> with FeatureFixture({'app.maintenance_message': maintenance_text}):
+    ...     content = front_page_content()
+    >>> maintenance_text in content
+    True
+
+    >>> content = front_page_content()
+    >>> maintenance_text not in content
+    True
diff --git a/lib/lp/app/templates/launchpad-maintenance.pt b/lib/lp/app/templates/launchpad-maintenance.pt
index 364c5fa..d1b6ab4 100644
--- a/lib/lp/app/templates/launchpad-maintenance.pt
+++ b/lib/lp/app/templates/launchpad-maintenance.pt
@@ -1,8 +1,13 @@
-<p
+<div
   xmlns:tal="http://xml.zope.org/namespaces/tal";
   xmlns:metal="http://xml.zope.org/namespaces/metal";
-  xmlns:i18n="http://xml.zope.org/namespaces/i18n";
-  class="warning message">
-  Launchpad will be going offline for maintenance
-  <tal:soon replace="view/timelefttext">in 3 minutes</tal:soon>.
-</p>
+  xmlns:i18n="http://xml.zope.org/namespaces/i18n";>
+  <p class="warning message"
+     tal:condition="view/timelefttext">
+    Launchpad will be going offline for maintenance
+    <tal:soon replace="view/timelefttext">in 3 minutes</tal:soon>.
+  </p>
+  <p class="warning message"
+     tal:condition="view/featuretext"
+     tal:content="structure view/featuretext" />
+</div>