merge-requests/30/head
Bob Mottram 2024-04-10 10:51:43 +01:00
parent 40713760ed
commit cf351a2fd4
2 changed files with 28 additions and 19 deletions

View File

@ -8,6 +8,8 @@ __status__ = "Production"
__module_group__ = "Core GET" __module_group__ = "Core GET"
from utils import get_instance_url from utils import get_instance_url
from utils import string_ends_with
from utils import string_contains
from httpheaders import redirect_headers from httpheaders import redirect_headers
from fitnessFunctions import fitness_performance from fitnessFunctions import fitness_performance
@ -21,31 +23,20 @@ def redirect_to_login_screen(self, calling_domain: str, path: str,
"""Redirects to the login screen if necessary """Redirects to the login screen if necessary
""" """
divert_to_login_screen = False divert_to_login_screen = False
if '/media/' not in path and \ non_login_paths = ('/media/', '/ontologies/', '/data/', '/sharefiles/',
'/ontologies/' not in path and \ '/statuses/', '/emoji/', '/tags/', '/tagmaps/',
'/data/' not in path and \ '/avatars/', '/favicons/', '/headers/', '/fonts/',
'/sharefiles/' not in path and \ '/icons/')
'/statuses/' not in path and \ if not string_contains(path, non_login_paths):
'/emoji/' not in path and \
'/tags/' not in path and \
'/tagmaps/' not in path and \
'/avatars/' not in path and \
'/favicons/' not in path and \
'/headers/' not in path and \
'/fonts/' not in path and \
'/icons/' not in path:
divert_to_login_screen = True divert_to_login_screen = True
if path.startswith('/users/'): if path.startswith('/users/'):
nick_str = path.split('/users/')[1] nick_str = path.split('/users/')[1]
if '/' not in nick_str and '?' not in nick_str: if '/' not in nick_str and '?' not in nick_str:
divert_to_login_screen = False divert_to_login_screen = False
else: else:
if path.endswith('/following') or \ possible_endings = ('/following', '/followers',
path.endswith('/followers') or \ '/skills', '/roles', '/wanted', '/shares')
path.endswith('/skills') or \ if string_ends_with(path, possible_endings):
path.endswith('/roles') or \
path.endswith('/wanted') or \
path.endswith('/shares'):
divert_to_login_screen = False divert_to_login_screen = False
if divert_to_login_screen and not authorized: if divert_to_login_screen and not authorized:

View File

@ -5266,3 +5266,21 @@ def get_post_attachments(post_json_object: {}) -> []:
if isinstance(post_obj['attachment'], dict): if isinstance(post_obj['attachment'], dict):
return [post_obj['attachment']] return [post_obj['attachment']]
return [] return []
def string_ends_with(text: str, possible_endings: []) -> bool:
""" Does the given text end with at least one of the endings
"""
for ending in possible_endings:
if text.endswith(ending):
return True
return False
def string_contains(text: str, possible_substrings: []) -> bool:
""" Does the given text contain at least one of the possible substrings
"""
for substring in possible_substrings:
if substring in text:
return True
return False