From b03f54f59479f32cd0ab264d5438faed28938860 Mon Sep 17 00:00:00 2001 From: Nicole Tibay Date: Tue, 19 Dec 2023 10:59:26 +0800 Subject: [PATCH] Be able to disable audit logging from django settings Keep existing behaviour for allowing disabling auditlog app wide. In Mathspace monolity, this is configured as: AUDITLOG = {"disable_auditlog": False} --- auditlog/conf.py | 3 +++ auditlog/registry.py | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/auditlog/conf.py b/auditlog/conf.py index 9046669..c7f93f5 100644 --- a/auditlog/conf.py +++ b/auditlog/conf.py @@ -40,3 +40,6 @@ settings.AUDITLOG_TWO_STEP_MIGRATION = getattr( settings.AUDITLOG_USE_TEXT_CHANGES_IF_JSON_IS_NOT_PRESENT = getattr( settings, "AUDITLOG_USE_TEXT_CHANGES_IF_JSON_IS_NOT_PRESENT", False ) + +# Custom +settings.AUDITLOG_DISABLE_AUDITLOG = getattr(settings, "AUDITLOG", {}).get("disable_auditlog", False) diff --git a/auditlog/registry.py b/auditlog/registry.py index 3f1f8f3..7f9a918 100644 --- a/auditlog/registry.py +++ b/auditlog/registry.py @@ -55,6 +55,9 @@ class AuditlogModelRegistry: self._signals = {} self._m2m_signals = defaultdict(dict) + if settings.AUDITLOG_DISABLE_AUDITLOG: + return + if create: self._signals[post_save] = log_create if update: @@ -195,6 +198,9 @@ class AuditlogModelRegistry: """ from auditlog.receivers import make_log_m2m_changes + if settings.AUDITLOG_DISABLE_AUDITLOG: + return + for signal, receiver in self._signals.items(): signal.connect( receiver,