[FIX] website_slides: fix multiple course review bug
Before this commit, it was possible for one to post multiple reviews when all the already posted reviews had the 'Employee Only' state. A traceback was also thrown when trying to update an 'Employee Only' comment. It was also possible to edit a log note. This commit fixes all these issues. Task-2810085 closes odoo/odoo#121052 X-original-commit: 2e4f8ff553b11ecae444933aa2b9fab6175e64ef Signed-off-by: Stéphane Debauche (std) <std@odoo.com> Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
This commit is contained in:
@@ -57,10 +57,11 @@ class SlidesPortalChatter(PortalChatter):
|
||||
# fetch and update mail.message
|
||||
message_id = int(message_id)
|
||||
message_body = plaintext2html(message)
|
||||
subtype_comment_id = request.env['ir.model.data']._xmlid_to_res_id('mail.mt_comment')
|
||||
domain = [
|
||||
('model', '=', res_model),
|
||||
('res_id', '=', res_id),
|
||||
('is_internal', '=', False),
|
||||
('subtype_id', '=', subtype_comment_id),
|
||||
('author_id', '=', request.env.user.partner_id.id),
|
||||
('message_type', '=', 'comment'),
|
||||
('id', '=', message_id)
|
||||
@@ -75,7 +76,7 @@ class SlidesPortalChatter(PortalChatter):
|
||||
|
||||
# update rating
|
||||
if post.get('rating_value'):
|
||||
domain = [('res_model', '=', res_model), ('res_id', '=', res_id), ('is_internal', '=', False), ('message_id', '=', message.id)]
|
||||
domain = [('res_model', '=', res_model), ('res_id', '=', res_id), ('message_id', '=', message.id)]
|
||||
rating = request.env['rating.rating'].sudo().search(domain, order='write_date DESC', limit=1)
|
||||
rating.write({
|
||||
'rating': float(post['rating_value']),
|
||||
|
||||
@@ -715,12 +715,13 @@ class WebsiteSlides(WebsiteProfile):
|
||||
}
|
||||
|
||||
if not request.env.user._is_public():
|
||||
subtype_comment_id = request.env['ir.model.data']._xmlid_to_res_id('mail.mt_comment')
|
||||
last_message = request.env['mail.message'].search([
|
||||
('model', '=', channel._name),
|
||||
('res_id', '=', channel.id),
|
||||
('author_id', '=', request.env.user.partner_id.id),
|
||||
('message_type', '=', 'comment'),
|
||||
('is_internal', '=', False)
|
||||
('subtype_id', '=', subtype_comment_id)
|
||||
], order='write_date DESC', limit=1)
|
||||
|
||||
if last_message:
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
/** @odoo-module **/
|
||||
|
||||
import { registry } from '@web/core/registry';
|
||||
|
||||
/**
|
||||
* This tour test that a log note isn't considered
|
||||
* as a course review. And also that a member can
|
||||
* add only one review.
|
||||
*/
|
||||
registry.category('web_tour.tours').add('course_reviews', {
|
||||
url: '/slides',
|
||||
test: true,
|
||||
steps: [
|
||||
{
|
||||
trigger: 'a:contains("Basics of Gardening - Test")',
|
||||
}, {
|
||||
trigger: 'a[id="review-tab"]',
|
||||
}, {
|
||||
trigger: '.o_portal_chatter_message:contains("Log note")',
|
||||
run: function() {},
|
||||
}, {
|
||||
trigger: 'span:contains("Add Review")',
|
||||
// If it fails here, it means the log note is considered as a review
|
||||
}, {
|
||||
trigger: 'div.o_portal_chatter_composer_body textarea',
|
||||
extra_trigger: 'div.modal_shown',
|
||||
run: 'text Great course!',
|
||||
in_modal: false,
|
||||
}, {
|
||||
trigger: 'button.o_portal_chatter_composer_btn',
|
||||
in_modal: false,
|
||||
}, {
|
||||
trigger: 'a[id="review-tab"]',
|
||||
}, {
|
||||
trigger: 'button:contains("Visible")',
|
||||
}, {
|
||||
trigger: 'span:contains("Edit Review")',
|
||||
// If it fails here, it means the system is allowing you to add another review.
|
||||
}, {
|
||||
trigger: 'div.o_portal_chatter_composer_body textarea:contains("Great course!")',
|
||||
run: function() {},
|
||||
}
|
||||
]});
|
||||
@@ -131,6 +131,19 @@ class TestUi(TestUICommon):
|
||||
|
||||
self.start_tour(self.env['website'].get_client_action_url('/slides'), 'full_screen_web_editor', login=user_demo.login)
|
||||
|
||||
def test_course_reviews_elearning_officer(self):
|
||||
user_demo = self.user_demo
|
||||
user_demo.write({
|
||||
'groups_id': [(6, 0, (self.env.ref('base.group_user') | self.env.ref('website_slides.group_website_slides_officer')).ids)]
|
||||
})
|
||||
|
||||
# The user must be a course member before being able to post a log note.
|
||||
self.channel._action_add_members(user_demo.partner_id)
|
||||
self.channel.with_user(user_demo).message_post(
|
||||
body='Log note', subtype_xmlid='mail.mt_note', message_type='comment')
|
||||
|
||||
self.start_tour('/slides', 'course_reviews', login=user_demo.login)
|
||||
|
||||
|
||||
@tests.common.tagged('post_install', '-at_install')
|
||||
class TestUiPublisher(HttpCaseWithUserDemo):
|
||||
|
||||
Reference in New Issue
Block a user