diff --git a/addons/im_livechat/controllers/livechat.py b/addons/im_livechat/controllers/livechat.py index 47129d8116a..bcd6ee785f9 100644 --- a/addons/im_livechat/controllers/livechat.py +++ b/addons/im_livechat/controllers/livechat.py @@ -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 diff --git a/addons/im_livechat/im_livechat.py b/addons/im_livechat/im_livechat.py index 7dde9a945ae..91c02810591 100644 --- a/addons/im_livechat/im_livechat.py +++ b/addons/im_livechat/im_livechat.py @@ -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: