Skip to content

Commit

Permalink
[FIX] website_forum: Preventing user from posting answers on [Close] …
Browse files Browse the repository at this point in the history
…and [Deleted] questions. Solving issue of Red background when question is deleted
  • Loading branch information
jsh-odoo authored and tde-banana-odoo committed Jul 30, 2014
1 parent 6ed3056 commit feb2dff
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
3 changes: 3 additions & 0 deletions addons/website_forum/models/forum.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,9 @@ def create(self, cr, uid, vals, context=None):
create_context = dict(context, mail_create_nolog=True)
post_id = super(Post, self).create(cr, uid, vals, context=create_context)
post = self.browse(cr, SUPERUSER_ID, post_id, context=context) # SUPERUSER_ID to avoid read access rights issues when creating
# deleted or closed questions
if post.parent_id and (post.parent_id.state == 'close' or post.parent_id.active == False):
osv.except_osv(_('Error !'), _('Posting answer on [Deleted] or [Closed] question is prohibited'))
# karma-based access
if post.parent_id and not post.can_ask:
raise KarmaError('Not enough karma to create a new question')
Expand Down
21 changes: 13 additions & 8 deletions addons/website_forum/views/website_forum.xml
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@
<!-- Specific Post Layout -->
<template id="post_description_full" name="Question Navigation">
<t t-call="website_forum.header">
<div t-attf-class="question #{not question.active and 'alert alert-danger' or ''}">
<div t-attf-class="question">
<div class="col-md-2 hidden-xs text-center">
<t t-call="website_forum.vote">
<t t-set="post" t-value="question"/>
Expand All @@ -468,7 +468,7 @@
t-attf-class="favourite_question no-decoration fa fa-2x fa-star #{question.user_favourite and 'forum_favourite_question' or ''}"/>
</div>
</div>
<div class="col-md-10">
<div t-attf-class="col-md-10 #{not question.active and 'alert alert-danger' or ''}">
<h1 class="mt0">
<a t-attf-href="/forum/#{ slug(forum) }/question/#{ slug(question) }" t-field="question.name"/>
<span t-if="not question.active"><b> [Deleted]</b></span>
Expand Down Expand Up @@ -659,7 +659,7 @@
</div>
</div>
</div>
<div t-if="not question.uid_has_answered">
<div t-if="not question.uid_has_answered and question.state != 'close' and question.active != False">
<t t-call="website_forum.post_answer"/>
</div>
<div t-if="question.uid_has_answered" class="mb16">
Expand All @@ -680,11 +680,16 @@
class="close comment_delete">&amp;times;</button>
<span t-field="message.body"/>
<t t-set="required_karma" t-value="message.author_id.id == user.partner_id.id and object.forum_id.karma_comment_convert_own or object.forum_id.karma_comment_convert_all"/>
<t t-call="website_forum.link_button">
<t t-set="url" t-value="'/forum/' + slug(forum) + '/post/' + slug(object) + '/comment/' + slug(message) + '/convert_to_answer'"/>
<t t-set="label" t-value="'Convert as an answer'"/>
<t t-set="karma" t-value="user.karma&lt;required_karma and required_karma or 0"/>
<t t-set="classes" t-value="'fa-magic pull-right'"/>
<t t-if="(object.parent_id and object.parent_id.state != 'close' and object.parent_id.active != False) or (not object.parent_id and object.state != 'close' and object.active != False)">
<t t-set="allow_post_comment" t-value="True" />
</t>
<t t-if="allow_post_comment">
<t t-call="website_forum.link_button" >
<t t-set="url" t-value="'/forum/' + slug(forum) + '/post/' + slug(object) + '/comment/' + slug(message) + '/convert_to_answer'"/>
<t t-set="label" t-value="'Convert as an answer'"/>
<t t-set="karma" t-value="user.karma&lt;required_karma and required_karma or 0"/>
<t t-set="classes" t-value="'fa-magic pull-right'"/>
</t>
</t>
<a t-attf-href="/forum/#{slug(forum)}/partner/#{message.author_id.id}"
t-field="message.author_id" t-field-options='{"widget": "contact", "country_image": true, "fields": ["name", "country_id"]}'
Expand Down

0 comments on commit feb2dff

Please sign in to comment.