Follow approve path only contains user

master
Bob Mottram 2019-08-07 15:08:32 +01:00
parent 6ddfb88dff
commit 1645e223f0
2 changed files with 6 additions and 33 deletions

View File

@ -82,7 +82,6 @@ from utils import getNicknameFromActor
from utils import getDomainFromActor from utils import getDomainFromActor
from manualapprove import manualDenyFollowRequest from manualapprove import manualDenyFollowRequest
from manualapprove import manualApproveFollowRequest from manualapprove import manualApproveFollowRequest
from manualapprove import addHandleToApproveFile
from announce import createAnnounce from announce import createAnnounce
from announce import outboxAnnounce from announce import outboxAnnounce
from content import addMentions from content import addMentions
@ -751,22 +750,18 @@ class PubServer(BaseHTTPRequestHandler):
return return
# send a follow request approval from the web interface # send a follow request approval from the web interface
if authorized and '/followapprove=' in self.path: if authorized and '/followapprove=' in self.path and self.path.startswith('/users/'):
originPathStr=self.path.split('/followapprove=')[0] originPathStr=self.path.split('/followapprove=')[0]
followerNickname=getNicknameFromActor(originPathStr) followerNickname=originPathStr.replace('/users/','')
followerDomain,FollowerPort=getDomainFromActor(originPathStr)
followingHandle=self.path.split('/followapprove=')[1] followingHandle=self.path.split('/followapprove=')[1]
if '@' in followingHandle: if '@' in followingHandle:
if not self.server.session: if not self.server.session:
self.server.session= \ self.server.session= \
createSession(self.server.domain,self.server.port,self.server.useTor) createSession(self.server.domain,self.server.port,self.server.useTor)
addHandleToApproveFile(self.server.baseDir, \
followerNickname,followerDomain, \
followingHandle)
manualApproveFollowRequest(self.server.session, \ manualApproveFollowRequest(self.server.session, \
self.server.baseDir, \ self.server.baseDir, \
self.server.httpPrefix, \ self.server.httpPrefix, \
followerNickname,followerDomain,FollowerPort, \ followerNickname,self.server.domain,self.server.port, \
followingHandle, \ followingHandle, \
self.server.federationList, \ self.server.federationList, \
self.server.sendThreads, \ self.server.sendThreads, \
@ -780,17 +775,13 @@ class PubServer(BaseHTTPRequestHandler):
return return
# deny a follow request from the web interface # deny a follow request from the web interface
if authorized and '/followdeny=' in self.path: if authorized and '/followdeny=' in self.path and self.path.startswith('/users/'):
originPathStr=self.path.split('/followdeny=')[0] originPathStr=self.path.split('/followdeny=')[0]
followerNickname=getNicknameFromActor(originPathStr) followerNickname=originPathStr.replace('/users/','')
followerDomain,FollowerPort=getDomainFromActor(originPathStr)
followingHandle=self.path.split('/followdeny=')[1] followingHandle=self.path.split('/followdeny=')[1]
if '@' in followingHandle: if '@' in followingHandle:
addHandleToApproveFile(self.server.baseDir, \
followerNickname,followerDomain, \
followingHandle)
manualDenyFollowRequest(self.server.baseDir, \ manualDenyFollowRequest(self.server.baseDir, \
followerNickname,followerDomain, \ followerNickname,self.server.domain, \
followingHandle) followingHandle)
self._redirect_headers(originPathStr,cookie) self._redirect_headers(originPathStr,cookie)
self.server.GETbusy=False self.server.GETbusy=False

View File

@ -32,24 +32,6 @@ def manualDenyFollowRequest(baseDir: str,nickname: str,domain: str,denyHandle: s
approvefilenew.close() approvefilenew.close()
os.rename(approveFollowsFilename+'.new',approveFollowsFilename) os.rename(approveFollowsFilename+'.new',approveFollowsFilename)
print('Follow request from '+denyHandle+' was denied.') print('Follow request from '+denyHandle+' was denied.')
def addHandleToApproveFile(baseDir: str,nickname: str,domain: str,addHandle: str) -> None:
"""Adds the given handle to the follow requests for the given account
"""
handle=nickname+'@'+domain
accountsDir=baseDir+'/accounts/'+handle
approveFollowsFilename=accountsDir+'/followrequests.txt'
appendHandle=True
if os.path.isfile(approveFollowsFilename):
if addHandle in open(approveFollowsFilename).read():
appendHandle=False
approvefilenew = open(approveFollowsFilename+'.add', 'w+')
with open(approveFollowsFilename, 'r') as approvefile:
for handle in approvefile:
approvefilenew.write(handle)
approvefilenew.write(addHandle)
approvefilenew.close()
os.rename(approveFollowsFilename+'.add',approveFollowsFilename)
def manualApproveFollowRequest(session,baseDir: str, \ def manualApproveFollowRequest(session,baseDir: str, \
httpPrefix: str, httpPrefix: str,