launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #24928
[Merge] ~pappacena/launchpad:hide-empty-search-ociproject into launchpad:master
Thiago F. Pappacena has proposed merging ~pappacena/launchpad:hide-empty-search-ociproject into launchpad:master.
Commit message:
Hiding the "search OCI project" link on pillars that do not have any OCI project registered yet.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~pappacena/launchpad/+git/launchpad/+merge/386539
--
Your team Launchpad code reviewers is requested to review the proposed merge of ~pappacena/launchpad:hide-empty-search-ociproject into launchpad:master.
diff --git a/lib/lp/code/browser/tests/test_product.py b/lib/lp/code/browser/tests/test_product.py
index 57540e3..bfedbc9 100644
--- a/lib/lp/code/browser/tests/test_product.py
+++ b/lib/lp/code/browser/tests/test_product.py
@@ -434,10 +434,25 @@ class TestProductOverviewOCIProject(TestCaseWithFactory):
def test_displays_create_and_list_oci_project_link(self):
product = self.factory.makeProduct()
+ self.factory.makeOCIProject(pillar=product)
browser = self.getUserBrowser(
canonical_url(product), user=product.owner)
text = extract_text(find_tag_by_id(browser.contents, 'global-actions'))
+ # Search link should be available because we have an OCI project
+ # created.
self.assertIn("Search for OCI Project", text)
self.assertIn("Create an OCI Project", text)
+
+ def test_show_create_and_hide_list_oci_project_link(self):
+ product = self.factory.makeProduct()
+
+ browser = self.getUserBrowser(
+ canonical_url(product), user=product.owner)
+ text = extract_text(find_tag_by_id(browser.contents, 'global-actions'))
+
+ # Search link should not be available, since do not have any OCI
+ # project created.
+ self.assertNotIn("Search for OCI Project", text)
+ self.assertIn("Create an OCI Project", text)
diff --git a/lib/lp/registry/browser/distribution.py b/lib/lp/registry/browser/distribution.py
index 351aa1a..fcf8865 100644
--- a/lib/lp/registry/browser/distribution.py
+++ b/lib/lp/registry/browser/distribution.py
@@ -105,6 +105,7 @@ from lp.registry.interfaces.distributionmirror import (
MirrorContent,
MirrorSpeed,
)
+from lp.registry.interfaces.ociproject import IOCIProjectSet
from lp.registry.interfaces.series import SeriesStatus
from lp.services.database.decoratedresultset import DecoratedResultSet
from lp.services.feeds.browser import FeedsMixin
@@ -323,8 +324,13 @@ class DistributionNavigationMenu(NavigationMenu, DistributionLinksMixin):
return Link('+new-oci-project', text, icon='add')
def search_oci_project(self):
+ pillar = self.context
+ oci_projects = getUtility(IOCIProjectSet).findByPillarAndName(
+ pillar, u'')
text = 'Search for OCI Project'
- return Link('+search-oci-project', text, icon='info')
+ link = Link('+search-oci-project', text, icon='info')
+ link.enabled = not oci_projects.is_empty()
+ return link
@cachedproperty
def links(self):
diff --git a/lib/lp/registry/browser/product.py b/lib/lp/registry/browser/product.py
index 71595ee..6694303 100644
--- a/lib/lp/registry/browser/product.py
+++ b/lib/lp/registry/browser/product.py
@@ -181,6 +181,7 @@ from lp.registry.browser.pillar import (
PillarViewMixin,
)
from lp.registry.enums import VCSType
+from lp.registry.interfaces.ociproject import IOCIProjectSet
from lp.registry.interfaces.pillar import IPillarNameSet
from lp.registry.interfaces.product import (
IProduct,
@@ -509,8 +510,13 @@ class ProductEditLinksMixin(StructuralSubscriptionMenuMixin):
return Link('+sharing', 'Sharing', icon='edit')
def search_oci_project(self):
+ pillar = self.context.context
+ oci_projects = getUtility(IOCIProjectSet).findByPillarAndName(
+ pillar, u'')
text = 'Search for OCI Project'
- return Link('+search-oci-project', text, icon='info')
+ link = Link('+search-oci-project', text, icon='info')
+ link.enabled = not oci_projects.is_empty()
+ return link
@enabled_with_permission('launchpad.Driver')
def new_oci_project(self):
diff --git a/lib/lp/registry/browser/tests/test_distribution.py b/lib/lp/registry/browser/tests/test_distribution.py
index d3cd559..f8cbe86 100644
--- a/lib/lp/registry/browser/tests/test_distribution.py
+++ b/lib/lp/registry/browser/tests/test_distribution.py
@@ -111,6 +111,32 @@ class TestDistributionPage(TestCaseWithFactory):
)
self.assertThat(view.render(), series_matches)
+ def test_distributionpage_search_oci_project_link_is_hidden(self):
+ # User can't see the +search-oci-project link if there are no
+ # available OCI projects.
+ admin = login_celebrity('admin')
+ browser = self.getUserBrowser(canonical_url(self.distro), user=admin)
+ matchers = Not(soupmatchers.HTMLContains(
+ soupmatchers.Tag(
+ 'link to search oci project', 'a',
+ attrs={'href': canonical_url(
+ self.distro, view_name='+search-oci-project')},
+ text='Search for OCI Project')))
+ self.assertThat(browser.contents, matchers)
+
+ def test_distributionpage_search_oci_project_link_is_shown(self):
+ # User can see the +search-oci-project link if there are OCI projects.
+ self.factory.makeOCIProject(pillar=self.distro)
+ admin = login_celebrity('admin')
+ browser = self.getUserBrowser(canonical_url(self.distro), user=admin)
+ matchers = soupmatchers.HTMLContains(
+ soupmatchers.Tag(
+ 'link to search oci project', 'a',
+ attrs={'href': canonical_url(
+ self.distro, view_name='+search-oci-project')},
+ text='Search for OCI Project'))
+ self.assertThat(browser.contents, matchers)
+
def test_distributionpage_addseries_link_noadmin(self):
# A non-admin does not see the +addseries link nor the series
# header (since there is no series yet).
Follow ups