authenticators: adjust show_condition field contraints (#65472)
This commit is contained in:
parent
d01300d6f1
commit
297b97d633
|
@ -32,6 +32,7 @@ class Migration(migrations.Migration):
|
|||
'show_condition',
|
||||
models.CharField(
|
||||
blank=True,
|
||||
default='',
|
||||
help_text=(
|
||||
'Django template controlling authenticator display. For example, "\'backoffice\' '
|
||||
'in login_hint or remotre_addr == \'1.2.3.4\'" would hide the authenticator from '
|
||||
|
@ -39,7 +40,7 @@ class Migration(migrations.Migration):
|
|||
'variables include service_ou_slug, service_slug, remote_addr, login_hint and '
|
||||
'headers.'
|
||||
),
|
||||
max_length=128,
|
||||
max_length=1024,
|
||||
verbose_name='Show condition',
|
||||
),
|
||||
),
|
||||
|
|
|
@ -14,7 +14,7 @@ def create_login_password_authenticator(apps, schema_editor):
|
|||
slug='password-authenticator',
|
||||
defaults={
|
||||
'order': password_settings.get('priority', 0),
|
||||
'show_condition': password_settings.get('show_condition', ''),
|
||||
'show_condition': password_settings.get('show_condition') or '',
|
||||
'enabled': app_settings.A2_AUTH_PASSWORD_ENABLE,
|
||||
'remember_me': app_settings.A2_USER_REMEMBER_ME,
|
||||
'include_ou_selector': app_settings.A2_LOGIN_FORM_OU_SELECTOR,
|
||||
|
|
|
@ -46,8 +46,9 @@ class BaseAuthenticator(models.Model):
|
|||
enabled = models.BooleanField(default=False, editable=False)
|
||||
show_condition = models.CharField(
|
||||
_('Show condition'),
|
||||
max_length=128,
|
||||
max_length=1024,
|
||||
blank=True,
|
||||
default='',
|
||||
help_text=_(
|
||||
'Django template controlling authenticator display. For example, "\'backoffice\' in '
|
||||
'login_hint or remotre_addr == \'1.2.3.4\'" would hide the authenticator from normal users '
|
||||
|
|
|
@ -10,14 +10,16 @@ from authentic2_auth_oidc import app_settings
|
|||
def add_base_authenticators(apps, schema_editor):
|
||||
kwargs_settings = getattr(global_settings, 'AUTH_FRONTENDS_KWARGS', {})
|
||||
oidc_provider_settings = kwargs_settings.get('oidc', {})
|
||||
show_condition = oidc_provider_settings.get('show_condition')
|
||||
show_condition = oidc_provider_settings.get('show_condition') or ''
|
||||
|
||||
BaseAuthenticator = apps.get_model('authenticators', 'BaseAuthenticator')
|
||||
OIDCProvider = apps.get_model('authentic2_auth_oidc', 'OIDCProvider')
|
||||
|
||||
for provider in OIDCProvider.objects.all():
|
||||
if isinstance(show_condition, dict):
|
||||
show_condition = show_condition.get(provider.slug, '')
|
||||
show_condition_authenticator = show_condition.get(provider.slug) or ''
|
||||
else:
|
||||
show_condition_authenticator = show_condition
|
||||
|
||||
base_authenticator = BaseAuthenticator.objects.create(
|
||||
name=provider.name,
|
||||
|
@ -25,7 +27,7 @@ def add_base_authenticators(apps, schema_editor):
|
|||
ou=provider.ou,
|
||||
enabled=provider.show and app_settings.ENABLE,
|
||||
order=oidc_provider_settings.get('priority', 2),
|
||||
show_condition=show_condition,
|
||||
show_condition=show_condition_authenticator,
|
||||
)
|
||||
provider.baseauthenticator_ptr = base_authenticator.pk
|
||||
provider.save()
|
||||
|
|
Loading…
Reference in New Issue