Skip to content
Permalink
Browse files

[IMP] models: show better server error message

This will show better and clearer error message in case of access rights issues
  • Loading branch information...
jev-odoo committed Mar 26, 2019
1 parent 0196a6f commit a4937d6a3352c32c1a444a0cf4879a7d2261e13f
@@ -4047,6 +4047,14 @@ msgstr ""
msgid "Record Thread ID"
msgstr ""

#. module: mail
#: code:addons/mail/models/mail_activity.py:182
#: code:addons/mail/models/mail_message.py:599
#: code:addons/mail/models/mail_message.py:700
#, python-format
msgid "Records: %s, User: %s)"
msgstr ""

#. module: mail
#: model:ir.model.fields,field_description:mail.field_mail_mail_references
msgid "References"
@@ -178,8 +178,9 @@ def _check_access(self, operation):
self.env[model].browse(res_ids).check_access_rule(doc_operation)
except exceptions.AccessError:
raise exceptions.AccessError(
_('The requested operation cannot be completed due to security restrictions. Please contact your system administrator.\n\n(Document type: %s, Operation: %s)') %
(self._description, operation))
_('The requested operation cannot be completed due to security restrictions. Please contact your system administrator.\n\n(Document type: %s, Operation: %s, ') % (self._description, operation) +
_('Records: %s, User: %s)') % (res_ids[:6], self._uid)
)

@api.model
def create(self, values):
@@ -595,8 +595,9 @@ def _generate_model_record_ids(msg_val, msg_ids):
WHERE message.message_type = %%s AND (message.subtype_id IS NULL OR subtype.internal IS TRUE) AND message.id = ANY (%%s)''' % (self._table), ('comment', self.ids,))
if self._cr.fetchall():
raise AccessError(
_('The requested operation cannot be completed due to security restrictions. Please contact your system administrator.\n\n(Document type: %s, Operation: %s)') %
(self._description, operation))
_('The requested operation cannot be completed due to security restrictions. Please contact your system administrator.\n\n(Document type: %s, Operation: %s, ') % (self._description, operation) +
_('Records: %s, User: %s)') % (self.ids[:6], self._uid)
)

# Read mail_message.ids to have their values
message_values = dict((res_id, {}) for res_id in self.ids)
@@ -695,8 +696,9 @@ def _generate_model_record_ids(msg_val, msg_ids):
if not (other_ids and self.browse(other_ids).exists()):
return
raise AccessError(
_('The requested operation cannot be completed due to security restrictions. Please contact your system administrator.\n\n(Document type: %s, Operation: %s)') %
(self._description, operation))
_('The requested operation cannot be completed due to security restrictions. Please contact your system administrator.\n\n(Document type: %s, Operation: %s, ') % (self._description, operation) +
_('Records: %s, User: %s)') % (other_ids[:6], self._uid)
)

@api.model
def _get_record_name(self, values):
@@ -149,6 +149,12 @@ msgstr ""
msgid "Published"
msgstr ""

#. module: website_mail
#: code:addons/website_mail/models/mail_message.py:59
#, python-format
msgid "Records: %s, User: %s)"
msgstr ""

#. module: website_mail
#: model:ir.ui.view,arch_db:website_mail.follow
msgid "Subscribe"
@@ -54,7 +54,10 @@ def check_access_rule(self, operation):
if self.user_has_groups('base.group_public'):
self.env.cr.execute('SELECT id FROM "%s" WHERE website_published IS FALSE AND id = ANY (%%s)' % (self._table), (self.ids,))
if self.env.cr.fetchall():
raise AccessError(_('The requested operation cannot be completed due to security restrictions. Please contact your system administrator.\n\n(Document type: %s, Operation: %s)') % (self._description, operation))
raise AccessError(
_('The requested operation cannot be completed due to security restrictions. Please contact your system administrator.\n\n(Document type: %s, Operation: %s, ') % (self._description, operation) +
_('Records: %s, User: %s)') % (self.ids[:6], self._uid)
)
return super(MailMessage, self).check_access_rule(operation=operation)

@api.multi
msgid "Record rules"
msgstr ""

#. module: base
#: code:addons/models.py:2864
#, python-format
msgid "Records: %r, User: %s)"
msgstr ""

#. module: base
#: code:addons/models.py:2778
#, python-format
msgid "Records: %s, User: %s)"
msgstr ""

#. module: base
#: model:ir.module.category,name:base.module_category_hr_recruitment
msgid "Recruitment"
@@ -2774,8 +2774,8 @@ def qualify(field):
(self._name, 'read', ','.join([str(r.id) for r in self][:6]), self._uid))
# store an access error exception in existing records
exc = AccessError(
_('The requested operation cannot be completed due to security restrictions. Please contact your system administrator.\n\n(Document type: %s, Operation: %s)') % \
(self._name, 'read')
_('The requested operation cannot be completed due to security restrictions. Please contact your system administrator.\n\n(Document type: %s, Operation: %s, ') % (self._description, operation) +
_('Records: %s, User: %s)') % (','.join([str(r.id) for r in self][:6]), self._uid)
)
self.env.cache.set_failed(forbidden, self._fields.values(), exc)

@@ -2859,8 +2859,10 @@ def _check_record_rules_result_count(self, result_ids, operation):
if self._uid == SUPERUSER_ID:
return
_logger.info('Access Denied by record rules for operation: %s on record ids: %r, uid: %s, model: %s', operation, forbidden_ids, self._uid, self._name)
raise AccessError(_('The requested operation cannot be completed due to security restrictions. Please contact your system administrator.\n\n(Document type: %s, Operation: %s)') % \
(self._description, operation))
raise AccessError(
_('The requested operation cannot be completed due to security restrictions. Please contact your system administrator.\n\n(Document type: %s, Operation: %s, ') % (self._description, operation) +
_('Records: %r, User: %s)') % (forbidden_ids[:6], self._uid)
)
else:
# If we get here, the missing_ids are not in the database
if operation in ('read','unlink'):

0 comments on commit a4937d6

Please sign in to comment.
You can’t perform that action at this time.