[FIX] web, mail: error when adding attachments
Fix errors when adding attachment to records with read only permission: Current behavior: 1. Error adding attachment to records with read only permission. 2. The message is not as clear as version 13.0 closes odoo/odoo#88036 Expect: Only display the message "You are not allowed to upload an attachment here." if you do not have permission to upload files. X-original-commit: 8385f192873cfd33f311e00d9074571f1b3810a7 Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
This commit is contained in:
committed by
Sébastien Theys
parent
e5943d649d
commit
dfe70c656b
@@ -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')]
|
||||
|
||||
@@ -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 <b>#%s</b>."
|
||||
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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user