[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/<id>/<field>/<model>
and can be simplified to:
/web/partner_image/<id> 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) <odo@openerp.com>
This commit is contained in:
Alexandre Kühn
2019-05-08 10:35:37 +00:00
committed by Olivier Dony
parent 9e067d7d9d
commit 893e07e590
2 changed files with 21 additions and 2 deletions
@@ -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';
}
+20 -1
View File
@@ -1003,6 +1003,15 @@ class Binary(http.Controller):
response.set_cookie('fileToken', token)
return response
@http.route(['/web/partner_image',
'/web/partner_image/<int:rec_id>',
'/web/partner_image/<int:rec_id>/<string:field>',
'/web/partner_image/<int:rec_id>/<string:field>/<string:model>/'], 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/<string:xmlid>',
'/web/image/<string:xmlid>/<string:filename>',
@@ -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,