Merge ~lgp171188/launchpad:allow-launchpad-team-to-view-mirror-prober-logs into launchpad:master

Proposed by Guruprasad
Status: Merged
Approved by: Guruprasad
Approved revision: 984cbfa861756b5a2b9477a1a2cd7f5748788e42
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~lgp171188/launchpad:allow-launchpad-team-to-view-mirror-prober-logs
Merge into: launchpad:master
Diff against target: 147 lines (+59/-4)
6 files modified
lib/lp/registry/browser/configure.zcml (+1/-1)
lib/lp/registry/browser/distributionmirror.py (+1/-1)
lib/lp/registry/security.py (+11/-0)
lib/lp/registry/stories/distributionmirror/xx-distributionmirror-prober-logs.rst (+26/-1)
lib/lp/registry/templates/distributionmirror-index.pt (+1/-1)
lib/lp/registry/tests/test_distributionmirror.py (+19/-0)
Reviewer Review Type Date Requested Status
Colin Watson (community) Approve
Ioana Lasc (community) Approve
Review via email: mp+434409@code.launchpad.net

Commit message

Allow Launchpad team members to view mirror prober logs

Show the side menu with a link to the prober logs for users
with the 'launchpad.Moderate' permission on a distribution mirror.

To post a comment you must log in.
Revision history for this message
Ioana Lasc (ilasc) wrote :

Looks good!

review: Approve
Revision history for this message
Colin Watson (cjwatson) :
review: Approve
Revision history for this message
Guruprasad (lgp171188) :
Revision history for this message
Guruprasad (lgp171188) :
Revision history for this message
Colin Watson (cjwatson) :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/lib/lp/registry/browser/configure.zcml b/lib/lp/registry/browser/configure.zcml
index 80a57d0..22096c8 100644
--- a/lib/lp/registry/browser/configure.zcml
+++ b/lib/lp/registry/browser/configure.zcml
@@ -2598,7 +2598,7 @@
2598 name="+prober-logs"2598 name="+prober-logs"
2599 for="lp.registry.interfaces.distributionmirror.IDistributionMirror"2599 for="lp.registry.interfaces.distributionmirror.IDistributionMirror"
2600 class="lp.registry.browser.distributionmirror.DistributionMirrorProberLogView"2600 class="lp.registry.browser.distributionmirror.DistributionMirrorProberLogView"
2601 permission="launchpad.Edit"2601 permission="launchpad.Moderate"
2602 template="../templates/distributionmirror-prober-logs.pt">2602 template="../templates/distributionmirror-prober-logs.pt">
2603 </browser:page>2603 </browser:page>
2604 <browser:menus2604 <browser:menus
diff --git a/lib/lp/registry/browser/distributionmirror.py b/lib/lp/registry/browser/distributionmirror.py
index 75aa827..262784e 100644
--- a/lib/lp/registry/browser/distributionmirror.py
+++ b/lib/lp/registry/browser/distributionmirror.py
@@ -61,7 +61,7 @@ class DistributionMirrorOverviewMenu(NavigationMenu):
61 text = "Change details"61 text = "Change details"
62 return Link("+edit", text, icon="edit")62 return Link("+edit", text, icon="edit")
6363
64 @enabled_with_permission("launchpad.Edit")64 @enabled_with_permission("launchpad.Moderate")
65 def proberlogs(self):65 def proberlogs(self):
66 text = "Prober logs"66 text = "Prober logs"
67 enabled = self.context.last_probe_record is not None67 enabled = self.context.last_probe_record is not None
diff --git a/lib/lp/registry/security.py b/lib/lp/registry/security.py
index 0487001..97e7643 100644
--- a/lib/lp/registry/security.py
+++ b/lib/lp/registry/security.py
@@ -385,6 +385,17 @@ class EditDistributionMirrorByOwnerOrDistroOwnerOrMirrorAdminsOrAdmins(
385 )385 )
386386
387387
388class ModerateDistributionMirror(AuthorizationBase):
389 permission = "launchpad.Moderate"
390 usedfor = IDistributionMirror
391
392 def checkAuthenticated(self, user):
393 return (
394 self.forwardCheckAuthenticated(user, self.obj, "launchpad.Edit")
395 or user.in_launchpad_developers
396 )
397
398
388class ViewDistributionMirror(AnonymousAuthorization):399class ViewDistributionMirror(AnonymousAuthorization):
389 """Anyone can view an IDistributionMirror."""400 """Anyone can view an IDistributionMirror."""
390401
diff --git a/lib/lp/registry/stories/distributionmirror/xx-distributionmirror-prober-logs.rst b/lib/lp/registry/stories/distributionmirror/xx-distributionmirror-prober-logs.rst
index 8b9ae98..581bb7f 100644
--- a/lib/lp/registry/stories/distributionmirror/xx-distributionmirror-prober-logs.rst
+++ b/lib/lp/registry/stories/distributionmirror/xx-distributionmirror-prober-logs.rst
@@ -3,7 +3,7 @@ Distribution mirror prober logs
33
4Every time we probe a mirror for its contents we keep a log of the probe.4Every time we probe a mirror for its contents we keep a log of the probe.
5All these logs can be seen by the mirror owner or the mirror admin of5All these logs can be seen by the mirror owner or the mirror admin of
6that mirror's distribution.6that mirror's distribution or Launchpad team members.
77
8 >>> browser.addHeader("Authorization", "Basic mark@example.com:test")8 >>> browser.addHeader("Authorization", "Basic mark@example.com:test")
9 >>> browser.open("http://launchpad.test/ubuntu/+mirror/archive-mirror2/")9 >>> browser.open("http://launchpad.test/ubuntu/+mirror/archive-mirror2/")
@@ -18,6 +18,31 @@ that mirror's distribution.
18 >>> print(extract_text(navigation.decode_contents()))18 >>> print(extract_text(navigation.decode_contents()))
19 1...→...1...of...1...result19 1...→...1...of...1...result
2020
21 >>> login("admin@canonical.com")
22 >>> from zope.component import getUtility
23 >>> from lp.app.interfaces.launchpad import ILaunchpadCelebrities
24 >>> launchpad_developer = factory.makePerson(
25 ... member_of=[getUtility(ILaunchpadCelebrities).launchpad_developers]
26 ... )
27 >>> from lp.testing import logout
28 >>> logout()
29
30 >>> from lp.testing.pages import setupBrowserForUser
31 >>> lp_dev_browser = setupBrowserForUser(launchpad_developer)
32 >>> lp_dev_browser.open(
33 ... "http://launchpad.test/ubuntu/+mirror/archive-mirror2/"
34 ... )
35 >>> lp_dev_browser.getLink("Prober logs").click()
36 >>> lp_dev_browser.url
37 'http://launchpad.test/ubuntu/+mirror/archive-mirror2/+prober-logs'
38
39 >>> navigation = find_tags_by_class(
40 ... lp_dev_browser.contents, "batch-navigation-index"
41 ... )[0]
42 >>> print(extract_text(navigation.decode_contents()))
43 1...→...1...of...1...result
44
45
21A random logged in user won't have the rights to see that page.46A random logged in user won't have the rights to see that page.
2247
23 >>> user_browser.open(48 >>> user_browser.open(
diff --git a/lib/lp/registry/templates/distributionmirror-index.pt b/lib/lp/registry/templates/distributionmirror-index.pt
index 3d840d0..2e7cbec 100644
--- a/lib/lp/registry/templates/distributionmirror-index.pt
+++ b/lib/lp/registry/templates/distributionmirror-index.pt
@@ -157,7 +157,7 @@
157 </div>157 </div>
158 </tal:main>158 </tal:main>
159159
160 <tal:side metal:fill-slot="side" condition="context/required:launchpad.Edit">160 <tal:side metal:fill-slot="side" condition="context/required:launchpad.Moderate">
161 <tal:menu replace="structure context/@@+global-actions" />161 <tal:menu replace="structure context/@@+global-actions" />
162 </tal:side>162 </tal:side>
163</body>163</body>
diff --git a/lib/lp/registry/tests/test_distributionmirror.py b/lib/lp/registry/tests/test_distributionmirror.py
index 4e301c5..7d6a2ee 100644
--- a/lib/lp/registry/tests/test_distributionmirror.py
+++ b/lib/lp/registry/tests/test_distributionmirror.py
@@ -18,11 +18,14 @@ from lp.registry.interfaces.person import IPersonSet
18from lp.registry.interfaces.pocket import PackagePublishingPocket18from lp.registry.interfaces.pocket import PackagePublishingPocket
19from lp.services.database.sqlbase import flush_database_updates19from lp.services.database.sqlbase import flush_database_updates
20from lp.services.mail import stub20from lp.services.mail import stub
21from lp.services.webapp.authorization import check_permission
21from lp.services.webapp.interfaces import OAuthPermission22from lp.services.webapp.interfaces import OAuthPermission
22from lp.services.worlddata.interfaces.country import ICountrySet23from lp.services.worlddata.interfaces.country import ICountrySet
23from lp.testing import (24from lp.testing import (
24 TestCaseWithFactory,25 TestCaseWithFactory,
26 admin_logged_in,
25 api_url,27 api_url,
28 celebrity_logged_in,
26 login,29 login,
27 login_as,30 login_as,
28 person_logged_in,31 person_logged_in,
@@ -57,6 +60,22 @@ class TestDistributionMirror(TestCaseWithFactory):
57 )60 )
58 removeSecurityProxy(bin_mirror).freshness = freshness61 removeSecurityProxy(bin_mirror).freshness = freshness
5962
63 def test_distributionmirror_moderate_permission(self):
64 with admin_logged_in():
65 self.assertTrue(
66 check_permission("launchpad.Moderate", self.archive_mirror)
67 )
68
69 with person_logged_in(self.archive_mirror.distribution.owner):
70 self.assertTrue(
71 check_permission("launchpad.Moderate", self.archive_mirror)
72 )
73
74 with celebrity_logged_in("launchpad_developers"):
75 self.assertTrue(
76 check_permission("launchpad.Moderate", self.archive_mirror)
77 )
78
60 def test_archive_mirror_without_content_should_be_disabled(self):79 def test_archive_mirror_without_content_should_be_disabled(self):
61 self.assertTrue(self.archive_mirror.shouldDisable())80 self.assertTrue(self.archive_mirror.shouldDisable())
6281

Subscribers

People subscribed via source and target branches

to status/vote changes: