summaryrefslogtreecommitdiff
path: root/addons/website_mail/controllers/main.py
diff options
context:
space:
mode:
authorJérome Maes <jem@openerp.com>2017-08-09 13:09:32 +0200
committerJérome Maes <jem@openerp.com>2017-08-16 14:56:40 +0200
commit3cfd64f63f6153c170c9c876fa65976a95da22cb (patch)
treedcd477f6e8225ed788fa38484fc28272e77073bb /addons/website_mail/controllers/main.py
parent2972976962617d4b8a0113bae58c640ab41cdff8 (diff)
[MOV] portal,website_mail: move chatter frontend to portal
This split responsiblilies : - portal provides basic chatter for portal document, and website documents (slides, blog, ...). - website_mail provides comments moderation (unpublished mail message) - website_rating integrate rating when posting comments
Diffstat (limited to 'addons/website_mail/controllers/main.py')
-rw-r--r--addons/website_mail/controllers/main.py95
1 files changed, 0 insertions, 95 deletions
diff --git a/addons/website_mail/controllers/main.py b/addons/website_mail/controllers/main.py
index c10525fd5e0..ac73c0653c1 100644
--- a/addons/website_mail/controllers/main.py
+++ b/addons/website_mail/controllers/main.py
@@ -1,56 +1,8 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
-from werkzeug.exceptions import NotFound, Forbidden
-
from odoo import http
from odoo.http import request
-from odoo.tools import consteq
-
-
-def _special_access_object(res_model, res_id, token='', token_field=''):
- record = request.env[res_model].browse(res_id).sudo()
- if token and record and getattr(record, token_field, None) and consteq(getattr(record, token_field), token):
- return True
- return False
-
-def _message_post_helper(res_model='', res_id=None, message='', token='', token_field='token', nosubscribe=True, **kw):
- """ Generic chatter function, allowing to write on *any* object that inherits mail.thread.
- If a token is specified, all logged in users will be able to write a message regardless
- of access rights; if the user is the public user, the message will be posted under the name
- of the partner_id of the object (or the public user if there is no partner_id on the object).
-
- :param string res_model: model name of the object
- :param int res_id: id of the object
- :param string message: content of the message
-
- optional keywords arguments:
- :param string token: access token if the object's model uses some kind of public access
- using tokens (usually a uuid4) to bypass access rules
- :param string token_field: name of the field that contains the token on the object (defaults to 'token')
- :param bool nosubscribe: set False if you want the partner to be set as follower of the object when posting (default to True)
-
- The rest of the kwargs are passed on to message_post()
- """
- record = request.env[res_model].browse(res_id)
- author_id = request.env.user.partner_id.id if request.env.user.partner_id else False
- if token_field and token:
- access_as_sudo = _special_access_object(res_model, res_id, token=token, token_field=token_field)
- if access_as_sudo:
- record = record.sudo()
- if request.env.user == request.env.ref('base.public_user'):
- author_id = record.partner_id.id if hasattr(record, 'partner_id') else author_id
- else:
- if not author_id:
- raise NotFound()
- else:
- raise Forbidden()
- kw.pop('csrf_token', None)
- return record.with_context(mail_create_nosubscribe=nosubscribe).message_post(body=message,
- message_type=kw.pop('message_type', "comment"),
- subtype=kw.pop('subtype', "mt_comment"),
- author_id=author_id,
- **kw)
class WebsiteMail(http.Controller):
@@ -108,50 +60,3 @@ class WebsiteMail(http.Controller):
('partner_id', '=', partner.id)
]))
return values
-
- @http.route(['/website_mail/post/post'], type='http', methods=['POST'], auth='public', website=True)
- def website_chatter_post(self, res_model, res_id, message, **kw):
- url = request.httprequest.referrer
- if message:
- _message_post_helper(res_model, int(res_id), message, **kw)
- url = url + "#discussion"
- return request.redirect(url)
-
- @http.route('/website_mail/init', type='json', auth='public', website=True)
- def website_chatter_init(self, res_model, res_id, domain=False, limit=False, **kwargs):
- is_user_public = bool(request.env.user == request.website.user_id)
- message_data = self.website_message_fetch(res_model, res_id, domain=domain, limit=limit, **kwargs)
- display_composer = False
- if kwargs.get('allow_composer'):
- display_composer = kwargs.get('token') or not is_user_public
- return {
- 'messages': message_data['messages'],
- 'options': {
- 'message_count': message_data['message_count'],
- 'is_user_public': is_user_public,
- 'is_user_publisher': request.env.user.has_group('website.group_website_publisher'),
- 'display_composer': display_composer,
- 'partner_id': request.env.user.partner_id.id
- }
- }
-
- @http.route('/website_mail/fetch', type='json', auth='public', website=True)
- def website_message_fetch(self, res_model, res_id, domain=False, limit=10, offset=0, **kw):
- if not domain:
- domain = []
- # Only search into website_message_ids, so apply the same domain to perform only one search
- # extract domain from the 'website_message_ids' field
- field_domain = request.env[res_model]._fields['website_message_ids'].domain
- domain += field_domain(request.env[res_model]) if callable(field_domain) else field_domain
- domain += [('res_id', '=', res_id)]
- # Check access
- Message = request.env['mail.message']
- if kw.get('token'):
- access_as_sudo = _special_access_object(res_model, res_id, token=kw.get('token'), token_field=kw.get('token_field'))
- if not access_as_sudo: # if token is not correct, raise Forbidden
- raise Forbidden()
- Message = request.env['mail.message'].sudo()
- return {
- 'messages': Message.search(domain, limit=limit, offset=offset).website_message_format(),
- 'message_count': Message.search_count(domain)
- }