mirror of https://gitlab.com/bashrc2/epicyon
Function to check for presence of actor in activity
parent
c8a5bd9c36
commit
8e6084d42d
|
@ -19,6 +19,7 @@ from utils import hasObjectDict
|
||||||
from utils import acctDir
|
from utils import acctDir
|
||||||
from utils import hasGroupType
|
from utils import hasGroupType
|
||||||
from utils import localActorUrl
|
from utils import localActorUrl
|
||||||
|
from utils import hasActor
|
||||||
|
|
||||||
|
|
||||||
def _createAcceptReject(baseDir: str, federationList: [],
|
def _createAcceptReject(baseDir: str, federationList: [],
|
||||||
|
@ -191,9 +192,7 @@ def receiveAcceptReject(session, baseDir: str,
|
||||||
"""
|
"""
|
||||||
if messageJson['type'] != 'Accept' and messageJson['type'] != 'Reject':
|
if messageJson['type'] != 'Accept' and messageJson['type'] != 'Reject':
|
||||||
return False
|
return False
|
||||||
if not messageJson.get('actor'):
|
if not hasActor(messageJson, debug):
|
||||||
if debug:
|
|
||||||
print('DEBUG: ' + messageJson['type'] + ' has no actor')
|
|
||||||
return False
|
return False
|
||||||
if not hasUsersPath(messageJson['actor']):
|
if not hasUsersPath(messageJson['actor']):
|
||||||
if debug:
|
if debug:
|
||||||
|
|
|
@ -24,6 +24,7 @@ from utils import undoAnnounceCollectionEntry
|
||||||
from utils import updateAnnounceCollection
|
from utils import updateAnnounceCollection
|
||||||
from utils import localActorUrl
|
from utils import localActorUrl
|
||||||
from utils import replaceUsersWithAt
|
from utils import replaceUsersWithAt
|
||||||
|
from utils import hasActor
|
||||||
from posts import sendSignedJson
|
from posts import sendSignedJson
|
||||||
from posts import getPersonBox
|
from posts import getPersonBox
|
||||||
from session import postJson
|
from session import postJson
|
||||||
|
@ -54,7 +55,7 @@ def outboxAnnounce(recentPostsCache: {},
|
||||||
""" Adds or removes announce entries from the shares collection
|
""" Adds or removes announce entries from the shares collection
|
||||||
within a given post
|
within a given post
|
||||||
"""
|
"""
|
||||||
if not messageJson.get('actor'):
|
if not hasActor(messageJson, debug):
|
||||||
return False
|
return False
|
||||||
if not isinstance(messageJson['actor'], str):
|
if not isinstance(messageJson['actor'], str):
|
||||||
return False
|
return False
|
||||||
|
|
|
@ -19,6 +19,7 @@ from utils import loadJson
|
||||||
from utils import saveJson
|
from utils import saveJson
|
||||||
from utils import acctDir
|
from utils import acctDir
|
||||||
from utils import localActorUrl
|
from utils import localActorUrl
|
||||||
|
from utils import hasActor
|
||||||
|
|
||||||
|
|
||||||
def setAvailability(baseDir: str, nickname: str, domain: str,
|
def setAvailability(baseDir: str, nickname: str, domain: str,
|
||||||
|
@ -60,7 +61,7 @@ def outboxAvailability(baseDir: str, nickname: str, messageJson: {},
|
||||||
return False
|
return False
|
||||||
if not messageJson['type'] == 'Availability':
|
if not messageJson['type'] == 'Availability':
|
||||||
return False
|
return False
|
||||||
if not messageJson.get('actor'):
|
if not hasActor(messageJson, debug):
|
||||||
return False
|
return False
|
||||||
if not messageJson.get('object'):
|
if not messageJson.get('object'):
|
||||||
return False
|
return False
|
||||||
|
|
|
@ -29,6 +29,7 @@ from utils import getDomainFromActor
|
||||||
from utils import getNicknameFromActor
|
from utils import getNicknameFromActor
|
||||||
from utils import acctDir
|
from utils import acctDir
|
||||||
from utils import localActorUrl
|
from utils import localActorUrl
|
||||||
|
from utils import hasActor
|
||||||
from conversation import muteConversation
|
from conversation import muteConversation
|
||||||
from conversation import unmuteConversation
|
from conversation import unmuteConversation
|
||||||
|
|
||||||
|
@ -699,7 +700,7 @@ def outboxMute(baseDir: str, httpPrefix: str,
|
||||||
"""
|
"""
|
||||||
if not messageJson.get('type'):
|
if not messageJson.get('type'):
|
||||||
return
|
return
|
||||||
if not messageJson.get('actor'):
|
if not hasActor(messageJson, debug):
|
||||||
return
|
return
|
||||||
domainFull = getFullDomain(domain, port)
|
domainFull = getFullDomain(domain, port)
|
||||||
if not messageJson['actor'].endswith(domainFull + '/users/' + nickname):
|
if not messageJson['actor'].endswith(domainFull + '/users/' + nickname):
|
||||||
|
@ -754,7 +755,7 @@ def outboxUndoMute(baseDir: str, httpPrefix: str,
|
||||||
"""
|
"""
|
||||||
if not messageJson.get('type'):
|
if not messageJson.get('type'):
|
||||||
return
|
return
|
||||||
if not messageJson.get('actor'):
|
if not hasActor(messageJson, debug):
|
||||||
return
|
return
|
||||||
domainFull = getFullDomain(domain, port)
|
domainFull = getFullDomain(domain, port)
|
||||||
if not messageJson['actor'].endswith(domainFull + '/users/' + nickname):
|
if not messageJson['actor'].endswith(domainFull + '/users/' + nickname):
|
||||||
|
|
|
@ -26,6 +26,7 @@ from utils import saveJson
|
||||||
from utils import hasObjectDict
|
from utils import hasObjectDict
|
||||||
from utils import acctDir
|
from utils import acctDir
|
||||||
from utils import localActorUrl
|
from utils import localActorUrl
|
||||||
|
from utils import hasActor
|
||||||
from posts import getPersonBox
|
from posts import getPersonBox
|
||||||
from session import postJson
|
from session import postJson
|
||||||
|
|
||||||
|
@ -539,9 +540,7 @@ def outboxBookmark(recentPostsCache: {},
|
||||||
return
|
return
|
||||||
if messageJson['type'] != 'Add':
|
if messageJson['type'] != 'Add':
|
||||||
return
|
return
|
||||||
if not messageJson.get('actor'):
|
if not hasActor(messageJson, debug):
|
||||||
if debug:
|
|
||||||
print('DEBUG: no actor in bookmark Add')
|
|
||||||
return
|
return
|
||||||
if not hasObjectDict(messageJson):
|
if not hasObjectDict(messageJson):
|
||||||
if debug:
|
if debug:
|
||||||
|
@ -603,9 +602,7 @@ def outboxUndoBookmark(recentPostsCache: {},
|
||||||
return
|
return
|
||||||
if messageJson['type'] != 'Remove':
|
if messageJson['type'] != 'Remove':
|
||||||
return
|
return
|
||||||
if not messageJson.get('actor'):
|
if not hasActor(messageJson, debug):
|
||||||
if debug:
|
|
||||||
print('DEBUG: no actor in unbookmark Remove')
|
|
||||||
return
|
return
|
||||||
if not hasObjectDict(messageJson):
|
if not hasObjectDict(messageJson):
|
||||||
if debug:
|
if debug:
|
||||||
|
|
16
daemon.py
16
daemon.py
|
@ -234,6 +234,7 @@ from categories import updateHashtagCategories
|
||||||
from languages import getActorLanguages
|
from languages import getActorLanguages
|
||||||
from languages import setActorLanguages
|
from languages import setActorLanguages
|
||||||
from like import updateLikesCollection
|
from like import updateLikesCollection
|
||||||
|
from utils import hasActor
|
||||||
from utils import setReplyIntervalHours
|
from utils import setReplyIntervalHours
|
||||||
from utils import canReplyTo
|
from utils import canReplyTo
|
||||||
from utils import isDM
|
from utils import isDM
|
||||||
|
@ -725,24 +726,15 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
else:
|
else:
|
||||||
self.send_header('Cache-Control', 'public')
|
self.send_header('Cache-Control', 'public')
|
||||||
self.send_header('Origin', self.server.domainFull)
|
self.send_header('Origin', self.server.domainFull)
|
||||||
self.send_header('X-AP-Instance-ID', self.server.instanceId)
|
|
||||||
self.send_header('X-Clacks-Overhead', 'GNU Natalie Nguyen')
|
|
||||||
if length > -1:
|
if length > -1:
|
||||||
self.send_header('Content-Length', str(length))
|
self.send_header('Content-Length', str(length))
|
||||||
if callingDomain:
|
if callingDomain:
|
||||||
self.send_header('Host', callingDomain)
|
self.send_header('Host', callingDomain)
|
||||||
if permissive:
|
if permissive:
|
||||||
self.send_header('Access-Control-Allow-Origin', '*')
|
self.send_header('Access-Control-Allow-Origin', '*')
|
||||||
if 'image/' in fileFormat or \
|
|
||||||
'audio/' in fileFormat or \
|
|
||||||
'video/' in fileFormat:
|
|
||||||
acStr = \
|
|
||||||
'Host, Server, x-goog-meta-frames, Content-Length, ' + \
|
|
||||||
'Content-Type, Range, X-Requested-With, ' + \
|
|
||||||
'If-Modified-Since, If-None-Match'
|
|
||||||
self.send_header('Access-Control-Allow-Headers', acStr)
|
|
||||||
self.send_header('Access-Control-Expose-Headers', acStr)
|
|
||||||
return
|
return
|
||||||
|
self.send_header('X-AP-Instance-ID', self.server.instanceId)
|
||||||
|
self.send_header('X-Clacks-Overhead', 'GNU Natalie Nguyen')
|
||||||
if cookie:
|
if cookie:
|
||||||
cookieStr = cookie
|
cookieStr = cookie
|
||||||
if 'HttpOnly;' not in cookieStr:
|
if 'HttpOnly;' not in cookieStr:
|
||||||
|
@ -1278,7 +1270,7 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
|
|
||||||
# check for blocked domains so that they can be rejected early
|
# check for blocked domains so that they can be rejected early
|
||||||
messageDomain = None
|
messageDomain = None
|
||||||
if not messageJson.get('actor'):
|
if not hasActor(messageJson, self.server.debug):
|
||||||
print('Message arriving at inbox queue has no actor')
|
print('Message arriving at inbox queue has no actor')
|
||||||
self._400()
|
self._400()
|
||||||
self.server.POSTbusy = False
|
self.server.POSTbusy = False
|
||||||
|
|
|
@ -9,6 +9,7 @@ __module_group__ = "ActivityPub"
|
||||||
|
|
||||||
from pprint import pprint
|
from pprint import pprint
|
||||||
import os
|
import os
|
||||||
|
from utils import hasActor
|
||||||
from utils import removeDomainPort
|
from utils import removeDomainPort
|
||||||
from utils import hasObjectDict
|
from utils import hasObjectDict
|
||||||
from utils import hasUsersPath
|
from utils import hasUsersPath
|
||||||
|
@ -648,9 +649,7 @@ def receiveFollowRequest(session, baseDir: str, httpPrefix: str,
|
||||||
if not messageJson['type'].startswith('Join'):
|
if not messageJson['type'].startswith('Join'):
|
||||||
return False
|
return False
|
||||||
print('Receiving follow request')
|
print('Receiving follow request')
|
||||||
if not messageJson.get('actor'):
|
if not hasActor(messageJson, debug):
|
||||||
if debug:
|
|
||||||
print('DEBUG: follow request has no actor')
|
|
||||||
return False
|
return False
|
||||||
if not hasUsersPath(messageJson['actor']):
|
if not hasUsersPath(messageJson['actor']):
|
||||||
if debug:
|
if debug:
|
||||||
|
|
37
inbox.py
37
inbox.py
|
@ -73,6 +73,7 @@ from utils import undoAnnounceCollectionEntry
|
||||||
from utils import dangerousMarkup
|
from utils import dangerousMarkup
|
||||||
from utils import isDM
|
from utils import isDM
|
||||||
from utils import isReply
|
from utils import isReply
|
||||||
|
from utils import hasActor
|
||||||
from httpsig import messageContentDigest
|
from httpsig import messageContentDigest
|
||||||
from posts import savePostToBox
|
from posts import savePostToBox
|
||||||
from posts import isCreateInsideAnnounce
|
from posts import isCreateInsideAnnounce
|
||||||
|
@ -307,7 +308,7 @@ def inboxPermittedMessage(domain: str, messageJson: {},
|
||||||
federationList: []) -> bool:
|
federationList: []) -> bool:
|
||||||
""" check that we are receiving from a permitted domain
|
""" check that we are receiving from a permitted domain
|
||||||
"""
|
"""
|
||||||
if not messageJson.get('actor'):
|
if not hasActor(messageJson, False):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
actor = messageJson['actor']
|
actor = messageJson['actor']
|
||||||
|
@ -685,9 +686,7 @@ def _receiveUndo(session, baseDir: str, httpPrefix: str,
|
||||||
return False
|
return False
|
||||||
if debug:
|
if debug:
|
||||||
print('DEBUG: Undo activity received')
|
print('DEBUG: Undo activity received')
|
||||||
if not messageJson.get('actor'):
|
if not hasActor(messageJson, debug):
|
||||||
if debug:
|
|
||||||
print('DEBUG: follow request has no actor')
|
|
||||||
return False
|
return False
|
||||||
if not hasUsersPath(messageJson['actor']):
|
if not hasUsersPath(messageJson['actor']):
|
||||||
if debug:
|
if debug:
|
||||||
|
@ -807,7 +806,7 @@ def _receiveUpdateToQuestion(recentPostsCache: {}, messageJson: {},
|
||||||
# message url of the question
|
# message url of the question
|
||||||
if not messageJson.get('id'):
|
if not messageJson.get('id'):
|
||||||
return
|
return
|
||||||
if not messageJson.get('actor'):
|
if not hasActor(messageJson, False):
|
||||||
return
|
return
|
||||||
messageId = removeIdEnding(messageJson['id'])
|
messageId = removeIdEnding(messageJson['id'])
|
||||||
if '#' in messageId:
|
if '#' in messageId:
|
||||||
|
@ -849,9 +848,7 @@ def _receiveUpdate(recentPostsCache: {}, session, baseDir: str,
|
||||||
"""
|
"""
|
||||||
if messageJson['type'] != 'Update':
|
if messageJson['type'] != 'Update':
|
||||||
return False
|
return False
|
||||||
if not messageJson.get('actor'):
|
if not hasActor(messageJson, debug):
|
||||||
if debug:
|
|
||||||
print('DEBUG: ' + messageJson['type'] + ' has no actor')
|
|
||||||
return False
|
return False
|
||||||
if not hasObjectDict(messageJson):
|
if not hasObjectDict(messageJson):
|
||||||
if debug:
|
if debug:
|
||||||
|
@ -925,9 +922,7 @@ def _receiveLike(recentPostsCache: {},
|
||||||
"""
|
"""
|
||||||
if messageJson['type'] != 'Like':
|
if messageJson['type'] != 'Like':
|
||||||
return False
|
return False
|
||||||
if not messageJson.get('actor'):
|
if not hasActor(messageJson, debug):
|
||||||
if debug:
|
|
||||||
print('DEBUG: ' + messageJson['type'] + ' has no actor')
|
|
||||||
return False
|
return False
|
||||||
if not messageJson.get('object'):
|
if not messageJson.get('object'):
|
||||||
if debug:
|
if debug:
|
||||||
|
@ -1034,7 +1029,7 @@ def _receiveUndoLike(recentPostsCache: {},
|
||||||
"""
|
"""
|
||||||
if messageJson['type'] != 'Undo':
|
if messageJson['type'] != 'Undo':
|
||||||
return False
|
return False
|
||||||
if not messageJson.get('actor'):
|
if not hasActor(messageJson, debug):
|
||||||
return False
|
return False
|
||||||
if not hasObjectDict(messageJson):
|
if not hasObjectDict(messageJson):
|
||||||
return False
|
return False
|
||||||
|
@ -1136,9 +1131,7 @@ def _receiveBookmark(recentPostsCache: {},
|
||||||
return False
|
return False
|
||||||
if messageJson['type'] != 'Add':
|
if messageJson['type'] != 'Add':
|
||||||
return False
|
return False
|
||||||
if not messageJson.get('actor'):
|
if not hasActor(messageJson, debug):
|
||||||
if debug:
|
|
||||||
print('DEBUG: no actor in inbox bookmark Add')
|
|
||||||
return False
|
return False
|
||||||
if not hasObjectDict(messageJson):
|
if not hasObjectDict(messageJson):
|
||||||
if debug:
|
if debug:
|
||||||
|
@ -1252,9 +1245,7 @@ def _receiveUndoBookmark(recentPostsCache: {},
|
||||||
return False
|
return False
|
||||||
if messageJson['type'] != 'Remove':
|
if messageJson['type'] != 'Remove':
|
||||||
return False
|
return False
|
||||||
if not messageJson.get('actor'):
|
if not hasActor(messageJson, debug):
|
||||||
if debug:
|
|
||||||
print('DEBUG: no actor in inbox undo bookmark Remove')
|
|
||||||
return False
|
return False
|
||||||
if not hasObjectDict(messageJson):
|
if not hasObjectDict(messageJson):
|
||||||
if debug:
|
if debug:
|
||||||
|
@ -1359,9 +1350,7 @@ def _receiveDelete(session, handle: str, isGroup: bool, baseDir: str,
|
||||||
"""
|
"""
|
||||||
if messageJson['type'] != 'Delete':
|
if messageJson['type'] != 'Delete':
|
||||||
return False
|
return False
|
||||||
if not messageJson.get('actor'):
|
if not hasActor(messageJson, debug):
|
||||||
if debug:
|
|
||||||
print('DEBUG: ' + messageJson['type'] + ' has no actor')
|
|
||||||
return False
|
return False
|
||||||
if debug:
|
if debug:
|
||||||
print('DEBUG: Delete activity arrived')
|
print('DEBUG: Delete activity arrived')
|
||||||
|
@ -1456,9 +1445,7 @@ def _receiveAnnounce(recentPostsCache: {},
|
||||||
if debug:
|
if debug:
|
||||||
print('DEBUG: bad handle ' + handle)
|
print('DEBUG: bad handle ' + handle)
|
||||||
return False
|
return False
|
||||||
if not messageJson.get('actor'):
|
if not hasActor(messageJson, debug):
|
||||||
if debug:
|
|
||||||
print('DEBUG: ' + messageJson['type'] + ' has no actor')
|
|
||||||
return False
|
return False
|
||||||
if debug:
|
if debug:
|
||||||
print('DEBUG: receiving announce on ' + handle)
|
print('DEBUG: receiving announce on ' + handle)
|
||||||
|
@ -1669,7 +1656,7 @@ def _receiveUndoAnnounce(recentPostsCache: {},
|
||||||
"""
|
"""
|
||||||
if messageJson['type'] != 'Undo':
|
if messageJson['type'] != 'Undo':
|
||||||
return False
|
return False
|
||||||
if not messageJson.get('actor'):
|
if not hasActor(messageJson, debug):
|
||||||
return False
|
return False
|
||||||
if not hasObjectDict(messageJson):
|
if not hasObjectDict(messageJson):
|
||||||
return False
|
return False
|
||||||
|
|
|
@ -28,6 +28,7 @@ from utils import loadJson
|
||||||
from utils import saveJson
|
from utils import saveJson
|
||||||
from utils import acctDir
|
from utils import acctDir
|
||||||
from utils import localActorUrl
|
from utils import localActorUrl
|
||||||
|
from utils import hasActor
|
||||||
from blocking import isBlockedDomain
|
from blocking import isBlockedDomain
|
||||||
from blocking import outboxBlock
|
from blocking import outboxBlock
|
||||||
from blocking import outboxUndoBlock
|
from blocking import outboxUndoBlock
|
||||||
|
@ -92,9 +93,7 @@ def _outboxPersonReceiveUpdate(recentPostsCache: {},
|
||||||
if debug:
|
if debug:
|
||||||
print('DEBUG: c2s actor update has no "to" field')
|
print('DEBUG: c2s actor update has no "to" field')
|
||||||
return
|
return
|
||||||
if not messageJson.get('actor'):
|
if not hasActor(messageJson, debug):
|
||||||
if debug:
|
|
||||||
print('DEBUG: c2s actor update has no actor field')
|
|
||||||
return
|
return
|
||||||
if not messageJson.get('id'):
|
if not messageJson.get('id'):
|
||||||
if debug:
|
if debug:
|
||||||
|
|
|
@ -20,6 +20,7 @@ from utils import getOccupationSkills
|
||||||
from utils import setOccupationSkillsList
|
from utils import setOccupationSkillsList
|
||||||
from utils import acctDir
|
from utils import acctDir
|
||||||
from utils import localActorUrl
|
from utils import localActorUrl
|
||||||
|
from utils import hasActor
|
||||||
|
|
||||||
|
|
||||||
def setSkillsFromDict(actorJson: {}, skillsDict: {}) -> []:
|
def setSkillsFromDict(actorJson: {}, skillsDict: {}) -> []:
|
||||||
|
@ -150,7 +151,7 @@ def outboxSkills(baseDir: str, nickname: str, messageJson: {},
|
||||||
return False
|
return False
|
||||||
if not messageJson['type'] == 'Skill':
|
if not messageJson['type'] == 'Skill':
|
||||||
return False
|
return False
|
||||||
if not messageJson.get('actor'):
|
if not hasActor(messageJson, debug):
|
||||||
return False
|
return False
|
||||||
if not messageJson.get('object'):
|
if not messageJson.get('object'):
|
||||||
return False
|
return False
|
||||||
|
|
2
tests.py
2
tests.py
|
@ -1299,7 +1299,7 @@ def testPostMessageBetweenServers(baseDir: str) -> None:
|
||||||
assert attached.get('type')
|
assert attached.get('type')
|
||||||
assert attached.get('url')
|
assert attached.get('url')
|
||||||
assert attached['mediaType'] == 'image/png'
|
assert attached['mediaType'] == 'image/png'
|
||||||
if not '/system/media_attachments/files/' in attached['url']:
|
if '/system/media_attachments/files/' not in attached['url']:
|
||||||
print(attached['url'])
|
print(attached['url'])
|
||||||
assert '/system/media_attachments/files/' in attached['url']
|
assert '/system/media_attachments/files/' in attached['url']
|
||||||
assert attached['url'].endswith('.png')
|
assert attached['url'].endswith('.png')
|
||||||
|
|
14
utils.py
14
utils.py
|
@ -3020,3 +3020,17 @@ def replaceUsersWithAt(actor: str) -> str:
|
||||||
actor = actor.replace(path, '/@')
|
actor = actor.replace(path, '/@')
|
||||||
break
|
break
|
||||||
return actor
|
return actor
|
||||||
|
|
||||||
|
|
||||||
|
def hasActor(postJsonObject: {}, debug: bool) -> bool:
|
||||||
|
"""Does the given post have an actor?
|
||||||
|
"""
|
||||||
|
if postJsonObject.get('actor'):
|
||||||
|
return True
|
||||||
|
if debug:
|
||||||
|
if postJsonObject.get('type'):
|
||||||
|
msg = postJsonObject['type'] + ' has missing actor'
|
||||||
|
if postJsonObject.get('id'):
|
||||||
|
msg += ' ' + postJsonObject['id']
|
||||||
|
print(msg)
|
||||||
|
return False
|
||||||
|
|
Loading…
Reference in New Issue