summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Beguin <dbe@odoo.com>2018-11-06 14:02:43 +0000
committerDavid Beguin <dbe@odoo.com>2018-12-05 14:37:14 +0000
commitf513ee902cd76079a54f0bfadc22bfaeda51cce5 (patch)
tree74297c69aaa1240fd58258936dd056bc330716a9
parentbfb18f4326c8191e46518ea9e50697918391d347 (diff)
[IMP] im_livechat, website_livechat : add livechat username
To avoid that people know the complete name of the support members (for privacy purpose), a username can be used. Users have the opportunity to set and modify their username in their user preferences. If the username is not set, the complete name will still be used. If the username is set, it is used for the discussion title, the name of the message sender, the name of the team members in the channel statistics. All of this, only in the livechat context. Task ID : 1895998 Closes PR #28283
-rw-r--r--addons/im_livechat/__manifest__.py1
-rw-r--r--addons/im_livechat/models/__init__.py2
-rw-r--r--addons/im_livechat/models/im_livechat_channel.py2
-rw-r--r--addons/im_livechat/models/mail_channel.py13
-rw-r--r--addons/im_livechat/models/res_partner.py36
-rw-r--r--addons/im_livechat/models/res_users.py27
-rw-r--r--addons/im_livechat/static/src/scss/im_livechat.scss4
-rw-r--r--addons/im_livechat/views/res_users_views.xml36
-rw-r--r--addons/website_livechat/views/website_livechat.xml19
9 files changed, 134 insertions, 6 deletions
diff --git a/addons/im_livechat/__manifest__.py b/addons/im_livechat/__manifest__.py
index e6fbb6a436d..a7ca18b1525 100644
--- a/addons/im_livechat/__manifest__.py
+++ b/addons/im_livechat/__manifest__.py
@@ -26,6 +26,7 @@ Help your customers with this chat, and analyse their feedback.
"views/mail_channel_views.xml",
"views/im_livechat_channel_views.xml",
"views/im_livechat_channel_templates.xml",
+ "views/res_users_views.xml",
"report/im_livechat_report_channel_views.xml",
"report/im_livechat_report_operator_views.xml"
],
diff --git a/addons/im_livechat/models/__init__.py b/addons/im_livechat/models/__init__.py
index 7ed0b5e53f9..ed7159b0294 100644
--- a/addons/im_livechat/models/__init__.py
+++ b/addons/im_livechat/models/__init__.py
@@ -1,4 +1,6 @@
# -*- coding: utf-8 -*
+from . import res_users
+from . import res_partner
from . import im_livechat_channel
from . import ir_autovacuum
from . import mail_channel
diff --git a/addons/im_livechat/models/im_livechat_channel.py b/addons/im_livechat/models/im_livechat_channel.py
index 91e47b1151b..a5c187a1067 100644
--- a/addons/im_livechat/models/im_livechat_channel.py
+++ b/addons/im_livechat/models/im_livechat_channel.py
@@ -162,7 +162,7 @@ class ImLivechatChannel(models.Model):
'anonymous_name': False if user_id else anonymous_name,
'country_id': country_id,
'channel_type': 'livechat',
- 'name': ', '.join([self.env['res.users'].browse(user_id).name if user_id else anonymous_name, operator.name]),
+ 'name': ', '.join([self.env['res.users'].browse(user_id).name if user_id else anonymous_name, operator.livechat_username if operator.livechat_username else operator.name]),
'public': 'private',
'email_send': False,
})
diff --git a/addons/im_livechat/models/mail_channel.py b/addons/im_livechat/models/mail_channel.py
index 1e21c5b2d11..bb38a314fb0 100644
--- a/addons/im_livechat/models/mail_channel.py
+++ b/addons/im_livechat/models/mail_channel.py
@@ -47,7 +47,10 @@ class MailChannel(models.Model):
clicking on livechat button). So when the anonymous person is sending its FIRST message, the channel header
should be added to the notification, since the user cannot be listining to the channel.
"""
- notifications = super(MailChannel, self)._channel_message_notifications(message)
+ livechat_channels = self.filtered(lambda x: x.channel_type == 'livechat')
+ other_channels = self.filtered(lambda x: x.channel_type != 'livechat')
+ notifications = super(MailChannel, livechat_channels)._channel_message_notifications(message.with_context(im_livechat_use_username=True)) + \
+ super(MailChannel, other_channels)._channel_message_notifications(message)
for channel in self:
# add uuid for private livechat channels to allow anonymous to listen
if channel.channel_type == 'livechat' and channel.public == 'private':
@@ -60,6 +63,12 @@ class MailChannel(models.Model):
return notifications
@api.multi
+ def channel_fetch_message(self, last_id=False, limit=20):
+ """ Override to add the context of the livechat username."""
+ channel = self.with_context(im_livechat_use_username=True) if self.channel_type == 'livechat' else self
+ return super(MailChannel, channel).channel_fetch_message(last_id=last_id, limit=limit)
+
+ @api.multi
def channel_info(self, extra_info=False):
""" Extends the channel header by adding the livechat operator and the 'anonymous' profile
:rtype : list(dict)
@@ -71,7 +80,7 @@ class MailChannel(models.Model):
if channel.channel_type == 'livechat':
# add the operator id
if channel.livechat_operator_id:
- channel_infos_dict[channel.id]['operator_pid'] = channel.livechat_operator_id.display_name
+ channel_infos_dict[channel.id]['operator_pid'] = channel.livechat_operator_id.with_context(im_livechat_use_username=True).name_get()[0]
# add the anonymous or partner name
channel_infos_dict[channel.id]['correspondent_name'] = channel._channel_get_livechat_partner_name()
last_msg = self.env['mail.message'].search([("channel_ids", "in", [channel.id])], limit=1)
diff --git a/addons/im_livechat/models/res_partner.py b/addons/im_livechat/models/res_partner.py
new file mode 100644
index 00000000000..e3f85594151
--- /dev/null
+++ b/addons/im_livechat/models/res_partner.py
@@ -0,0 +1,36 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from odoo import models, api
+
+
+class Partners(models.Model):
+ """ Update of res.partners class
+ - override name_get to take into account the livechat username
+ """
+ _inherit = 'res.partner'
+
+ @api.multi
+ def name_get(self):
+ if self.env.context.get('im_livechat_use_username'):
+ # process the ones with livechat username
+ users_with_livechatname = self.env['res.users'].search([('partner_id', 'in', self.ids), ('livechat_username', '!=', False)])
+ map_with_livechatname = {}
+ for user in users_with_livechatname:
+ map_with_livechatname[user.partner_id.id] = user.livechat_username
+
+ # process the ones without livecaht username
+ partner_without_livechatname = self - users_with_livechatname.mapped('partner_id')
+ no_livechatname_name_get = super(Partners, partner_without_livechatname).name_get()
+ map_without_livechatname = dict(no_livechatname_name_get)
+
+ # restore order
+ result = []
+ for partner in self:
+ name = map_with_livechatname.get(partner.id)
+ if not name:
+ name = map_without_livechatname.get(partner.id)
+ result.append((partner.id, name))
+ else:
+ result = super(Partners, self).name_get()
+ return result
diff --git a/addons/im_livechat/models/res_users.py b/addons/im_livechat/models/res_users.py
new file mode 100644
index 00000000000..e909d0dae93
--- /dev/null
+++ b/addons/im_livechat/models/res_users.py
@@ -0,0 +1,27 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from odoo import fields, models, api
+
+
+class Users(models.Model):
+ """ Update of res.users class
+ - add a preference about username for livechat purpose
+ """
+ _inherit = 'res.users'
+
+ livechat_username = fields.Char("Livechat Username", help="This username will be used as your name in the livechat channels.")
+
+ def __init__(self, pool, cr):
+ """ Override of __init__ to add access rights on livechat_username
+ Access rights are disabled by default, but allowed
+ on some specific fields defined in self.SELF_{READ/WRITE}ABLE_FIELDS.
+ """
+ init_res = super(Users, self).__init__(pool, cr)
+ # duplicate list to avoid modifying the original reference
+ type(self).SELF_WRITEABLE_FIELDS = list(self.SELF_WRITEABLE_FIELDS)
+ type(self).SELF_WRITEABLE_FIELDS.extend(['livechat_username'])
+ # duplicate list to avoid modifying the original reference
+ type(self).SELF_READABLE_FIELDS = list(self.SELF_READABLE_FIELDS)
+ type(self).SELF_READABLE_FIELDS.extend(['livechat_username'])
+ return init_res
diff --git a/addons/im_livechat/static/src/scss/im_livechat.scss b/addons/im_livechat/static/src/scss/im_livechat.scss
index af21085a2c1..409b6a6726c 100644
--- a/addons/im_livechat/static/src/scss/im_livechat.scss
+++ b/addons/im_livechat/static/src/scss/im_livechat.scss
@@ -73,6 +73,10 @@
}
}
+.o_livechat_operator_avatar {
+ padding-right: 8px;
+}
+
.o_livechat_no_rating {
opacity: 0.5;
}
diff --git a/addons/im_livechat/views/res_users_views.xml b/addons/im_livechat/views/res_users_views.xml
new file mode 100644
index 00000000000..28f6ac490e9
--- /dev/null
+++ b/addons/im_livechat/views/res_users_views.xml
@@ -0,0 +1,36 @@
+<?xml version="1.0"?>
+<odoo>
+ <data>
+
+ <!-- Update Preferences form !-->
+ <record id="res_users_form_view_simple_modif" model="ir.ui.view">
+ <field name="name">res.users.preferences.form.im_livechat</field>
+ <field name="model">res.users</field>
+ <field name="inherit_id" ref="base.view_users_form_simple_modif"/>
+ <field name="arch" type="xml">
+ <xpath expr="//group[@name='preferences']" position="after">
+ <group name="livechat" string="Livechat Preferences">
+ <group>
+ <field name="livechat_username" readonly="0"/>
+ </group>
+ </group>
+ </xpath>
+ </field>
+ </record>
+
+ <!-- Update user form !-->
+ <record id="res_users_form_view" model="ir.ui.view">
+ <field name="name">res.users.form.im_livechat</field>
+ <field name="model">res.users</field>
+ <field name="inherit_id" ref="base.view_users_form"/>
+ <field name="arch" type="xml">
+ <xpath expr="//group[@name='messaging']" position="after">
+ <group name="livechat" string="Livechat">
+ <field name="livechat_username"/>
+ </group>
+ </xpath>
+ </field>
+ </record>
+
+ </data>
+</odoo>
diff --git a/addons/website_livechat/views/website_livechat.xml b/addons/website_livechat/views/website_livechat.xml
index 22770a3d7b4..a76f5503029 100644
--- a/addons/website_livechat/views/website_livechat.xml
+++ b/addons/website_livechat/views/website_livechat.xml
@@ -147,11 +147,24 @@
<t t-foreach="team" t-as="user">
<div class="media mt-3">
<t t-if="user.image_small">
- <img t-att-src="user.image_small and image_data_uri(user.image_small) or '/web/static/src/img/placeholder.png'"
- class="rounded" style="padding-right: 8px;" t-att-alt="user.name"/>
+ <t t-if="user.livechat_username">
+ <img t-att-src="user.image_small and image_data_uri(user.image_small) or '/web/static/src/img/placeholder.png'"
+ class="rounded o_livechat_operator_avatar" t-att-alt="user.livechat_username"/>
+ </t>
+ <t t-else="">
+ <img t-att-src="user.image_small and image_data_uri(user.image_small) or '/web/static/src/img/placeholder.png'"
+ class="rounded o_livechat_operator_avatar" t-att-alt="user.name"/>
+ </t>
</t>
<div class="media-body">
- <h5><t t-esc="user.name"/></h5>
+ <h5>
+ <t t-if="user.livechat_username">
+ <t t-esc="user.livechat_username"/>
+ </t>
+ <t t-else="">
+ <t t-esc="user.name"/>
+ </t>
+ </h5>
<div class="col-lg-12">
<div class="row">
<div class="col-lg-4 pl-0 pr-0">