This is an automated email from the ASF dual-hosted git repository.
brondsem pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/allura.git
The following commit(s) were added to refs/heads/master by this push:
new 0ce187a added noindex tag to profiles with no activity and no projects
0ce187a is described below
commit 0ce187aed2caebf816e2b6eccfa3e018f3517009
Author: Guillermo Cruz <[email protected]>
AuthorDate: Thu Feb 11 15:44:31 2021 -0700
added noindex tag to profiles with no activity and no projects
added tests for profile and wiki section. Added noindex key to wiki
templates
added rel nofollow to send message button also instead of post count check
for page path and version to include noindex tag. removed decorator from test
added missing return in setup_context and fixed boolean value
setup_context returns the context values
self.context is now set in setup_context
---
.../ext/user_profile/templates/user_index.html | 4 ++++
Allura/allura/ext/user_profile/user_main.py | 10 +++++++++-
Allura/allura/lib/widgets/user_profile.py | 23 +++++++++++++---------
Allura/allura/tests/functional/test_discuss.py | 3 +++
.../allura/tests/functional/test_user_profile.py | 11 +++++++++++
ForgeActivity/forgeactivity/main.py | 1 +
ForgeActivity/forgeactivity/templates/index.html | 6 ++++++
ForgeWiki/forgewiki/templates/wiki/page_view.html | 3 +++
ForgeWiki/forgewiki/tests/functional/test_root.py | 4 ++++
ForgeWiki/forgewiki/wiki_main.py | 3 ++-
10 files changed, 57 insertions(+), 11 deletions(-)
diff --git a/Allura/allura/ext/user_profile/templates/user_index.html
b/Allura/allura/ext/user_profile/templates/user_index.html
index 17db505..c55196d 100644
--- a/Allura/allura/ext/user_profile/templates/user_index.html
+++ b/Allura/allura/ext/user_profile/templates/user_index.html
@@ -24,6 +24,9 @@
{% block header %}{{ user.display_name|default(user.username) }}{% endblock %}
{% block head %}
+ {% if noindex %}
+ <meta name="robots" content="noindex, follow">
+ {% endif %}
<link rel="alternate" type="application/rss+xml" title="RSS" href="feed.rss">
<link rel="alternate" type="application/atom+xml" title="Atom"
href="feed.atom">
{% endblock %}
@@ -37,6 +40,7 @@
{{ g.icons['mail'].render(
title='Send Message',
show_title=True,
+ rel="nofollow",
href=c.app.url + 'send_message',
extra_css='btn',
id='user-message') }}
diff --git a/Allura/allura/ext/user_profile/user_main.py
b/Allura/allura/ext/user_profile/user_main.py
index 2125605..f63bffe 100644
--- a/Allura/allura/ext/user_profile/user_main.py
+++ b/Allura/allura/ext/user_profile/user_main.py
@@ -153,10 +153,18 @@ class UserProfileController(BaseController,
FeedController):
provider = AuthenticationProvider.get(request)
sections = [section(user, c.project)
for section in c.app.profile_sections]
+
+ noindex = True
+ for s in sections:
+ s.setup_context()
+ if s.context.get('projects') or s.context.get('timeline'):
+ noindex = False
return dict(
user=user,
reg_date=provider.user_registration_date(user),
- sections=sections)
+ sections=sections,
+ noindex=noindex,
+ )
def get_feed(self, project, app, user):
"""Return a :class:`allura.controllers.feed.FeedArgs` object describing
diff --git a/Allura/allura/lib/widgets/user_profile.py
b/Allura/allura/lib/widgets/user_profile.py
index 587bf45..e6162b0 100644
--- a/Allura/allura/lib/widgets/user_profile.py
+++ b/Allura/allura/lib/widgets/user_profile.py
@@ -93,6 +93,7 @@ class SectionBase(object):
the same name.
"""
self.user = user
+ self.context = None
def check_display(self):
"""
@@ -107,6 +108,16 @@ class SectionBase(object):
"""
return context
+ def setup_context(self):
+ self.context = self.prepare_context({
+ 'h': h,
+ 'c': c,
+ 'g': g,
+ 'user': self.user,
+ 'config': tg.config,
+ 'auth': AuthenticationProvider.get(request),
+ })
+
def display(self, *a, **kw):
"""
Renders the section using the context from :meth:`prepare_context`
@@ -120,15 +131,9 @@ class SectionBase(object):
return ''
try:
tmpl = g.jinja2_env.get_template(self.template)
- context = self.prepare_context({
- 'h': h,
- 'c': c,
- 'g': g,
- 'user': self.user,
- 'config': tg.config,
- 'auth': AuthenticationProvider.get(request),
- })
- return Markup(tmpl.render(context))
+ if not self.context:
+ self.setup_context()
+ return Markup(tmpl.render(self.context))
except Exception as e:
log.exception('Error rendering section %s: %s',
type(self).__name__, e)
if asbool(tg.config.get('debug')):
diff --git a/Allura/allura/tests/functional/test_discuss.py
b/Allura/allura/tests/functional/test_discuss.py
index de143c4..1169396 100644
--- a/Allura/allura/tests/functional/test_discuss.py
+++ b/Allura/allura/tests/functional/test_discuss.py
@@ -536,3 +536,6 @@ class TestAttachment(TestDiscussBase):
# ... but moderator can
self.app.get(alink, status=200, extra_environ=moderator)
self.app.get(thumblink, status=200, extra_environ=moderator)
+
+
+
diff --git a/Allura/allura/tests/functional/test_user_profile.py
b/Allura/allura/tests/functional/test_user_profile.py
index 4583da3..30d81a5 100644
--- a/Allura/allura/tests/functional/test_user_profile.py
+++ b/Allura/allura/tests/functional/test_user_profile.py
@@ -232,6 +232,17 @@ class TestUserProfile(TestController):
assert_in('Section d', r.text)
assert_not_in('Section f', r.text)
+ def test_no_index_tag_in_empty_profile(self):
+ r = self.app.get('/u/test-user/profile/')
+ assert_in('content="noindex, follow"', r.text)
+
+ def test_remove_no_index_tag_profile(self):
+ r = self.app.get('/u/test-admin/profile/')
+ assert 'content="noindex, follow"' not in r.text
+
+
+
+
class TestUserProfileHasAccessAPI(TestRestApiBase):
diff --git a/ForgeActivity/forgeactivity/main.py
b/ForgeActivity/forgeactivity/main.py
index 4ca24c4..2fafebd 100644
--- a/ForgeActivity/forgeactivity/main.py
+++ b/ForgeActivity/forgeactivity/main.py
@@ -136,6 +136,7 @@ class ForgeActivityController(BaseController):
followee=followee,
following=following,
timeline=filtered_timeline,
+ noindex=False if filtered_timeline else True,
page=page,
limit=limit,
has_more=has_more,
diff --git a/ForgeActivity/forgeactivity/templates/index.html
b/ForgeActivity/forgeactivity/templates/index.html
index d2eb731..f8d572f 100644
--- a/ForgeActivity/forgeactivity/templates/index.html
+++ b/ForgeActivity/forgeactivity/templates/index.html
@@ -20,6 +20,12 @@
{% extends g.theme.master %}
{% import 'forgeactivity:templates/macros.html' as am with context %}
+{% block head %}
+ {% if noindex %}
+ <meta name="robots" content="noindex, follow">
+ {% endif %}
+{% endblock %}
+
{% block title %}{{c.project.name}} Activity{% endblock %}
{% block header %}
diff --git a/ForgeWiki/forgewiki/templates/wiki/page_view.html
b/ForgeWiki/forgewiki/templates/wiki/page_view.html
index 03b836f..c9064ad 100644
--- a/ForgeWiki/forgewiki/templates/wiki/page_view.html
+++ b/ForgeWiki/forgewiki/templates/wiki/page_view.html
@@ -32,6 +32,9 @@
{% endblock %}
{% block head %}
+ {% if noindex %}
+ <meta name="robots" content="noindex, follow">
+ {% endif %}
<link rel="alternate" type="application/rss+xml" title="Page RSS"
href="feed.rss"/>
<link rel="alternate" type="application/atom+xml" title="Page Atom"
href="feed.atom"/>
<link rel="alternate" type="application/rss+xml" title="Wiki RSS"
href="../feed.rss"/>
diff --git a/ForgeWiki/forgewiki/tests/functional/test_root.py
b/ForgeWiki/forgewiki/tests/functional/test_root.py
index b5f589c..4d8fbdd 100644
--- a/ForgeWiki/forgewiki/tests/functional/test_root.py
+++ b/ForgeWiki/forgewiki/tests/functional/test_root.py
@@ -954,3 +954,7 @@ class TestRootController(TestController):
assert_equal(menu, None)
assert_invisible_for('*anonymous')
assert_invisible_for('test-user')
+
+ def test_no_index_tag_on_empty_wiki(self):
+ r = self.app.get('/u/test-user/wiki/Home/')
+ assert_in('content="noindex, follow"', r.text)
diff --git a/ForgeWiki/forgewiki/wiki_main.py b/ForgeWiki/forgewiki/wiki_main.py
index 568a8e3..f150305 100644
--- a/ForgeWiki/forgewiki/wiki_main.py
+++ b/ForgeWiki/forgewiki/wiki_main.py
@@ -603,7 +603,8 @@ class PageController(BaseController, FeedController):
cur=cur, prev=prev, next=next,
page_subscribed=subscribed_to_page,
hide_left_bar=hide_left_bar, show_meta=c.app.show_right_bar,
- pagenum=pagenum, limit=limit, count=post_count)
+ pagenum=pagenum, limit=limit, count=post_count,
+ noindex=True if page['title'] == 'Home' and page['version'] == 1
else False)
@without_trailing_slash
@expose('jinja:forgewiki:templates/wiki/page_edit.html')