mirror of
https://gitlab.science.ru.nl/technicie/MarietjeDjango.git
synced 2025-12-09 21:02:24 +01:00
Only show relevant stuff to internal clients
This commit is contained in:
@ -1,6 +1,37 @@
|
||||
import ipaddress
|
||||
|
||||
from django.conf import settings
|
||||
|
||||
def _client_internal(request):
|
||||
"""
|
||||
If the client is internal, we will allow to show more info
|
||||
|
||||
A client is considered internal if:
|
||||
- Logged in
|
||||
- Accesses from a trusted IP range
|
||||
"""
|
||||
if request.user.is_authenticated:
|
||||
return True
|
||||
|
||||
remote_ip = ipaddress.ip_address(request.META['REMOTE_ADDR'])
|
||||
|
||||
|
||||
for ip_range in getattr(settings, 'TRUSTED_IP_RANGES', []):
|
||||
net = ipaddress.ip_network(ip_range)
|
||||
if remote_ip in net:
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
|
||||
def global_settings(request):
|
||||
return {'issues_url': settings.ISSUES_URL, 'contact_email': settings.CONTACT_EMAIL,
|
||||
'merge_requests_url': settings.MERGE_REQUESTS_URL}
|
||||
internal = _client_internal(request)
|
||||
contact_email = settings.CONTACT_EMAIL
|
||||
if not internal:
|
||||
contact_email = contact_email.replace('@', ' [at] ')
|
||||
return {
|
||||
'client_internal': internal,
|
||||
'issues_url': settings.ISSUES_URL,
|
||||
'contact_email': contact_email,
|
||||
'merge_requests_url': settings.MERGE_REQUESTS_URL
|
||||
}
|
||||
|
||||
@ -138,3 +138,7 @@ STATS_REQUEST_IGNORE_USER_IDS = []
|
||||
|
||||
ISSUES_URL = 'https://gitlab.science.ru.nl/Marietje/MarietjeDjango/issues'
|
||||
MERGE_REQUESTS_URL = 'https://gitlab.science.ru.nl/Marietje/MarietjeDjango/merge_requests'
|
||||
TRUSTED_IP_RANGES = [
|
||||
'131.174.0.0/16' # RU wired
|
||||
'145.116.136.0/22' # eduroam
|
||||
]
|
||||
|
||||
@ -69,10 +69,12 @@
|
||||
{% endif %}
|
||||
{% block content %}{% endblock content %}
|
||||
</div>
|
||||
{% if client_internal %}
|
||||
<footer>
|
||||
<a href="{% url 'privacy' %}">Privacy (Dutch)</a> |
|
||||
<a href="{{ issues_url }}" target="_blank">Issues</a> |
|
||||
Email: <a href="mailto:{{ contact_email }}">{{ contact_email }}</a>.<br>
|
||||
</footer>
|
||||
{% endif %}
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@ -27,7 +27,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="text-center">
|
||||
Don't have an account? Send an email to {{ contact_email }}<br>
|
||||
Don't have an account? Send an email to <{{ contact_email }}><br>
|
||||
<a href="{% url 'forgotpassword' %}" >Forgot your password? Reset password</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user