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

Proposed by Tom Wardill
Status: Merged
Approved by: Tom Wardill
Approved revision: 088e517e2f81b5ee3687833e2c669e2a3b89cc9c
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~twom/launchpad:oci-policy-default-the-current-officialness
Merge into: launchpad:master
Diff against target: 41 lines (+18/-1)
2 files modified
lib/lp/oci/browser/ocirecipe.py (+1/-1)
lib/lp/oci/browser/tests/test_ocirecipe.py (+17/-0)
Reviewer Review Type Date Requested Status
Tom Wardill (community) Approve
Thiago F. Pappacena (community) Approve
Review via email: mp+396844@code.launchpad.net

Commit message

Fix official value on editing while not an admin

Description of the change

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.

To post a comment you must log in.
Revision history for this message
Thiago F. Pappacena (pappacena) wrote :

LGTM

review: Approve
be4750a... by Tom Wardill

Add negative check to existing test

Revision history for this message
Tom Wardill (twom) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/lp/oci/browser/ocirecipe.py b/lib/lp/oci/browser/ocirecipe.py
2index d1bd570..abaff05 100644
3--- a/lib/lp/oci/browser/ocirecipe.py
4+++ b/lib/lp/oci/browser/ocirecipe.py
5@@ -996,7 +996,7 @@ class OCIRecipeEditView(BaseOCIRecipeEditView, EnableProcessorsMixin,
6 "Allows use of distribution registry credentials "
7 "and the default git repository routing. "
8 "May only be enabled by the owner of the OCI Project."),
9- default=False,
10+ default=self.context.official,
11 required=False, readonly=False))
12
13 def validate(self, data):
14diff --git a/lib/lp/oci/browser/tests/test_ocirecipe.py b/lib/lp/oci/browser/tests/test_ocirecipe.py
15index 7c3ccdb..d9cb417 100644
16--- a/lib/lp/oci/browser/tests/test_ocirecipe.py
17+++ b/lib/lp/oci/browser/tests/test_ocirecipe.py
18@@ -887,6 +887,23 @@ class TestOCIRecipeEditView(OCIConfigHelperMixin, BaseTestOCIRecipeView):
19 browser.getLink("Edit OCI recipe").click()
20 official_control = browser.getControl("Official recipe")
21 self.assertTrue(official_control.disabled)
22+ self.assertFalse(official_control.selected)
23+
24+ def test_official_is_set_while_disabled(self):
25+ distribution = self.factory.makeDistribution(
26+ oci_project_admin=self.person)
27+ non_admin = self.factory.makePerson()
28+ oci_project = self.factory.makeOCIProject(pillar=distribution)
29+ recipe = self.factory.makeOCIRecipe(
30+ registrant=non_admin, owner=non_admin,
31+ oci_project=oci_project)
32+ with person_logged_in(self.person):
33+ oci_project.setOfficialRecipeStatus(recipe, True)
34+ browser = self.getViewBrowser(recipe, user=non_admin)
35+ browser.getLink("Edit OCI recipe").click()
36+ official_control = browser.getControl("Official recipe")
37+ self.assertTrue(official_control.disabled)
38+ self.assertTrue(official_control.selected)
39
40 def test_official_is_enabled(self):
41 distribution = self.factory.makeDistribution(

Subscribers

People subscribed via source and target branches

to status/vote changes: