Revert "[FIX] website_mail, website_sale : redirect to login page to post comment"
This reverts commit 7974bf5441.
This commit is contained in:
@@ -1,14 +1,10 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
import urllib
|
||||
|
||||
from hashlib import sha1
|
||||
from time import time
|
||||
from werkzeug.exceptions import NotFound
|
||||
from werkzeug import url_encode
|
||||
|
||||
from openerp import SUPERUSER_ID, _
|
||||
from openerp import SUPERUSER_ID
|
||||
from openerp.addons.web import http
|
||||
from openerp.addons.web.http import request
|
||||
|
||||
@@ -69,7 +65,6 @@ def _message_post_helper(res_model='', res_id=None, message='', token='', token_
|
||||
res = res.sudo()
|
||||
else:
|
||||
raise NotFound()
|
||||
kw.pop('force_display', False)
|
||||
return res.with_context({'mail_create_nosubscribe': nosubscribe}).message_post(body=message,
|
||||
message_type=kw.pop('message_type', False) or "comment",
|
||||
subtype=kw.pop('subtype', False) or "mt_comment",
|
||||
@@ -152,47 +147,27 @@ class WebsiteMail(http.Controller):
|
||||
], context=context)) == 1
|
||||
return values
|
||||
|
||||
def _generate_login_url(self):
|
||||
url_params = request.params
|
||||
url_params.pop('force_display')
|
||||
url_params.update(redirect=request.httprequest.referrer)
|
||||
redirect_login_url = '/website_mail/post/post' + '?' + url_encode(url_params)
|
||||
url = '/web/login?redirect=%s' % urllib.quote(redirect_login_url)
|
||||
return url
|
||||
|
||||
@http.route(['/website_mail/post/json'], type='json', auth='public', website=True)
|
||||
def chatter_json(self, res_model='', res_id=None, message='', **kw):
|
||||
# if the chatter is displayed but the user is not logged, redirect him to login page
|
||||
if kw.get('force_display') and not request.session.uid:
|
||||
return {'redirect': self._generate_login_url()}
|
||||
# otherwise, try to post the comment
|
||||
res_id = int(res_id)
|
||||
try:
|
||||
if message:
|
||||
msg = _message_post_helper(res_model, res_id, message, **kw)
|
||||
data = {
|
||||
'id': msg.id,
|
||||
'body': msg.body,
|
||||
'date': msg.date,
|
||||
'author': msg.author_id.name,
|
||||
'image_url': request.website.image_url(msg.author_id, 'image_small')
|
||||
}
|
||||
return data
|
||||
else:
|
||||
return {'error': _('Empty comments are not allowed. Please fill the textearea.')}
|
||||
msg = _message_post_helper(res_model, res_id, message, **kw)
|
||||
data = {
|
||||
'id': msg.id,
|
||||
'body': msg.body,
|
||||
'date': msg.date,
|
||||
'author': msg.author_id.name,
|
||||
'image_url': request.website.image_url(msg.author_id, 'image_small')
|
||||
}
|
||||
return data
|
||||
except Exception:
|
||||
return {'error': _('Oops! Something went wrong. Try to reload the page and to log in.')}
|
||||
return False
|
||||
|
||||
@http.route(['/website_mail/post/post'], type='http', method=['POST'], auth='public', website=True)
|
||||
def chatter_post(self, res_model='', res_id=None, message='', redirect=None, **kw):
|
||||
res_id = int(res_id)
|
||||
url = request.httprequest.referrer
|
||||
if kw.get('force_display') and not request.session.uid:
|
||||
# set the redirection param to be redirect here when logged in
|
||||
url = self._generate_login_url()
|
||||
else:
|
||||
res_id = int(res_id)
|
||||
url = redirect or url
|
||||
if message:
|
||||
message = _message_post_helper(res_model, res_id, message, **kw)
|
||||
url = url + "#message-%s" % (message.id,)
|
||||
if message:
|
||||
message = _message_post_helper(res_model, res_id, message, **kw)
|
||||
url = url + "#message-%s" % (message.id,)
|
||||
return request.redirect(url)
|
||||
|
||||
@@ -38,16 +38,11 @@ odoo.define('website_mail.thread', function(require) {
|
||||
$button.prepend('<i class="fa fa-refresh fa-spin"></i> ');
|
||||
// post message, shw/hide error message and empty textarea
|
||||
ajax.jsonRpc(action, 'call', data).then(function (result) {
|
||||
if (!result['error']) {
|
||||
if(result['redirect']){
|
||||
window.location.replace(result['redirect']);
|
||||
}else{
|
||||
$error.fadeOut();
|
||||
self.prepend_message(result);
|
||||
$form.find('textarea').val('');
|
||||
}
|
||||
} else { // display error message from server
|
||||
$error.html(result['error']);
|
||||
if (result) {
|
||||
$error.fadeOut();
|
||||
self.prepend_message(result);
|
||||
$form.find('textarea').val('');
|
||||
} else {
|
||||
$error.fadeIn();
|
||||
}
|
||||
$button.html(button_bk);
|
||||
|
||||
@@ -38,11 +38,10 @@
|
||||
object_shasign function defined in the main controller of website_portal
|
||||
:sha_time string (optional): timestamp of the shasign generation
|
||||
:chatter_mode string: 'json' or 'post' depending on what kind of request you want
|
||||
:force_display : True if the chatter should be display, but posting a message required a logged user. Otherwise, the user will be redirect to the login page.
|
||||
-->
|
||||
<section id="discussion" class="hidden-print oe_website_portal o_website_mail_thread">
|
||||
<section class="mb32 css_editable_mode_hidden hidden-print">
|
||||
<form class="o_website_chatter_form" t-attf-action="/website_mail/post/#{chatter_mode}" method="POST" t-if="website.env.user != request.env['ir.model.data'].xmlid_to_object('base.public_user') or token or sha_in or force_display">
|
||||
<form class="o_website_chatter_form" t-attf-action="/website_mail/post/#{chatter_mode}" method="POST" t-if="website.env.user != request.env['ir.model.data'].xmlid_to_object('base.public_user') or token or sha_in">
|
||||
<img class="img pull-left img-circle" t-attf-src="/web/image/res.partner/#{user_id.partner_id.id}/image_small/50x50" style="width: 50px; margin-right: 10px;"/>
|
||||
<div class="pull-left mb32" style="width: 75%%">
|
||||
<textarea rows="4" name="message" class="form-control" placeholder="Write a message..."></textarea>
|
||||
@@ -52,7 +51,6 @@
|
||||
<input type='hidden' name="sha_in" t-att-value="sha_in" t-if="sha_in"/>
|
||||
<input type='hidden' name="sha_time" t-att-value="sha_time" t-if="sha_time"/>
|
||||
<input type='hidden' name="token_field" t-att-value="token_field" t-if="token_field"/>
|
||||
<input type='hidden' name="force_display" t-att-value="force_display" t-if="force_display"/>
|
||||
<div class="alert alert-danger mt8 mb0 o_website_chatter_error" style="display:none;">
|
||||
Oops! Something went wrong. Try to reload the page and to log in.
|
||||
</div>
|
||||
|
||||
@@ -15,24 +15,24 @@ class WebsiteMailController(WebsiteMail):
|
||||
def chatter_json(self, res_model='', res_id=None, message='', **kw):
|
||||
params = kw.copy()
|
||||
params.pop('rating', False)
|
||||
result = super(WebsiteMailController, self).chatter_json(res_model=res_model, res_id=res_id, message=message, **params)
|
||||
if result and result.get('id') and kw.get('rating') and res_model == 'product.template': # restrict rating only for product template
|
||||
message_data = super(WebsiteMailController, self).chatter_json(res_model=res_model, res_id=res_id, message=message, **params)
|
||||
if message_data and kw.get('rating') and res_model == 'product.template': # restrict rating only for product template
|
||||
rating = request.env['rating.rating'].create({
|
||||
'rating': float(kw.get('rating')),
|
||||
'res_model': res_model,
|
||||
'res_id': res_id,
|
||||
'message_id': result['id'],
|
||||
'message_id': message_data['id'],
|
||||
})
|
||||
result.update({
|
||||
message_data.update({
|
||||
'rating_default_value': rating.rating,
|
||||
'rating_disabled': True,
|
||||
})
|
||||
return result
|
||||
return message_data
|
||||
|
||||
@http.route(['/website_mail/post/post'], type='http', method=['POST'], auth='public', website=True)
|
||||
def chatter_post(self, res_model='', res_id=None, message='', redirect=None, **kw):
|
||||
params = kw.copy()
|
||||
params.pop('rating', False)
|
||||
params.pop('rating')
|
||||
response = super(WebsiteMailController, self).chatter_post(res_model=res_model, res_id=res_id, message=message, redirect=redirect, **params)
|
||||
if kw.get('rating') and res_model == 'product.template': # restrict rating only for product template
|
||||
try:
|
||||
|
||||
@@ -593,7 +593,6 @@
|
||||
<t t-set="object" t-value="product"/>
|
||||
<t t-set="chatter_mode" t-value="'json'"/>
|
||||
<t t-set="rating_enable" t-value="True"/>
|
||||
<t t-set="force_display" t-value="True"/>
|
||||
</t>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
Reference in New Issue
Block a user