Allow accounts as users path

main
Bob Mottram 2020-08-13 17:19:35 +01:00
parent 5ab09b996b
commit 58bba56e75
15 changed files with 76 additions and 30 deletions

View File

@ -202,6 +202,7 @@ def receiveAcceptReject(session, baseDir: str,
print('DEBUG: ' + messageJson['type'] + ' has no actor')
return False
if '/users/' not in messageJson['actor'] and \
'/accounts/' not in messageJson['actor'] and \
'/channel/' not in messageJson['actor'] and \
'/profile/' not in messageJson['actor']:
if debug:

View File

@ -147,6 +147,7 @@ def createAnnounce(session, baseDir: str, federationList: [],
announceDomain = None
announcePort = None
if '/users/' in objectUrl or \
'/accounts/' in objectUrl or \
'/channel/' in objectUrl or \
'/profile/' in objectUrl:
announceNickname = getNicknameFromActor(objectUrl)
@ -263,6 +264,7 @@ def undoAnnounce(session, baseDir: str, federationList: [],
announceDomain = None
announcePort = None
if '/users/' in objectUrl or \
'/accounts/' in objectUrl or \
'/channel/' in objectUrl or \
'/profile/' in objectUrl:
announceNickname = getNicknameFromActor(objectUrl)

View File

@ -57,6 +57,7 @@ def authorizeBasic(baseDir: str, path: str, authHeader: str,
'contain a space character')
return False
if '/users/' not in path and \
'/accounts/' not in path and \
'/channel/' not in path and \
'/profile/' not in path:
if debug:

View File

@ -220,6 +220,7 @@ def outboxBlock(baseDir: str, httpPrefix: str,
print('DEBUG: c2s block object is not a status')
return
if '/users/' not in messageId and \
'/accounts/' not in messageId and \
'/channel/' not in messageId and \
'/profile/' not in messageId:
if debug:
@ -298,6 +299,7 @@ def outboxUndoBlock(baseDir: str, httpPrefix: str,
print('DEBUG: c2s undo block object is not a status')
return
if '/users/' not in messageId and \
'/accounts/' not in messageId and \
'/channel/' not in messageId and \
'/profile/' not in messageId:
if debug:

View File

@ -262,6 +262,7 @@ def bookmark(recentPostsCache: {},
bookmarkedPostDomain, bookmarkedPostPort = getDomainFromActor(acBm)
else:
if '/users/' in objectUrl or \
'/accounts/' in objectUrl or \
'/channel/' in objectUrl or \
'/profile/' in objectUrl:
ou = objectUrl
@ -362,6 +363,7 @@ def undoBookmark(recentPostsCache: {},
bookmarkedPostDomain, bookmarkedPostPort = getDomainFromActor(acBm)
else:
if '/users/' in objectUrl or \
'/accounts/' in objectUrl or \
'/channel/' in objectUrl or \
'/profile/' in objectUrl:
ou = objectUrl

View File

@ -5914,7 +5914,7 @@ class PubServer(BaseHTTPRequestHandler):
return
self._400()
elif path.startswith('/api/v1/crypto/keys/query'):
# given a handle (nickname@domain) return the devices
# given a handle (nickname@domain) return a list of the devices
# registered to that handle
if not self._cryptoAPIQuery():
self._400()

View File

@ -67,6 +67,7 @@ def createDelete(session, baseDir: str, federationList: [],
deleteDomain = None
deletePort = None
if '/users/' in objectUrl or \
'/accounts/' in objectUrl or \
'/channel/' in objectUrl or \
'/profile/' in objectUrl:
deleteNickname = getNicknameFromActor(objectUrl)
@ -262,6 +263,7 @@ def outboxDelete(baseDir: str, httpPrefix: str,
print('DEBUG: c2s delete object is not a status')
return
if '/users/' not in messageId and \
'/accounts/' not in messageId and \
'/channel/' not in messageId and \
'/profile/' not in messageId:
if debug:

View File

@ -1130,6 +1130,7 @@ if args.actor:
args.actor = args.actor.replace(prefix, '')
args.actor = args.actor.replace('/@', '/users/')
if '/users/' not in args.actor and \
'/accounts/' not in args.actor and \
'/channel/' not in args.actor and \
'/profile/' not in args.actor:
print('Expected actor format: ' +
@ -1143,10 +1144,14 @@ if args.actor:
nickname = args.actor.split('/profile/')[1]
nickname = nickname.replace('\n', '').replace('\r', '')
domain = args.actor.split('/profile/')[0]
else:
elif '/channel/' in args.actor:
nickname = args.actor.split('/channel/')[1]
nickname = nickname.replace('\n', '').replace('\r', '')
domain = args.actor.split('/channel/')[0]
elif '/accounts/' in args.actor:
nickname = args.actor.split('/accounts/')[1]
nickname = nickname.replace('\n', '').replace('\r', '')
domain = args.actor.split('/accounts/')[0]
else:
# format: @nick@domain
if '@' not in args.actor:
@ -1198,6 +1203,7 @@ if args.actor:
if wfRequest.get('errors'):
print('wfRequest error: ' + str(wfRequest['errors']))
if '/users/' in args.actor or \
'/accounts/' in args.actor or \
'/profile/' in args.actor or \
'/channel/' in args.actor:
personUrl = originalActor
@ -1212,6 +1218,7 @@ if args.actor:
personUrl = getUserUrl(wfRequest)
if nickname == domain:
personUrl = personUrl.replace('/users/', '/actor/')
personUrl = personUrl.replace('/accounts/', '/actor/')
personUrl = personUrl.replace('/channel/', '/actor/')
personUrl = personUrl.replace('/profile/', '/actor/')
if not personUrl:
@ -1221,7 +1228,7 @@ if args.actor:
asHeader = {
'Accept': 'application/ld+json; profile="' + profileStr + '"'
}
if '/channel/' in personUrl:
if '/channel/' in personUrl or '/accounts/' in personUrl:
profileStr = 'https://www.w3.org/ns/activitystreams'
asHeader = {
'Accept': 'application/ld+json; profile="' + profileStr + '"'

View File

@ -555,6 +555,7 @@ def receiveFollowRequest(session, baseDir: str, httpPrefix: str,
print('DEBUG: follow request has no actor')
return False
if '/users/' not in messageJson['actor'] and \
'/accounts/' not in messageJson['actor'] and \
'/channel/' not in messageJson['actor'] and \
'/profile/' not in messageJson['actor']:
if debug:
@ -582,6 +583,7 @@ def receiveFollowRequest(session, baseDir: str, httpPrefix: str,
if not messageJson.get('to'):
messageJson['to'] = messageJson['object']
if '/users/' not in messageJson['object'] and \
'/accounts/' not in messageJson['object'] and \
'/channel/' not in messageJson['object'] and \
'/profile/' not in messageJson['object']:
if debug:

View File

@ -661,6 +661,7 @@ def receiveUndoFollow(session, baseDir: str, httpPrefix: str,
print('DEBUG: follow request has no actor within object')
return False
if '/users/' not in messageJson['object']['actor'] and \
'/accounts/' not in messageJson['object']['actor'] and \
'/channel/' not in messageJson['object']['actor'] and \
'/profile/' not in messageJson['object']['actor']:
if debug:
@ -735,6 +736,7 @@ def receiveUndo(session, baseDir: str, httpPrefix: str,
print('DEBUG: follow request has no actor')
return False
if '/users/' not in messageJson['actor'] and \
'/accounts/' not in messageJson['actor'] and \
'/channel/' not in messageJson['actor'] and \
'/profile/' not in messageJson['actor']:
if debug:
@ -791,6 +793,8 @@ def personReceiveUpdate(baseDir: str,
actor = updateDomainFull + '/profile/' + updateNickname
if actor not in personJson['id']:
actor = updateDomainFull + '/channel/' + updateNickname
if actor not in personJson['id']:
actor = updateDomainFull + '/accounts/' + updateNickname
if actor not in personJson['id']:
if debug:
print('actor: ' + actor)
@ -907,6 +911,7 @@ def receiveUpdate(recentPostsCache: {}, session, baseDir: str,
print('DEBUG: ' + messageJson['type'] + ' object has no type')
return False
if '/users/' not in messageJson['actor'] and \
'/accounts/' not in messageJson['actor'] and \
'/channel/' not in messageJson['actor'] and \
'/profile/' not in messageJson['actor']:
if debug:
@ -1008,6 +1013,7 @@ def receiveLike(recentPostsCache: {},
print('DEBUG: ' + messageJson['type'] + ' has no "to" list')
return False
if '/users/' not in messageJson['actor'] and \
'/accounts/' not in messageJson['actor'] and \
'/channel/' not in messageJson['actor'] and \
'/profile/' not in messageJson['actor']:
if debug:
@ -1076,6 +1082,7 @@ def receiveUndoLike(recentPostsCache: {},
' like object is not a string')
return False
if '/users/' not in messageJson['actor'] and \
'/accounts/' not in messageJson['actor'] and \
'/channel/' not in messageJson['actor'] and \
'/profile/' not in messageJson['actor']:
if debug:
@ -1288,6 +1295,7 @@ def receiveDelete(session, handle: str, isGroup: bool, baseDir: str,
print('DEBUG: ' + messageJson['type'] + ' has no "to" list')
return False
if '/users/' not in messageJson['actor'] and \
'/accounts/' not in messageJson['actor'] and \
'/channel/' not in messageJson['actor'] and \
'/profile/' not in messageJson['actor']:
if debug:
@ -1358,6 +1366,7 @@ def receiveAnnounce(recentPostsCache: {},
print('DEBUG: ' + messageJson['type'] + ' has no "to" list')
return False
if '/users/' not in messageJson['actor'] and \
'/accounts/' not in messageJson['actor'] and \
'/channel/' not in messageJson['actor'] and \
'/profile/' not in messageJson['actor']:
if debug:
@ -1366,6 +1375,7 @@ def receiveAnnounce(recentPostsCache: {},
messageJson['type'])
return False
if '/users/' not in messageJson['object'] and \
'/accounts/' not in messageJson['object'] and \
'/channel/' not in messageJson['object'] and \
'/profile/' not in messageJson['object']:
if debug:
@ -1434,6 +1444,7 @@ def receiveAnnounce(recentPostsCache: {},
lookupActor = attrib
if lookupActor:
if '/users/' in lookupActor or \
'/accounts/' in lookupActor or \
'/channel/' in lookupActor or \
'/profile/' in lookupActor:
if '/statuses/' in lookupActor:
@ -1485,6 +1496,7 @@ def receiveUndoAnnounce(recentPostsCache: {},
if messageJson['object']['type'] != 'Announce':
return False
if '/users/' not in messageJson['actor'] and \
'/accounts/' not in messageJson['actor'] and \
'/channel/' not in messageJson['actor'] and \
'/profile/' not in messageJson['actor']:
if debug:
@ -1679,6 +1691,7 @@ def obtainAvatarForReplyPost(session, baseDir: str, httpPrefix: str,
return
if not ('/users/' in lookupActor or
'/accounts/' in lookupActor or
'/channel/' in lookupActor or
'/profile/' in lookupActor):
return

View File

@ -90,6 +90,7 @@ def like(recentPostsCache: {},
likedPostDomain, likedPostPort = getDomainFromActor(actorLiked)
else:
if '/users/' in objectUrl or \
'/accounts/' in objectUrl or \
'/channel/' in objectUrl or \
'/profile/' in objectUrl:
likedPostNickname = getNicknameFromActor(objectUrl)
@ -193,6 +194,7 @@ def undolike(recentPostsCache: {},
likedPostDomain, likedPostPort = getDomainFromActor(actorLiked)
else:
if '/users/' in objectUrl or \
'/accounts/' in objectUrl or \
'/channel/' in objectUrl or \
'/profile/' in objectUrl:
likedPostNickname = getNicknameFromActor(objectUrl)

View File

@ -136,6 +136,7 @@ def getUserUrl(wfRequest: {}) -> str:
if link.get('type') and link.get('href'):
if link['type'] == 'application/activity+json':
if not ('/users/' in link['href'] or
'/accounts/' in link['href'] or
'/profile/' in link['href'] or
'/channel/' in link['href']):
print('Webfinger activity+json contains ' +
@ -207,7 +208,7 @@ def getPersonBox(baseDir: str, session, wfRequest: {},
return None, None, None, None, None, None, None, None
personJson = getPersonFromCache(baseDir, personUrl, personCache)
if not personJson:
if '/channel/' in personUrl:
if '/channel/' in personUrl or '/accounts/' in personUrl:
asHeader = {
'Accept': 'application/ld+json; profile="' + profileStr + '"'
}
@ -3188,7 +3189,8 @@ def downloadAnnounce(session, baseDir: str, httpPrefix: str,
asHeader = {
'Accept': 'application/activity+json; profile="' + profileStr + '"'
}
if '/channel/' in postJsonObject['actor']:
if '/channel/' in postJsonObject['actor'] or \
'/accounts/' in postJsonObject['actor']:
asHeader = {
'Accept': 'application/ld+json; profile="' + profileStr + '"'
}
@ -3238,6 +3240,7 @@ def downloadAnnounce(session, baseDir: str, httpPrefix: str,
rejectAnnounce(announceFilename)
return None
if '/users/' not in announcedJson['id'] and \
'/accounts/' not in announcedJson['id'] and \
'/channel/' not in announcedJson['id'] and \
'/profile/' not in announcedJson['id']:
rejectAnnounce(announceFilename)

View File

@ -222,14 +222,20 @@ def getNicknameFromActor(actor: str) -> str:
return nickStr
else:
return nickStr.split('/')[0]
if '/channel/' in actor:
elif '/channel/' in actor:
nickStr = actor.split('/channel/')[1].replace('@', '')
if '/' not in nickStr:
return nickStr
else:
return nickStr.split('/')[0]
elif '/accounts/' in actor:
nickStr = actor.split('/accounts/')[1].replace('@', '')
if '/' not in nickStr:
return nickStr
else:
return nickStr.split('/')[0]
elif '/@' in actor:
# https://domain/@nick
if '/@' in actor:
nickStr = actor.split('/@')[1]
if '/' in nickStr:
nickStr = nickStr.split('/')[0]
@ -251,13 +257,15 @@ def getDomainFromActor(actor: str) -> (str, int):
domain = actor.split('/profile/')[0]
for prefix in prefixes:
domain = domain.replace(prefix, '')
else:
if '/channel/' in actor:
elif '/accounts/' in actor:
domain = actor.split('/accounts/')[0]
for prefix in prefixes:
domain = domain.replace(prefix, '')
elif '/channel/' in actor:
domain = actor.split('/channel/')[0]
for prefix in prefixes:
domain = domain.replace(prefix, '')
else:
if '/users/' not in actor:
elif '/users/' not in actor:
domain = actor
for prefix in prefixes:
domain = domain.replace(prefix, '')

View File

@ -252,7 +252,7 @@ def updateAvatarImageCache(session, baseDir: str, httpPrefix: str,
print('Failed to download avatar image: ' + str(avatarUrl))
print(e)
prof = 'https://www.w3.org/ns/activitystreams'
if '/channel/' not in actor:
if '/channel/' not in actor or '/accounts/' not in actor:
sessionHeaders = {
'Accept': 'application/activity+json; profile="' + prof + '"'
}
@ -6281,6 +6281,7 @@ def htmlProfileAfterSearch(recentPostsCache: {}, maxRecentPosts: int,
"""Show a profile page after a search for a fediverse address
"""
if '/users/' in profileHandle or \
'/accounts/' in profileHandle or \
'/channel/' in profileHandle or \
'/profile/' in profileHandle or \
'/@' in profileHandle: