Repository: modoboa/modoboa (language: python)

Issue:
Can't save settings in New admin interface (bad request 400)
# Impacted versions
Modoboa 2.0.1

* OS Type: Debian
* OS Version: 11
* Database Type: MySQL
* Database version: ?
* Modoboa: 2.0.1
* Installer used: Yes
* Webserver: Nginx

# Steps to reproduce
1) Login in new interface (mail.example.com/new-admin/) using admin.
2) Go to Settings -> General (/new-admin/parameters/core) and try to save any configuration using the button Save
![image](https://user-images.githubusercontent.com/9668277/177678728-6cd329e4-d52a-4500-a346-ca676e29f56a.png)

# Current behavior
After clicking the save button. No error message appears and does not save the settings.

Console of my browser:
![image](https://user-images.githubusercontent.com/9668277/177679853-b3f231f2-6696-4936-9379-30409f275e2b.png)

Response:
![image](https://user-images.githubusercontent.com/9668277/177680004-9e2b7bd8-9918-4b0a-aabf-89427a5c1061.png)

But the toggle "Enable password recovery by SMS" is off:
![image](https://user-images.githubusercontent.com/9668277/177680119-e172e1a0-874b-4bd0-8a7a-85611cf104c2.png)

Where is the field "default_top_redirection"???

# Expected behavior
Save the requested configuration

# Video/Screenshot link (optional)




Discussion / hints:

Fix patch:
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"
         )
diff --git a/modoboa/core/api/v2/serializers.py b/modoboa/core/api/v2/serializers.py
index 1c28f2101..3e99e6d96 100644
--- a/modoboa/core/api/v2/serializers.py
+++ b/modoboa/core/api/v2/serializers.py
@@ -13,6 +13,7 @@
 from ... import constants
 from ... import models
 from ... import sms_backends
+from ... import app_settings
 
 
 class CoreGlobalParametersSerializer(serializers.Serializer):
@@ -44,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")
@@ -106,7 +107,8 @@ class CoreGlobalParametersSerializer(serializers.Serializer):
     )
 
     # Dashboard settings
-    rss_feed_url = serializers.URLField(allow_blank=True)
+    rss_feed_url = serializers.URLField(
+        allow_blank=True, required=False, allow_null=True)
     hide_features_widget = serializers.BooleanField(default=False)
 
     # Notification settings
@@ -126,7 +128,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=[("user", _("User profile"))], required=False)
 
     def __init__(self, *args, **kwargs):
         super().__init__(*args, **kwargs)
@@ -134,6 +136,8 @@ def __init__(self, *args, **kwargs):
         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:
diff --git a/modoboa/core/sms_backends/ovh.py b/modoboa/core/sms_backends/ovh.py
index 6c9af68d5..f36f036c6 100644
--- a/modoboa/core/sms_backends/ovh.py
+++ b/modoboa/core/sms_backends/ovh.py
@@ -75,19 +75,25 @@ class OVHBackend(SMSBackend):
         "sms_ovh_application_key": {
             "type": serializers.CharField,
             "attrs": {
-                "required": False
+                "required": False,
+                "allow_blank": True,
+                "allow_null": True,
             }
         },
         "sms_ovh_application_secret": {
             "type": serializers.CharField,
             "attrs": {
-                "required": False
+                "required": False,
+                "allow_blank": True,
+                "allow_null": True,
             }
         },
         "sms_ovh_consumer_key": {
             "type": serializers.CharField,
             "attrs": {
-                "required": False
+                "required": False,
+                "allow_blank": True,
+                "allow_null": True,
             }
         }
     }


Test patch:
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 @@
     "top_notifications_check_interval": 30,
     "log_maximum_age": 365,
     "items_per_page": 30,
-    "default_top_redirection": ""
+    "default_top_redirection": "user"
 }