diff --git a/modoboa/admin/tests/test_alias.py b/modoboa/admin/tests/test_alias.py index 9bdaf62cd..21397310f 100644 --- a/modoboa/admin/tests/test_alias.py +++ b/modoboa/admin/tests/test_alias.py @@ -1,3 +1,5 @@ +"""Admin test cases.""" + from django.urls import reverse from modoboa.core.models import User @@ -5,8 +7,6 @@ from modoboa.lib.tests import ModoTestCase from .. import factories from ..models import Alias, AliasRecipient, Domain -"""Admin test cases.""" - class AliasTestCase(ModoTestCase): diff --git a/modoboa/core/app_settings.py b/modoboa/core/app_settings.py index 427a62da9..3539e387d 100644 --- a/modoboa/core/app_settings.py +++ b/modoboa/core/app_settings.py @@ -82,6 +82,18 @@ class GeneralParametersForm(param_forms.AdminParametersForm): "Length of randomly generated passwords.") ) + update_password_url = forms.URLField( + label=ugettext_lazy("Update password service URL"), + initial="", + required=False, + help_text=ugettext_lazy( + "The URL of an external page where users will be able" + " to update their password. It applies only to non local" + " users, ie. those automatically created after a successful" + " external authentication (LDAP, SMTP)." + ) + ) + # LDAP specific settings ldap_sep = SeparatorField(label=ugettext_lazy("LDAP settings")) diff --git a/modoboa/core/commands/deploy.py b/modoboa/core/commands/deploy.py index ec2b88f66..d22ce1573 100644 --- a/modoboa/core/commands/deploy.py +++ b/modoboa/core/commands/deploy.py @@ -58,7 +58,7 @@ class DeployCommand(Command): "--domain", type=str, default=None, help="The domain under which you want to deploy modoboa") self._parser.add_argument( - "--lang", type=str, default="en-us", + "--lang", type=str, default="en", help="Set the default language" ) self._parser.add_argument( diff --git a/modoboa/core/templates/core/api_access.html b/modoboa/core/templates/core/api_access.html index b2bae6495..6215d0ca2 100644 --- a/modoboa/core/templates/core/api_access.html +++ b/modoboa/core/templates/core/api_access.html @@ -3,7 +3,7 @@

{% trans "API access" %} {% trans "Control your access to Modoboa API" %}


- {% url "api-docs:docs-index" as api_doc_url %} + {% url "docs-index" as api_doc_url %} {% blocktrans with url=api_doc_url trimmed %} A documentation of the API is available here. {% endblocktrans %} @@ -19,7 +19,7 @@

{% endif %} -
{% csrf_token %}
diff --git a/modoboa/core/templates/core/user_profile.html b/modoboa/core/templates/core/user_profile.html index c2425f31e..a824dd57f 100644 --- a/modoboa/core/templates/core/user_profile.html +++ b/modoboa/core/templates/core/user_profile.html @@ -2,11 +2,20 @@

{% trans "Profile" %} {% trans "Update your personal information" %}


- {% csrf_token %} {% render_form form %} -
+ {% if show_password_url %} + + {% endif %} +
diff --git a/modoboa/core/tests/test_core.py b/modoboa/core/tests/test_core.py index c9f34e8be..f2c5f5d9f 100644 --- a/modoboa/core/tests/test_core.py +++ b/modoboa/core/tests/test_core.py @@ -154,6 +154,23 @@ class ProfileTestCase(ModoTestCase): self.client.login(username="user@test.com", password="Toto1234") ) + def test_update_password_url(self): + """Check if external is used when defined.""" + self.set_global_parameter( + "update_password_url", "http://update.password") + non_local_user = factories.UserFactory( + username="user@external.com", groups=("SimpleUsers",), + is_local=False + ) + self.client.force_login(non_local_user) + url = reverse("core:user_profile") + response = self.client.get(url) + self.assertContains(response, "http://update.password") + + self.client.force_login(self.account) + response = self.client.get(url) + self.assertNotContains(response, "http://update.password") + class APIAccessFormTestCase(ModoTestCase): diff --git a/modoboa/core/views/user.py b/modoboa/core/views/user.py index 11f51a02a..8115a0d4e 100644 --- a/modoboa/core/views/user.py +++ b/modoboa/core/views/user.py @@ -30,6 +30,12 @@ def profile(request, tplname="core/user_profile.html"): sender="profile", user=request.user) if True in [result[1] for result in results]: update_password = False + password_url = request.localconfig.parameters.get_value( + "update_password_url") + show_password_url = False + if not request.user.is_local and password_url: + show_password_url = True + update_password = False if request.method == "POST": form = ProfileForm( @@ -51,7 +57,9 @@ def profile(request, tplname="core/user_profile.html"): form = ProfileForm(update_password, instance=request.user) return render_to_json_response({ "content": render_to_string(tplname, { - "form": form + "form": form, + "show_password_url": show_password_url, + "password_url": password_url }, request) }) diff --git a/modoboa/urls.py b/modoboa/urls.py index ba3f06e69..4239a412f 100644 --- a/modoboa/urls.py +++ b/modoboa/urls.py @@ -61,7 +61,8 @@ schema_view = get_schema_view( urlpatterns += [ path('docs/openapi.json', schema_view, name="openapi_schema"), path('docs/api/', login_required( - TemplateView.as_view(template_name="swagger-ui.html"))), + TemplateView.as_view(template_name="swagger-ui.html")), + name="docs-index"), path('api/v1/', include("modoboa.urls_api")), ]