epicyon/acceptreject.py

44 lines
1.8 KiB
Python
Raw Normal View History

2019-07-02 11:31:26 +00:00
__filename__ = "acceptreject.py"
__author__ = "Bob Mottram"
__license__ = "AGPL3+"
__version__ = "0.0.1"
__maintainer__ = "Bob Mottram"
__email__ = "bob@freedombone.net"
__status__ = "Production"
import json
import commentjson
from utils import getStatusNumber
from utils import createOutboxDir
from utils import urlPermitted
2019-07-06 10:33:57 +00:00
def createAcceptReject(baseDir: str,federationList: [],capsList: [],nickname: str,domain: str,port: int,toUrl: str,ccUrl: str,httpPrefix: str,objectUrl: str,acceptType: str) -> {}:
2019-07-02 11:31:26 +00:00
"""Accepts or rejects something (eg. a follow request)
Typically toUrl will be https://www.w3.org/ns/activitystreams#Public
and ccUrl might be a specific person favorited or repeated and the followers url
objectUrl is typically the url of the message, corresponding to url or atomUri in createPostBase
"""
2019-07-06 10:33:57 +00:00
if not urlPermitted(objectUrl,federationList,capsList,"inbox:write"):
2019-07-02 11:31:26 +00:00
return None
if port!=80 and port!=443:
domain=domain+':'+str(port)
newAccept = {
'type': acceptType,
2019-07-03 19:00:03 +00:00
'actor': httpPrefix+'://'+domain+'/users/'+nickname,
2019-07-02 11:31:26 +00:00
'to': [toUrl],
'cc': [],
2019-07-02 18:38:51 +00:00
'object': objectUrl
2019-07-02 11:31:26 +00:00
}
if ccUrl:
if len(ccUrl)>0:
newAccept['cc']=ccUrl
return newAccept
2019-07-06 13:49:25 +00:00
def createAccept(baseDir: str,federationList: [],capsList: [],nickname: str,domain: str,port: int,toUrl: str,ccUrl: str,httpPrefix: str,objectUrl: str) -> {}:
return createAcceptReject(baseDir,federationList,capsList,nickname,domain,port,toUrl,ccUrl,httpPrefix,objectUrl,'Accept')
2019-07-02 11:31:26 +00:00
2019-07-06 13:49:25 +00:00
def createReject(baseDir: str,federationList: [],capsList: [],nickname: str,domain: str,port: int,toUrl: str,ccUrl: str,httpPrefix: str,objectUrl: str) -> {}:
return createAcceptReject(baseDir,federationList,capsList,nickname,domain,port,toUrl,ccUrl,httpPrefix,objectUrl,'Reject')