Added setting to define external password url. (#1849)

* Added setting to define external password url.

see #1848

* Fixed tests.
This commit is contained in:
Antoine Nguyen
2020-02-27 10:24:51 +01:00
committed by GitHub
parent a086a1b81c
commit cb9bd8b2e8
8 changed files with 56 additions and 9 deletions
+2 -2
View File
@@ -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):
+12
View File
@@ -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"))
+1 -1
View File
@@ -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(
+2 -2
View File
@@ -3,7 +3,7 @@
<h2>{% trans "API access" %} <small>{% trans "Control your access to Modoboa API" %}</small></h2>
<hr>
<div class="alert alert-info">
{% 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 <strong><a href="{{ url }}" target="_blank">here</a></strong>.
{% endblocktrans %}
@@ -19,7 +19,7 @@
</div>
<br>
{% endif %}
<form class="form-inline" method="POST" action="{% url 'core:user_api_access' %}"
<form class="form-inline" method="POST" action="{% url 'core:user_api_access' %}"
id="api_form">
{% csrf_token %}
<div class="row">
+11 -2
View File
@@ -2,11 +2,20 @@
<h2>{% trans "Profile" %} <small>{% trans "Update your personal information" %}</small></h2>
<hr>
<form class="form-horizontal" method="POST" action="{% url 'core:user_profile' %}"
<form class="form-horizontal" method="POST" action="{% url 'core:user_profile' %}"
id="uprefs_form">
{% csrf_token %}
{% render_form form %}
<div class="form-actions">
{% if show_password_url %}
<div class="row">
<div class="col-sm-offset-4 col-sm-8">
<a href="{{ password_url }}" target="_blank">
{% trans "Click here to update your password" %}
</a>
</div>
</div>
{% endif %}
<div class="form-actions" style="margin-top: 15px;">
<button type="submit" class="btn btn-primary btn-lg col-sm-offset-4 col-sm-4" id="update" name="update">{% trans 'Update' %}</button>
</div>
</form>
+17
View File
@@ -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):
+9 -1
View File
@@ -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)
})
+2 -1
View File
@@ -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")),
]