← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~pappacena/launchpad:noindex-for-recent-projects into launchpad:master

 

Thiago F. Pappacena has proposed merging ~pappacena/launchpad:noindex-for-recent-projects into launchpad:master.

Commit message:
Prevent crawlers from indexing deactivated projects or projects created by users without karma.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)
Related bugs:
  Bug #1884545 in Launchpad itself: "Don't allow crawlers to index deactivated projects"
  https://bugs.launchpad.net/launchpad/+bug/1884545

For more details, see:
https://code.launchpad.net/~pappacena/launchpad/+git/launchpad/+merge/386221
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~pappacena/launchpad:noindex-for-recent-projects into launchpad:master.
diff --git a/lib/lp/registry/browser/product.py b/lib/lp/registry/browser/product.py
index 268952d..71595ee 100644
--- a/lib/lp/registry/browser/product.py
+++ b/lib/lp/registry/browser/product.py
@@ -940,6 +940,10 @@ class ProductDownloadFileMixin:
 class ProductView(PillarViewMixin, HasAnnouncementsView, SortSeriesMixin,
                   FeedsMixin, ProductDownloadFileMixin):
 
+    @cachedproperty
+    def is_probationary_or_invalid_project(self):
+        return not self.context.active or self.context.owner.is_probationary
+
     @property
     def maintainer_widget(self):
         return InlinePersonEditPickerWidget(
diff --git a/lib/lp/registry/browser/tests/test_product.py b/lib/lp/registry/browser/tests/test_product.py
index cbf03bc..02e5989 100644
--- a/lib/lp/registry/browser/tests/test_product.py
+++ b/lib/lp/registry/browser/tests/test_product.py
@@ -335,6 +335,27 @@ class TestProductView(BrowserTestCase):
     def setUp(self):
         super(TestProductView, self).setUp()
         self.product = self.factory.makeProduct(name='fnord')
+        self.tag_meta_noindex = Tag(
+            'meta_noindex', 'meta', attrs={
+                'name': 'robots', 'content': 'noindex,nofollow'})
+
+    def test_robots_noindex_for_probationary_products(self):
+        # Probationary project pages should have noindex meta tag for robots.
+        product = removeSecurityProxy(self.factory.makeProduct())
+        owner = product.owner
+        with person_logged_in(owner):
+            browser = self.getViewBrowser(product, '+index', user=owner)
+        self.assertThat(
+            browser.contents, HTMLContains(self.tag_meta_noindex))
+
+    def test_robots_without_noindex_for_valid_products(self):
+        # Probationary project page shouldn't have noindex meta tag for robots.
+        owner = self.factory.makePerson(karma=15)
+        product = removeSecurityProxy(self.factory.makeProduct(owner=owner))
+        with person_logged_in(owner):
+            browser = self.getViewBrowser(product, '+index', user=owner)
+        self.assertThat(
+            browser.contents, Not(HTMLContains(self.tag_meta_noindex)))
 
     def test_code_link_bzr(self):
         branch = self.factory.makeBranch(target=self.product)
diff --git a/lib/lp/registry/templates/product-index.pt b/lib/lp/registry/templates/product-index.pt
index 6b62fcc..a22574c 100644
--- a/lib/lp/registry/templates/product-index.pt
+++ b/lib/lp/registry/templates/product-index.pt
@@ -25,6 +25,8 @@
           });
       </script>
     </tal:uses_launchpad_bugtracker>
+    <meta tal:condition="view/is_probationary_or_invalid_project"
+          name="robots" content="noindex,nofollow" />
 
     <meta name="go-import" tal:condition="view/golang_import_spec"
           tal:attributes="content view/golang_import_spec" />