summaryrefslogtreecommitdiff
path: root/addons
diff options
context:
space:
mode:
authorJay Patel <jpa@openerp.com>2014-12-26 10:08:12 +0530
committerThibault Delavallée <tde@openerp.com>2015-02-24 11:01:26 +0100
commitccba676ed72ec6ab0bb4f1a5aba082f410b5037e (patch)
tree61d80980818af005f41c352094276dd9f1d22d32 /addons
parent6acb9e8e9f5a65a8d20510ef8a6e1bf292a3cf40 (diff)
[IMP] website_forum: added check of links and images in posted
content. This is done at model level and raises a karma error. Unnecessary fields have been removed; only one field for editor remain currently.
Diffstat (limited to 'addons')
-rw-r--r--addons/website_forum/models/forum.py10
-rw-r--r--addons/website_forum/views/forum.xml3
2 files changed, 9 insertions, 4 deletions
diff --git a/addons/website_forum/models/forum.py b/addons/website_forum/models/forum.py
index 526690ec80e..04fab67ccaf 100644
--- a/addons/website_forum/models/forum.py
+++ b/addons/website_forum/models/forum.py
@@ -99,8 +99,6 @@ class Forum(models.Model):
karma_downvote = fields.Integer(string='Downvote', default=50)
karma_answer_accept_own = fields.Integer(string='Accept an answer on its own questions', default=20)
karma_answer_accept_all = fields.Integer(string='Accept an answers to all questions', default=500)
- karma_editor_link_files = fields.Integer(string='Linking files (Editor)', default=20)
- karma_editor_clickable_link = fields.Integer(string='Add clickable links (Editor)', default=20)
karma_comment_own = fields.Integer(string='Comment its own posts', default=1)
karma_comment_all = fields.Integer(string='Comment all posts', default=1)
karma_comment_convert_own = fields.Integer(string='Convert its own answers to comments and vice versa', default=50)
@@ -110,6 +108,8 @@ class Forum(models.Model):
karma_retag = fields.Integer(string='Change question tags', default=75)
karma_flag = fields.Integer(string='Flag a post as offensive', default=500)
karma_dofollow = fields.Integer(string='Disabled links', help='If the author has not enough karma, a nofollow attribute is added to links', default=500)
+ karma_editor = fields.Integer(string='Karma to post an image or link (question, answer, edit).',
+ default=30, oldname='karma_editor_link_files')
@api.model
def create(self, values):
@@ -316,6 +316,12 @@ class Post(models.Model):
if content and self.env.user.karma < forum.karma_dofollow:
for match in re.findall(r'<a\s.*href=".*?">', content):
content = re.sub(match, match[:3] + 'rel="nofollow" ' + match[3:], content)
+
+ if self.env.user.karma <= forum.karma_editor:
+ filter_regexp = r'(<img.*?>)|(<a[^>]*?href[^>]*?>)|(<[a-z|A-Z]+[^>]*style\s*=\s*[\'"][^\'"]*\s*background[^:]*:[^url;]*url)'
+ content_match = re.search(filter_regexp, content, re.I)
+ if content_match:
+ raise KarmaError('User karma not sufficient to post an image or link.')
return content
@api.model
diff --git a/addons/website_forum/views/forum.xml b/addons/website_forum/views/forum.xml
index 777edd3cf04..d9cbde28bd2 100644
--- a/addons/website_forum/views/forum.xml
+++ b/addons/website_forum/views/forum.xml
@@ -83,8 +83,7 @@
<group>
<field name="karma_answer_accept_own"/>
<field name="karma_answer_accept_all"/>
- <field name="karma_editor_link_files"/>
- <field name="karma_editor_clickable_link"/>
+ <field name="karma_editor"/>
<field name="karma_comment_own"/>
<field name="karma_comment_all"/>
<field name="karma_comment_convert_own"/>