main
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"
from utils import get_instance_url
from utils import string_ends_with
from utils import string_contains
from httpheaders import redirect_headers
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
"""
divert_to_login_screen = False
if '/media/' not in path and \
'/ontologies/' not in path and \
'/data/' not in path and \
'/sharefiles/' not in path and \
'/statuses/' not in path and \
'/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:
non_login_paths = ('/media/', '/ontologies/', '/data/', '/sharefiles/',
'/statuses/', '/emoji/', '/tags/', '/tagmaps/',
'/avatars/', '/favicons/', '/headers/', '/fonts/',
'/icons/')
if not string_contains(path, non_login_paths):
divert_to_login_screen = True
if path.startswith('/users/'):
nick_str = path.split('/users/')[1]
if '/' not in nick_str and '?' not in nick_str:
divert_to_login_screen = False
else:
if path.endswith('/following') or \
path.endswith('/followers') or \
path.endswith('/skills') or \
path.endswith('/roles') or \
path.endswith('/wanted') or \
path.endswith('/shares'):
possible_endings = ('/following', '/followers',
'/skills', '/roles', '/wanted', '/shares')
if string_ends_with(path, possible_endings):
divert_to_login_screen = False
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):
return [post_obj['attachment']]
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