[REF] mail: move channel of message post controller to discuss
Part of task-3265211 closes odoo/odoo#120002 Signed-off-by: Louis Wicket (wil) <wil@odoo.com>
This commit is contained in:
@@ -62,13 +62,7 @@ class ThreadController(http.Controller):
|
||||
|
||||
@http.route("/mail/message/post", methods=["POST"], type="json", auth="public")
|
||||
def mail_message_post(self, thread_model, thread_id, post_data):
|
||||
if thread_model == "discuss.channel":
|
||||
channel_member_sudo = request.env["discuss.channel.member"]._get_as_sudo_from_request_or_raise(
|
||||
request=request, channel_id=int(thread_id)
|
||||
)
|
||||
thread = channel_member_sudo.channel_id
|
||||
else:
|
||||
thread = request.env[thread_model].browse(int(thread_id)).exists()
|
||||
thread = request.env[thread_model]._get_from_request_or_raise(request, int(thread_id))
|
||||
if "body" in post_data:
|
||||
post_data["body"] = Markup(post_data["body"]) # contains HTML such as @mentions
|
||||
message_data = thread.message_post(
|
||||
|
||||
@@ -279,6 +279,13 @@ class Channel(models.Model):
|
||||
if not self._cr.fetchone():
|
||||
self._cr.execute('CREATE INDEX discuss_channel_member_seen_message_id_idx ON discuss_channel_member (channel_id,partner_id,seen_message_id)')
|
||||
|
||||
@api.model
|
||||
def _get_from_request_or_raise(self, request, thread_id):
|
||||
"""Overridden because guests and (portal) users need sudo to post on channels. This ensures they are actually
|
||||
members before granting them access, as well as properly setting up the guest context on the resulting thread
|
||||
if applicable."""
|
||||
return self.env["discuss.channel.member"]._get_as_sudo_from_request_or_raise(request, thread_id).channel_id
|
||||
|
||||
# ------------------------------------------------------------
|
||||
# MEMBERS MANAGEMENT
|
||||
# ------------------------------------------------------------
|
||||
|
||||
@@ -454,6 +454,10 @@ class MailThread(models.AbstractModel):
|
||||
if any(message.message_type != 'comment' for message in messages):
|
||||
raise exceptions.UserError(_("Only messages type comment can have their content updated"))
|
||||
|
||||
@api.model
|
||||
def _get_from_request_or_raise(self, request, thread_id):
|
||||
return self.search([("id", "=", thread_id)])
|
||||
|
||||
# ------------------------------------------------------------
|
||||
# FIELDS HELPERS
|
||||
# ------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user