utils: add is_portal_agent function (#58851)

This commit is contained in:
Frédéric Péters 2022-01-18 13:30:45 +01:00
parent 75a5bac20a
commit c7530e8813
2 changed files with 11 additions and 7 deletions

View File

@ -57,6 +57,7 @@ from combo.data.utils import (
import_site_tar,
)
from combo.urls_utils import staff_required
from combo.utils.misc import is_portal_agent
from .forms import (
CellVisibilityForm,
@ -862,13 +863,8 @@ def menu_json(request):
else:
label = _('Content Management')
slug = 'portal'
if getattr(settings, 'KNOWN_SERVICES') and 'combo' in settings.KNOWN_SERVICES:
# switch to custom slug if the site is the portal agent.
for service in settings.KNOWN_SERVICES['combo'].values():
if service.get('is-portal-agent') and not service.get('secret'):
slug = 'portal-agent'
break
# use a custom slug if the site is the portal agent.
slug = 'portal-agent' if is_portal_agent() else 'portal'
json_str = json.dumps(
[

View File

@ -56,3 +56,11 @@ def is_url_from_known_service(url):
if not netloc:
return True
return bool(get_known_service_for_url(url))
def is_portal_agent():
if getattr(settings, 'KNOWN_SERVICES') and 'combo' in settings.KNOWN_SERVICES:
for service in settings.KNOWN_SERVICES['combo'].values():
if service.get('is-portal-agent') and not service.get('secret'):
return True
return False