mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-10-18 05:51:26 +02:00
Few enhancements.
This commit is contained in:
@@ -306,22 +306,24 @@ class IdentitySerializer(serializers.Serializer):
|
||||
def __init__(self, instance=None, data=..., **kwargs):
|
||||
super().__init__(instance, data, **kwargs)
|
||||
self.fields["possible_actions"] = serializers.SerializerMethodField()
|
||||
|
||||
|
||||
def get_possible_actions(self, identity):
|
||||
if not isinstance(identity, core_models.User):
|
||||
# Return empty action list if identity type is an alias (not used for now)
|
||||
# Return empty action list if identity type is an alias
|
||||
# (not used for now)
|
||||
return []
|
||||
actions = admin_signals.extra_account_identities_actions.send(
|
||||
self.__class__, account=identity)
|
||||
cleaned_actions = []
|
||||
for action in actions:
|
||||
try :
|
||||
try:
|
||||
serialized_data = IdPossibleActionsSerializer(action[1]).data
|
||||
cleaned_actions.append(serialized_data)
|
||||
except (ValidationError, AttributeError):
|
||||
continue
|
||||
return cleaned_actions
|
||||
|
||||
|
||||
class AccountResourceSerializer(serializers.ModelSerializer):
|
||||
"""Serializer for user resource."""
|
||||
|
||||
|
||||
@@ -30,3 +30,9 @@ class DMARCAligmentSerializer(serializers.Serializer):
|
||||
failed = serializers.DictField(
|
||||
child=serializers.DictField(child=SourceSerializer())
|
||||
)
|
||||
|
||||
|
||||
class DmarcGlobalParametersSerializer(serializers.Serializer):
|
||||
"""Serializer for global parameters."""
|
||||
|
||||
enable_rlookups = serializers.BooleanField(default=False)
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
"""Custom forms."""
|
||||
|
||||
import collections
|
||||
|
||||
from django import forms
|
||||
from django.utils import timezone
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from modoboa.dmarc.api.v2 import serializers
|
||||
from modoboa.lib import form_utils
|
||||
from modoboa.parameters import forms as param_forms
|
||||
|
||||
@@ -43,9 +46,29 @@ class ParametersForm(param_forms.AdminParametersForm):
|
||||
)
|
||||
|
||||
|
||||
GLOBAL_PARAMETERS_STRUCT = collections.OrderedDict([
|
||||
("dns", {
|
||||
"label": _("DNS settings"),
|
||||
"params": collections.OrderedDict([
|
||||
("enable_rlookups", {
|
||||
"label": _("Enable reverse lookups"),
|
||||
"help_text": _(
|
||||
"Enable reverse DNS lookups (reports will be longer to display)"
|
||||
)
|
||||
})
|
||||
])
|
||||
})
|
||||
])
|
||||
|
||||
|
||||
def load_settings():
|
||||
"""Load app settings."""
|
||||
from modoboa.parameters import tools as param_tools
|
||||
|
||||
param_tools.registry.add(
|
||||
"global", ParametersForm, _("DMARC"))
|
||||
param_tools.registry.add2(
|
||||
"global", "dmarc", _("DMARC"),
|
||||
GLOBAL_PARAMETERS_STRUCT,
|
||||
serializers.DmarcGlobalParametersSerializer
|
||||
)
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
"""Handlers for PDF credientials api v2."""
|
||||
|
||||
import os
|
||||
|
||||
from django.urls import reverse
|
||||
from django.dispatch import receiver
|
||||
from django.utils.translation import ugettext as _
|
||||
|
||||
from modoboa.admin import signals as admin_signals
|
||||
from modoboa.parameters import tools as param_tools
|
||||
|
||||
from ...lib import get_creds_filename
|
||||
|
||||
|
||||
@receiver(admin_signals.extra_account_identities_actions)
|
||||
def extra_identities_actions(sender, account, **kwargs):
|
||||
"""
|
||||
Add download credential action for identity.
|
||||
Used for api v2.
|
||||
"""
|
||||
if not param_tools.get_global_parameter("enabled_pdfcredentials"):
|
||||
return []
|
||||
fname = get_creds_filename(account)
|
||||
if not os.path.exists(fname):
|
||||
return []
|
||||
return {
|
||||
"name": "get_credentials",
|
||||
"url": reverse("v2:get-credentials",
|
||||
args=[account.id]),
|
||||
"icon": "mdi-file-download-outline",
|
||||
"label": _("Download PDF credentials.")
|
||||
}
|
||||
@@ -7,11 +7,10 @@ from django.utils.translation import ugettext_lazy as _
|
||||
from rest_framework import serializers, status
|
||||
from rest_framework.exceptions import PermissionDenied, APIException
|
||||
|
||||
|
||||
from modoboa.core.models import User
|
||||
from modoboa.parameters import tools as param_tools
|
||||
from ...lib import decrypt_file, get_creds_filename
|
||||
|
||||
from ...lib import decrypt_file, get_creds_filename
|
||||
from ...constants import CONNECTION_SECURITY_MODES
|
||||
|
||||
|
||||
@@ -31,14 +30,17 @@ class PDFCredentialsSettingsSerializer(serializers.Serializer):
|
||||
# Customization options
|
||||
title = serializers.CharField(default=_("Personal account information"))
|
||||
webpanel_url = serializers.URLField()
|
||||
custom_message = serializers.CharField(required=False, allow_blank=True)
|
||||
custom_message = serializers.CharField(
|
||||
required=False, allow_blank=True, allow_null=True)
|
||||
include_connection_settings = serializers.BooleanField(default=False)
|
||||
smtp_server_address = serializers.CharField()
|
||||
smtp_server_port = serializers.IntegerField(default=587)
|
||||
smtp_connection_security = serializers.ChoiceField(choices=CONNECTION_SECURITY_MODES, default="starttls")
|
||||
smtp_connection_security = serializers.ChoiceField(
|
||||
choices=CONNECTION_SECURITY_MODES, default="starttls")
|
||||
imap_server_address = serializers.CharField()
|
||||
imap_server_port = serializers.IntegerField(default=143)
|
||||
imap_connection_security = serializers.ChoiceField(choices=CONNECTION_SECURITY_MODES, default="starttls")
|
||||
imap_connection_security = serializers.ChoiceField(
|
||||
choices=CONNECTION_SECURITY_MODES, default="starttls")
|
||||
|
||||
|
||||
class GetAccountCredentialsSerializer(serializers.Serializer):
|
||||
@@ -57,7 +59,10 @@ class GetAccountCredentialsSerializer(serializers.Serializer):
|
||||
def save(self):
|
||||
fname = get_creds_filename(self.context["account"])
|
||||
if not os.path.exists(fname):
|
||||
raise APIException( _("No document available for this user"), status.HTTP_400_BAD_REQUEST)
|
||||
raise APIException(
|
||||
_("No document available for this user"),
|
||||
status.HTTP_400_BAD_REQUEST
|
||||
)
|
||||
self.context["content"] = decrypt_file(fname)
|
||||
if param_tools.get_global_parameter("delete_first_dl"):
|
||||
os.remove(fname)
|
||||
|
||||
@@ -82,26 +82,32 @@ PDF_CREDENTIALS_PARAMETERS_STRUCT = collections.OrderedDict([
|
||||
}),
|
||||
("smtp_server_address", {
|
||||
"label": _("SMTP server address"),
|
||||
"display": "include_connection_settings=True",
|
||||
"help_text": _("Address of the SMTP server (hostname or IP)")
|
||||
}),
|
||||
("smtp_server_port", {
|
||||
"label": _("SMTP server port"),
|
||||
"help_port": _("Listening port of the SMTP server")
|
||||
"display": "include_connection_settings=true",
|
||||
"help_text": _("Listening port of the SMTP server")
|
||||
}),
|
||||
("smtp_connection_security", {
|
||||
"label": _("SMTP connection security"),
|
||||
"display": "include_connection_settings=true",
|
||||
"help_text": _("Connection security mechanism")
|
||||
}),
|
||||
("imap_server_address", {
|
||||
"label": _("IMAP server address"),
|
||||
"display": "include_connection_settings=true",
|
||||
"help_text": _("Address of the IMAP server (hostname or IP)")
|
||||
}),
|
||||
("imap_server_port", {
|
||||
"label": _("IMAP server port"),
|
||||
"display": "include_connection_settings=true",
|
||||
"help_text": _("Listening port of the IMAP server")
|
||||
}),
|
||||
("imap_connection_security", {
|
||||
"label": _("IMAP connection security"),
|
||||
"display": "include_connection_settings=true",
|
||||
"help_text": _("Connection security mechanism")
|
||||
})
|
||||
])
|
||||
@@ -109,7 +115,6 @@ PDF_CREDENTIALS_PARAMETERS_STRUCT = collections.OrderedDict([
|
||||
])
|
||||
|
||||
|
||||
|
||||
class ParametersForm(param_forms.AdminParametersForm):
|
||||
"""Admin parameters form."""
|
||||
|
||||
@@ -118,7 +123,7 @@ class ParametersForm(param_forms.AdminParametersForm):
|
||||
general = form_utils.SeparatorField(label=_("General"))
|
||||
|
||||
enabled_pdfcredentials = form_utils.YesNoField(
|
||||
label= _("Enable PDF credentials"),
|
||||
label=_("Enable PDF credentials"),
|
||||
initial=True,
|
||||
help_text=_("Enabled PDF credentials document generation on account creation.")
|
||||
)
|
||||
|
||||
@@ -31,5 +31,5 @@ class PDFCredentialsConfig(AppConfig):
|
||||
|
||||
def ready(self):
|
||||
from . import handlers
|
||||
from .api.v2 import handlers
|
||||
|
||||
load_pdfcredential_settings()
|
||||
|
||||
@@ -7,6 +7,7 @@ from django.db.models import signals
|
||||
from django.dispatch import receiver
|
||||
from django.utils.translation import ugettext as _
|
||||
|
||||
from modoboa.admin import signals as admin_signals
|
||||
from modoboa.core import models as core_models
|
||||
from modoboa.core import signals as core_signals
|
||||
from modoboa.parameters import tools as param_tools
|
||||
@@ -51,3 +52,21 @@ def extra_account_actions(sender, account, **kwargs):
|
||||
}]
|
||||
|
||||
|
||||
@receiver(admin_signals.extra_account_identities_actions)
|
||||
def extra_identities_actions(sender, account, **kwargs):
|
||||
"""
|
||||
Add download credential action for identity.
|
||||
Used for api v2.
|
||||
"""
|
||||
if not param_tools.get_global_parameter("enabled_pdfcredentials"):
|
||||
return []
|
||||
fname = get_creds_filename(account)
|
||||
if not os.path.exists(fname):
|
||||
return []
|
||||
return {
|
||||
"name": "get_credentials",
|
||||
"url": reverse("v2:get-credentials",
|
||||
args=[account.id]),
|
||||
"icon": "mdi-file-download-outline",
|
||||
"label": _("Download PDF credentials")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user