diff --git a/addons/mail/controllers/discuss.py b/addons/mail/controllers/discuss.py index 4ed8c3855d5..8cfc77bd9a1 100644 --- a/addons/mail/controllers/discuss.py +++ b/addons/mail/controllers/discuss.py @@ -151,8 +151,11 @@ class DiscussController(http.Controller): raise NotFound() return channel_partner_sudo.env['ir.http']._get_content_common(res_id=int(attachment_id), download=True) - @http.route('/mail/channel//image//x', methods=['GET'], type='http', auth='public') - def fetch_image(self, channel_id, attachment_id, width, height, **kwargs): + @http.route([ + '/mail/channel//image/', + '/mail/channel//image//x', + ], methods=['GET'], type='http', auth='public') + def fetch_image(self, channel_id, attachment_id, width=0, height=0, **kwargs): channel_partner_sudo = request.env['mail.channel.partner']._get_as_sudo_from_request_or_raise(request=request, channel_id=int(channel_id)) if not channel_partner_sudo.env['ir.attachment'].search([('id', '=', int(attachment_id)), ('res_id', '=', int(channel_id)), ('res_model', '=', 'mail.channel')], limit=1): raise NotFound() diff --git a/addons/mail/static/src/components/attachment_viewer/attachment_viewer.xml b/addons/mail/static/src/components/attachment_viewer/attachment_viewer.xml index 45766630d33..0d20ea193fe 100644 --- a/addons/mail/static/src/components/attachment_viewer/attachment_viewer.xml +++ b/addons/mail/static/src/components/attachment_viewer/attachment_viewer.xml @@ -43,7 +43,7 @@ - Viewer + Viewer diff --git a/addons/mail/static/src/models/attachment_viewer/attachment_viewer.js b/addons/mail/static/src/models/attachment_viewer/attachment_viewer.js index 80343d562c6..1b96601c351 100644 --- a/addons/mail/static/src/models/attachment_viewer/attachment_viewer.js +++ b/addons/mail/static/src/models/attachment_viewer/attachment_viewer.js @@ -20,6 +20,25 @@ function factory(dependencies) { dialog.delete(); } } + + //---------------------------------------------------------------------- + // Private + //---------------------------------------------------------------------- + + /** + * @private + * @returns {string} + */ + _computeImageUrl() { + if (!this.attachment) { + return; + } + if (!this.attachment.accessToken && this.attachment.originThread && this.attachment.originThread.model === 'mail.channel') { + return `/mail/channel/${this.attachment.originThread.id}/image/${this.attachment.id}`; + } + const accessToken = this.attachment.accessToken ? `?access_token=${this.attachment.accessToken}` : ''; + return `/web/image/${this.attachment.id}${accessToken}`; + } } AttachmentViewer.fields = { @@ -47,6 +66,13 @@ function factory(dependencies) { isCausal: true, readonly: true, }), + /** + * Determines the source URL to use for the image. + */ + imageUrl: attr({ + compute: '_computeImageUrl', + readonly: true, + }), /** * Determine whether the image is loading or not. Useful to diplay * a spinner when loading image initially. diff --git a/addons/mail/static/src/public/discuss_public_boot.js b/addons/mail/static/src/public/discuss_public_boot.js index 26142db85ea..135225df538 100644 --- a/addons/mail/static/src/public/discuss_public_boot.js +++ b/addons/mail/static/src/public/discuss_public_boot.js @@ -66,6 +66,10 @@ owl.Component.env = legacyEnv; async function createAndMountDiscussPublicView() { const messaging = await owl.Component.env.services.messaging.get(); + // needed by the attachment viewer + const DialogManager = getMessagingComponent('DialogManager'); + const dialogManagerComponent = new DialogManager(null, {}); + await dialogManagerComponent.mount(document.body); messaging.models['mail.thread'].insert(messaging.models['mail.thread'].convertData(data.channelData)); const discussPublicView = messaging.models['mail.discuss_public_view'].create(data.discussPublicViewData); if (discussPublicView.shouldDisplayWelcomeViewInitially) {