0004-hobo_deploy-allow-several-templates-for-user-agent-c.patch
hobo/matomo/utils.py | ||
---|---|---|
89 | 89 |
def get_tenant_name_and_public_urls(): |
90 | 90 |
"""get an alias for our matomo's id and urls to monitor""" |
91 | 91 |
tenant_name = None |
92 |
services = [x for x in Combo.objects.all() if x.template_name == 'portal-user']
|
|
92 |
services = [x for x in Combo.objects.all() if 'portal-user' in x.template_name]
|
|
93 | 93 |
if services != [] and services[0] != '': |
94 | 94 |
tenant_name = urlparse.urlparse(services[0].base_url).netloc |
95 | 95 |
services += [x for x in Wcs.objects.all()] |
hobo/multitenant/settings_loaders.py | ||
---|---|---|
99 | 99 |
service.get('title'), |
100 | 100 |
service.get('variables').get('ou-label')) |
101 | 101 | |
102 |
if service.get('service-id') == 'combo' and service.get('template_name') == 'portal-agent': |
|
102 |
if (service.get('service-id') == 'combo' and |
|
103 |
'portal-agent' in service.get('template_name', '')): |
|
103 | 104 |
service_data['is-portal-agent'] = True |
104 | 105 | |
105 | 106 |
# compute a symmetric shared secret using XOR |
... | ... | |
132 | 133 |
variables['%s_url' % service.get('slug').replace('-','_')] = service.get('base_url') |
133 | 134 | |
134 | 135 |
if service.get('service-id') == 'combo' and not service.get('secondary'): |
135 |
if service.get('template_name') == 'portal-agent':
|
|
136 |
if 'portal-agent' in service.get('template_name', ''):
|
|
136 | 137 |
variables['portal_agent_url'] = service.get('base_url') |
137 | 138 |
variables['portal_agent_title'] = service.get('title') |
138 |
if service.get('template_name') == 'portal-user':
|
|
139 |
if 'portal-user' in service.get('template_name', ''):
|
|
139 | 140 |
variables['portal_user_url'] = service.get('base_url') |
140 | 141 |
variables['portal_user_title'] = service.get('title') |
141 | 142 | |
... | ... | |
151 | 152 |
variables.update(service.get('variables') or {}) |
152 | 153 |
variables['site_title'] = service.get('title') |
153 | 154 | |
154 |
if service.get('template_name') == 'portal-agent':
|
|
155 |
if 'portal-agent' in service.get('template_name', ''):
|
|
155 | 156 |
variables['is_portal_agent'] = True |
156 | 157 | |
157 | 158 |
if getattr(settings, 'HOBO_MANAGER_HOMEPAGE_TITLE_VAR', None): |
... | ... | |
257 | 258 |
for service in hobo_json.get('services', []): |
258 | 259 |
if service.get('service-id') != 'combo': |
259 | 260 |
continue |
260 |
if service.get('template_name') != 'portal-user':
|
|
261 |
if 'portal-user' not in service.get('template_name', ''):
|
|
261 | 262 |
continue |
262 | 263 |
if service.get('secondary'): |
263 | 264 |
continue |
... | ... | |
336 | 337 |
for service in hobo_json.get('services', []): |
337 | 338 |
if service.get('service-id') != 'combo': |
338 | 339 |
continue |
339 |
if service.get('template_name') != 'portal-user':
|
|
340 |
if 'portal-user' not in service.get('template_name', ''):
|
|
340 | 341 |
continue |
341 | 342 |
tenant_settings.A2_HOMEPAGE_URL = service.get('base_url') |
342 | 343 |
tests/test_matomo_utils.py | ||
---|---|---|
7 | 7 | |
8 | 8 |
from django.test import override_settings |
9 | 9 | |
10 |
from hobo.environment.models import Variable, Wcs, Combo, Fargo
|
|
10 |
from hobo.environment.models import Variable, Combo, Hobo, Fargo, Wcs
|
|
11 | 11 |
from hobo.matomo.utils import \ |
12 | 12 |
get_variable, get_variable_value, get_tracking_js, put_tracking_js, \ |
13 | 13 |
get_tenant_name_and_public_urls, MatomoError, MatomoException, MatomoWS, \ |
... | ... | |
208 | 208 |
def test_get_tenant_name_and_public_urls(): |
209 | 209 |
Combo.objects.create(base_url='https://combo.dev.publik.love', |
210 | 210 |
template_name='portal-user') |
211 |
Combo.objects.create(base_url='https://agent-combo.dev.publik.love', |
|
212 |
template_name='portal-agent') |
|
213 |
Combo.objects.create(base_url='https://another-combo.dev.publik.love', |
|
214 |
template_name='another-portal-user') |
|
215 |
Combo.objects.create(base_url='https://no-template-combo.dev.publik.love') |
|
211 | 216 |
Wcs.objects.create(base_url='https://wcs.dev.publik.love') |
212 | 217 |
Fargo.objects.create(base_url='https://fargo.dev.publik.love') |
218 |
Hobo.objects.create(base_url='https://hobo.dev.publik.love') |
|
213 | 219 |
tenant_name, site_urls = get_tenant_name_and_public_urls() |
214 | 220 |
assert tenant_name == 'combo.dev.publik.love' |
215 |
assert site_urls[2] == 'https://fargo.dev.publik.love/' |
|
221 |
assert site_urls == ['https://combo.dev.publik.love/', |
|
222 |
'https://another-combo.dev.publik.love/', |
|
223 |
'https://wcs.dev.publik.love/', |
|
224 |
'https://fargo.dev.publik.love/'] |
|
216 | 225 | |
217 | 226 |
def test_matomo_constructor(): |
218 | 227 |
"""build the matomo webservice object""" |
219 |
- |