forked from indymedia/epicyon
Remember manual follow approvals
parent
d1493585bc
commit
a5dffaa5f7
26
follow.py
26
follow.py
|
@ -28,6 +28,19 @@ from auth import createBasicAuthHeader
|
||||||
from auth import createPassword
|
from auth import createPassword
|
||||||
from session import postJson
|
from session import postJson
|
||||||
|
|
||||||
|
def preApprovedFollower(baseDir: str, \
|
||||||
|
nickname: str,domain: str, \
|
||||||
|
approveHandle: str) -> bool:
|
||||||
|
"""Is the given handle an already manually approved follower?
|
||||||
|
"""
|
||||||
|
handle=nickname+'@'+domain
|
||||||
|
accountDir=baseDir+'/accounts/'+handle
|
||||||
|
approvedFilename=accountDir+'/approved.txt'
|
||||||
|
if os.path.isfile(approvedFilename):
|
||||||
|
if approveHandle in open(approvedFilename).read():
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
def removeFromFollowBase(baseDir: str, \
|
def removeFromFollowBase(baseDir: str, \
|
||||||
nickname: str,domain: str, \
|
nickname: str,domain: str, \
|
||||||
acceptOrDenyHandle: str,followFile: str, \
|
acceptOrDenyHandle: str,followFile: str, \
|
||||||
|
@ -331,9 +344,14 @@ def getFollowingFeed(baseDir: str,domain: str,port: int,path: str, \
|
||||||
return following
|
return following
|
||||||
|
|
||||||
def followApprovalRequired(baseDir: str,nicknameToFollow: str, \
|
def followApprovalRequired(baseDir: str,nicknameToFollow: str, \
|
||||||
domainToFollow: str,debug: bool) -> bool:
|
domainToFollow: str,debug: bool, \
|
||||||
|
followRequestHandle: str) -> bool:
|
||||||
""" Returns the policy for follower approvals
|
""" Returns the policy for follower approvals
|
||||||
"""
|
"""
|
||||||
|
if preApprovedFollower(baseDir,nicknameToFollow,domainToFollow, \
|
||||||
|
followRequestHandle):
|
||||||
|
return False
|
||||||
|
|
||||||
manuallyApproveFollows=False
|
manuallyApproveFollows=False
|
||||||
if ':' in domainToFollow:
|
if ':' in domainToFollow:
|
||||||
domainToFollow=domainToFollow.split(':')[0]
|
domainToFollow=domainToFollow.split(':')[0]
|
||||||
|
@ -487,8 +505,9 @@ def receiveFollowRequest(session,baseDir: str,httpPrefix: str, \
|
||||||
return True
|
return True
|
||||||
|
|
||||||
# what is the followers policy?
|
# what is the followers policy?
|
||||||
|
approveHandle=nickname+'@'+domainFull
|
||||||
if followApprovalRequired(baseDir,nicknameToFollow, \
|
if followApprovalRequired(baseDir,nicknameToFollow, \
|
||||||
domainToFollow,debug):
|
domainToFollow,debug,approveHandle):
|
||||||
print('Storing follow request for approval')
|
print('Storing follow request for approval')
|
||||||
return storeFollowRequest(baseDir, \
|
return storeFollowRequest(baseDir, \
|
||||||
nicknameToFollow,domainToFollow,port, \
|
nicknameToFollow,domainToFollow,port, \
|
||||||
|
@ -499,9 +518,6 @@ def receiveFollowRequest(session,baseDir: str,httpPrefix: str, \
|
||||||
# update the followers
|
# update the followers
|
||||||
if os.path.isdir(baseDir+'/accounts/'+nicknameToFollow+'@'+domainToFollow):
|
if os.path.isdir(baseDir+'/accounts/'+nicknameToFollow+'@'+domainToFollow):
|
||||||
followersFilename=baseDir+'/accounts/'+nicknameToFollow+'@'+domainToFollow+'/followers.txt'
|
followersFilename=baseDir+'/accounts/'+nicknameToFollow+'@'+domainToFollow+'/followers.txt'
|
||||||
approveHandle=nickname+'@'+domain
|
|
||||||
if fromPort:
|
|
||||||
approveHandle=approveHandle+':'+str(fromPort)
|
|
||||||
print('Updating followers file: '+followersFilename+' adding '+approveHandle)
|
print('Updating followers file: '+followersFilename+' adding '+approveHandle)
|
||||||
if os.path.isfile(followersFilename):
|
if os.path.isfile(followersFilename):
|
||||||
if approveHandle not in open(followersFilename).read():
|
if approveHandle not in open(followersFilename).read():
|
||||||
|
|
|
@ -60,6 +60,21 @@ def manualDenyFollowRequest(session,baseDir: str, \
|
||||||
|
|
||||||
print('Follow request from '+denyHandle+' was denied.')
|
print('Follow request from '+denyHandle+' was denied.')
|
||||||
|
|
||||||
|
def approveFollowerHandle(accountDir: str,approveHandle: str) -> None:
|
||||||
|
""" Record manually approved handles so that if they unfollow and then
|
||||||
|
re-follow later then they don't need to be manually approved again
|
||||||
|
"""
|
||||||
|
approvedFilename=accountDir+'/approved.txt'
|
||||||
|
if os.path.isfile(approvedFilename):
|
||||||
|
if approveHandle not in open(approvedFilename).read():
|
||||||
|
approvedFile=open(approvedFilename, "a+")
|
||||||
|
approvedFile.write(approveHandle+'\n')
|
||||||
|
approvedFile.close()
|
||||||
|
else:
|
||||||
|
approvedFile=open(approvedFilename, "w+")
|
||||||
|
approvedFile.write(approveHandle+'\n')
|
||||||
|
approvedFile.close()
|
||||||
|
|
||||||
def manualApproveFollowRequest(session,baseDir: str, \
|
def manualApproveFollowRequest(session,baseDir: str, \
|
||||||
httpPrefix: str,
|
httpPrefix: str,
|
||||||
nickname: str,domain: str,port: int, \
|
nickname: str,domain: str,port: int, \
|
||||||
|
@ -146,6 +161,8 @@ def manualApproveFollowRequest(session,baseDir: str, \
|
||||||
# only update the follow requests file if the follow is confirmed to be
|
# only update the follow requests file if the follow is confirmed to be
|
||||||
# in followers.txt
|
# in followers.txt
|
||||||
if approveHandle in open(followersFilename).read():
|
if approveHandle in open(followersFilename).read():
|
||||||
|
# mark this handle as approved for following
|
||||||
|
approveFollowerHandle(accountDir,approveHandle)
|
||||||
# update the follow requests with the handles not yet approved
|
# update the follow requests with the handles not yet approved
|
||||||
os.rename(approveFollowsFilename+'.new',approveFollowsFilename)
|
os.rename(approveFollowsFilename+'.new',approveFollowsFilename)
|
||||||
# remove the .follow file
|
# remove the .follow file
|
||||||
|
|
Loading…
Reference in New Issue