Skip to content
This repository was archived by the owner on Feb 16, 2026. It is now read-only.

Commit 5d1cde6

Browse files
committed
{ADD]
1 parent cd15def commit 5d1cde6

5 files changed

Lines changed: 29 additions & 29 deletions

File tree

auditlog_security/__manifest__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
"contacts",
1414
],
1515
"data": [
16-
"demo/auditlog_rule.xml",
1716
"views/auditlog_view.xml",
1817
],
1918
"application": True,

auditlog_security/demo/auditlog_rule.xml

Lines changed: 0 additions & 10 deletions
This file was deleted.

auditlog_security/models/auditlog_rule.py

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright 2021 Therp B.V.
22
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
33

4-
from odoo import models, fields, api, modules, _
4+
from odoo import exceptions, models, fields, api, modules, _
55
from odoo.addons.auditlog.models.rule import FIELDS_BLACKLIST
66

77

@@ -19,8 +19,22 @@ class AuditlogRule(models.Model):
1919
)
2020
all_fields = fields.Boolean(
2121
string="Publicly visible log lines for all fields",
22+
readonly=True,
23+
compute="compute_all_fields",
24+
store=False,
2225
help="Check this field if you want this model to be visible by everyone")
2326

27+
@api.depends('field_ids')
28+
def compute_all_fields(self):
29+
for this in self.sudo():
30+
this.all_fields = not bool(len(this.field_ids))
31+
32+
@api.onchange('model_id')
33+
def onchange_model_id(self):
34+
# if model changes we must wipe out all field ids
35+
self.field_ids = False
36+
37+
2438

2539
def get_field_ids_domain(self):
2640
""" note this solution will work only with a hardcoded design of models,
@@ -34,27 +48,26 @@ def get_field_ids_domain(self):
3448
def unlink(self):
3549
# if we delete auditlog rule, corresponding ir.rules are removed
3650
# TODO PROPOSAL: a warning here with detailed information?
51+
to_delete = self.env["ir.rule"].with_context(auditlog_write=True).search(
52+
[("auditlog_id", "=", self.ids)])
3753
res = super(AuditlogRule, self).unlink()
38-
return (
39-
res
40-
and self.env["ir.rule"]
41-
.with_context(auditlog_write=True)
42-
.search([("auditlog_id", "in", self.ids)])
43-
.unlink()
44-
)
45-
54+
if res:
55+
res = res and to_delete.unlink()
56+
return res
4657

4758
@api.model
4859
def create(self, vals):
4960
if 'group_ids' not in vals:
5061
# if group has been removed and no group specified ad base user default
5162
vals['group_ids'] = [(6, 0, [self.env.ref('base.group_user').id])]
52-
if field_ids not in vals and not vals.get('all_fields'):
63+
if 'field_ids' not in vals and not vals.get('all_fields'):
5364
# this was done because of a
5465
# bug in attrs={'required': [('all_fields', '!=', True}
55-
raise exceptions.validationerror(
66+
raise exceptions.ValidationError(
5667
_("please specify fields to log or make all_fields true"))
57-
return super(AuditlogRule, self).create(vals)
68+
res = super(AuditlogRule, self).create(vals)
69+
res.generate_rules()
70+
return res
5871

5972
@api.multi
6073
def write(self, vals):

auditlog_security/models/ir_rule.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,15 @@ def create(self, values):
3232
def write(self, vals):
3333
if "auditlog_id" in vals and not self.env.context.get(
3434
'auditlog_write'):
35-
raise exceptions.validationerror(_("""Cannot change auditlog_id"""))
35+
raise exceptions.ValidationError(_("""Cannot change auditlog_id"""))
3636
return super(IrRule, self).write(vals)
3737

3838
@api.multi
3939
def unlink(self):
40-
self.prevent_rule_mod()
4140
auditlog_write = self.env.context.get("auditlog_write")
4241
for this in self:
4342
if this.auditlog_id and not auditlog_write:
44-
raise exceptions.validationerror(
43+
raise exceptions.ValidationError(
4544
_(
4645

4746
"""

auditlog_security/views/auditlog_view.xml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,12 @@
4949
<!-- in the domain are the blacklisted fields in auditlog they
5050
would be skipped anyway, so we repeat here to avoid incongruencies
5151
-->
52-
<field name="global_rule"/>
5352
<field name="field_ids"
54-
domain="[('model_id', '=' , model_id),('name', 'not in', ['id', 'create_uid', 'create_date', 'write_uid', 'write_date','display_name', '__last_update']) ]"
55-
attrs="{'required' : [('global_rule', '!=', True)]}"/>
53+
domain="[('model_id', '=' , model_id),('name', 'not in', ['id', 'create_uid', 'create_date', 'write_uid', 'write_date','display_name', '__last_update']) ]"/>
5654
</group>
5755
<group>
5856
<field name="group_ids" />
57+
<field name="all_fields"/>
5958
</group>
6059
</xpath>
6160

0 commit comments

Comments
 (0)