From 023aa7acdf6eb859ada2f8c616fedf9dbc060c80 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Mon, 12 May 2014 18:34:55 +0200 Subject: [PATCH 1/3] [FIX] website_forum links which should not be, post-install crawler * move URLs of purely-JS-hook to data-href so the crawler does not try to access them (they're JSON-RPC endpoints...) * replace side-effecting links (...) by styled buttons * fix crawler to not take fragments in account when deduplicating and navigating URLs --- addons/website/tests/test_requests.py | 16 +++++++- .../static/src/css/website_forum.css | 4 ++ .../static/src/css/website_forum.sass | 3 ++ .../static/src/js/website_forum.js | 8 ++-- addons/website_forum/views/website_forum.xml | 38 ++++++++++++++----- 5 files changed, 54 insertions(+), 15 deletions(-) diff --git a/addons/website/tests/test_requests.py b/addons/website/tests/test_requests.py index 127aea274d5..e0309c9ab4b 100644 --- a/addons/website/tests/test_requests.py +++ b/addons/website/tests/test_requests.py @@ -41,6 +41,9 @@ class CrawlSuite(unittest2.TestSuite): starting the crawl """ + at_install = False + post_install = True + def __init__(self, user=None, password=None): super(CrawlSuite, self).__init__() @@ -108,14 +111,23 @@ class CrawlSuite(unittest2.TestSuite): for link in doc.xpath('//a[@href]'): href = link.get('href') + parts = urlparse.urlsplit(href) + # href with any fragment removed + href = urlparse.urlunsplit(( + parts.scheme, + parts.netloc, + parts.path, + parts.query, + '' + )) + # avoid repeats, even for links we won't crawl no need to # bother splitting them if we've already ignored them # previously if href in seen: continue seen.add(href) - parts = urlparse.urlsplit(href) - + # FIXME: handle relative link (not parts.path.startswith /) if parts.netloc or \ not parts.path.startswith('/') or \ parts.path == '/web' or\ diff --git a/addons/website_forum/static/src/css/website_forum.css b/addons/website_forum/static/src/css/website_forum.css index b90c1786e24..75befd62b1c 100644 --- a/addons/website_forum/static/src/css/website_forum.css +++ b/addons/website_forum/static/src/css/website_forum.css @@ -94,3 +94,7 @@ a.no-decoration { font: 1.2em "Helvetica Neue", Helvetica, Arial, sans-serif !important; height: 1.2em !important; } + +button.btn-link.text-muted { + color: #999999; +} diff --git a/addons/website_forum/static/src/css/website_forum.sass b/addons/website_forum/static/src/css/website_forum.sass index f8e46f06b79..d800d293de8 100644 --- a/addons/website_forum/static/src/css/website_forum.sass +++ b/addons/website_forum/static/src/css/website_forum.sass @@ -74,3 +74,6 @@ a.no-decoration .text-tags .text-tag .text-button font: 1.2em "Helvetica Neue", Helvetica, Arial, sans-serif !important height: 1.2em !important + +button.btn-link.text-muted + color: #999 diff --git a/addons/website_forum/static/src/js/website_forum.js b/addons/website_forum/static/src/js/website_forum.js index e84e76e14fa..0b45d4311c1 100644 --- a/addons/website_forum/static/src/js/website_forum.js +++ b/addons/website_forum/static/src/js/website_forum.js @@ -3,7 +3,7 @@ $(document).ready(function () { $('.vote_up ,.vote_down').on('click', function (ev) { ev.preventDefault(); var $link = $(ev.currentTarget); - openerp.jsonRpc($link.attr('href'), 'call', {}) + openerp.jsonRpc($link.data('href'), 'call', {}) .then(function (data) { if (data['error']){ if (data['error'] == 'own_post'){ @@ -47,7 +47,7 @@ $(document).ready(function () { $('.accept_answer').on('click', function (ev) { ev.preventDefault(); var $link = $(ev.currentTarget); - openerp.jsonRpc($link.attr('href'), 'call', {}).then(function (data) { + openerp.jsonRpc($link.data('href'), 'call', {}).then(function (data) { if (data['error']) { if (data['error'] == 'anonymous_user'){ var $warning = $('
'+ @@ -83,7 +83,7 @@ $(document).ready(function () { $('.favourite_question').on('click', function (ev) { ev.preventDefault(); var $link = $(ev.currentTarget); - openerp.jsonRpc($link.attr('href'), 'call', {}).then(function (data) { + openerp.jsonRpc($link.data('href'), 'call', {}).then(function (data) { if (data) { $link.addClass("forum_favourite_question") } else { @@ -96,7 +96,7 @@ $(document).ready(function () { $('.comment_delete').on('click', function (ev) { ev.preventDefault(); var $link = $(ev.currentTarget); - openerp.jsonRpc($link.attr('href'), 'call', {}).then(function (data) { + openerp.jsonRpc($link.data('href'), 'call', {}).then(function (data) { $link.parents('.comment').first().remove(); }); return true; diff --git a/addons/website_forum/views/website_forum.xml b/addons/website_forum/views/website_forum.xml index c73486d7d39..fbda6a40532 100644 --- a/addons/website_forum/views/website_forum.xml +++ b/addons/website_forum/views/website_forum.xml @@ -20,6 +20,14 @@ + + +