Thiago F. Pappacena has proposed merging ~pappacena/launchpad:oci-recipes-link-for-teams into launchpad:master.
Commit message: Moving "View OCI recipe" link to correct place and adding it to team page Requested reviews: Launchpad code reviewers (launchpad-reviewers) For more details, see: https://code.launchpad.net/~pappacena/launchpad/+git/launchpad/+merge/400897 -- Your team Launchpad code reviewers is requested to review the proposed merge of ~pappacena/launchpad:oci-recipes-link-for-teams into launchpad:master.
diff --git a/lib/lp/oci/browser/hasocirecipes.py b/lib/lp/oci/browser/hasocirecipes.py new file mode 100644 index 0000000..2df4148 --- /dev/null +++ b/lib/lp/oci/browser/hasocirecipes.py @@ -0,0 +1,27 @@ +# Copyright 2021 Canonical Ltd. This software is licensed under the +# GNU Affero General Public License version 3 (see the file LICENSE). + +"""Mixins for browser classes for objects related to OCI recipe.""" + +from __future__ import absolute_import, print_function, unicode_literals + +__metaclass__ = type +__all__ = [ + 'HasOCIRecipesMenuMixin', + ] + +from lp.oci.interfaces.ocirecipe import IOCIRecipeSet +from zope.component import getUtility + +from lp.services.webapp import Link + + +class HasOCIRecipesMenuMixin: + """A mixin for context menus for objects that has OCI recipes.""" + + def view_oci_recipes(self): + target = '+oci-recipes' + text = 'View OCI recipes' + enabled = not getUtility(IOCIRecipeSet).findByContext( + self.context, visible_by_user=self.user).is_empty() + return Link(target, text, enabled=enabled, icon='info') diff --git a/lib/lp/registry/browser/person.py b/lib/lp/registry/browser/person.py index 6d5d8da..2b71694 100644 --- a/lib/lp/registry/browser/person.py +++ b/lib/lp/registry/browser/person.py @@ -138,11 +138,9 @@ from lp.code.browser.sourcepackagerecipelisting import HasRecipesMenuMixin from lp.code.errors import InvalidNamespace from lp.code.interfaces.branchnamespace import IBranchNamespaceSet from lp.code.interfaces.gitlookup import IGitTraverser +from lp.oci.browser.hasocirecipes import HasOCIRecipesMenuMixin from lp.oci.interfaces.ocipushrule import IOCIPushRuleSet -from lp.oci.interfaces.ocirecipe import ( - IOCIRecipe, - IOCIRecipeSet, - ) +from lp.oci.interfaces.ocirecipe import IOCIRecipe from lp.oci.interfaces.ociregistrycredentials import ( IOCIRegistryCredentialsSet, OCIRegistryCredentialsAlreadyExist, @@ -777,13 +775,6 @@ class CommonMenuLinks: enabled = user_can_edit_credentials_for_owner(self.context, self.user) return Link(target, text, enabled=enabled, icon='info') - def oci_recipes(self): - target = '+oci-recipes' - text = 'OCI recipes' - enabled = not getUtility(IOCIRecipeSet).findByContext( - self.context, visible_by_user=self.user).is_empty() - return Link(target, text, enabled=enabled, icon='info') - class PersonMenuMixin(CommonMenuLinks): @@ -818,8 +809,8 @@ class PersonMenuMixin(CommonMenuLinks): return Link(target, text, icon='edit') -class PersonOverviewMenu(ApplicationMenu, PersonMenuMixin, - HasRecipesMenuMixin, HasSnapsMenuMixin): +class PersonOverviewMenu(ApplicationMenu, PersonMenuMixin, HasRecipesMenuMixin, + HasSnapsMenuMixin, HasOCIRecipesMenuMixin): usedfor = IPerson facet = 'overview' @@ -848,10 +839,10 @@ class PersonOverviewMenu(ApplicationMenu, PersonMenuMixin, 'ppa', 'oauth_tokens', 'oci_registry_credentials', - 'oci_recipes', 'related_software_summary', 'view_recipes', 'view_snaps', + 'view_oci_recipes', 'subscriptions', 'structural_subscriptions', ] diff --git a/lib/lp/registry/browser/team.py b/lib/lp/registry/browser/team.py index 93f121c..d419603 100644 --- a/lib/lp/registry/browser/team.py +++ b/lib/lp/registry/browser/team.py @@ -1,4 +1,4 @@ -# Copyright 2009-2020 Canonical Ltd. This software is licensed under the +# Copyright 2009-2021 Canonical Ltd. This software is licensed under the # GNU Affero General Public License version 3 (see the file LICENSE). __metaclass__ = type @@ -94,6 +94,7 @@ from lp.app.widgets.itemswidgets import ( from lp.app.widgets.owner import HiddenUserWidget from lp.app.widgets.popup import PersonPickerWidget from lp.code.browser.sourcepackagerecipelisting import HasRecipesMenuMixin +from lp.oci.browser.hasocirecipes import HasOCIRecipesMenuMixin from lp.registry.browser.branding import BrandingChangeView from lp.registry.browser.mailinglists import enabled_with_active_mailing_list from lp.registry.browser.objectreassignment import ObjectReassignmentView @@ -1623,7 +1624,7 @@ class TeamMenuMixin(PPANavigationMenuMixIn, CommonMenuLinks): class TeamOverviewMenu(ApplicationMenu, TeamMenuMixin, HasRecipesMenuMixin, - HasSnapsMenuMixin): + HasSnapsMenuMixin, HasOCIRecipesMenuMixin): usedfor = ITeam facet = 'overview' @@ -1653,6 +1654,7 @@ class TeamOverviewMenu(ApplicationMenu, TeamMenuMixin, HasRecipesMenuMixin, 'related_software_summary', 'view_recipes', 'view_snaps', + 'view_oci_recipes', 'subscriptions', 'structural_subscriptions', 'upcomingwork', diff --git a/lib/lp/registry/browser/tests/test_person.py b/lib/lp/registry/browser/tests/test_person.py index bbc2f4e..b327adc 100644 --- a/lib/lp/registry/browser/tests/test_person.py +++ b/lib/lp/registry/browser/tests/test_person.py @@ -479,7 +479,7 @@ class TestPersonIndexView(BrowserTestCase): 'OCI recipes link', 'a', attrs={ 'href': expected_url}, - text='OCI recipes')) + text='View OCI recipes')) self.assertThat(markup, link_match) login(ANONYMOUS) @@ -501,7 +501,7 @@ class TestPersonIndexView(BrowserTestCase): 'OCI recipes link', 'a', attrs={ 'href': expected_url}, - text='OCI recipes')) + text='View OCI recipes')) self.assertThat(markup, Not(link_match)) login(ANONYMOUS) diff --git a/lib/lp/registry/browser/tests/test_team.py b/lib/lp/registry/browser/tests/test_team.py index a26c701..03a7d3f 100644 --- a/lib/lp/registry/browser/tests/test_team.py +++ b/lib/lp/registry/browser/tests/test_team.py @@ -1,4 +1,4 @@ -# Copyright 2010-2020 Canonical Ltd. This software is licensed under the +# Copyright 2010-2021 Canonical Ltd. This software is licensed under the # GNU Affero General Public License version 3 (see the file LICENSE). from __future__ import absolute_import, print_function, unicode_literals @@ -16,6 +16,7 @@ from zope.component import getUtility from zope.security.proxy import removeSecurityProxy from lp.app.enums import InformationType +from lp.oci.interfaces.ocirecipe import OCI_RECIPE_ALLOW_CREATE from lp.registry.browser.team import ( TeamIndexMenu, TeamMailingListArchiveView, @@ -35,6 +36,7 @@ from lp.registry.interfaces.teammembership import ( ITeamMembershipSet, TeamMembershipStatus, ) +from lp.services.features.testing import FeatureFixture from lp.services.propertycache import get_property_cache from lp.services.webapp.authorization import check_permission from lp.services.webapp.escaping import html_escape @@ -936,6 +938,54 @@ class TestTeamIndexView(TestCaseWithFactory): self.assertNotEqual('', markup) self.assertThat(markup, Not(link_match)) + def test_show_oci_recipes_link(self): + self.useFixture(FeatureFixture({OCI_RECIPE_ALLOW_CREATE: "on"})) + member = self.factory.makePerson() + team = self.factory.makeTeam(owner=member, members=[member]) + + # Creates a recipe, so the link appears. + self.factory.makeOCIRecipe(owner=team, registrant=member) + with person_logged_in(member): + expected_url = 'http://launchpad.test/~%s/+oci-recipes' % team.name + team_url = canonical_url(team) + browser = self.getUserBrowser(team_url, user=member) + + link_match = soupmatchers.HTMLContains( + soupmatchers.Tag( + 'OCI recipes link', 'a', + attrs={ + 'href': expected_url}, + text='View OCI recipes')) + self.assertThat(browser.contents, link_match) + + browser = self.getUserBrowser(team_url, user=None) + self.assertThat(browser.contents, link_match) + + def test_hides_oci_recipes_link_if_user_doesnt_have_oci_recipes(self): + self.useFixture(FeatureFixture({OCI_RECIPE_ALLOW_CREATE: "on"})) + member = self.factory.makePerson() + team = self.factory.makeTeam(owner=member, members=[member]) + + # Creates a recipe from another user, just to make sure it will not + # interfere. + self.factory.makeOCIRecipe() + + with person_logged_in(member): + expected_url = 'http://launchpad.test/~%s/+oci-recipes' % team.name + team_url = canonical_url(team) + browser = self.getUserBrowser(team_url, user=member) + + link_match = soupmatchers.HTMLContains( + soupmatchers.Tag( + 'OCI recipes link', 'a', + attrs={ + 'href': expected_url}, + text='View OCI recipes')) + self.assertThat(browser.contents, Not(link_match)) + + browser = self.getUserBrowser(team_url, user=None) + self.assertThat(browser.contents, Not(link_match)) + class TestPersonIndexVisibilityView(TestCaseWithFactory): diff --git a/lib/lp/registry/templates/person-index.pt b/lib/lp/registry/templates/person-index.pt index 708c477..1261219 100644 --- a/lib/lp/registry/templates/person-index.pt +++ b/lib/lp/registry/templates/person-index.pt @@ -92,10 +92,6 @@ tal:define="link context/menu:overview/oci_registry_credentials" tal:condition="link/enabled" tal:content="structure link/fmt:link" /> - <li - tal:define="link context/menu:overview/oci_recipes" - tal:condition="link/enabled" - tal:content="structure link/fmt:link" /> </ul> <div class="yui-g"> diff --git a/lib/lp/registry/templates/team-index.pt b/lib/lp/registry/templates/team-index.pt index 25db8f5..8d78109 100644 --- a/lib/lp/registry/templates/team-index.pt +++ b/lib/lp/registry/templates/team-index.pt @@ -90,7 +90,8 @@ <div class="yui-g"> <!-- First portlet column. --> <div class="first yui-u"> - <div tal:content="structure context/@@+portlet-ppas" /> + <span tal:content="context/menu:overview/view_oci_recipes" /> + vai menu: <div tal:content="structure context/@@+portlet-ppas" /> <div tal:content="structure context/@@+portlet-mailinglist" /> </div> diff --git a/lib/lp/soyuz/templates/person-portlet-ppas.pt b/lib/lp/soyuz/templates/person-portlet-ppas.pt index 8f6453e..19b7e6e 100644 --- a/lib/lp/soyuz/templates/person-portlet-ppas.pt +++ b/lib/lp/soyuz/templates/person-portlet-ppas.pt @@ -33,15 +33,19 @@ </div> <ul class="horizontal" style="margin-top: 0;" tal:define="recipes_link context/menu:overview/view_recipes; - snaps_link context/menu:overview/view_snaps" - tal:condition="python: recipes_link.enabled or snaps_link.enabled"> + snaps_link context/menu:overview/view_snaps; + oci_recipes_link context/menu:overview/view_oci_recipes" + tal:condition="python: recipes_link.enabled + or snaps_link.enabled + or oci_recipes_link.enabled"> <li tal:condition="recipes_link/enabled"> <a tal:replace="structure recipes_link/fmt:link" /> </li> <li tal:condition="snaps_link/enabled"> <a tal:replace="structure snaps_link/fmt:link" /> </li> + <li tal:condition="oci_recipes_link/enabled"> + <a tal:replace="structure oci_recipes_link/fmt:link" /> + </li> </ul> - - </tal:root>
_______________________________________________ Mailing list: https://launchpad.net/~launchpad-reviewers Post to : launchpad-reviewers@lists.launchpad.net Unsubscribe : https://launchpad.net/~launchpad-reviewers More help : https://help.launchpad.net/ListHelp