From 71c19e81e3318dda2930c148f6c400f06f3c4b01 Mon Sep 17 00:00:00 2001 From: Valentin Deniaud Date: Tue, 26 Jul 2022 17:30:06 +0200 Subject: [PATCH 3/4] auth_saml: use login form customization fields (#51363) --- .../migrations/0003_auto_20220726_1713.py | 24 +++++++++++++++++++ .../templates/authentic2_auth_saml/login.html | 5 +++- src/authentic2_auth_saml/views.py | 1 + tests/test_auth_saml.py | 10 +++++++- 4 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 src/authentic2_auth_saml/migrations/0003_auto_20220726_1713.py diff --git a/src/authentic2_auth_saml/migrations/0003_auto_20220726_1713.py b/src/authentic2_auth_saml/migrations/0003_auto_20220726_1713.py new file mode 100644 index 00000000..569ff63b --- /dev/null +++ b/src/authentic2_auth_saml/migrations/0003_auto_20220726_1713.py @@ -0,0 +1,24 @@ +# Generated by Django 2.2.26 on 2022-07-26 15:13 + +from django.conf import settings +from django.db import migrations +from django.utils import translation +from django.utils.translation import ugettext as _ + + +def set_default_button_label(apps, schema_editor): + SAMLAuthenticator = apps.get_model('authentic2_auth_saml', 'SAMLAuthenticator') + with translation.override(settings.LANGUAGE_CODE): + SAMLAuthenticator.objects.update(button_label=_('Login')) + + +class Migration(migrations.Migration): + + dependencies = [ + ('authentic2_auth_saml', '0002_auto_20220608_1559'), + ('authenticators', '0004_auto_20220726_1708'), + ] + + operations = [ + migrations.RunPython(set_default_button_label, reverse_code=migrations.RunPython.noop), + ] diff --git a/src/authentic2_auth_saml/templates/authentic2_auth_saml/login.html b/src/authentic2_auth_saml/templates/authentic2_auth_saml/login.html index 2cae84a9..3689dd8c 100644 --- a/src/authentic2_auth_saml/templates/authentic2_auth_saml/login.html +++ b/src/authentic2_auth_saml/templates/authentic2_auth_saml/login.html @@ -1,12 +1,15 @@ {% load i18n %} {% block before-login %} +{% if authenticator.button_description %} +

{{ authenticator.button_description }}

+{% endif %} {% endblock %} {% block login %}
- + {% if cancel %} {% endif %} diff --git a/src/authentic2_auth_saml/views.py b/src/authentic2_auth_saml/views.py index 38ea321a..1cb44cf3 100644 --- a/src/authentic2_auth_saml/views.py +++ b/src/authentic2_auth_saml/views.py @@ -9,6 +9,7 @@ def login(request, authenticator, *args, **kwargs): context = kwargs.pop('context', {}).copy() submit_name = 'login-saml-%s' % authenticator.slug context['submit_name'] = submit_name + context['authenticator'] = authenticator if request.method == 'POST' and submit_name in request.POST: from .adapters import AuthenticAdapter diff --git a/tests/test_auth_saml.py b/tests/test_auth_saml.py index 60713969..c4e65c20 100644 --- a/tests/test_auth_saml.py +++ b/tests/test_auth_saml.py @@ -45,7 +45,13 @@ def patched_adapter(monkeypatch): def test_providers_on_login_page(db, app, settings): - SAMLAuthenticator.objects.create(enabled=True, metadata='meta1.xml', slug='idp1') + SAMLAuthenticator.objects.create( + enabled=True, + metadata='meta1.xml', + slug='idp1', + button_label='Test label', + button_description='This is a test.', + ) response = app.get('/login/') assert response.pyquery('button[name="login-saml-idp1"]') @@ -57,6 +63,8 @@ def test_providers_on_login_page(db, app, settings): # two frontends should be present on login page assert response.pyquery('button[name="login-saml-idp1"]') assert response.pyquery('button[name="login-saml-idp2"]') + assert 'Test label' in response.text + assert 'This is a test.' in response.text @pytest.fixture -- 2.30.2