← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~pappacena/launchpad:snap-project-links into launchpad:master

 

Thiago F. Pappacena has proposed merging ~pappacena/launchpad:snap-project-links into launchpad:master with ~pappacena/launchpad:snap-create-on-project as a prerequisite.

Commit message:
Adding +new-snap link to project page

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~pappacena/launchpad/+git/launchpad/+merge/399224

This is a complementary MP for the +new-snap page on project (https://code.launchpad.net/~pappacena/launchpad/+git/launchpad/+merge/399184)
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~pappacena/launchpad:snap-project-links into launchpad:master.
diff --git a/lib/lp/code/browser/tests/test_product.py b/lib/lp/code/browser/tests/test_product.py
index 2115eb5..61a6240 100644
--- a/lib/lp/code/browser/tests/test_product.py
+++ b/lib/lp/code/browser/tests/test_product.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).
 
 """Tests for the product view classes and templates."""
@@ -430,14 +430,39 @@ class TestCanConfigureBranches(TestCaseWithFactory):
         self.assertTrue(view.can_configure_branches())
 
 
-class TestProductOverviewOCIProject(TestCaseWithFactory):
+class TestProductOverviewLinks(TestCaseWithFactory):
 
     layer = DatabaseFunctionalLayer
 
     def setUp(self, user=ANONYMOUS):
-        super(TestProductOverviewOCIProject, self).setUp(user)
+        super(TestProductOverviewLinks, self).setUp(user)
         self.useFixture(FeatureFixture({OCI_PROJECT_ALLOW_CREATE: True}))
 
+    def test_displays_create_and_list_snaps(self):
+        project = self.factory.makeProduct()
+        self.factory.makeSnap(project=project)
+
+        browser = self.getUserBrowser(
+            canonical_url(project), user=project.owner)
+        text = extract_text(
+            find_tag_by_id(browser.contents, 'project-link-info'))
+
+        # Search link should be available because we have an Snap created.
+        self.assertIn("View snap packages", text)
+        self.assertIn("Create snap package", text)
+
+    def test_hides_list_snaps_if_no_snap_is_available(self):
+        project = self.factory.makeProduct()
+
+        browser = self.getUserBrowser(
+            canonical_url(project), user=project.owner)
+        text = extract_text(
+            find_tag_by_id(browser.contents, 'project-link-info'))
+
+        # Search link should not be available.
+        self.assertNotIn("View snap packages", text)
+        self.assertIn("Create snap package", text)
+
     def test_displays_create_and_list_oci_project_link_for_owner(self):
         product = self.factory.makeProduct()
         self.factory.makeOCIProject(pillar=product)
diff --git a/lib/lp/registry/browser/product.py b/lib/lp/registry/browser/product.py
index 780c236..df7ee7a 100644
--- a/lib/lp/registry/browser/product.py
+++ b/lib/lp/registry/browser/product.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).
 
 """Browser views for products."""
@@ -233,6 +233,7 @@ from lp.services.webapp.vhosts import allvhosts
 from lp.services.worlddata.helpers import browser_languages
 from lp.services.worlddata.interfaces.country import ICountry
 from lp.snappy.browser.hassnaps import HasSnapsMenuMixin
+from lp.snappy.interfaces.snap import ISnapSet
 from lp.translations.browser.customlanguagecode import (
     HasCustomLanguageCodesTraversalMixin,
     )
@@ -585,6 +586,7 @@ class ProductOverviewMenu(ApplicationMenu, ProductEditLinksMixin,
         'branding',
         'view_recipes',
         'view_snaps',
+        'create_snap',
         ]
 
     def top_contributors(self):
diff --git a/lib/lp/registry/templates/product-index.pt b/lib/lp/registry/templates/product-index.pt
index a22574c..73d339b 100644
--- a/lib/lp/registry/templates/product-index.pt
+++ b/lib/lp/registry/templates/product-index.pt
@@ -168,7 +168,7 @@
               <a tal:replace="structure overview_menu/edit/fmt:icon" />
             </p>
 
-            <ul class="horizontal">
+            <ul class="horizontal" id="project-link-info">
               <li tal:condition="overview_menu/series_add/enabled">
                 <a tal:replace="structure overview_menu/series_add/fmt:link" />
               </li>
@@ -183,6 +183,10 @@
                   tal:condition="link/enabled">
                 <a tal:replace="structure link/fmt:link" />
               </li>
+              <li tal:define="link context/menu:overview/create_snap"
+                  tal:condition="link/enabled">
+                <a tal:replace="structure link/fmt:link" />
+              </li>
             </ul>
           </div>
         </div>
diff --git a/lib/lp/snappy/model/snap.py b/lib/lp/snappy/model/snap.py
index 2ee8802..90b55e7 100644
--- a/lib/lp/snappy/model/snap.py
+++ b/lib/lp/snappy/model/snap.py
@@ -1392,7 +1392,6 @@ class SnapSet:
         """See `ISnapSet`."""
         return BRANCH_POLICY_ALLOWED_TYPES[project.branch_sharing_policy]
 
-
     def isValidInformationType(self, information_type, owner, branch=None,
                                git_ref=None):
         private = information_type not in PUBLIC_INFORMATION_TYPES
@@ -1478,9 +1477,14 @@ class SnapSet:
                 collection.visibleByUser(visible_by_user),
                 visible_by_user=visible_by_user)
 
+        snaps_for_project = IStore(Snap).find(
+            Snap,
+            Snap.project == project,
+            get_snap_privacy_filter(visible_by_user))
         bzr_collection = removeSecurityProxy(IBranchCollection(project))
         git_collection = removeSecurityProxy(IGitCollection(project))
-        return _getSnaps(bzr_collection).union(_getSnaps(git_collection))
+        return snaps_for_project.union(
+            _getSnaps(bzr_collection)).union(_getSnaps(git_collection))
 
     def findByBranch(self, branch, visible_by_user=None):
         """See `ISnapSet`."""

Follow ups