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 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, \
|
||||
nickname: str,domain: str, \
|
||||
acceptOrDenyHandle: str,followFile: str, \
|
||||
|
@ -331,9 +344,14 @@ def getFollowingFeed(baseDir: str,domain: str,port: int,path: str, \
|
|||
return following
|
||||
|
||||
def followApprovalRequired(baseDir: str,nicknameToFollow: str, \
|
||||
domainToFollow: str,debug: bool) -> bool:
|
||||
domainToFollow: str,debug: bool, \
|
||||
followRequestHandle: str) -> bool:
|
||||
""" Returns the policy for follower approvals
|
||||
"""
|
||||
if preApprovedFollower(baseDir,nicknameToFollow,domainToFollow, \
|
||||
followRequestHandle):
|
||||
return False
|
||||
|
||||
manuallyApproveFollows=False
|
||||
if ':' in domainToFollow:
|
||||
domainToFollow=domainToFollow.split(':')[0]
|
||||
|
@ -487,8 +505,9 @@ def receiveFollowRequest(session,baseDir: str,httpPrefix: str, \
|
|||
return True
|
||||
|
||||
# what is the followers policy?
|
||||
approveHandle=nickname+'@'+domainFull
|
||||
if followApprovalRequired(baseDir,nicknameToFollow, \
|
||||
domainToFollow,debug):
|
||||
domainToFollow,debug,approveHandle):
|
||||
print('Storing follow request for approval')
|
||||
return storeFollowRequest(baseDir, \
|
||||
nicknameToFollow,domainToFollow,port, \
|
||||
|
@ -499,9 +518,6 @@ def receiveFollowRequest(session,baseDir: str,httpPrefix: str, \
|
|||
# update the followers
|
||||
if os.path.isdir(baseDir+'/accounts/'+nicknameToFollow+'@'+domainToFollow):
|
||||
followersFilename=baseDir+'/accounts/'+nicknameToFollow+'@'+domainToFollow+'/followers.txt'
|
||||
approveHandle=nickname+'@'+domain
|
||||
if fromPort:
|
||||
approveHandle=approveHandle+':'+str(fromPort)
|
||||
print('Updating followers file: '+followersFilename+' adding '+approveHandle)
|
||||
if os.path.isfile(followersFilename):
|
||||
if approveHandle not in open(followersFilename).read():
|
||||
|
|
|
@ -60,6 +60,21 @@ def manualDenyFollowRequest(session,baseDir: str, \
|
|||
|
||||
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, \
|
||||
httpPrefix: str,
|
||||
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
|
||||
# in followers.txt
|
||||
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
|
||||
os.rename(approveFollowsFilename+'.new',approveFollowsFilename)
|
||||
# remove the .follow file
|
||||
|
|
Loading…
Reference in New Issue