Merge ~twom/launchpad:oci-admin-roles-need-edit into launchpad:master

Proposed by Tom Wardill
Status: Merged
Approved by: Tom Wardill
Approved revision: 416f566eebe5c94a61e3f48db4680cdc4c639c3f
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~twom/launchpad:oci-admin-roles-need-edit
Merge into: launchpad:master
Diff against target: 97 lines (+49/-9)
3 files modified
lib/lp/registry/browser/tests/test_ociproject.py (+30/-0)
lib/lp/registry/tests/test_ociproject.py (+14/-0)
lib/lp/security.py (+5/-9)
Reviewer Review Type Date Requested Status
Thiago F. Pappacena (community) Approve
Review via email: mp+384191@code.launchpad.net

Commit message

Allow edit permissions to oci_project_admin

Description of the change

The oci_project_admin team/role on a Distribution should be allowed to edit OCI Projects and OCI Project Series.
Add that to the list of allowed permissions.

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

Good set of tests. Thanks!
Added a comment that might worth thinking about, but it looks good to me.

review: Approve
416f566... by Tom Wardill

Use delegated authorization

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/lib/lp/registry/browser/tests/test_ociproject.py b/lib/lp/registry/browser/tests/test_ociproject.py
index 5a22137..5187cd6 100644
--- a/lib/lp/registry/browser/tests/test_ociproject.py
+++ b/lib/lp/registry/browser/tests/test_ociproject.py
@@ -128,6 +128,36 @@ class TestOCIProjectEditView(BrowserTestCase):
128 "Name:\nnew-name\nEdit OCI project",128 "Name:\nnew-name\nEdit OCI project",
129 MatchesTagText(content, "name"))129 MatchesTagText(content, "name"))
130130
131 def test_edit_oci_project_ad_oci_project_admin(self):
132 admin_person = self.factory.makePerson()
133 admin_team = self.factory.makeTeam(members=[admin_person])
134 original_distribution = self.factory.makeDistribution(
135 oci_project_admin=admin_team)
136 oci_project = self.factory.makeOCIProject(
137 pillar=original_distribution)
138 new_distribution = self.factory.makeDistribution(
139 oci_project_admin=admin_team)
140
141 browser = self.getViewBrowser(
142 oci_project, user=admin_person)
143 browser.getLink("Edit OCI project").click()
144 browser.getControl(name="field.distribution").value = [
145 new_distribution.name]
146 browser.getControl(name="field.name").value = "new-name"
147 browser.getControl("Update OCI project").click()
148
149 content = find_main_content(browser.contents)
150 self.assertEqual(
151 "OCI project new-name for %s" % new_distribution.display_name,
152 extract_text(content.h1))
153 self.assertThat(
154 "Distribution:\n%s\nEdit OCI project" % (
155 new_distribution.display_name),
156 MatchesTagText(content, "distribution"))
157 self.assertThat(
158 "Name:\nnew-name\nEdit OCI project",
159 MatchesTagText(content, "name"))
160
131 def test_edit_oci_project_sets_date_last_modified(self):161 def test_edit_oci_project_sets_date_last_modified(self):
132 # Editing an OCI project sets the date_last_modified property.162 # Editing an OCI project sets the date_last_modified property.
133 date_created = datetime(2000, 1, 1, tzinfo=pytz.UTC)163 date_created = datetime(2000, 1, 1, tzinfo=pytz.UTC)
diff --git a/lib/lp/registry/tests/test_ociproject.py b/lib/lp/registry/tests/test_ociproject.py
index fdddb4c..6ac98bb 100644
--- a/lib/lp/registry/tests/test_ociproject.py
+++ b/lib/lp/registry/tests/test_ociproject.py
@@ -58,6 +58,20 @@ class TestOCIProject(TestCaseWithFactory):
58 registrant)58 registrant)
59 self.assertProvides(series, IOCIProjectSeries)59 self.assertProvides(series, IOCIProjectSeries)
6060
61 def test_newSeries_as_oci_project_admin(self):
62 admin_person = self.factory.makePerson()
63 admin_team = self.factory.makeTeam(members=[admin_person])
64 distribution = self.factory.makeDistribution(
65 oci_project_admin=admin_team)
66 oci_project = self.factory.makeOCIProject(pillar=distribution)
67 registrant = self.factory.makePerson()
68 with person_logged_in(admin_person):
69 series = oci_project.newSeries(
70 'test-series',
71 'test-summary',
72 registrant)
73 self.assertProvides(series, IOCIProjectSeries)
74
61 def test_newSeries_bad_permissions(self):75 def test_newSeries_bad_permissions(self):
62 distribution = self.factory.makeDistribution()76 distribution = self.factory.makeDistribution()
63 registrant = self.factory.makePerson()77 registrant = self.factory.makePerson()
diff --git a/lib/lp/security.py b/lib/lp/security.py
index 0eec9f3..f7d7bf8 100644
--- a/lib/lp/security.py
+++ b/lib/lp/security.py
@@ -3462,21 +3462,17 @@ class EditOCIProject(AuthorizationBase):
34623462
3463 def checkAuthenticated(self, user):3463 def checkAuthenticated(self, user):
3464 """Maintainers, drivers, and admins can drive projects."""3464 """Maintainers, drivers, and admins can drive projects."""
3465 # XXX twom 2019-10-29 This ideally shouldn't be driver, but a
3466 # new role name that cascades upwards from the OCIProject
3467 # to the pillar
3468 return (user.in_admin or3465 return (user.in_admin or
3469 user.isDriver(self.obj.pillar))3466 user.isDriver(self.obj.pillar) or
3467 user.inTeam(self.obj.pillar.oci_project_admin))
34703468
34713469
3472class EditOCIProjectSeries(AuthorizationBase):3470class EditOCIProjectSeries(DelegatedAuthorization):
3473 permission = 'launchpad.Edit'3471 permission = 'launchpad.Edit'
3474 usedfor = IOCIProjectSeries3472 usedfor = IOCIProjectSeries
34753473
3476 def checkAuthenticated(self, user):3474 def __init__(self, obj):
3477 """Maintainers, drivers, and admins can drive projects."""3475 super(EditOCIProjectSeries, self).__init__(obj, obj.oci_project)
3478 return (user.in_admin or
3479 user.isDriver(self.obj.oci_project.pillar))
34803476
34813477
3482class ViewOCIRecipeBuildRequest(DelegatedAuthorization):3478class ViewOCIRecipeBuildRequest(DelegatedAuthorization):

Subscribers

People subscribed via source and target branches

to status/vote changes: