misc: look for portal agent associated to user OU when in Authentic (#29658)
This commit is contained in:
parent
6b6f4dc4b3
commit
7aa49fcf12
|
@ -205,6 +205,7 @@ if 'TEMPLATE_DEBUG' in globals():
|
||||||
TEMPLATE_CONTEXT_PROCESSORS = (
|
TEMPLATE_CONTEXT_PROCESSORS = (
|
||||||
'hobo.context_processors.template_vars',
|
'hobo.context_processors.template_vars',
|
||||||
'hobo.context_processors.theme_base',
|
'hobo.context_processors.theme_base',
|
||||||
|
'hobo.context_processors.portal_agent_url',
|
||||||
) + TEMPLATE_CONTEXT_PROCESSORS
|
) + TEMPLATE_CONTEXT_PROCESSORS
|
||||||
else:
|
else:
|
||||||
assert len(TEMPLATES)
|
assert len(TEMPLATES)
|
||||||
|
@ -226,6 +227,7 @@ else:
|
||||||
TEMPLATES[0]['OPTIONS']['context_processors'] = [
|
TEMPLATES[0]['OPTIONS']['context_processors'] = [
|
||||||
'hobo.context_processors.template_vars',
|
'hobo.context_processors.template_vars',
|
||||||
'hobo.context_processors.theme_base',
|
'hobo.context_processors.theme_base',
|
||||||
|
'hobo.context_processors.portal_agent_url',
|
||||||
] + TEMPLATES[0]['OPTIONS']['context_processors']
|
] + TEMPLATES[0]['OPTIONS']['context_processors']
|
||||||
|
|
||||||
# needed by hobo.context_processors.theme_base:
|
# needed by hobo.context_processors.theme_base:
|
||||||
|
|
|
@ -61,6 +61,7 @@ class Command(hobo_deploy.Command):
|
||||||
'secret_key': service_dict.get('secret_key')})
|
'secret_key': service_dict.get('secret_key')})
|
||||||
service.title = service_dict['title']
|
service.title = service_dict['title']
|
||||||
service.secret_key = service_dict.get('secret_key')
|
service.secret_key = service_dict.get('secret_key')
|
||||||
|
service.template_name = service_dict.get('template_name') or ''
|
||||||
service.slug = service_slug
|
service.slug = service_slug
|
||||||
service.use_as_idp_for_self = True
|
service.use_as_idp_for_self = True
|
||||||
service.last_operational_check_timestamp = now()
|
service.last_operational_check_timestamp = now()
|
||||||
|
|
|
@ -147,8 +147,30 @@ def theme_base(request):
|
||||||
'theme_base_filename': template_vars(request).get('theme_base_filename') or 'theme.html'
|
'theme_base_filename': template_vars(request).get('theme_base_filename') or 'theme.html'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def portal_agent_url(request):
|
||||||
|
def get_portal_agent_url():
|
||||||
|
portal_agents = []
|
||||||
|
if 'authentic2' in settings.INSTALLED_APPS:
|
||||||
|
portal_agents = [x for x in settings.KNOWN_SERVICES.get('combo', {}).values()
|
||||||
|
if x.get('is-portal-agent')]
|
||||||
|
if len(portal_agents) > 1 and request.user and request.user.is_authenticated() and request.user.ou_id:
|
||||||
|
ou_slug = request.user.ou.slug
|
||||||
|
for portal_agent in portal_agents:
|
||||||
|
variables = portal_agent.get('variables') or {}
|
||||||
|
if variables.get('ou-slug') == ou_slug:
|
||||||
|
return portal_agent['url']
|
||||||
|
variables = getattr(settings, 'TEMPLATE_VARS', {})
|
||||||
|
return variables.get(settings.HOBO_MANAGER_HOMEPAGE_URL_VAR)
|
||||||
|
|
||||||
|
return {'manager_homepage_url': get_portal_agent_url}
|
||||||
|
|
||||||
|
|
||||||
def hobo_json(request):
|
def hobo_json(request):
|
||||||
|
# this context processor gives Hobo itself variables that would be defined
|
||||||
|
# from settings loaders based on hobo.json.
|
||||||
from hobo.multitenant.settings_loaders import TemplateVars
|
from hobo.multitenant.settings_loaders import TemplateVars
|
||||||
from hobo.deploy.utils import get_hobo_json
|
from hobo.deploy.utils import get_hobo_json
|
||||||
# XXX: needs some cache ?
|
context = TemplateVars.get_hobo_json_variables(get_hobo_json())
|
||||||
return TemplateVars.get_hobo_json_variables(get_hobo_json())
|
context['manager_homepage_url'] = context.get(settings.HOBO_MANAGER_HOMEPAGE_URL_VAR)
|
||||||
|
return context
|
||||||
|
|
|
@ -89,6 +89,7 @@ class KnownServices(FileBaseSettingsLoader):
|
||||||
'verif_orig': verif_orig,
|
'verif_orig': verif_orig,
|
||||||
'variables': service.get('variables'),
|
'variables': service.get('variables'),
|
||||||
'secondary': service.get('secondary'),
|
'secondary': service.get('secondary'),
|
||||||
|
'template_name': service.get('template_name'),
|
||||||
}
|
}
|
||||||
|
|
||||||
if service.get('secondary') and (service.get('variables') and
|
if service.get('secondary') and (service.get('variables') and
|
||||||
|
@ -129,7 +130,7 @@ class TemplateVars(FileBaseSettingsLoader):
|
||||||
continue
|
continue
|
||||||
variables['%s_url' % service.get('slug').replace('-','_')] = service.get('base_url')
|
variables['%s_url' % service.get('slug').replace('-','_')] = service.get('base_url')
|
||||||
|
|
||||||
if service.get('service-id') == 'combo':
|
if service.get('service-id') == 'combo' and not service.get('secondary'):
|
||||||
if service.get('template_name') == 'portal-agent':
|
if service.get('template_name') == 'portal-agent':
|
||||||
variables['portal_agent_url'] = service.get('base_url')
|
variables['portal_agent_url'] = service.get('base_url')
|
||||||
variables['portal_agent_title'] = service.get('title')
|
variables['portal_agent_title'] = service.get('title')
|
||||||
|
@ -149,9 +150,6 @@ class TemplateVars(FileBaseSettingsLoader):
|
||||||
variables.update(service.get('variables') or {})
|
variables.update(service.get('variables') or {})
|
||||||
variables['site_title'] = service.get('title')
|
variables['site_title'] = service.get('title')
|
||||||
|
|
||||||
if getattr(settings, 'HOBO_MANAGER_HOMEPAGE_URL_VAR', None):
|
|
||||||
variables['manager_homepage_url'] = \
|
|
||||||
variables.get(settings.HOBO_MANAGER_HOMEPAGE_URL_VAR)
|
|
||||||
if getattr(settings, 'HOBO_MANAGER_HOMEPAGE_TITLE_VAR', None):
|
if getattr(settings, 'HOBO_MANAGER_HOMEPAGE_TITLE_VAR', None):
|
||||||
variables['manager_homepage_title'] = \
|
variables['manager_homepage_title'] = \
|
||||||
variables.get(settings.HOBO_MANAGER_HOMEPAGE_TITLE_VAR)
|
variables.get(settings.HOBO_MANAGER_HOMEPAGE_TITLE_VAR)
|
||||||
|
@ -257,6 +255,8 @@ class SharedThemeSettings(FileBaseSettingsLoader):
|
||||||
continue
|
continue
|
||||||
if service.get('template_name') != 'portal-user':
|
if service.get('template_name') != 'portal-user':
|
||||||
continue
|
continue
|
||||||
|
if service.get('secondary'):
|
||||||
|
continue
|
||||||
tenant_settings.THEME_SKELETON_URL = '%s__skeleton__/' % (
|
tenant_settings.THEME_SKELETON_URL = '%s__skeleton__/' % (
|
||||||
service.get('base_url'))
|
service.get('base_url'))
|
||||||
break
|
break
|
||||||
|
|
|
@ -8,3 +8,5 @@ INSTALLED_APPS += ('kombu.transport.django', 'hobo.contrib.ozwillo',)
|
||||||
ALLOWED_HOSTS.append('localhost')
|
ALLOWED_HOSTS.append('localhost')
|
||||||
|
|
||||||
TEMPLATES[0]['OPTIONS']['debug'] = True
|
TEMPLATES[0]['OPTIONS']['debug'] = True
|
||||||
|
|
||||||
|
HOBO_MANAGER_HOMEPAGE_URL_VAR = 'portal_agent_url'
|
||||||
|
|
|
@ -227,7 +227,7 @@ def test_known_services(tenants, settings):
|
||||||
assert hasattr(settings, 'KNOWN_SERVICES')
|
assert hasattr(settings, 'KNOWN_SERVICES')
|
||||||
assert 'authentic' in settings.KNOWN_SERVICES
|
assert 'authentic' in settings.KNOWN_SERVICES
|
||||||
assert 'other' in settings.KNOWN_SERVICES['authentic']
|
assert 'other' in settings.KNOWN_SERVICES['authentic']
|
||||||
assert (set(['url', 'backoffice-menu-url', 'title', 'orig', 'verif_orig', 'secret', 'variables', 'secondary'])
|
assert (set(['url', 'backoffice-menu-url', 'title', 'orig', 'verif_orig', 'secret', 'template_name', 'variables', 'secondary'])
|
||||||
== set(settings.KNOWN_SERVICES['authentic']['other'].keys()))
|
== set(settings.KNOWN_SERVICES['authentic']['other'].keys()))
|
||||||
assert (settings.KNOWN_SERVICES['authentic']['other']['url']
|
assert (settings.KNOWN_SERVICES['authentic']['other']['url']
|
||||||
== hobo_json['services'][2]['base_url'])
|
== hobo_json['services'][2]['base_url'])
|
||||||
|
|
Loading…
Reference in New Issue