diff --git a/debian/debian_config_common.py b/debian/debian_config_common.py index e9cc69d..6350b41 100644 --- a/debian/debian_config_common.py +++ b/debian/debian_config_common.py @@ -205,6 +205,7 @@ if 'TEMPLATE_DEBUG' in globals(): TEMPLATE_CONTEXT_PROCESSORS = ( 'hobo.context_processors.template_vars', 'hobo.context_processors.theme_base', + 'hobo.context_processors.portal_agent_url', ) + TEMPLATE_CONTEXT_PROCESSORS else: assert len(TEMPLATES) @@ -226,6 +227,7 @@ else: TEMPLATES[0]['OPTIONS']['context_processors'] = [ 'hobo.context_processors.template_vars', 'hobo.context_processors.theme_base', + 'hobo.context_processors.portal_agent_url', ] + TEMPLATES[0]['OPTIONS']['context_processors'] # needed by hobo.context_processors.theme_base: diff --git a/hobo/agent/hobo/management/commands/hobo_deploy.py b/hobo/agent/hobo/management/commands/hobo_deploy.py index ceddae2..1b39bb0 100644 --- a/hobo/agent/hobo/management/commands/hobo_deploy.py +++ b/hobo/agent/hobo/management/commands/hobo_deploy.py @@ -61,6 +61,7 @@ class Command(hobo_deploy.Command): 'secret_key': service_dict.get('secret_key')}) service.title = service_dict['title'] service.secret_key = service_dict.get('secret_key') + service.template_name = service_dict.get('template_name') or '' service.slug = service_slug service.use_as_idp_for_self = True service.last_operational_check_timestamp = now() diff --git a/hobo/context_processors.py b/hobo/context_processors.py index 0fdc27b..1e2ed5d 100644 --- a/hobo/context_processors.py +++ b/hobo/context_processors.py @@ -147,8 +147,30 @@ def theme_base(request): '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): + # 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.deploy.utils import get_hobo_json - # XXX: needs some cache ? - return TemplateVars.get_hobo_json_variables(get_hobo_json()) + context = TemplateVars.get_hobo_json_variables(get_hobo_json()) + context['manager_homepage_url'] = context.get(settings.HOBO_MANAGER_HOMEPAGE_URL_VAR) + return context diff --git a/hobo/multitenant/settings_loaders.py b/hobo/multitenant/settings_loaders.py index fc21960..ffd9d6d 100644 --- a/hobo/multitenant/settings_loaders.py +++ b/hobo/multitenant/settings_loaders.py @@ -89,6 +89,7 @@ class KnownServices(FileBaseSettingsLoader): 'verif_orig': verif_orig, 'variables': service.get('variables'), 'secondary': service.get('secondary'), + 'template_name': service.get('template_name'), } if service.get('secondary') and (service.get('variables') and @@ -129,7 +130,7 @@ class TemplateVars(FileBaseSettingsLoader): continue 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': variables['portal_agent_url'] = service.get('base_url') variables['portal_agent_title'] = service.get('title') @@ -149,9 +150,6 @@ class TemplateVars(FileBaseSettingsLoader): variables.update(service.get('variables') or {}) 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): variables['manager_homepage_title'] = \ variables.get(settings.HOBO_MANAGER_HOMEPAGE_TITLE_VAR) @@ -257,6 +255,8 @@ class SharedThemeSettings(FileBaseSettingsLoader): continue if service.get('template_name') != 'portal-user': continue + if service.get('secondary'): + continue tenant_settings.THEME_SKELETON_URL = '%s__skeleton__/' % ( service.get('base_url')) break diff --git a/tests/settings.py b/tests/settings.py index e0cfd36..b57968c 100644 --- a/tests/settings.py +++ b/tests/settings.py @@ -8,3 +8,5 @@ INSTALLED_APPS += ('kombu.transport.django', 'hobo.contrib.ozwillo',) ALLOWED_HOSTS.append('localhost') TEMPLATES[0]['OPTIONS']['debug'] = True + +HOBO_MANAGER_HOMEPAGE_URL_VAR = 'portal_agent_url' diff --git a/tests_multitenant/test_settings.py b/tests_multitenant/test_settings.py index f982661..85738de 100644 --- a/tests_multitenant/test_settings.py +++ b/tests_multitenant/test_settings.py @@ -227,7 +227,7 @@ def test_known_services(tenants, settings): assert hasattr(settings, 'KNOWN_SERVICES') assert 'authentic' in settings.KNOWN_SERVICES 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())) assert (settings.KNOWN_SERVICES['authentic']['other']['url'] == hobo_json['services'][2]['base_url'])