From 0867eda8f7a02baf631382ecac98ec47dcdac06f Mon Sep 17 00:00:00 2001 From: Spitap Date: Thu, 8 Sep 2022 19:18:57 +0200 Subject: [PATCH 1/6] Fixed core parameters unable to save on v2 --- modoboa/core/api/v2/serializers.py | 5 +++-- modoboa/core/sms_backends/ovh.py | 9 ++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/modoboa/core/api/v2/serializers.py b/modoboa/core/api/v2/serializers.py index 1c28f2101..66a4bf1db 100644 --- a/modoboa/core/api/v2/serializers.py +++ b/modoboa/core/api/v2/serializers.py @@ -13,6 +13,7 @@ from modoboa.lib import fields as lib_fields from ... import constants from ... import models from ... import sms_backends +from ... import app_settings class CoreGlobalParametersSerializer(serializers.Serializer): @@ -106,7 +107,7 @@ class CoreGlobalParametersSerializer(serializers.Serializer): ) # Dashboard settings - rss_feed_url = serializers.URLField(allow_blank=True) + rss_feed_url = serializers.URLField(allow_blank=True, required=False) hide_features_widget = serializers.BooleanField(default=False) # Notification settings @@ -126,7 +127,7 @@ class CoreGlobalParametersSerializer(serializers.Serializer): log_maximum_age = serializers.IntegerField(default=365) items_per_page = serializers.IntegerField(default=30) default_top_redirection = serializers.ChoiceField( - default="user", choices=[""]) + default="user", choices=app_settings.enabled_applications()) def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) diff --git a/modoboa/core/sms_backends/ovh.py b/modoboa/core/sms_backends/ovh.py index 6c9af68d5..c614ccbd2 100644 --- a/modoboa/core/sms_backends/ovh.py +++ b/modoboa/core/sms_backends/ovh.py @@ -75,19 +75,22 @@ class OVHBackend(SMSBackend): "sms_ovh_application_key": { "type": serializers.CharField, "attrs": { - "required": False + "required": False, + "allow_blank": True } }, "sms_ovh_application_secret": { "type": serializers.CharField, "attrs": { - "required": False + "required": False, + "allow_blank": True } }, "sms_ovh_consumer_key": { "type": serializers.CharField, "attrs": { - "required": False + "required": False, + "allow_blank": True } } } From a341198ce2448cf9ea7bcfdafa2f7704109d9873 Mon Sep 17 00:00:00 2001 From: Spitap Date: Thu, 8 Sep 2022 19:55:59 +0200 Subject: [PATCH 2/6] Allow none (happens on fresh instance) --- modoboa/core/api/v2/serializers.py | 6 +++--- modoboa/core/sms_backends/ovh.py | 9 ++++++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/modoboa/core/api/v2/serializers.py b/modoboa/core/api/v2/serializers.py index 66a4bf1db..508d5613b 100644 --- a/modoboa/core/api/v2/serializers.py +++ b/modoboa/core/api/v2/serializers.py @@ -45,7 +45,7 @@ class CoreGlobalParametersSerializer(serializers.Serializer): required=False, allow_blank=True) sms_password_recovery = serializers.BooleanField(default=False) sms_provider = serializers.ChoiceField( - choices=constants.SMS_BACKENDS, required=False) + choices=constants.SMS_BACKENDS, required=False, allow_null=True) # LDAP settings ldap_server_address = serializers.CharField(default="localhost") @@ -107,7 +107,7 @@ class CoreGlobalParametersSerializer(serializers.Serializer): ) # Dashboard settings - rss_feed_url = serializers.URLField(allow_blank=True, required=False) + rss_feed_url = serializers.URLField(allow_blank=True, required=False, allow_null=True) hide_features_widget = serializers.BooleanField(default=False) # Notification settings @@ -127,7 +127,7 @@ class CoreGlobalParametersSerializer(serializers.Serializer): log_maximum_age = serializers.IntegerField(default=365) items_per_page = serializers.IntegerField(default=30) default_top_redirection = serializers.ChoiceField( - default="user", choices=app_settings.enabled_applications()) + default="user", choices=app_settings.enabled_applications(), required=False) def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) diff --git a/modoboa/core/sms_backends/ovh.py b/modoboa/core/sms_backends/ovh.py index c614ccbd2..f36f036c6 100644 --- a/modoboa/core/sms_backends/ovh.py +++ b/modoboa/core/sms_backends/ovh.py @@ -76,21 +76,24 @@ class OVHBackend(SMSBackend): "type": serializers.CharField, "attrs": { "required": False, - "allow_blank": True + "allow_blank": True, + "allow_null": True, } }, "sms_ovh_application_secret": { "type": serializers.CharField, "attrs": { "required": False, - "allow_blank": True + "allow_blank": True, + "allow_null": True, } }, "sms_ovh_consumer_key": { "type": serializers.CharField, "attrs": { "required": False, - "allow_blank": True + "allow_blank": True, + "allow_null": True, } } } From 467dbecaf22ed5147d3e2c4ed34a752cb98df0f4 Mon Sep 17 00:00:00 2001 From: Spitap Date: Thu, 8 Sep 2022 19:59:51 +0200 Subject: [PATCH 3/6] Updated test for real case --- modoboa/core/api/v2/tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modoboa/core/api/v2/tests.py b/modoboa/core/api/v2/tests.py index df66e3e13..d8d06c75b 100644 --- a/modoboa/core/api/v2/tests.py +++ b/modoboa/core/api/v2/tests.py @@ -58,7 +58,7 @@ CORE_SETTINGS = { "top_notifications_check_interval": 30, "log_maximum_age": 365, "items_per_page": 30, - "default_top_redirection": "" + "default_top_redirection": "user" } From 735d61ed08acc4c9281cfd6e613a4faa33c613b8 Mon Sep 17 00:00:00 2001 From: Spitap Date: Thu, 8 Sep 2022 21:21:41 +0200 Subject: [PATCH 4/6] added fix for admin settings on fresh install --- modoboa/admin/app_settings.py | 1 + 1 file changed, 1 insertion(+) diff --git a/modoboa/admin/app_settings.py b/modoboa/admin/app_settings.py index 76f683b5c..5bf9543a2 100644 --- a/modoboa/admin/app_settings.py +++ b/modoboa/admin/app_settings.py @@ -94,6 +94,7 @@ class AdminParametersForm(param_forms.AdminParametersForm): custom_dns_server = GenericIPAddressField( label=ugettext_lazy("Custom DNS server"), required=False, + initial="", help_text=ugettext_lazy( "Use a custom DNS server instead of local server configuration" ) From 3b54c51b833c085d1c3737d536e01cfcdcc9e39f Mon Sep 17 00:00:00 2001 From: Spitap Date: Wed, 14 Sep 2022 08:32:19 +0200 Subject: [PATCH 5/6] getting choices on init --- modoboa/core/api/v2/serializers.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modoboa/core/api/v2/serializers.py b/modoboa/core/api/v2/serializers.py index 508d5613b..06183a277 100644 --- a/modoboa/core/api/v2/serializers.py +++ b/modoboa/core/api/v2/serializers.py @@ -127,7 +127,7 @@ class CoreGlobalParametersSerializer(serializers.Serializer): log_maximum_age = serializers.IntegerField(default=365) items_per_page = serializers.IntegerField(default=30) default_top_redirection = serializers.ChoiceField( - default="user", choices=app_settings.enabled_applications(), required=False) + default="user", choices=[("user", _("User profile"))], required=False) def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) @@ -135,6 +135,8 @@ class CoreGlobalParametersSerializer(serializers.Serializer): for field, definition in sms_backend_fields.items(): self.fields[field] = definition["type"]( **definition["attrs"]) + #Choices serializer for default_top_redirection field + self.fields["default_top_redirection"].choices = app_settings.enabled_applications() def validate_ldap_user_dn_template(self, value): try: From f25fb7fbbc3cc7ce16748240c8b1a26fa60a667d Mon Sep 17 00:00:00 2001 From: Spitap Date: Wed, 14 Sep 2022 16:45:40 +0200 Subject: [PATCH 6/6] PEP8 formating --- modoboa/core/api/v2/serializers.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/modoboa/core/api/v2/serializers.py b/modoboa/core/api/v2/serializers.py index 06183a277..3e99e6d96 100644 --- a/modoboa/core/api/v2/serializers.py +++ b/modoboa/core/api/v2/serializers.py @@ -107,7 +107,8 @@ class CoreGlobalParametersSerializer(serializers.Serializer): ) # Dashboard settings - rss_feed_url = serializers.URLField(allow_blank=True, required=False, allow_null=True) + rss_feed_url = serializers.URLField( + allow_blank=True, required=False, allow_null=True) hide_features_widget = serializers.BooleanField(default=False) # Notification settings @@ -135,7 +136,7 @@ class CoreGlobalParametersSerializer(serializers.Serializer): for field, definition in sms_backend_fields.items(): self.fields[field] = definition["type"]( **definition["attrs"]) - #Choices serializer for default_top_redirection field + # Choices serializer for default_top_redirection field self.fields["default_top_redirection"].choices = app_settings.enabled_applications() def validate_ldap_user_dn_template(self, value):