rss: use permalinks without slashes for feeds. Fixes #5557

This commit is contained in:
Marcin Kuzminski 2019-07-09 12:29:39 +02:00
parent 111252e3d2
commit 7e6bc58c63
7 changed files with 69 additions and 13 deletions

View file

@ -485,13 +485,21 @@ def includeme(config):
name='edit_repo_audit_logs',
pattern='/{repo_name:.*?[^/]}/settings/audit_logs', repo_route=True)
# ATOM/RSS Feed
# ATOM/RSS Feed, shouldn't contain slashes for outlook compatibility
config.add_route(
name='rss_feed_home',
pattern='/{repo_name:.*?[^/]}/feed/rss', repo_route=True)
pattern='/{repo_name:.*?[^/]}/feed-rss', repo_route=True)
config.add_route(
name='atom_feed_home',
pattern='/{repo_name:.*?[^/]}/feed-atom', repo_route=True)
config.add_route(
name='rss_feed_home_old',
pattern='/{repo_name:.*?[^/]}/feed/rss', repo_route=True)
config.add_route(
name='atom_feed_home_old',
pattern='/{repo_name:.*?[^/]}/feed/atom', repo_route=True)
# NOTE(marcink): needs to be at the end for catch-all

View file

@ -27,8 +27,10 @@ def route_path(name, params=None, **kwargs):
import urllib
base_url = {
'rss_feed_home': '/{repo_name}/feed/rss',
'atom_feed_home': '/{repo_name}/feed/atom',
'rss_feed_home': '/{repo_name}/feed-rss',
'atom_feed_home': '/{repo_name}/feed-atom',
'rss_feed_home_old': '/{repo_name}/feed/rss',
'atom_feed_home_old': '/{repo_name}/feed/atom',
}[name].format(**kwargs)
if params:
@ -73,6 +75,42 @@ class TestFeedView(TestController):
assert response.content_type == content_type
@pytest.mark.parametrize("feed_type, content_type", [
('rss', "application/rss+xml"),
('atom', "application/atom+xml")
])
def test_feed_with_auth_token_by_uid(
self, backend, user_admin, feed_type, content_type):
auth_token = user_admin.feed_token
assert auth_token != ''
response = self.app.get(
route_path(
'{}_feed_home'.format(feed_type),
repo_name='_{}'.format(backend.repo.repo_id),
params=dict(auth_token=auth_token)),
status=200)
assert response.content_type == content_type
@pytest.mark.parametrize("feed_type, content_type", [
('rss', "application/rss+xml"),
('atom', "application/atom+xml")
])
def test_feed_old_urls_with_auth_token(
self, backend, user_admin, feed_type, content_type):
auth_token = user_admin.feed_token
assert auth_token != ''
response = self.app.get(
route_path(
'{}_feed_home_old'.format(feed_type),
repo_name=backend.repo_name,
params=dict(auth_token=auth_token)),
status=200)
assert response.content_type == content_type
@pytest.mark.parametrize("feed_type", ['rss', 'atom'])
def test_feed_with_auth_token_of_wrong_type(
self, backend, user_util, feed_type):

View file

@ -40,8 +40,6 @@ log = logging.getLogger(__name__)
class RepoFeedView(RepoAppView):
def load_default_context(self):
c = self._get_local_tmpl_context()
self._load_defaults()
return c
@ -117,6 +115,9 @@ class RepoFeedView(RepoAppView):
@view_config(
route_name='atom_feed_home', request_method='GET',
renderer=None)
@view_config(
route_name='atom_feed_home_old', request_method='GET',
renderer=None)
def atom(self):
"""
Produce an atom-1.0 feed via feedgenerator module
@ -181,6 +182,9 @@ class RepoFeedView(RepoAppView):
@view_config(
route_name='rss_feed_home', request_method='GET',
renderer=None)
@view_config(
route_name='rss_feed_home_old', request_method='GET',
renderer=None)
def rss(self):
"""
Produce an rss2 feed via feedgenerator module

View file

@ -1840,6 +1840,10 @@ class Repository(Base, BaseModel):
return q.all()
@property
def repo_uid(self):
return '_{}'.format(self.repo_id)
@property
def forks(self):
"""

View file

@ -263,8 +263,10 @@ function registerRCRoutes() {
pyroutes.register('strip_check', '/%(repo_name)s/settings/strip_check', ['repo_name']);
pyroutes.register('strip_execute', '/%(repo_name)s/settings/strip_execute', ['repo_name']);
pyroutes.register('edit_repo_audit_logs', '/%(repo_name)s/settings/audit_logs', ['repo_name']);
pyroutes.register('rss_feed_home', '/%(repo_name)s/feed/rss', ['repo_name']);
pyroutes.register('atom_feed_home', '/%(repo_name)s/feed/atom', ['repo_name']);
pyroutes.register('rss_feed_home', '/%(repo_name)s/feed-rss', ['repo_name']);
pyroutes.register('atom_feed_home', '/%(repo_name)s/feed-atom', ['repo_name']);
pyroutes.register('rss_feed_home_old', '/%(repo_name)s/feed/rss', ['repo_name']);
pyroutes.register('atom_feed_home_old', '/%(repo_name)s/feed/atom', ['repo_name']);
pyroutes.register('repo_summary', '/%(repo_name)s', ['repo_name']);
pyroutes.register('repo_summary_slash', '/%(repo_name)s/', ['repo_name']);
pyroutes.register('edit_repo_group', '/%(repo_group_name)s/_edit', ['repo_group_name']);

View file

@ -217,7 +217,7 @@
## Context Actions
<div class="pull-right">
%if c.rhodecode_user.username != h.DEFAULT_USER:
<a href="${h.route_path('atom_feed_home', repo_name=c.rhodecode_db_repo.repo_name, _query=dict(auth_token=c.rhodecode_user.feed_token))}" title="${_('RSS Feed')}" class="btn btn-sm"><i class="icon-rss-sign"></i>RSS</a>
<a href="${h.route_path('atom_feed_home', repo_name=c.rhodecode_db_repo.repo_uid, _query=dict(auth_token=c.rhodecode_user.feed_token))}" title="${_('RSS Feed')}" class="btn btn-sm"><i class="icon-rss-sign"></i>RSS</a>
<a href="#WatchRepo" onclick="toggleFollowingRepo(this, templateContext.repo_id); return false" title="${_('Watch this Repository and actions on it in your personalized journal')}" class="btn btn-sm ${('watching' if c.repository_is_user_following else '')}">
% if c.repository_is_user_following:
@ -228,7 +228,7 @@
</a>
%else:
<a href="${h.route_path('atom_feed_home', repo_name=c.rhodecode_db_repo.repo_name)}" title="${_('RSS Feed')}" class="btn btn-sm"><i class="icon-rss-sign"></i>RSS</a>
<a href="${h.route_path('atom_feed_home', repo_name=c.rhodecode_db_repo.repo_uid)}" title="${_('RSS Feed')}" class="btn btn-sm"><i class="icon-rss-sign"></i>RSS</a>
%endif
</div>

View file

@ -2,7 +2,7 @@
<%def name="title()">
## represents page title
${_('%s Summary') % c.repo_name}
${_('{} Summary').format(c.repo_name)}
%if c.rhodecode_name:
&middot; ${h.branding(c.rhodecode_name)}
%endif
@ -10,8 +10,8 @@
<%def name="head_extra()">
<link href="${h.route_path('atom_feed_home', repo_name=c.rhodecode_db_repo.repo_name, _query=dict(auth_token=c.rhodecode_user.feed_token))}" rel="alternate" title="${h.tooltip(_('%s ATOM feed') % c.repo_name)}" type="application/atom+xml" />
<link href="${h.route_path('rss_feed_home', repo_name=c.rhodecode_db_repo.repo_name, _query=dict(auth_token=c.rhodecode_user.feed_token))}" rel="alternate" title="${h.tooltip(_('%s RSS feed') % c.repo_name)}" type="application/rss+xml" />
<link href="${h.route_path('atom_feed_home', repo_name=c.rhodecode_db_repo.repo_uid, _query=dict(auth_token=c.rhodecode_user.feed_token))}" rel="alternate" title="${h.tooltip(_('%s ATOM feed') % c.repo_name)}" type="application/atom+xml" />
<link href="${h.route_path('rss_feed_home', repo_name=c.rhodecode_db_repo.repo_uid, _query=dict(auth_token=c.rhodecode_user.feed_token))}" rel="alternate" title="${h.tooltip(_('%s RSS feed') % c.repo_name)}" type="application/rss+xml" />
</%def>