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