diff --git a/src/eke.knowledge/src/eke/knowledge/protocols.py b/src/eke.knowledge/src/eke/knowledge/protocols.py index 93005108..05d04b13 100644 --- a/src/eke.knowledge/src/eke/knowledge/protocols.py +++ b/src/eke.knowledge/src/eke/knowledge/protocols.py @@ -17,6 +17,7 @@ from django.db.models.functions import Lower from django.http import HttpRequest from django.template.loader import render_to_string +from django.urls import reverse from django.utils.text import slugify from django_plotly_dash import DjangoDash from modelcluster.fields import ParentalManyToManyField @@ -147,6 +148,12 @@ class RDFMeta: str(rdflib.DCTERMS.description): _ComplexDescriptionRDFAttribute('description', scalar=True), esu('protocolType'): RDFAttribute('kind', scalar=True) } + def _authentication(self, request: HttpRequest) -> dict: + '''Given a request, determine if the user is authenticated and what the login link would be if not.''' + params = {'authenticated': request.user.is_authenticated} + if not params['authenticated']: + params['login'] = reverse('wagtailcore_login') + '?next=' + request.path + return params def get_context(self, request: HttpRequest, *args, **kwargs) -> dict: '''Get the context for the page template.''' context = super().get_context(request, args, kwargs) @@ -158,6 +165,8 @@ def get_context(self, request: HttpRequest, *args, **kwargs) -> dict: total_collections = dcs.count() dcs = filter_by_user(dcs, request.user) invisible_collections = total_collections - dcs.count() + if invisible_collections: + context.update(self._authentication(request)) context['data_collections'] = dcs context['invisible_collections'] = invisible_collections from eke.biomarkers.biomarker import Biomarker diff --git a/src/eke.knowledge/src/eke/knowledge/templates/eke.knowledge/protocol.html b/src/eke.knowledge/src/eke/knowledge/templates/eke.knowledge/protocol.html index 36ceeda7..29475acb 100644 --- a/src/eke.knowledge/src/eke/knowledge/templates/eke.knowledge/protocol.html +++ b/src/eke.knowledge/src/eke/knowledge/templates/eke.knowledge/protocol.html @@ -80,10 +80,22 @@

Data Collections

{% endfor %} {% endif %} - {% if invisible_collections == 1 %} -

There is one collection of data that has not yet been made public.

- {% elif invisible_collections > 1 %} -

There are {{invisible_collections}} collections of data that have not yet been made public.

+ {% if invisible_collections %} +

+ {% if invisible_collections == 1 %} + There is one collection of data that has not yet been made public. + {% elif invisible_collections > 1 %} + There are {{invisible_collections}} collections of data that have not yet been made public. + {% endif %} + {% if authenticated %} + You are currently logged in, but not with an account that can view the names of the + non-public data collections. + Logging in with a different account may give you access. + {% else %} + Logging in may you give you access to the names of the + non-public data collections. + {% endif %} +

{% endif %} {% else %}