/
mail.py
54 lines (43 loc) · 1.95 KB
/
mail.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
import logging
from odoo.http import request
import werkzeug
from werkzeug.exceptions import NotFound, Forbidden
from odoo import http
from odoo.addons.portal.controllers.mail import _check_special_access
from odoo.tools import plaintext2html
_logger = logging.getLogger(__name__)
class SlidesMail(http.Controller):
@http.route('/slides/mail/update_comment', type='http', auth="user")
def mail_update_message(self, res_id, message, message_id, **post):
res_model = 'slide.channel' # keep this mecanism intern to slide
message_body = plaintext2html(message)
res_id = int(res_id)
message_id = int(message_id)
pid = int(post['pid']) if post.get('pid') else False
if not _check_special_access(res_model, res_id, token=post.get('token'), _hash=post.get('hash'), pid=pid):
raise Forbidden()
# update mail.message
domain = [
('model', '=', res_model),
('res_id', '=', res_id),
('website_published', '=', True),
('author_id', '=', request.env.user.partner_id.id),
('message_type', '=', 'comment'),
('id', '=', message_id)
] # restrict to the given message_id
message = request.env['mail.message'].search(domain, limit=1)
if not message:
raise NotFound()
message.write({
'body': message_body
})
# update rating
if post.get('rating_value'):
domain = [('res_model', '=', res_model), ('res_id', '=', res_id), ('website_published', '=', True), ('message_id', '=', message.id)]
rating = request.env['rating.rating'].search(domain, order='write_date DESC', limit=1)
rating.write({
'rating': float(post['rating_value'])
})
return werkzeug.utils.redirect(request.httprequest.referrer, 302)