← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~twom/launchpad:oci-policy-default-the-current-officialness into launchpad:master

 

Tom Wardill has proposed merging ~twom/launchpad:oci-policy-default-the-current-officialness into launchpad:master.

Commit message:
Fix official value on editing while not an admin

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

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

If a recipe had been set to official, but you were not an admin, the official control would default to False and the edit would fail as you have no permissions to change it.

Fix by making the default value of the control to be the current official status, rather than defaulting to False.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~twom/launchpad:oci-policy-default-the-current-officialness into launchpad:master.
diff --git a/lib/lp/oci/browser/ocirecipe.py b/lib/lp/oci/browser/ocirecipe.py
index d1bd570..abaff05 100644
--- a/lib/lp/oci/browser/ocirecipe.py
+++ b/lib/lp/oci/browser/ocirecipe.py
@@ -996,7 +996,7 @@ class OCIRecipeEditView(BaseOCIRecipeEditView, EnableProcessorsMixin,
                 "Allows use of distribution registry credentials "
                 "and the default git repository routing. "
                 "May only be enabled by the owner of the OCI Project."),
-            default=False,
+            default=self.context.official,
             required=False, readonly=False))
 
     def validate(self, data):
diff --git a/lib/lp/oci/browser/tests/test_ocirecipe.py b/lib/lp/oci/browser/tests/test_ocirecipe.py
index 7c3ccdb..22634c1 100644
--- a/lib/lp/oci/browser/tests/test_ocirecipe.py
+++ b/lib/lp/oci/browser/tests/test_ocirecipe.py
@@ -888,6 +888,22 @@ class TestOCIRecipeEditView(OCIConfigHelperMixin, BaseTestOCIRecipeView):
         official_control = browser.getControl("Official recipe")
         self.assertTrue(official_control.disabled)
 
+    def test_official_is_set_while_disabled(self):
+        distribution = self.factory.makeDistribution(
+            oci_project_admin=self.person)
+        non_admin = self.factory.makePerson()
+        oci_project = self.factory.makeOCIProject(pillar=distribution)
+        recipe = self.factory.makeOCIRecipe(
+            registrant=non_admin, owner=non_admin,
+            oci_project=oci_project)
+        with person_logged_in(self.person):
+            oci_project.setOfficialRecipeStatus(recipe, True)
+        browser = self.getViewBrowser(recipe, user=non_admin)
+        browser.getLink("Edit OCI recipe").click()
+        official_control = browser.getControl("Official recipe")
+        self.assertTrue(official_control.disabled)
+        self.assertTrue(official_control.selected)
+
     def test_official_is_enabled(self):
         distribution = self.factory.makeDistribution(
             oci_project_admin=self.person)