PURPOSE
Rating model should be available only for internal users. External users
access them only through dedicated routes or controllers using sudo and/or
granting access through tokens. Therefore simplifying ACLs should be feasible.
SPECIFICATIONS
Remove access to rating.rating for public and portal users. Only employees
can access it, with full access given to system admins.
Update various functional flows to use sudo() and check that access is
verified before using sudo.
Impacted modules
* rating / mail: add groups on some rating related fields as only
internal users should access them now;
* rating / mail: set some statistics fields using compute_sudo as their
value should be accessible for external people even without access to
the underlying rating.rating records;
* project: makes some use of rating and has to be updated, notably for
the public rating page;
* website_{livechat, rating, slides}: add sudo in public routes as access
is already granted;
* website_slides: set statistics field using compute_sudo as their
value should be accessible for external people;
TASK ID 2053096
PR #36592
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
29 lines
1.3 KiB
Python
29 lines
1.3 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from odoo import models
|
|
|
|
|
|
class MailMessage(models.Model):
|
|
_inherit = 'mail.message'
|
|
|
|
def _portal_message_format(self, field_list):
|
|
# inlude rating value in data if requested
|
|
if self._context.get('rating_include'):
|
|
field_list += ['rating_value']
|
|
return super(MailMessage, self)._portal_message_format(field_list)
|
|
|
|
def _message_read_dict_postprocess(self, message_values, message_tree):
|
|
""" Override the method to add information about a publisher comment
|
|
on each rating messages if requested, and compute a plaintext value of it.
|
|
"""
|
|
res = super(MailMessage, self)._message_read_dict_postprocess(message_values, message_tree)
|
|
|
|
if self._context.get('rating_include'):
|
|
infos = ["id", "publisher_comment", "publisher_id", "publisher_datetime", "message_id"]
|
|
related_rating = self.env['rating.rating'].sudo().search([('message_id', 'in', self.ids)]).read(infos)
|
|
mid_rating_tree = dict((rating['message_id'][0], rating) for rating in related_rating)
|
|
for values in message_values:
|
|
values["rating"] = mid_rating_tree.get(values['id'], {})
|
|
return res
|