[FIX] website_forum: decrease indexed pages which will return 404

Add filter in domain converter to remove some posts in sitemap.

Avoid to add in sitemap some pages that could not be read
by public user due to a karma restriction.
This commit is contained in:
Jeremy Kersten
2016-02-01 12:16:43 +01:00
parent 22c80fff6e
commit f39e5358bc
3 changed files with 25 additions and 4 deletions
+1 -2
View File
@@ -220,9 +220,8 @@ class WebsiteForum(http.Controller):
except URLError:
return False
@http.route(['''/forum/<model("forum.forum"):forum>/question/<model("forum.post", "[('forum_id','=',forum[0]),('parent_id','=',False)]"):question>'''], type='http', auth="public", website=True)
@http.route(['''/forum/<model("forum.forum"):forum>/question/<model("forum.post", "[('forum_id','=',forum[0]),('parent_id','=',False),('can_view', '=', True)]"):question>'''], type='http', auth="public", website=True)
def question(self, forum, question, **post):
# Hide posts from abusers (negative karma), except for moderators
if not question.can_view:
raise werkzeug.exceptions.NotFound()
+23 -1
View File
@@ -265,12 +265,34 @@ class Post(models.Model):
can_downvote = fields.Boolean('Can Downvote', compute='_get_post_karma_rights')
can_comment = fields.Boolean('Can Comment', compute='_get_post_karma_rights')
can_comment_convert = fields.Boolean('Can Convert to Comment', compute='_get_post_karma_rights')
can_view = fields.Boolean('Can View', compute='_get_post_karma_rights')
can_view = fields.Boolean('Can View', compute='_get_post_karma_rights', search='_search_can_view')
can_display_biography = fields.Boolean("Is the author's biography visible from his post", compute='_get_post_karma_rights')
can_post = fields.Boolean('Can Automatically be Validated', compute='_get_post_karma_rights')
can_flag = fields.Boolean('Can Flag', compute='_get_post_karma_rights')
can_moderate = fields.Boolean('Can Moderate', compute='_get_post_karma_rights')
def _search_can_view(self, operator, value):
if operator not in ('=', '!=', '<>'):
raise ValueError('Invalid operator: %s' % (operator,))
is_admin = self._uid == SUPERUSER_ID
if is_admin:
return [(1, '=', 1)]
user = self.env['res.users'].browse(self._uid)
req = """
SELECT p.id
FROM forum_post p
LEFT JOIN res_users u ON p.create_uid = u.id
LEFT JOIN forum_forum f ON p.forum_id = f.id
WHERE
u.karma > 0
or (p.create_uid = %s and f.karma_close_own <= %s)
or (p.create_uid != %s and f.karma_close_all <= %s)
"""
# don't use param named because orm will add other param (test_active, ...)
return [('id', '%sselect' % (operator == "=" and "in" or "not in"), (req, (user.id, user.karma, user.id, user.karma)))]
@api.one
@api.depends('content')
def _get_plain_content(self):
+1 -1
View File
@@ -907,7 +907,7 @@ class expression(object):
push(leaf)
else:
for elem in reversed(domain):
push(create_substitution_leaf(leaf, elem, model))
push(create_substitution_leaf(leaf, elem, model, internal=True))
# -------------------------------------------------
# FUNCTION FIELD