[REF] mail: support only model / res_id in mail/view redirection controller
Currently mail/view controller supports either a message_id, either a model/res_id . Using a message_id is just a shortcut to find its model and res_id before redirecting to the record view. If the message has been removed the controller does not work anymore although with model and res_id it still works while the record exists. Same functional behavior can be achieved with only model and res_id. Let us drop support of message_id to lessen code size.
This commit is contained in:
@@ -164,7 +164,7 @@ class MailController(http.Controller):
|
||||
return subtypes_list
|
||||
|
||||
@http.route('/mail/view', type='http', auth='none')
|
||||
def mail_action_view(self, model=None, res_id=None, message_id=None, access_token=None, **kwargs):
|
||||
def mail_action_view(self, model=None, res_id=None, access_token=None, **kwargs):
|
||||
""" Generic access point from notification emails. The heuristic to
|
||||
choose where to redirect the user is the following :
|
||||
|
||||
@@ -176,19 +176,8 @@ class MailController(http.Controller):
|
||||
|
||||
models that have an access_token may apply variations on this.
|
||||
"""
|
||||
if message_id:
|
||||
try:
|
||||
message = request.env['mail.message'].sudo().browse(int(message_id)).exists()
|
||||
except:
|
||||
message = request.env['mail.message']
|
||||
if message:
|
||||
model, res_id = message.model, message.res_id
|
||||
else:
|
||||
# either a wrong message_id, either someone trying ids -> just go to messaging
|
||||
return self._redirect_to_messaging()
|
||||
elif res_id and isinstance(res_id, pycompat.string_types):
|
||||
if res_id and isinstance(res_id, pycompat.string_types):
|
||||
res_id = int(res_id)
|
||||
|
||||
return self._redirect_to_record(model, res_id, access_token)
|
||||
|
||||
@http.route('/mail/assign', type='http', auth='user', methods=['GET'])
|
||||
|
||||
@@ -613,15 +613,10 @@ class MailThread(models.AbstractModel):
|
||||
@api.multi
|
||||
def _notify_get_action_link(self, link_type, **kwargs):
|
||||
local_kwargs = dict(kwargs) # do not modify in-place, modify copy instead
|
||||
if kwargs.get('message_id'):
|
||||
base_params = {
|
||||
'message_id': kwargs['message_id'],
|
||||
}
|
||||
else:
|
||||
base_params = {
|
||||
'model': kwargs.get('model', self._name),
|
||||
'res_id': kwargs.get('res_id', self.ids and self.ids[0] or False),
|
||||
}
|
||||
base_params = {
|
||||
'model': kwargs.get('model', self._name),
|
||||
'res_id': kwargs.get('res_id', self.ids and self.ids[0] or False),
|
||||
}
|
||||
|
||||
local_kwargs.pop('message_id', None)
|
||||
local_kwargs.pop('model', None)
|
||||
@@ -680,10 +675,7 @@ class MailThread(models.AbstractModel):
|
||||
# access rights checks and speedup the computation.
|
||||
result = {}
|
||||
|
||||
if self._context.get('auto_delete', False):
|
||||
access_link = self._notify_get_action_link('view')
|
||||
else:
|
||||
access_link = self._notify_get_action_link('view', message_id=message.id)
|
||||
access_link = self._notify_get_action_link('view')
|
||||
|
||||
if message.model:
|
||||
model_name = self.env['ir.model']._get(message.model).display_name
|
||||
|
||||
Reference in New Issue
Block a user