from urllib.parse import urlsplit
from django import template
from apps.operations.context import shell

register = template.Library()


@register.simple_tag
def report_navigation(request, sections):
    groups = shell(request)["workspace"]["groups"]
    allowed = {link["url"] for group in groups if group["label"] == "Reports" for link in group["links"]}
    return [(label,url) for label,url in sections if urlsplit(url).path in allowed]
