Skip to content

Commit

Permalink
[FIX] mail: log correct user deleting the record
Browse files Browse the repository at this point in the history
When using sudo, the administrator is logged as deleting the action.
For audit reason, log the correct user.
To avoid access rights errors, only group system can delete the action.
  • Loading branch information
tde-banana-odoo committed Jul 7, 2018
1 parent 6033439 commit 9148665
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
12 changes: 6 additions & 6 deletions addons/mail/models/mail_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,22 +234,22 @@ def copy(self, default=None):
def unlink_action(self):
for template in self:
if template.ref_ir_act_window:
template.ref_ir_act_window.sudo().unlink()
template.ref_ir_act_window.unlink()
if template.ref_ir_value:
template.ref_ir_value.sudo().unlink()
template.ref_ir_value.unlink()
return True

@api.multi
def create_action(self):
ActWindowSudo = self.env['ir.actions.act_window'].sudo()
IrValuesSudo = self.env['ir.values'].sudo()
ActWindow = self.env['ir.actions.act_window']
IrValues = self.env['ir.values']
view = self.env.ref('mail.email_compose_message_wizard_form')

for template in self:
src_obj = template.model_id.model

button_name = _('Send Mail (%s)') % template.name
action = ActWindowSudo.create({
action = ActWindow.create({
'name': button_name,
'type': 'ir.actions.act_window',
'res_model': 'mail.compose.message',
Expand All @@ -260,7 +260,7 @@ def create_action(self):
'view_id': view.id,
'target': 'new',
'auto_refresh': 1})
ir_value = IrValuesSudo.create({
ir_value = IrValues.create({
'name': button_name,
'model': src_obj,
'key2': 'client_action_multi',
Expand Down
7 changes: 5 additions & 2 deletions addons/mail/views/mail_template_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,18 @@
<sheet>
<div class="oe_button_box" name="button_box">
<field name="ref_ir_act_window" invisible="1"/>
<button class="oe_stat_button" name="create_action" type="object"
<button class="oe_stat_button"
groups="base.group_system"
name="create_action" type="object"
attrs="{'invisible':[('ref_ir_act_window','!=',False)]}" icon="fa-plus"
help="Display an option on related documents to open a composition wizard with this template">
<div class="o_form_field o_stat_info">
<span class="o_stat_text">Add</span>
<span class="o_stat_text">Context Action</span>
</div>
</button>
<button name="unlink_action" type="object"
<button name="unlink_action" type="object"
groups="base.group_system"
class="oe_stat_button" icon="fa-minus"
attrs="{'invisible':[('ref_ir_act_window','=',False)]}"
help="Remove the contextual action to use this template on related documents" widget="statinfo">
Expand Down

0 comments on commit 9148665

Please sign in to comment.