[IMP] website_forum: multi forum pending

This change introduces ability for users (who don't have enough karma)
to create one pending post per forum.
Previously users could only do it in all of forums.

ticket-3354435

closes odoo/odoo#124112

Related: odoo/upgrade#4841
Signed-off-by: Stéphane Debauche (std) <std@odoo.com>
This commit is contained in:
dane@odoo.com
2023-06-28 17:41:35 +02:00
parent c5cb357d90
commit fc66f54ed4
5 changed files with 20 additions and 21 deletions
@@ -335,8 +335,7 @@ class WebsiteForum(WebsiteProfile):
})
post_tag_ids = forum._tag_to_write_vals(post.get('post_tags', ''))
if request.env.user.forum_waiting_posts_count:
if forum.has_pending_post:
return request.redirect("/forum/%s/ask" % slug(forum))
new_question = request.env['forum.post'].create({
@@ -130,6 +130,21 @@ class Forum(models.Model):
karma_user_bio = fields.Integer(string='Display detailed user biography', default=750)
karma_post = fields.Integer(string='Ask questions without validation', default=100)
karma_moderate = fields.Integer(string='Moderate posts', default=1000)
has_pending_post = fields.Boolean(string='Has pending post', compute='_compute_has_pending_post')
@api.depends_context('uid')
def _compute_has_pending_post(self):
domain = [
('create_uid', '=', self.env.user.id),
('state', '=', 'pending'),
('parent_id', '=', False),
]
pending_forums = self.env['forum.forum'].search([
('id', 'in', self.ids),
('post_ids', 'any', domain),
])
pending_forums.has_pending_post = True
(self - pending_forums).has_pending_post = False
@api.depends('description')
def _compute_teaser(self):
-15
View File
@@ -8,21 +8,6 @@ class Users(models.Model):
_inherit = 'res.users'
create_date = fields.Datetime('Create Date', readonly=True, index=True)
forum_waiting_posts_count = fields.Integer(
'Waiting post', compute="_compute_forum_waiting_posts_count")
def _compute_forum_waiting_posts_count(self):
read_group_res = self.env['forum.post']._read_group(
[('create_uid', 'in', self.ids), ('state', '=', 'pending'), ('parent_id', '=', False)],
['create_uid'],
['__count'],
)
mapping = {
create_uid.id: count
for create_uid, count in read_group_res
}
for user in self:
user.forum_waiting_posts_count = mapping.get(user.id, 0)
# Wrapper for call_kw with inherits
def open_website_url(self):
@@ -30,7 +30,7 @@
<a t-att-href="url_for('/forum') + '/' + slug(forum) + '?' + keep_query( 'search', 'sorting', 'filters', 'my')" class="btn py-1">&#215;</a>
</span>
</div>
<div t-if="uid and request.env.user.forum_waiting_posts_count"
<div t-if="uid and forum and forum.has_pending_post"
title="You already have a pending post"
data-bs-toggle="popover" data-bs-trigger="hover" data-bs-content="Please wait for a moderator to validate your previous post before continuing.">
<a class="disabled btn btn-secondary btn-block mb-3 mb-md-0" t-attf-href="/forum/#{slug(forum)}/ask">New Post</a>
@@ -188,7 +188,7 @@
<!-- Edition: ask your question -->
<template id="new_question" name="New Post">
<t t-call="website_forum.header">
<div t-if="request.env.user.forum_waiting_posts_count" class="alert border" role="alert">
<div t-if="forum and forum.has_pending_post" class="alert border" role="alert">
<b>You already have a pending post.</b><br/>
<p>Please wait for a moderator to validate your previous post before continuing.</p>
<a t-attf-href="/forum/#{ slug(forum) }" title="All Topics"><i class="oi oi-chevron-left me-2"/>Back to All Topics</a>
@@ -293,11 +293,11 @@
</a>
</div>
<t t-if="question.state != 'close' and question.active != False and question.can_answer and not request.env.user.forum_waiting_posts_count">
<t t-if="question.state != 'close' and question.active != False and question.can_answer and forum and not forum.has_pending_post">
<div id="post_reply" class="collapse answer_collapse" t-if="(not question.uid_has_answered or question.forum_id.mode == 'discussions')">
<t t-call="website_forum.post_answer"/>
</div>
<div t-elif="uid and request.env.user.forum_waiting_posts_count" class="alert alert-info text-center">
<div t-elif="uid and has_pending_post" class="alert alert-info text-center">
<b class="d-block">You have a pending post</b>
Please wait for a moderator to validate your previous post to be allowed replying questions.
</div>