From 893e07e5906f4b5025ac7aa6b84f1d3cace811f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20K=C3=BChn?= Date: Fri, 12 Apr 2019 15:14:01 +0000 Subject: [PATCH] [IMP] im_livechat,web: use nicer placeholders for livechat In the context of a livechat session, a placeholder that looks like a person is better than a generic "missing picture" one, when the user has no public avatar. In order to allow a different placeholder without exposing a public placeholder parameter, a separate route is introduced for the purpose of displaying user avatars: /web/partner_image/// and can be simplified to: /web/partner_image/ for loading a partner avatar (`image_small`). The common part of the /web/image route was moved into a helper function that is not directly exposed. Task-ID 1924666 Closes #32664 Signed-off-by: Olivier Dony (odo) --- .../src/js/models/website_livechat_message.js | 2 +- addons/web/controllers/main.py | 21 ++++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/addons/im_livechat/static/src/js/models/website_livechat_message.js b/addons/im_livechat/static/src/js/models/website_livechat_message.js index 7ec9e4bc5a0..17634e11d2f 100644 --- a/addons/im_livechat/static/src/js/models/website_livechat_message.js +++ b/addons/im_livechat/static/src/js/models/website_livechat_message.js @@ -39,7 +39,7 @@ var WebsiteLivechatMessage = AbstractMessage.extend({ getAvatarSource: function () { var source = this._serverURL; if (this.hasAuthor()) { - source += '/web/image/res.partner/' + this.getAuthorID() + '/image_small?placeholder=user_placeholder.jpg'; + source += '/web/partner_image/' + this.getAuthorID(); } else { source += '/mail/static/src/img/smiley/avatar.jpg'; } diff --git a/addons/web/controllers/main.py b/addons/web/controllers/main.py index 14a73720340..e5384c9b167 100644 --- a/addons/web/controllers/main.py +++ b/addons/web/controllers/main.py @@ -1003,6 +1003,15 @@ class Binary(http.Controller): response.set_cookie('fileToken', token) return response + @http.route(['/web/partner_image', + '/web/partner_image/', + '/web/partner_image//', + '/web/partner_image////'], type='http', auth="public") + def content_image_partner(self, rec_id, field='image_small', model='res.partner', **kwargs): + # other kwargs are ignored on purpose + return self._content_image(id=rec_id, model='res.partner', field=field, + placeholder='user_placeholder.jpg') + @http.route(['/web/image', '/web/image/', '/web/image//', @@ -1023,7 +1032,17 @@ class Binary(http.Controller): def content_image(self, xmlid=None, model='ir.attachment', id=None, field='datas', filename_field='datas_fname', unique=None, filename=None, mimetype=None, download=None, width=0, height=0, crop=False, access_token=None, avoid_if_small=False, - upper_limit=False, placeholder='placeholder.png', **kw): + upper_limit=False, **kwargs): + # other kwargs are ignored on purpose + return self._content_image(xmlid=xmlid, model=model, id=id, field=field, + filename_field=filename_field, unique=unique, filename=filename, mimetype=mimetype, + download=download, width=width, height=height, crop=crop, access_token=access_token, + avoid_if_small=avoid_if_small, upper_limit=upper_limit) + + def _content_image(self, xmlid=None, model='ir.attachment', id=None, field='datas', + filename_field='datas_fname', unique=None, filename=None, mimetype=None, + download=None, width=0, height=0, crop=False, access_token=None, avoid_if_small=False, + upper_limit=False, placeholder='placeholder.png', **kwargs): status, headers, content = request.env['ir.http'].binary_content( xmlid=xmlid, model=model, id=id, field=field, unique=unique, filename=filename, filename_field=filename_field, download=download, mimetype=mimetype,