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/07/21 17:11:28 UTC

[allura] branch master updated: [#8446] test fixes and fix on only 301 redir for profiles

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

gcruz 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 210fb7604 [#8446] test fixes and fix on only 301 redir for profiles
210fb7604 is described below

commit 210fb7604d3f7e3fe692859e6c4b947996e7f0fd
Author: Guillermo Cruz <gu...@slashdotmedia.com>
AuthorDate: Thu Jul 21 11:11:15 2022 -0600

    [#8446] test fixes and fix on only 301 redir for profiles
---
 Allura/allura/controllers/project.py                | 5 ++++-
 Allura/allura/templates/jinja_master/lib.html       | 4 +++-
 Allura/allura/templates/macro/members.html          | 3 +--
 Allura/allura/templates/members.html                | 2 +-
 Allura/allura/tests/functional/test_home.py         | 4 ++--
 Allura/allura/tests/functional/test_neighborhood.py | 2 +-
 6 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/Allura/allura/controllers/project.py b/Allura/allura/controllers/project.py
index cf6ba15e1..153bd347b 100644
--- a/Allura/allura/controllers/project.py
+++ b/Allura/allura/controllers/project.py
@@ -49,6 +49,7 @@ from allura.lib.widgets import form_fields as ffw
 from allura.lib.widgets import project_list as plw
 from allura.lib import plugin, exceptions
 from .search import ProjectBrowseController
+from allura.ext.user_profile.user_main import UserProfileApp
 
 log = logging.getLogger(__name__)
 
@@ -398,7 +399,9 @@ class ProjectController(FeedController):
         if mount is not None:
             if hasattr(app, 'default_redirect'):
                 app.default_redirect()
-            redirect(app.url() if callable(app.url) else app.url, redirect_with=exc.HTTPMovedPermanently)  # Application has property; Subproject has method
+            # 301 redirect for user profiles only
+            args = dict(redirect_with=exc.HTTPMovedPermanently) if isinstance(app, UserProfileApp) else dict()
+            redirect(app.url() if callable(app.url) else app.url, **args)  # Application has property; Subproject has method
         else:
             redirect(c.project.app_configs[0].url())
 
diff --git a/Allura/allura/templates/jinja_master/lib.html b/Allura/allura/templates/jinja_master/lib.html
index 0af3f490e..34f4dc5ba 100644
--- a/Allura/allura/templates/jinja_master/lib.html
+++ b/Allura/allura/templates/jinja_master/lib.html
@@ -109,13 +109,15 @@
     {% endif %}
 {%- endmacro %}
 
-{% macro user_link(user, avatar=False, size=16, nofollow=False) -%}
+{% macro user_link(user, avatar=False, size=16, nofollow=False, show_username=False) -%}
     {% if user %}
         {% if not user.is_anonymous() %}
             {% set profile_path = user.url() + 'profile/' if g.user_profile_urls_with_profile_path else user.url() %}
             <a href="{{profile_path}}" class="user-mention" {% if nofollow %}rel="nofollow" {% endif %}>
                 {% if avatar %}
                     {{ gravatar_or_name(user, size) }}
+                {% elif show_username %}
+                    {{ h.really_unicode(user.username) }}
                 {% else %}
                     {{ h.really_unicode(user.display_name) }}
                 {% endif %}
diff --git a/Allura/allura/templates/macro/members.html b/Allura/allura/templates/macro/members.html
index c90ab7a8c..8ed27fcfb 100644
--- a/Allura/allura/templates/macro/members.html
+++ b/Allura/allura/templates/macro/members.html
@@ -18,9 +18,8 @@
 -#}
 <h6>Project Members:</h6>
 	<ul class="md-users-list">
-        {% set profile_path = 'profile/' if g.user_profile_urls_with_profile_path  else '' %}
 		{% for user in users -%}
-			<li><a href="{{user.url ~ profile_path}}">{{user.name}}</a>{{user.admin}}</li>
+			<li><a href="{{user.url}}">{{user.name}}</a>{{user.admin}}</li>
 		{%- endfor %}
 		{% if over_limit -%}
 				<li class="md-users-list-more"><a href="{{c.project.url()}}_members">All Members</a></li>
diff --git a/Allura/allura/templates/members.html b/Allura/allura/templates/members.html
index d77dbb368..ff81cfb1d 100644
--- a/Allura/allura/templates/members.html
+++ b/Allura/allura/templates/members.html
@@ -36,7 +36,7 @@
     {%for user in users%}
     <tr>
         <td>{{ user.display_name }}</td>
-        <td>{{ lib.user_link(user) }}</td>
+        <td>{{ lib.user_link(user, show_username=True) }}</td>
         <td>{{user.roles}}</td>
     </tr>
     {%endfor%}
diff --git a/Allura/allura/tests/functional/test_home.py b/Allura/allura/tests/functional/test_home.py
index 0a0a5fcd0..11af5d674 100644
--- a/Allura/allura/tests/functional/test_home.py
+++ b/Allura/allura/tests/functional/test_home.py
@@ -208,7 +208,7 @@ class TestProjectHome(TestController):
         r = self.app.get('/p/test/_members/')
 
         assert '<td>Test Admin</td>' in r
-        assert '<td><a href="/u/test-admin/">test-admin</a></td>' in r
+        assert '<td><a href="/u/test-admin/profile/">test-admin</a></td>' in r
         assert '<td>Admin</td>' in r
         tr = r.html.findAll('tr')
         assert "<td>Test Admin</td>" in str(tr[1])
@@ -223,7 +223,7 @@ class TestProjectHome(TestController):
         r = self.app.get('/p/test/_members/',
                          extra_environ=dict(username='*anonymous'))
         assert '<td>Test Admin</td>' in r
-        assert '<td><a href="/u/test-admin/">test-admin</a></td>' in r
+        assert '<td><a href="/u/test-admin/profile/">test-admin</a></td>' in r
         assert '<td>Admin</td>' in r
 
     def test_toolaccess_before_subproject(self):
diff --git a/Allura/allura/tests/functional/test_neighborhood.py b/Allura/allura/tests/functional/test_neighborhood.py
index 82ab2a078..9263f755a 100644
--- a/Allura/allura/tests/functional/test_neighborhood.py
+++ b/Allura/allura/tests/functional/test_neighborhood.py
@@ -950,7 +950,7 @@ class TestNeighborhood(TestController):
                             {'$set': {'disabled': True}})
         self.app.get('/u/donald-duck/', status=404, extra_environ={'username': '*anonymous'})
         self.app.get('/u/donald-duck/', status=404, extra_environ={'username': 'test-user'})
-        self.app.get('/u/donald-duck/', status=302, extra_environ={'username': 'test-admin'})  # site admin user
+        self.app.get('/u/donald-duck/', status=301, extra_environ={'username': 'test-admin'})  # site admin user
 
     def test_more_projects_link(self):
         r = self.app.get('/adobe/adobe-1/admin/')