← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~twom/launchpad:oci-export-setOfficialRecipeStatue into launchpad:master

 

Tom Wardill has proposed merging ~twom/launchpad:oci-export-setOfficialRecipeStatue into launchpad:master.

Commit message:
Export official recipe setting via api

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

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

We should be able to set the official recipe status via the API. So allow that.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~twom/launchpad:oci-export-setOfficialRecipeStatue into launchpad:master.
diff --git a/lib/lp/oci/interfaces/webservice.py b/lib/lp/oci/interfaces/webservice.py
index b337c70..92e58ab 100644
--- a/lib/lp/oci/interfaces/webservice.py
+++ b/lib/lp/oci/interfaces/webservice.py
@@ -24,12 +24,15 @@ from lp.registry.interfaces.ociprojectseries import IOCIProjectSeries
 from lp.services.webservice.apihelpers import (
     patch_collection_property,
     patch_entry_return_type,
+    patch_plain_parameter_type,
     patch_reference_property,
     )
 
 # IOCIProject
 patch_collection_property(IOCIProject, 'series', IOCIProjectSeries)
 patch_entry_return_type(IOCIProject, 'newRecipe', IOCIRecipe)
+patch_plain_parameter_type(
+    IOCIProject, 'setOfficialRecipeStatus', 'recipe', IOCIRecipe)
 
 # IOCIRecipe
 patch_collection_property(IOCIRecipe, 'builds', IOCIRecipeBuild)
diff --git a/lib/lp/registry/interfaces/ociproject.py b/lib/lp/registry/interfaces/ociproject.py
index 1845f8d..a8b6863 100644
--- a/lib/lp/registry/interfaces/ociproject.py
+++ b/lib/lp/registry/interfaces/ociproject.py
@@ -17,6 +17,7 @@ from lazr.restful.declarations import (
     call_with,
     error_status,
     export_factory_operation,
+    export_write_operation,
     exported,
     exported_as_webservice_entry,
     operation_for_version,
@@ -47,10 +48,7 @@ from lp import _
 from lp.app.validators.name import name_validator
 from lp.app.validators.path import path_does_not_escape
 from lp.bugs.interfaces.bugsupervisor import IHasBugSupervisor
-from lp.bugs.interfaces.bugtarget import (
-    IBugTarget,
-    IHasExpirableBugs,
-    )
+from lp.bugs.interfaces.bugtarget import IBugTarget
 from lp.code.interfaces.gitref import IGitRef
 from lp.code.interfaces.hasgitrepositories import IHasGitRepositories
 from lp.registry.interfaces.distribution import IDistribution
@@ -161,6 +159,18 @@ class IOCIProjectEdit(Interface):
                   status=SeriesStatus.DEVELOPMENT, date_created=DEFAULT):
         """Creates a new `IOCIProjectSeries`."""
 
+    @operation_parameters(
+        recipe=Reference(
+            Interface,
+            title=_("OCI Recipe"),
+            description=_("The OCI Recipe to change the status of."),
+            required=True),
+        status=Bool(
+            title=_("Official status"),
+            description=_("Whether the OCI Recipe should be official or not."),
+            required=True))
+    @export_write_operation()
+    @operation_for_version("devel")
     def setOfficialRecipeStatus(recipe, status):
         """Change whether an OCI Recipe is official or not for this project."""
 
diff --git a/lib/lp/registry/tests/test_ociproject.py b/lib/lp/registry/tests/test_ociproject.py
index 0232b2e..4082d10 100644
--- a/lib/lp/registry/tests/test_ociproject.py
+++ b/lib/lp/registry/tests/test_ociproject.py
@@ -20,6 +20,7 @@ from zope.schema.vocabulary import getVocabularyRegistry
 from zope.security.interfaces import Unauthorized
 from zope.security.proxy import removeSecurityProxy
 
+from lp.oci.interfaces.ocirecipe import OCI_RECIPE_ALLOW_CREATE
 from lp.registry.interfaces.ociproject import (
     IOCIProject,
     IOCIProjectSet,
@@ -315,6 +316,26 @@ class TestOCIProjectWebservice(TestCaseWithFactory):
 
         self.assertCanCreateOCIProject(distro, self.person)
 
+    def test_set_official_recipe_via_webservice(self):
+        self.useFixture(FeatureFixture({OCI_PROJECT_ALLOW_CREATE: 'on'}))
+        self.useFixture(FeatureFixture({OCI_RECIPE_ALLOW_CREATE: "on"}))
+        with person_logged_in(self.person):
+            distro = self.factory.makeDistribution(owner=self.person)
+            oci_project = self.factory.makeOCIProject(pillar=distro)
+            oci_recipe = self.factory.makeOCIRecipe(
+                oci_project=oci_project)
+            oci_recipe_url = api_url(oci_recipe)
+            url = api_url(oci_project)
+
+        obj = {"recipe": oci_recipe_url, "status": True}
+        self.webservice.named_post(
+            url, "setOfficialRecipeStatus", **obj)
+
+        with person_logged_in(self.person):
+            self.assertEqual(
+                [oci_recipe],
+                list(oci_project.getOfficialRecipes()))
+
 
 class TestOCIProjectVocabulary(TestCaseWithFactory):
     layer = DatabaseFunctionalLayer