mirror of
https://gitlab.science.ru.nl/technicie/MarietjeDjango.git
synced 2025-12-11 12:32:21 +01:00
38 lines
964 B
Python
38 lines
964 B
Python
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):
|
|
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
|
|
}
|