Group prefixes when follower approval is enabled

merge-requests/30/head
Bob Mottram 2021-07-31 13:24:46 +01:00
parent d48aff4807
commit bd0e462544
2 changed files with 29 additions and 4 deletions

View File

@ -546,7 +546,8 @@ def _storeFollowRequest(baseDir: str,
nicknameToFollow: str, domainToFollow: str, port: int, nicknameToFollow: str, domainToFollow: str, port: int,
nickname: str, domain: str, fromPort: int, nickname: str, domain: str, fromPort: int,
followJson: {}, followJson: {},
debug: bool, personUrl: str) -> bool: debug: bool, personUrl: str,
groupAccount: bool) -> bool:
"""Stores the follow request for later use """Stores the follow request for later use
""" """
accountsDir = baseDir + '/accounts/' + \ accountsDir = baseDir + '/accounts/' + \
@ -554,10 +555,12 @@ def _storeFollowRequest(baseDir: str,
if not os.path.isdir(accountsDir): if not os.path.isdir(accountsDir):
return False return False
approveHandle = nickname + '@' + domain
domainFull = getFullDomain(domain, fromPort) domainFull = getFullDomain(domain, fromPort)
approveHandle = getFullDomain(nickname + '@' + domain, fromPort) approveHandle = getFullDomain(nickname + '@' + domain, fromPort)
if groupAccount:
approveHandle = '!' + approveHandle
followersFilename = accountsDir + '/followers.txt' followersFilename = accountsDir + '/followers.txt'
if os.path.isfile(followersFilename): if os.path.isfile(followersFilename):
alreadyFollowing = False alreadyFollowing = False
@ -600,6 +603,8 @@ def _storeFollowRequest(baseDir: str,
approveHandleStored = approveHandle approveHandleStored = approveHandle
if '/users/' not in personUrl: if '/users/' not in personUrl:
approveHandleStored = personUrl approveHandleStored = personUrl
if groupAccount:
approveHandle = '!' + approveHandle
if os.path.isfile(approveFollowsFilename): if os.path.isfile(approveFollowsFilename):
if approveHandle not in open(approveFollowsFilename).read(): if approveHandle not in open(approveFollowsFilename).read():
@ -733,11 +738,26 @@ def receiveFollowRequest(session, baseDir: str, httpPrefix: str,
print('Too many follow requests') print('Too many follow requests')
return False return False
# Get the actor for the follower and add it to the cache.
# Getting their public key has the same result
if debug:
print('Obtaining the following actor: ' + messageJson['actor'])
if not getPersonPubKey(baseDir, session, messageJson['actor'],
personCache, debug, projectVersion,
httpPrefix, domainToFollow, onionDomain):
if debug:
print('Unable to obtain following actor: ' +
messageJson['actor'])
groupAccount = \
hasGroupType(baseDir, messageJson['object'], personCache)
print('Storing follow request for approval') print('Storing follow request for approval')
return _storeFollowRequest(baseDir, return _storeFollowRequest(baseDir,
nicknameToFollow, domainToFollow, port, nicknameToFollow, domainToFollow, port,
nickname, domain, fromPort, nickname, domain, fromPort,
messageJson, debug, messageJson['actor']) messageJson, debug, messageJson['actor'],
groupAccount)
else: else:
print('Follow request does not require approval') print('Follow request does not require approval')
# update the followers # update the followers

View File

@ -109,7 +109,10 @@ def manualApproveFollowRequest(session, baseDir: str,
if approveHandle in approveFollowsStr: if approveHandle in approveFollowsStr:
exists = True exists = True
elif '@' in approveHandle: elif '@' in approveHandle:
reqNick = approveHandle.split('@')[0] groupAccount = False
if approveHandle.startswith('!'):
groupAccount = True
reqNick = approveHandle.split('@')[0].replace('!', '')
reqDomain = approveHandle.split('@')[1].strip() reqDomain = approveHandle.split('@')[1].strip()
reqPrefix = httpPrefix + '://' + reqDomain reqPrefix = httpPrefix + '://' + reqDomain
paths = getUserPaths() paths = getUserPaths()
@ -117,6 +120,8 @@ def manualApproveFollowRequest(session, baseDir: str,
if reqPrefix + userPath + reqNick in approveFollowsStr: if reqPrefix + userPath + reqNick in approveFollowsStr:
exists = True exists = True
approveHandleFull = reqPrefix + userPath + reqNick approveHandleFull = reqPrefix + userPath + reqNick
if groupAccount:
approveHandleFull = '!' + approveHandleFull
break break
if not exists: if not exists:
print('Manual follow accept: ' + approveHandleFull + print('Manual follow accept: ' + approveHandleFull +