Better support for alternative users paths

merge-requests/30/head
Bob Mottram 2021-07-28 13:49:02 +01:00
parent 4e30a17d83
commit 3b94048e28
3 changed files with 10 additions and 19 deletions

View File

@ -28,7 +28,6 @@ from utils import saveJson
from utils import isAccountDir from utils import isAccountDir
from utils import getUserPaths from utils import getUserPaths
from utils import acctDir from utils import acctDir
from utils import getUsersPaths
from acceptreject import createAccept from acceptreject import createAccept
from acceptreject import createReject from acceptreject import createReject
from webfinger import webfingerHandle from webfinger import webfingerHandle
@ -109,12 +108,11 @@ def _removeFromFollowBase(baseDir: str,
acceptDenyDomain = acceptOrDenyHandle.split('@')[1] acceptDenyDomain = acceptOrDenyHandle.split('@')[1]
# for each possible users path construct an actor and # for each possible users path construct an actor and
# check if it exists in teh file # check if it exists in teh file
usersPaths = getUsersPaths() usersPaths = getUserPaths()
actorFound = False actorFound = False
for usersName in usersPaths: for usersName in usersPaths:
acceptDenyActor = \ acceptDenyActor = \
'://' + acceptDenyDomain + '/' + \ '://' + acceptDenyDomain + usersName + acceptDenyNickname
usersName + '/' + acceptDenyNickname
if acceptDenyActor in open(approveFollowsFilename).read(): if acceptDenyActor in open(approveFollowsFilename).read():
actorFound = True actorFound = True
break break

View File

@ -51,9 +51,8 @@ from utils import getProtocolPrefixes
from utils import hasUsersPath from utils import hasUsersPath
from utils import getImageExtensions from utils import getImageExtensions
from utils import isImageFile from utils import isImageFile
from utils import getUserPaths
from utils import acctDir from utils import acctDir
from utils import getUsersPaths from utils import getUserPaths
from session import createSession from session import createSession
from session import getJson from session import getJson
from webfinger import webfingerHandle from webfinger import webfingerHandle
@ -1194,10 +1193,10 @@ def _detectUsersPath(url: str) -> str:
""" """
if '/' not in url: if '/' not in url:
return '/users/' return '/users/'
usersPaths = getUsersPaths() usersPaths = getUserPaths()
for possibleUsersPath in usersPaths: for possibleUsersPath in usersPaths:
if '/' + possibleUsersPath + '/' in url: if possibleUsersPath in url:
return '/' + possibleUsersPath + '/' return possibleUsersPath
return '/users/' return '/users/'

View File

@ -28,13 +28,6 @@ invalidCharacters = (
) )
def getUsersPaths() -> []:
"""Returns the possible paths for users accounts
e.g. /users/nickname, /channel/nickname
"""
return ('users', 'profile', 'channel', 'accounts', 'u', 'c')
def getActorLanguagesList(actorJson: {}) -> []: def getActorLanguagesList(actorJson: {}) -> []:
"""Returns a list containing languages used by the given actor """Returns a list containing languages used by the given actor
""" """
@ -166,9 +159,9 @@ def getLockedAccount(actorJson: {}) -> bool:
def hasUsersPath(pathStr: str) -> bool: def hasUsersPath(pathStr: str) -> bool:
"""Whether there is a /users/ path (or equivalent) in the given string """Whether there is a /users/ path (or equivalent) in the given string
""" """
usersList = getUsersPaths() usersList = getUserPaths()
for usersStr in usersList: for usersStr in usersList:
if '/' + usersStr + '/' in pathStr: if usersStr in pathStr:
return True return True
if '://' in pathStr: if '://' in pathStr:
domain = pathStr.split('://')[1] domain = pathStr.split('://')[1]
@ -981,8 +974,9 @@ def getNicknameFromActor(actor: str) -> str:
def getUserPaths() -> []: def getUserPaths() -> []:
"""Returns possible user paths """Returns possible user paths
e.g. /users/nickname, /channel/nickname
""" """
return ('/users/', '/profile/', '/accounts/', '/channel/', '/u/') return ('/users/', '/profile/', '/accounts/', '/channel/', '/u/', '/c/')
def getDomainFromActor(actor: str) -> (str, int): def getDomainFromActor(actor: str) -> (str, int):