diff --git a/addons/mail/controllers/discuss.py b/addons/mail/controllers/discuss.py index 94d10a0fa03..d0edbfff24d 100644 --- a/addons/mail/controllers/discuss.py +++ b/addons/mail/controllers/discuss.py @@ -257,17 +257,20 @@ class DiscussController(http.Controller): if channel_partner.env.user.share: # Only generate the access token if absolutely necessary (= not for internal user). vals['access_token'] = channel_partner.env['ir.attachment']._generate_access_token() - attachment = channel_partner.env['ir.attachment'].create(vals) - attachment._post_add_create() - attachmentData = { - 'filename': ufile.filename, - 'id': attachment.id, - 'mimetype': attachment.mimetype, - 'name': attachment.name, - 'size': attachment.file_size - } - if attachment.access_token: - attachmentData['accessToken'] = attachment.access_token + try: + attachment = channel_partner.env['ir.attachment'].create(vals) + attachment._post_add_create() + attachmentData = { + 'filename': ufile.filename, + 'id': attachment.id, + 'mimetype': attachment.mimetype, + 'name': attachment.name, + 'size': attachment.file_size + } + if attachment.access_token: + attachmentData['accessToken'] = attachment.access_token + except AccessError: + attachmentData = {'error': _("You are not allowed to upload an attachment here.")} return request.make_response( data=json.dumps(attachmentData), headers=[('Content-Type', 'application/json')] diff --git a/addons/mail/i18n/mail.pot b/addons/mail/i18n/mail.pot index 6559226b383..23cabce156e 100644 --- a/addons/mail/i18n/mail.pot +++ b/addons/mail/i18n/mail.pot @@ -1374,6 +1374,14 @@ msgstr "" msgid "Channel" msgstr "" +#. module: mail +#: code:addons/mail/models/mail_channel.py:0 +#, python-format +msgid "" +"Channel \"%(channel_name)s\" only accepts members of group " +"\"%(group_name)s\". Forbidden for: %(guest_names)s" +msgstr "" + #. module: mail #: code:addons/mail/models/mail_channel.py:0 #, python-format @@ -7512,6 +7520,12 @@ msgstr "" msgid "You are in channel #%s." msgstr "" +#. module: mail +#: code:addons/mail/controllers/discuss.py:0 +#, python-format +msgid "You are not allowed to upload an attachment here." +msgstr "" + #. module: mail #. openerp-web #: code:addons/mail/static/src/models/discuss_sidebar_category_item/discuss_sidebar_category_item.js:0 diff --git a/addons/web/controllers/binary.py b/addons/web/controllers/binary.py index 7883635dea6..77afdd27c82 100644 --- a/addons/web/controllers/binary.py +++ b/addons/web/controllers/binary.py @@ -11,8 +11,9 @@ import unicodedata import odoo import odoo.modules.registry from odoo import http -from odoo.modules import get_resource_path +from odoo.exceptions import AccessError from odoo.http import request +from odoo.modules import get_resource_path from odoo.tools import pycompat from odoo.tools.mimetypes import guess_mimetype from odoo.tools.misc import file_open, file_path @@ -131,6 +132,8 @@ class Binary(http.Controller): 'res_id': int(id) }) attachment._post_add_create() + except AccessError: + args.append({'error': _("You are not allowed to upload an attachment here.")}) except Exception: args.append({'error': _("Something horrible happened")}) _logger.exception("Fail to upload attachment %s", ufile.filename) diff --git a/addons/web/i18n/web.pot b/addons/web/i18n/web.pot index e8ed4906240..99d93c5e6e2 100644 --- a/addons/web/i18n/web.pot +++ b/addons/web/i18n/web.pot @@ -4824,6 +4824,12 @@ msgstr "" msgid "Yesterday" msgstr "" +#. module: web +#: code:addons/web/controllers/main.py:0 +#, python-format +msgid "You are not allowed to upload an attachment here." +msgstr "" + #. module: web #. openerp-web #: code:addons/web/static/src/legacy/js/widgets/model_field_selector.js:0