forked from indymedia/epicyon
flake8 style
parent
abe216a2b3
commit
ae5b9f579f
105
acceptreject.py
105
acceptreject.py
|
@ -7,20 +7,18 @@ __email__="bob@freedombone.net"
|
|||
__status__ = "Production"
|
||||
|
||||
import os
|
||||
import json
|
||||
from capabilities import capabilitiesAccept
|
||||
from capabilities import capabilitiesGrantedSave
|
||||
from utils import getStatusNumber
|
||||
from utils import createOutboxDir
|
||||
from utils import urlPermitted
|
||||
from utils import getDomainFromActor
|
||||
from utils import getNicknameFromActor
|
||||
from utils import domainPermitted
|
||||
from utils import followPerson
|
||||
|
||||
def createAcceptReject(baseDir: str,federationList: [], \
|
||||
nickname: str,domain: str,port: int, \
|
||||
toUrl: str,ccUrl: str,httpPrefix: str, \
|
||||
|
||||
def createAcceptReject(baseDir: str, federationList: [],
|
||||
nickname: str, domain: str, port: int,
|
||||
toUrl: str, ccUrl: str, httpPrefix: str,
|
||||
objectJson: {}, ocapJson, acceptType: str) -> {}:
|
||||
"""Accepts or rejects something (eg. a follow request or offer)
|
||||
Typically toUrl will be https://www.w3.org/ns/activitystreams#Public
|
||||
|
@ -55,30 +53,33 @@ def createAcceptReject(baseDir: str,federationList: [], \
|
|||
newAccept['capabilities'] = ocapJson
|
||||
return newAccept
|
||||
|
||||
def createAccept(baseDir: str,federationList: [], \
|
||||
nickname: str,domain: str,port: int, \
|
||||
toUrl: str,ccUrl: str,httpPrefix: str, \
|
||||
objectJson: {}, \
|
||||
|
||||
def createAccept(baseDir: str, federationList: [],
|
||||
nickname: str, domain: str, port: int,
|
||||
toUrl: str, ccUrl: str, httpPrefix: str,
|
||||
objectJson: {},
|
||||
acceptedCaps=["inbox:write", "objects:read"]) -> {}:
|
||||
# create capabilities accept
|
||||
ocapNew= \
|
||||
capabilitiesAccept(baseDir,httpPrefix, \
|
||||
nickname,domain,port,toUrl,True,acceptedCaps)
|
||||
return createAcceptReject(baseDir,federationList, \
|
||||
nickname,domain,port, \
|
||||
toUrl,ccUrl,httpPrefix, \
|
||||
ocapNew = capabilitiesAccept(baseDir, httpPrefix,
|
||||
nickname, domain, port,
|
||||
toUrl, True, acceptedCaps)
|
||||
return createAcceptReject(baseDir, federationList,
|
||||
nickname, domain, port,
|
||||
toUrl, ccUrl, httpPrefix,
|
||||
objectJson, ocapNew, 'Accept')
|
||||
|
||||
def createReject(baseDir: str,federationList: [], \
|
||||
nickname: str,domain: str,port: int, \
|
||||
toUrl: str,ccUrl: str,httpPrefix: str, \
|
||||
|
||||
def createReject(baseDir: str, federationList: [],
|
||||
nickname: str, domain: str, port: int,
|
||||
toUrl: str, ccUrl: str, httpPrefix: str,
|
||||
objectJson: {}) -> {}:
|
||||
return createAcceptReject(baseDir,federationList, \
|
||||
nickname,domain,port, \
|
||||
toUrl,ccUrl, \
|
||||
return createAcceptReject(baseDir, federationList,
|
||||
nickname, domain, port,
|
||||
toUrl, ccUrl,
|
||||
httpPrefix, objectJson, None, 'Reject')
|
||||
|
||||
def acceptFollow(baseDir: str,domain : str,messageJson: {}, \
|
||||
|
||||
def acceptFollow(baseDir: str, domain: str, messageJson: {},
|
||||
federationList: [], debug: bool) -> None:
|
||||
"""Receiving a follow Accept activity
|
||||
"""
|
||||
|
@ -118,11 +119,12 @@ def acceptFollow(baseDir: str,domain : str,messageJson: {}, \
|
|||
print('DEBUG: nickname not found in '+thisActor)
|
||||
return
|
||||
if acceptedPort:
|
||||
if '/'+acceptedDomain+':'+str(acceptedPort)+'/users/'+nickname not in thisActor:
|
||||
if '/' + acceptedDomain + ':' + str(acceptedPort) + \
|
||||
'/users/' + nickname not in thisActor:
|
||||
if debug:
|
||||
print('Port: '+str(acceptedPort))
|
||||
print('Expected: /'+acceptedDomain+':'+str(acceptedPort)+ \
|
||||
'/users/'+nickname)
|
||||
print('Expected: /' + acceptedDomain + ':' +
|
||||
str(acceptedPort) + '/users/'+nickname)
|
||||
print('Actual: '+thisActor)
|
||||
print('DEBUG: unrecognized actor '+thisActor)
|
||||
return
|
||||
|
@ -136,7 +138,7 @@ def acceptFollow(baseDir: str,domain : str,messageJson: {}, \
|
|||
followedActor = messageJson['object']['object']
|
||||
followedDomain, port = getDomainFromActor(followedActor)
|
||||
if not followedDomain:
|
||||
print('DEBUG: no domain found within Follow activity object '+ \
|
||||
print('DEBUG: no domain found within Follow activity object ' +
|
||||
followedActor)
|
||||
return
|
||||
followedDomainFull = followedDomain
|
||||
|
@ -144,7 +146,7 @@ def acceptFollow(baseDir: str,domain : str,messageJson: {}, \
|
|||
followedDomainFull = followedDomain+':' + str(port)
|
||||
followedNickname = getNicknameFromActor(followedActor)
|
||||
if not followedNickname:
|
||||
print('DEBUG: no nickname found within Follow activity object '+ \
|
||||
print('DEBUG: no nickname found within Follow activity object ' +
|
||||
followedActor)
|
||||
return
|
||||
|
||||
|
@ -155,39 +157,41 @@ def acceptFollow(baseDir: str,domain : str,messageJson: {}, \
|
|||
# are capabilities attached? If so then store them
|
||||
if messageJson.get('capabilities'):
|
||||
if isinstance(messageJson['capabilities'], dict):
|
||||
capabilitiesGrantedSave(baseDir, \
|
||||
nickname,acceptedDomainFull, \
|
||||
capabilitiesGrantedSave(baseDir,
|
||||
nickname, acceptedDomainFull,
|
||||
messageJson['capabilities'])
|
||||
|
||||
# has this person already been unfollowed?
|
||||
unfollowedFilename= \
|
||||
baseDir+'/accounts/'+nickname+'@'+acceptedDomainFull+'/unfollowed.txt'
|
||||
unfollowedFilename = baseDir + '/accounts/' + \
|
||||
nickname + '@' + acceptedDomainFull + '/unfollowed.txt'
|
||||
if os.path.isfile(unfollowedFilename):
|
||||
if followedNickname+'@'+followedDomainFull in open(unfollowedFilename).read():
|
||||
if followedNickname + '@' + followedDomainFull in \
|
||||
open(unfollowedFilename).read():
|
||||
if debug:
|
||||
print('DEBUG: follow accept arrived for '+ \
|
||||
nickname+'@'+acceptedDomainFull+ \
|
||||
' from '+followedNickname+'@'+followedDomainFull+ \
|
||||
print('DEBUG: follow accept arrived for ' +
|
||||
nickname + '@' + acceptedDomainFull +
|
||||
' from ' + followedNickname + '@' + followedDomainFull +
|
||||
' but they have been unfollowed')
|
||||
return
|
||||
|
||||
if followPerson(baseDir, \
|
||||
nickname,acceptedDomainFull, \
|
||||
followedNickname,followedDomainFull, \
|
||||
if followPerson(baseDir,
|
||||
nickname, acceptedDomainFull,
|
||||
followedNickname, followedDomainFull,
|
||||
federationList, debug):
|
||||
if debug:
|
||||
print('DEBUG: '+nickname+'@'+acceptedDomainFull+ \
|
||||
print('DEBUG: ' + nickname + '@' + acceptedDomainFull +
|
||||
' followed ' + followedNickname + '@' + followedDomainFull)
|
||||
else:
|
||||
if debug:
|
||||
print('DEBUG: Unable to create follow - '+ \
|
||||
nickname+'@'+acceptedDomain+' -> '+ \
|
||||
print('DEBUG: Unable to create follow - ' +
|
||||
nickname + '@' + acceptedDomain+' -> ' +
|
||||
followedNickname + '@' + followedDomain)
|
||||
|
||||
def receiveAcceptReject(session,baseDir: str, \
|
||||
httpPrefix: str,domain :str,port: int, \
|
||||
sendThreads: [],postLog: [],cachedWebfingers: {}, \
|
||||
personCache: {},messageJson: {},federationList: [], \
|
||||
|
||||
def receiveAcceptReject(session, baseDir: str,
|
||||
httpPrefix: str, domain: str, port: int,
|
||||
sendThreads: [], postLog: [], cachedWebfingers: {},
|
||||
personCache: {}, messageJson: {}, federationList: [],
|
||||
debug: bool) -> bool:
|
||||
"""Receives an Accept or Reject within the POST section of HTTPServer
|
||||
"""
|
||||
|
@ -201,12 +205,12 @@ def receiveAcceptReject(session,baseDir: str, \
|
|||
'/channel/' not in messageJson['actor'] and \
|
||||
'/profile/' not in messageJson['actor']:
|
||||
if debug:
|
||||
print('DEBUG: "users" or "profile" missing from actor in '+ \
|
||||
print('DEBUG: "users" or "profile" missing from actor in ' +
|
||||
messageJson['type'] + '. Assuming single user instance.')
|
||||
domain, tempPort = getDomainFromActor(messageJson['actor'])
|
||||
if not domainPermitted(domain, federationList):
|
||||
if debug:
|
||||
print('DEBUG: '+messageJson['type']+ \
|
||||
print('DEBUG: ' + messageJson['type'] +
|
||||
' from domain not permitted - ' + domain)
|
||||
return False
|
||||
nickname = getNicknameFromActor(messageJson['actor'])
|
||||
|
@ -214,10 +218,9 @@ def receiveAcceptReject(session,baseDir: str, \
|
|||
# single user instance
|
||||
nickname = 'dev'
|
||||
if debug:
|
||||
print('DEBUG: '+messageJson['type']+ \
|
||||
' does not contain a nickname. '+ \
|
||||
print('DEBUG: ' + messageJson['type'] +
|
||||
' does not contain a nickname. ' +
|
||||
'Assuming single user instance.')
|
||||
handle=nickname.lower()+'@'+domain.lower()
|
||||
# receive follow accept
|
||||
acceptFollow(baseDir, domain, messageJson, federationList, debug)
|
||||
if debug:
|
||||
|
|
Loading…
Reference in New Issue