← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~ines-almeida/launchpad:fetch-service-option-ui-update into launchpad:master

 

Ines Almeida has proposed merging ~ines-almeida/launchpad:fetch-service-option-ui-update into launchpad:master with ~ines-almeida/launchpad:fetch-service-option-model-update as a prerequisite.

Commit message:
UI changes to allow admins to update a Snap's use_fetch_service
    
This is hidden behind the new snap.fetch_service.enable feature flag



Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~ines-almeida/launchpad/+git/launchpad/+merge/461649

Related to: https://code.launchpad.net/~ines-almeida/launchpad/+git/launchpad/+merge/461552
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~ines-almeida/launchpad:fetch-service-option-ui-update into launchpad:master.
diff --git a/lib/lp/snappy/browser/snap.py b/lib/lp/snappy/browser/snap.py
index 5744565..dc4d330 100644
--- a/lib/lp/snappy/browser/snap.py
+++ b/lib/lp/snappy/browser/snap.py
@@ -77,6 +77,7 @@ from lp.snappy.browser.widgets.snaparchive import SnapArchiveWidget
 from lp.snappy.browser.widgets.storechannels import StoreChannelsWidget
 from lp.snappy.interfaces.snap import (
     SNAP_SNAPCRAFT_CHANNEL_FEATURE_FLAG,
+    SNAP_USE_FETCH_SERVICE_FEATURE_FLAG,
     CannotAuthorizeStoreUploads,
     CannotFetchSnapcraftYaml,
     CannotParseSnapcraftYaml,
@@ -525,6 +526,7 @@ class ISnapEditSchema(Interface):
             "auto_build_channels",
             "store_upload",
             "pro_enable",
+            "use_fetch_service",
         ],
     )
 
@@ -929,13 +931,20 @@ class SnapAdminView(BaseSnapEditView):
     # XXX pappacena 2021-02-19: Once we have the whole privacy work in
     # place, we should move "project" and "information_type" from +admin
     # page to +edit, to allow common users to edit this.
-    field_names = [
-        "project",
-        "information_type",
-        "require_virtualized",
-        "allow_internet",
-        "pro_enable",
-    ]
+    @property
+    def field_names(self):
+        fields = [
+            "project",
+            "information_type",
+            "require_virtualized",
+            "allow_internet",
+            "pro_enable",
+        ]
+
+        if getFeatureFlag(SNAP_USE_FETCH_SERVICE_FEATURE_FLAG):
+            fields.append("use_fetch_service")
+
+        return fields
 
     @property
     def initial_values(self):
diff --git a/lib/lp/snappy/browser/tests/test_snap.py b/lib/lp/snappy/browser/tests/test_snap.py
index cb4d4de..1127a50 100644
--- a/lib/lp/snappy/browser/tests/test_snap.py
+++ b/lib/lp/snappy/browser/tests/test_snap.py
@@ -61,6 +61,7 @@ from lp.snappy.browser.snap import (
 )
 from lp.snappy.interfaces.snap import (
     SNAP_SNAPCRAFT_CHANNEL_FEATURE_FLAG,
+    SNAP_USE_FETCH_SERVICE_FEATURE_FLAG,
     CannotModifySnapProcessor,
     ISnapSet,
     SnapBuildRequestStatus,
@@ -821,6 +822,11 @@ class TestSnapAdminView(BaseTestSnapView):
 
     def test_admin_snap(self):
         # Admins can change require_virtualized, privacy, and allow_internet.
+
+        self.useFixture(
+            FeatureFixture({SNAP_USE_FETCH_SERVICE_FEATURE_FLAG: True})
+        )
+
         login("admin@xxxxxxxxxxxxx")
         admin = self.factory.makePerson(
             member_of=[getUtility(ILaunchpadCelebrities).admin]
@@ -835,6 +841,7 @@ class TestSnapAdminView(BaseTestSnapView):
         self.assertFalse(snap.private)
         self.assertTrue(snap.allow_internet)
         self.assertFalse(snap.pro_enable)
+        self.assertFalse(snap.use_fetch_service)
 
         self.factory.makeAccessPolicy(
             pillar=project, type=InformationType.PRIVATESECURITY
@@ -847,6 +854,7 @@ class TestSnapAdminView(BaseTestSnapView):
         browser.getControl(name="field.information_type").value = private
         browser.getControl("Allow external network access").selected = False
         browser.getControl("Enable Ubuntu Pro").selected = True
+        browser.getControl("Use fetch service").selected = True
         browser.getControl("Update snap package").click()
 
         login_admin()
@@ -855,6 +863,24 @@ class TestSnapAdminView(BaseTestSnapView):
         self.assertTrue(snap.private)
         self.assertFalse(snap.allow_internet)
         self.assertTrue(snap.pro_enable)
+        self.assertTrue(snap.use_fetch_service)
+
+    def test_admin_use_fetch_service_feature_flag(self):
+        admin = self.factory.makePerson(
+            member_of=[getUtility(ILaunchpadCelebrities).admin]
+        )
+        snap = self.factory.makeSnap(registrant=admin)
+        browser = self.getViewBrowser(snap, user=admin)
+
+        browser.getLink("Administer snap package").click()
+        self.assertFalse("Use fetch service" in browser.contents)
+
+        self.useFixture(
+            FeatureFixture({SNAP_USE_FETCH_SERVICE_FEATURE_FLAG: True})
+        )
+
+        browser.reload()
+        self.assertTrue("Use fetch service" in browser.contents)
 
     def test_admin_snap_private_without_project(self):
         # Cannot make snap private if it doesn't have a project associated.