mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-10-17 05:41:25 +02:00
Refactored rspamd capabilities checks
This commit is contained in:
@@ -13,7 +13,7 @@ from django.utils.translation import gettext as _
|
||||
from modoboa.core.extensions import exts_pool
|
||||
from modoboa.core.password_hashers import get_configured_password_hasher, PasswordHasher
|
||||
from modoboa.lib.api_client import ModoAPIClient
|
||||
from modoboa.rspamd.utils import check_rspamd_installed
|
||||
from modoboa.rspamd.utils import check_rspamd_installed, get_rspamd_options
|
||||
|
||||
|
||||
def parse_map_file(path):
|
||||
@@ -108,7 +108,8 @@ def get_capabilities():
|
||||
"""Return the list of capabilities of this modoboa instance."""
|
||||
capabilities = {}
|
||||
# Rspamd
|
||||
rspamd_options = check_rspamd_installed()
|
||||
if rspamd_options is not None:
|
||||
is_rspamd_installed = check_rspamd_installed()
|
||||
if is_rspamd_installed:
|
||||
rspamd_options = get_rspamd_options()
|
||||
capabilities.update({"rspamd": rspamd_options})
|
||||
return capabilities
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
"""Management command to create DKIM keys."""
|
||||
|
||||
from django.core.management.base import BaseCommand, CommandError
|
||||
|
||||
from modoboa.parameters import tools as param_tools
|
||||
|
||||
+19
-13
@@ -4,21 +4,27 @@ import shutil
|
||||
|
||||
from django.core.exceptions import AppRegistryNotReady
|
||||
|
||||
from modoboa.lib import signals as lib_signals
|
||||
|
||||
|
||||
def check_rspamd_installed():
|
||||
return shutil.which("rspamd") is not None
|
||||
|
||||
|
||||
def get_rspamd_options():
|
||||
try:
|
||||
is_rspamd_installed = shutil.which("rspamd") is not None
|
||||
rspamd_options = {} if is_rspamd_installed else None
|
||||
request = lib_signals.get_request()
|
||||
if is_rspamd_installed:
|
||||
if request is not None:
|
||||
rspamd_options["location"] = request.localconfig.parameters.get_value(
|
||||
"rspamd_dashboard_location"
|
||||
)
|
||||
else:
|
||||
rspamd_options["location"] = None
|
||||
from modoboa.core import models
|
||||
|
||||
is_rspamd_installed = check_rspamd_installed()
|
||||
if not is_rspamd_installed:
|
||||
return None
|
||||
rspamd_options = {}
|
||||
localconfig = models.LocalConfig.objects.first()
|
||||
rspamd_location = localconfig.parameters.get_value(
|
||||
"rspamd_dashboard_location", raise_exception=False
|
||||
)
|
||||
if not rspamd_location:
|
||||
return None
|
||||
rspamd_options["location"] = rspamd_location
|
||||
return rspamd_options
|
||||
except AppRegistryNotReady:
|
||||
# If the instance is not restarted after rspamd installation
|
||||
return None
|
||||
return rspamd_options
|
||||
|
||||
Reference in New Issue
Block a user