hobo_deploy: allow several templates for user/agent combo portals (#33876)
This commit is contained in:
parent
4839bffede
commit
090fc5b8de
|
@ -22,7 +22,8 @@ class Command(import_template.Command):
|
|||
try:
|
||||
return super(Command, self).handle(*args, **kwargs)
|
||||
except import_template.UnknownTemplateError:
|
||||
# ignore errors if template name is portal-user or portal-agent as
|
||||
# ignore errors if template name contains portal-user or portal-agent as
|
||||
# those names do not actually require an existing file to work.
|
||||
if kwargs.get('template_name') not in ('portal-user', 'portal-agent'):
|
||||
if not any(name in kwargs.get('template_name')
|
||||
for name in ('portal-user', 'portal-agent')):
|
||||
raise
|
||||
|
|
|
@ -89,7 +89,7 @@ def put_tracking_js(tracking_js):
|
|||
def get_tenant_name_and_public_urls():
|
||||
"""get an alias for our matomo's id and urls to monitor"""
|
||||
tenant_name = None
|
||||
services = [x for x in Combo.objects.all() if x.template_name == 'portal-user']
|
||||
services = [x for x in Combo.objects.all() if 'portal-user' in x.template_name]
|
||||
if services != [] and services[0] != '':
|
||||
tenant_name = urlparse.urlparse(services[0].base_url).netloc
|
||||
services += [x for x in Wcs.objects.all()]
|
||||
|
|
|
@ -99,7 +99,8 @@ class KnownServices(FileBaseSettingsLoader):
|
|||
service.get('title'),
|
||||
service.get('variables').get('ou-label'))
|
||||
|
||||
if service.get('service-id') == 'combo' and service.get('template_name') == 'portal-agent':
|
||||
if (service.get('service-id') == 'combo' and
|
||||
'portal-agent' in service.get('template_name', '')):
|
||||
service_data['is-portal-agent'] = True
|
||||
|
||||
# compute a symmetric shared secret using XOR
|
||||
|
@ -132,10 +133,10 @@ class TemplateVars(FileBaseSettingsLoader):
|
|||
variables['%s_url' % service.get('slug').replace('-','_')] = service.get('base_url')
|
||||
|
||||
if service.get('service-id') == 'combo' and not service.get('secondary'):
|
||||
if service.get('template_name') == 'portal-agent':
|
||||
if 'portal-agent' in service.get('template_name', ''):
|
||||
variables['portal_agent_url'] = service.get('base_url')
|
||||
variables['portal_agent_title'] = service.get('title')
|
||||
if service.get('template_name') == 'portal-user':
|
||||
if 'portal-user' in service.get('template_name', ''):
|
||||
variables['portal_user_url'] = service.get('base_url')
|
||||
variables['portal_user_title'] = service.get('title')
|
||||
|
||||
|
@ -151,7 +152,7 @@ class TemplateVars(FileBaseSettingsLoader):
|
|||
variables.update(service.get('variables') or {})
|
||||
variables['site_title'] = service.get('title')
|
||||
|
||||
if service.get('template_name') == 'portal-agent':
|
||||
if 'portal-agent' in service.get('template_name', ''):
|
||||
variables['is_portal_agent'] = True
|
||||
|
||||
if getattr(settings, 'HOBO_MANAGER_HOMEPAGE_TITLE_VAR', None):
|
||||
|
@ -258,7 +259,7 @@ class SharedThemeSettings(FileBaseSettingsLoader):
|
|||
for service in hobo_json.get('services', []):
|
||||
if service.get('service-id') != 'combo':
|
||||
continue
|
||||
if service.get('template_name') != 'portal-user':
|
||||
if 'portal-user' not in service.get('template_name', ''):
|
||||
continue
|
||||
if service.get('secondary'):
|
||||
continue
|
||||
|
@ -337,7 +338,7 @@ class Authentic(FileBaseSettingsLoader):
|
|||
for service in hobo_json.get('services', []):
|
||||
if service.get('service-id') != 'combo':
|
||||
continue
|
||||
if service.get('template_name') != 'portal-user':
|
||||
if 'portal-user' not in service.get('template_name', ''):
|
||||
continue
|
||||
if service.get('secondary'):
|
||||
continue
|
||||
|
|
|
@ -2,11 +2,11 @@ import pytest
|
|||
import mock
|
||||
|
||||
from django.conf import settings
|
||||
from django.core.management import load_command_class
|
||||
from django.core.management.base import CommandError
|
||||
from django.test import override_settings
|
||||
|
||||
from hobo.agent.common.management.commands.import_template import Command, UnknownTemplateError
|
||||
from django.core.management import load_command_class
|
||||
|
||||
|
||||
@mock.patch('hobo.agent.common.management.commands.import_template.os.path.exists')
|
||||
|
@ -79,7 +79,7 @@ def test_import_template_on_combo_agent(mocked_super):
|
|||
|
||||
# do nothing on internal templates
|
||||
mocked_super.side_effect = UnknownTemplateError
|
||||
for template in 'portal-user', 'portal-agent':
|
||||
for template in 'portal-user', 'portal-agent', 'x-portal-user-x', 'x-portal-agent-x':
|
||||
command.handle(template_name=template)
|
||||
|
||||
# template no found
|
||||
|
|
|
@ -7,7 +7,7 @@ from requests import Response
|
|||
|
||||
from django.test import override_settings
|
||||
|
||||
from hobo.environment.models import Variable, Wcs, Combo, Fargo
|
||||
from hobo.environment.models import Variable, Combo, Hobo, Fargo, Wcs
|
||||
from hobo.matomo.utils import \
|
||||
get_variable, get_variable_value, get_tracking_js, put_tracking_js, \
|
||||
get_tenant_name_and_public_urls, MatomoError, MatomoException, MatomoWS, \
|
||||
|
@ -207,12 +207,18 @@ def test_get_variable_value():
|
|||
|
||||
def test_get_tenant_name_and_public_urls():
|
||||
Combo.objects.create(base_url='https://combo.dev.publik.love',
|
||||
template_name='portal-user')
|
||||
template_name='...portal-user...')
|
||||
Combo.objects.create(base_url='https://agent-combo.dev.publik.love',
|
||||
template_name='...portal-agent...')
|
||||
Combo.objects.create(base_url='https://no-template-combo.dev.publik.love')
|
||||
Wcs.objects.create(base_url='https://wcs.dev.publik.love')
|
||||
Fargo.objects.create(base_url='https://fargo.dev.publik.love')
|
||||
Hobo.objects.create(base_url='https://hobo.dev.publik.love')
|
||||
tenant_name, site_urls = get_tenant_name_and_public_urls()
|
||||
assert tenant_name == 'combo.dev.publik.love'
|
||||
assert site_urls[2] == 'https://fargo.dev.publik.love/'
|
||||
assert site_urls == ['https://combo.dev.publik.love/',
|
||||
'https://wcs.dev.publik.love/',
|
||||
'https://fargo.dev.publik.love/']
|
||||
|
||||
def test_matomo_constructor():
|
||||
"""build the matomo webservice object"""
|
||||
|
@ -652,7 +658,7 @@ def test_auto_configure_matomo(mocked_post):
|
|||
logme_url_var = get_variable('matomo_logme_url', '')
|
||||
|
||||
Combo.objects.create(base_url='https://combo.dev.publik.love',
|
||||
template_name='portal-user')
|
||||
template_name='...portal-user...')
|
||||
Wcs.objects.create(base_url='https://wcs.dev.publik.love')
|
||||
Fargo.objects.create(base_url='https://fargo.dev.publik.love')
|
||||
|
||||
|
@ -685,7 +691,7 @@ def test_auto_configure_matomo_error(mocked_post):
|
|||
tracking_js_var = get_variable('visits_tracking_js', 'js_code')
|
||||
|
||||
Combo.objects.create(base_url='https://combo.dev.publik.love',
|
||||
template_name='portal-user')
|
||||
template_name='...portal-user...')
|
||||
Wcs.objects.create(base_url='https://wcs.dev.publik.love')
|
||||
Fargo.objects.create(base_url='https://fargo.dev.publik.love')
|
||||
|
||||
|
|
|
@ -63,7 +63,20 @@ def tenants(transactional_db, request, settings):
|
|||
'title': 'Other',
|
||||
'secret_key': 'abcde',
|
||||
'service-id': 'authentic',
|
||||
'base_url': 'http://other.example.net'},
|
||||
'base_url': 'http://other.example.net'
|
||||
},
|
||||
{'slug': 'another',
|
||||
'title': 'Agent portal',
|
||||
'service-id': 'combo',
|
||||
'template_name': '...portal-agent...',
|
||||
'base_url': 'http://portal-agent.example.net'
|
||||
},
|
||||
{'slug': 'another2',
|
||||
'title': 'User portal',
|
||||
'service-id': 'combo',
|
||||
'template_name': '...portal-user...',
|
||||
'base_url': 'http://portal-user.example.net'
|
||||
}
|
||||
]}, fd)
|
||||
t = Tenant(domain_url=name,
|
||||
schema_name=name.replace('-', '_').replace('.', '_'))
|
||||
|
|
|
@ -87,6 +87,8 @@ def test_tenant_template_vars(tenants, settings, client):
|
|||
assert django.conf.settings.TEMPLATE_VARS['other_url'] == 'http://other.example.net'
|
||||
assert django.conf.settings.TEMPLATE_VARS['site_title'] == 'Test'
|
||||
assert django.conf.settings.TEMPLATE_VARS['other_variable'] == 'bar'
|
||||
assert django.conf.settings.TEMPLATE_VARS['portal_agent_url'] == 'http://portal-agent.example.net'
|
||||
assert django.conf.settings.TEMPLATE_VARS['portal_user_url'] == 'http://portal-user.example.net'
|
||||
|
||||
# check it's no longer defined after going back to the public schema
|
||||
with pytest.raises(AttributeError):
|
||||
|
|
Loading…
Reference in New Issue