allow for fallback default variables in service info template (#75138) #25
|
@ -18,6 +18,7 @@ from django.conf import settings
|
|||
from pkg_resources import get_distribution
|
||||
|
||||
from . import app_settings, constants
|
||||
from .models import Setting
|
||||
from .utils import misc as utils_misc
|
||||
from .utils.service import get_home_url, get_service
|
||||
|
||||
|
@ -76,6 +77,9 @@ def a2_processor(request):
|
|||
variables['service_ou_colour'] = service.ou.colour
|
||||
if service.ou.logo:
|
||||
variables['service_ou_logo_url'] = service.ou.logo.url
|
||||
# fallback default appearance settings
|
||||
for setting in Setting.objects.filter_namespace('sso'):
|
||||
variables[setting.key.split(':')[-1]] = setting.value
|
||||
return variables
|
||||
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{% load i18n %}
|
||||
{% if service %}
|
||||
{% firstof service_colour service_ou_colour as colour %}
|
||||
{% firstof service.name service.ou.name as name %}
|
||||
{% firstof service_colour service_ou_colour default_service_colour as colour %}
|
||||
{% firstof service.name service.ou.name default_service_name as name %}
|
||||
|
||||
|
||||
{% if show_service_infos %}
|
||||
|
@ -16,12 +16,12 @@
|
|||
{% endblock %}
|
||||
|
||||
<div class="service-message">
|
||||
{% firstof service_logo_url service_ou_logo_url as logo_url %}
|
||||
{% firstof service_logo_url service_ou_logo_url default_service_logo_url as logo_url %}
|
||||
{% block service-logo %}
|
||||
{% if logo_url %}
|
||||
<picture>
|
||||
{% if service.home_url %}
|
||||
<a href="{{ home_url }}">
|
||||
{% if service.home_url or default_service_home_url %}
|
||||
<a href="{% firstof home_url default_service_home_url %}">
|
||||
{% endif %}
|
||||
<img src="{{ logo_url }}" alt="{{ name }}" class="service-message--logo" />
|
||||
{% if service.home_url %}
|
||||
|
@ -33,8 +33,8 @@
|
|||
|
||||
<div class="service-message--paragraph">
|
||||
{% block service-text %}
|
||||
{% if service.home_url %}
|
||||
<a href="{{ service.home_url }}" class="service-message--link">{{ name }}</a>
|
||||
{% if service.home_url or default_service_home_url %}
|
||||
<a href="{% firstof service.home_url default_service_home_url %}" class="service-message--link">
|
||||
{% else %}
|
||||
<span class="service-message--text">{{ name }}</span>
|
||||
{% endif %}
|
||||
|
|
|
@ -38,7 +38,7 @@ from jwcrypto.jwt import JWT
|
|||
from authentic2.a2_rbac.models import OrganizationalUnit, Role
|
||||
from authentic2.a2_rbac.utils import get_default_ou
|
||||
from authentic2.custom_user.models import Profile, ProfileType
|
||||
from authentic2.models import Attribute, AuthorizedRole
|
||||
from authentic2.models import Attribute, AuthorizedRole, Setting
|
||||
from authentic2.utils.misc import good_next_url, make_url
|
||||
from authentic2_auth_oidc.utils import parse_timestamp
|
||||
from authentic2_idp_oidc.models import OIDCAccessToken, OIDCAuthorization, OIDCClaim, OIDCClient, OIDCCode
|
||||
|
@ -110,7 +110,7 @@ OIDC_CLIENT_PARAMS = [
|
|||
]
|
||||
|
||||
|
||||
def test_login_from_client_with_home_url(oidc_client, app, simple_user):
|
||||
def test_login_from_client_with_home_url(oidc_client, app, simple_user, settings):
|
||||
redirect_uri = oidc_client.redirect_uris.split()[0]
|
||||
params = {
|
||||
'client_id': oidc_client.client_id,
|
||||
|
@ -126,6 +126,52 @@ def test_login_from_client_with_home_url(oidc_client, app, simple_user):
|
|||
assert not response.pyquery.find('.service-message--link')
|
||||
assert response.pyquery.find('.service-message--text')
|
||||
|
||||
# check default settings fallback
|
||||
colour = Setting.objects.get(key='sso:default_service_colour')
|
||||
colour.value = '#8c22ec'
|
||||
colour.save()
|
||||
home_url = Setting.objects.get(key='sso:default_service_home_url')
|
||||
home_url.value = 'https://default.example.net'
|
||||
home_url.save()
|
||||
logo_url = Setting.objects.get(key='sso:default_service_logo_url')
|
||||
logo_url.value = 'https://default.example.net/logo.jpg'
|
||||
logo_url.save()
|
||||
service_name = Setting.objects.get(key='sso:default_service_name')
|
||||
service_name.value = 'Some default service name'
|
||||
service_name.save()
|
||||
|
||||
old_service_name = oidc_client.name
|
||||
old_ou_name = oidc_client.ou.name
|
||||
oidc_client.name = ''
|
||||
oidc_client.ou.name = ''
|
||||
oidc_client.save()
|
||||
oidc_client.ou.save()
|
||||
|
||||
response = app.get(authorize_url).follow()
|
||||
assert response.pyquery.find('.service-message')
|
||||
link = response.pyquery.find('a.service-message--link')[0]
|
||||
assert link.attrib['href'] == 'https://default.example.net'
|
||||
assert 'color: #8c22ec' in response.text
|
||||
assert (
|
||||
response.pyquery.find('img.service-message--logo')[0].attrib['src']
|
||||
== 'https://default.example.net/logo.jpg'
|
||||
)
|
||||
assert response.pyquery.find('img.service-message--logo')[0].attrib['alt'] == 'Some default service name'
|
||||
|
||||
oidc_client.name = old_service_name
|
||||
oidc_client.ou.name = old_ou_name
|
||||
oidc_client.save()
|
||||
oidc_client.ou.save()
|
||||
|
||||
colour.value = ''
|
||||
colour.save()
|
||||
home_url.value = ''
|
||||
home_url.save()
|
||||
logo_url.value = ''
|
||||
logo_url.save()
|
||||
service_name.value = ''
|
||||
service_name.save()
|
||||
|
||||
ou = oidc_client.ou
|
||||
ou.home_url = 'https://ou.example.net'
|
||||
ou.colour = '#8c00ec'
|
||||
|
|
|
@ -154,7 +154,7 @@ def test_user_exclude(app, simple_user, mailoutbox, settings):
|
|||
assert 'no account was found associated with this address' in mailoutbox[0].body
|
||||
|
||||
|
||||
def test_old_url_redirect(app):
|
||||
def test_old_url_redirect(app, db):
|
||||
response = app.get('/password/reset/whatever')
|
||||
assert response.location == '/password/reset/'
|
||||
response = response.follow()
|
||||
|
|
Loading…
Reference in New Issue