Files
odoo_source/addons/auth_totp_mail/models/res_users.py
T
Thibault Delavallée f9dbd38720 [IMP] mail, various: rename custom_layout / notif_layout context usage
RATIONALE

Currently we can specify email used for notification layouting through context
use in mail composer. It is then propagated to message_post, stored on
mail.message and used to encapsulate emails sent based on posted messages.

SPECIFICATIONS

On template model: rename ``notif_layout`` parameter of ``send_mail`` to
``email_layout_xmlid`` to be coherent with naming used in other parts of the
code. Moreover it better indicates we expect an xml id.

On rating model: rename ``notif_layout`` parameter of ``rating_send_request``
to ``email_layout_xmlid``, for the same reasons as above.

In various wizards: support ``email_layout_xmlid`` context key when no field
is available, notably because this is still done manually in some wizards
like survey invite. Keep a fallback on ``notif_layout`` but remove support of
``custom_layout`` deprecated since quite a long time.

Task-2621326 (Mail: add 'view' button in 'light notification template')
Task-2647302 (Mail: add layout field in composer)

Part-of: odoo/odoo#76418
2021-11-10 09:58:09 +00:00

45 lines
1.6 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import _, models
class Users(models.Model):
_inherit = 'res.users'
def action_open_my_account_settings(self):
action = {
"name": _("Account Security"),
"type": "ir.actions.act_window",
"res_model": "res.users",
"views": [[self.env.ref('auth_totp_mail.res_users_view_form').id, "form"]],
"res_id": self.id,
}
return action
def get_totp_invite_url(self):
return '/web#action=auth_totp_mail.action_activate_two_factor_authentication'
def action_totp_invite(self):
invite_template = self.env.ref('auth_totp_mail.mail_template_totp_invite')
users_to_invite = self.sudo().filtered(lambda user: not user.totp_secret)
for user in users_to_invite:
email_values = {
'email_from': self.env.user.email_formatted,
'author_id': self.env.user.partner_id.id,
}
invite_template.send_mail(user.id, force_send=True, email_values=email_values,
email_layout_xmlid='mail.mail_notification_light')
# Display a confirmation toaster
return {
'type': 'ir.actions.client',
'tag': 'display_notification',
'params': {
'type': 'info',
'sticky': False,
'message': _("Invitation to use two-factor authentication sent for the following user(s): %s",
', '.join(users_to_invite.mapped('name'))),
}
}