[FIX] im_livechat : starting a conversation can be done by an identified user (ie: a portal user).

The bus channel will still be public (using the uuid), but access to the message history and session information should be with the authenticated user and not the anonymous one. There is no anonymous name, and the request.session is used to identify the user.
This commit is contained in:
Jérome Maes
2015-04-15 17:04:53 +02:00
parent e10820f354
commit f8be7105e3
2 changed files with 14 additions and 6 deletions
+5 -2
View File
@@ -50,16 +50,19 @@ class LivechatController(http.Controller):
@http.route('/im_livechat/get_session', type="json", auth="none")
def get_session(self, channel_id, anonymous_name, **kwargs):
cr, uid, context, db = request.cr, request.uid or openerp.SUPERUSER_ID, request.context, request.db
cr, uid, context, db = request.cr, request.session.uid, request.context, request.db
reg = openerp.modules.registry.RegistryManager.get(db)
# if geoip, add the country name to the anonymous name
if request.session.geoip:
anonymous_name = anonymous_name + " ("+request.session.geoip.get('country_name', "")+")"
# if the user is identifiy (eg: portal user on the frontend), don't use the anonymous name. The user will be added to session.
if request.session.uid:
anonymous_name = False
return reg.get("im_livechat.channel").get_channel_session(cr, uid, channel_id, anonymous_name, context=context)
@http.route('/im_livechat/available', type='json', auth="none")
def available(self, db, channel):
cr, uid, context, db = request.cr, request.uid or openerp.SUPERUSER_ID, request.context, request.db
cr, uid, context, db = request.cr, request.session.uid or openerp.SUPERUSER_ID, request.context, request.db
reg = openerp.modules.registry.RegistryManager.get(db)
with reg.cursor() as cr:
return len(reg.get('im_livechat.channel').get_available_users(cr, uid, channel)) > 0
+9 -4
View File
@@ -26,6 +26,7 @@ import re
from openerp.osv import osv, fields
from openerp import api, models, tools
from openerp import SUPERUSER_ID
class im_livechat_channel(osv.Model):
@@ -155,7 +156,7 @@ class im_livechat_channel(osv.Model):
def get_available_users(self, cr, uid, channel_id, context=None):
""" get available user of a given channel """
channel = self.browse(cr, uid, channel_id, context=context)
channel = self.browse(cr, SUPERUSER_ID, channel_id, context=context)
users = []
for user_id in channel.user_ids:
if (user_id.im_status == 'online'):
@@ -165,14 +166,18 @@ class im_livechat_channel(osv.Model):
def get_channel_session(self, cr, uid, channel_id, anonymous_name, context=None):
""" return a session given a channel : create on with a registered user, or return false otherwise """
# get the avalable user of the channel
users = self.get_available_users(cr, uid, channel_id, context=context)
users = self.get_available_users(cr, SUPERUSER_ID, channel_id, context=context)
if len(users) == 0:
return False
user_id = random.choice(users).id
# user to add to the session
user_to_add = [(4, user_id)]
if uid:
user_to_add.append((4, uid))
# create the session, and add the link with the given channel
Session = self.pool["im_chat.session"]
newid = Session.create(cr, uid, {'user_ids': [(4, user_id)], 'channel_id': channel_id, 'anonymous_name' : anonymous_name}, context=context)
return Session.session_info(cr, uid, [newid], context=context)
newid = Session.create(cr, SUPERUSER_ID, {'user_ids': user_to_add, 'channel_id': channel_id, 'anonymous_name' : anonymous_name}, context=context)
return Session.session_info(cr, SUPERUSER_ID, [newid], context=context)
def test_channel(self, cr, uid, channel, context=None):
if not channel: