diff --git a/auditlog/README.rst b/auditlog/README.rst index 6c603514dce..b583c0a7ac0 100644 --- a/auditlog/README.rst +++ b/auditlog/README.rst @@ -1,7 +1,3 @@ -.. image:: https://odoo-community.org/readme-banner-image - :target: https://odoo-community.org/get-involved?utm_source=readme - :alt: Odoo Community Association - ========= Audit Log ========= @@ -17,7 +13,7 @@ Audit Log .. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png :target: https://odoo-community.org/page/development-status :alt: Beta -.. |badge2| image:: https://img.shields.io/badge/license-AGPL--3-blue.png +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :alt: License: AGPL-3 .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--tools-lightgray.png?logo=github diff --git a/auditlog/__manifest__.py b/auditlog/__manifest__.py index b5d9a8bc86f..053c59be9bd 100644 --- a/auditlog/__manifest__.py +++ b/auditlog/__manifest__.py @@ -14,6 +14,7 @@ "security/ir.model.access.csv", "data/ir_cron.xml", "views/auditlog_view.xml", + "views/auditlog_rule_actions.xml", "views/http_session_view.xml", "views/http_request_view.xml", ], diff --git a/auditlog/models/rule.py b/auditlog/models/rule.py index 2cdb4ae8d2d..8042446471b 100644 --- a/auditlog/models/rule.py +++ b/auditlog/models/rule.py @@ -794,6 +794,15 @@ def unsubscribe(self): act_window.unlink() return self.write({"state": "draft"}) + def action_server_bulk_subscribe(self): + """Bulk subscribe rules""" + self.filtered(lambda rule: rule.state != "subscribed").subscribe() + return True + + def action_server_bulk_unsubscribe(self): + self.filtered(lambda rule: rule.state == "subscribed").unsubscribe() + return True + @api.model def _update_vals_list(self, vals_list): # Odoo supports empty recordset assignment (while it doesn't handle diff --git a/auditlog/static/description/index.html b/auditlog/static/description/index.html index 0859b2884b1..a30df380364 100644 --- a/auditlog/static/description/index.html +++ b/auditlog/static/description/index.html @@ -3,7 +3,7 @@ -README.rst +Audit Log -
+
+

Audit Log

- - -Odoo Community Association - -
-

Audit Log

-

Beta License: AGPL-3 OCA/server-tools Translate me on Weblate Try me on Runboat

+

Beta License: AGPL-3 OCA/server-tools Translate me on Weblate Try me on Runboat

This module allows the administrator to log user operations performed on data models such as create, read, write and delete.

Table of contents

@@ -393,7 +388,7 @@

Audit Log

-

Usage

+

Usage

Go to Settings / Technical / Audit / Rules to subscribe rules. A rule defines which operations to log for a given data model.

image

@@ -417,7 +412,7 @@

Usage

right to configure the auditlog configuration rules.

-

Known issues / Roadmap

+

Known issues / Roadmap

  • log only operations triggered by some users (currently it logs all @@ -428,7 +423,7 @@

    Known issues / Roadmap

-

Bug Tracker

+

Bug Tracker

Bugs are tracked on GitHub Issues. In case of trouble, please check there if your issue has already been reported. If you spotted it first, help us to smash it by providing a detailed and welcomed @@ -436,15 +431,15 @@

Bug Tracker

Do not contact contributors directly about support or help with technical issues.

-

Credits

+

Credits

-

Authors

+

Authors

  • ABF OSIELL
-

Contributors

+

Contributors

-

Other credits

+

Other credits

  • Icon: built with different icons from the Oxygen theme (LGPL)
-

Maintainers

+

Maintainers

This module is maintained by the OCA.

Odoo Community Association @@ -481,6 +476,5 @@

Maintainers

-
diff --git a/auditlog/tests/test_auditlog.py b/auditlog/tests/test_auditlog.py index a8df47d5f6f..58731360b8d 100644 --- a/auditlog/tests/test_auditlog.py +++ b/auditlog/tests/test_auditlog.py @@ -746,3 +746,78 @@ def test_01_AuditlogFast_field_exclude_write_log(self): ] ) ) + + +class AuditLogRuleBulkActions(AuditLogRuleCommon): + @classmethod + def setUpClass(cls): + super().setUpClass() + country_model = cls.env.ref("base.model_res_country") + state_model = cls.env.ref("base.model_res_country_state") + + existing_rules = cls.env["auditlog.rule"].search( + [("model_id", "in", (country_model.id, state_model.id))] + ) + existing_rules.action_server_bulk_unsubscribe() + existing_rules.unlink() + + cls.rule_country = cls.create_rule( + { + "name": "Country bulk rule", + "model_id": country_model.id, + "log_read": False, + "log_create": True, + "log_write": True, + "log_unlink": True, + "log_type": "fast", + } + ) + cls.rule_state = cls.create_rule( + { + "name": "State bulk rule", + "model_id": state_model.id, + "log_read": False, + "log_create": True, + "log_write": True, + "log_unlink": True, + "log_type": "fast", + } + ) + cls.rules = cls.rule_country | cls.rule_state + + @classmethod + def tearDownClass(cls): + if cls.rules: + cls.rules.action_server_bulk_unsubscribe() + cls.rules.unlink() + super().tearDownClass() + + def test_01_bulk_subscribe(self): + self.rules.action_server_bulk_unsubscribe() + + action_result = self.rules.action_server_bulk_subscribe() + + self.assertTrue(action_result) + self.rules.invalidate_recordset() + self.assertTrue(all(rule.state == "subscribed" for rule in self.rules)) + for rule in self.rules: + self.assertTrue(rule.action_id) + self.assertEqual(rule.action_id.binding_model_id, rule.model_id) + + def test_02_bulk_unsubscribe(self): + self.rules.action_server_bulk_unsubscribe() + self.rules.action_server_bulk_subscribe() + self.rules.invalidate_recordset() + action_ids = self.rules.mapped("action_id.id") + self.assertTrue(action_ids) + + action_result = self.rules.action_server_bulk_unsubscribe() + + self.assertTrue(action_result) + self.rules.invalidate_recordset() + self.assertTrue(all(rule.state == "draft" for rule in self.rules)) + self.assertFalse(any(self.rules.mapped("action_id"))) + remaining_actions = self.env["ir.actions.act_window"].search( + [("id", "in", action_ids)] + ) + self.assertFalse(remaining_actions) diff --git a/auditlog/views/auditlog_rule_actions.xml b/auditlog/views/auditlog_rule_actions.xml new file mode 100644 index 00000000000..2f9dc433d07 --- /dev/null +++ b/auditlog/views/auditlog_rule_actions.xml @@ -0,0 +1,20 @@ + + + + Subscribe Rules + + + action + code + action = records.action_server_bulk_subscribe() + + + + Unsubscribe Rules + + + action + code + action = records.action_server_bulk_unsubscribe() + +