You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by gc...@apache.org on 2022/06/30 19:16:40 UTC

[allura] branch gc/8443 updated: improved noindex detection for code repositories links

This is an automated email from the ASF dual-hosted git repository.

gcruz pushed a commit to branch gc/8443
in repository https://gitbox.apache.org/repos/asf/allura.git


The following commit(s) were added to refs/heads/gc/8443 by this push:
     new ecfc65a4a improved noindex detection for code repositories links
ecfc65a4a is described below

commit ecfc65a4a6727a8d632a76a9797dbfe8ddab220e
Author: Guillermo Cruz <gu...@slashdotmedia.com>
AuthorDate: Thu Jun 30 13:16:27 2022 -0600

    improved noindex detection for code repositories links
---
 Allura/allura/model/project.py                      | 9 ---------
 ForgeActivity/forgeactivity/main.py                 | 9 ++++-----
 ForgeActivity/forgeactivity/templates/timeline.html | 1 -
 3 files changed, 4 insertions(+), 15 deletions(-)

diff --git a/Allura/allura/model/project.py b/Allura/allura/model/project.py
index b16e5cd64..0e35ae309 100644
--- a/Allura/allura/model/project.py
+++ b/Allura/allura/model/project.py
@@ -337,15 +337,6 @@ class Project(SearchIndexable, MappedClass, ActivityNode, ActivityObject):
     def get_tool_data(self, tool, key, default=None):
         return self.tool_data.get(tool, {}).get(key, default)
 
-    def noindex_tool_name(self, activity_url):
-        noindex_tool_names = ['git', 'svn', 'hg']
-        tools = self.app_configs
-        for c in tools:
-            if hasattr(c, 'tool_name') and c.tool_name in noindex_tool_names:
-                if c.options.mount_point in activity_url:
-                    return True
-        return False
-
     def set_tool_data(self, tool, **kw):
         d = self.tool_data.setdefault(tool, {})
         d.update(kw)
diff --git a/ForgeActivity/forgeactivity/main.py b/ForgeActivity/forgeactivity/main.py
index d708dacb6..e99da124d 100644
--- a/ForgeActivity/forgeactivity/main.py
+++ b/ForgeActivity/forgeactivity/main.py
@@ -99,6 +99,7 @@ class ForgeActivityController(BaseController):
         g.register_app_css('css/activity.css', app=self.app)
 
     def _get_activities_data(self, **kw):
+        noindex_tools = ['git', 'svn', 'hg', 'merge-requests']
         activity_enabled = asbool(config.get('activitystream.enabled', False))
         if not activity_enabled:
             raise exc.HTTPNotFound()
@@ -148,10 +149,10 @@ class ForgeActivityController(BaseController):
                     t.actor.activity_extras.icon_url = re.sub(r'([&?])d=[^&]*',
                                                               r'\1d={}'.format(default_avatar),
                                                               t.actor.activity_extras.icon_url)
-            activity_obj = get_activity_object(t.obj)
-            t.obj.noindex = followee.noindex_tool_name(activity_obj.activity_url)
+            should_noindex = True if any(name in noindex_tools for name in t.tags) or any(tool_name in t.obj.activity_url for tool_name in noindex_tools) else False
+            t.obj.noindex = should_noindex
+            t.target.noindex = should_noindex
             session(t).expunge(t)  # don't save back these changes
-
         if extra_limit == limit:
             # if we didn't ask for extra, then we expect there's more if we got all we asked for
             has_more = len(timeline) == limit
@@ -331,8 +332,6 @@ class ForgeActivityProfileSection(ProfileSectionBase):
             session(activity).expunge(activity)
             activity_obj = get_activity_object(activity.obj)
             activity.obj.project = getattr(activity_obj, 'project', None)
-            if hasattr(c, 'project'):
-                activity.obj.noindex = c.project.noindex_tool_name(activity.obj.activity_url)
         context.update({
             'follow_toggle': W.follow_toggle,
             'following': g.director.is_connected(c.user, self.user),
diff --git a/ForgeActivity/forgeactivity/templates/timeline.html b/ForgeActivity/forgeactivity/templates/timeline.html
index c2365d211..37bf126db 100644
--- a/ForgeActivity/forgeactivity/templates/timeline.html
+++ b/ForgeActivity/forgeactivity/templates/timeline.html
@@ -18,7 +18,6 @@
 -#}
 
 {% import 'forgeactivity:templates/macros.html' as am with context %}
-
 {% for a in timeline %}
 <li id="{{a._id}}" data-page="{{page}}" {% if h.has_access(c.project.neighborhood, 'admin') %}data-can-delete{% endif %}>
   <time datetime="{{a.published|datetimeformat}}" title="{{a.published|datetimeformat}}">{{h.ago(a.published, show_date_after=None)}}</time>