From 4d771166e077134484de0a1a13ad61f4b0dc803c Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sun, 22 Aug 2021 19:38:02 +0100 Subject: [PATCH] Replace /users/ with other possible paths --- announce.py | 3 ++- daemon.py | 3 ++- person.py | 3 ++- pgp.py | 3 ++- posts.py | 7 ++++--- utils.py | 11 +++++++++++ webapp_calendar.py | 3 ++- 7 files changed, 25 insertions(+), 8 deletions(-) diff --git a/announce.py b/announce.py index 8fc49bf8d..4e9261e98 100644 --- a/announce.py +++ b/announce.py @@ -23,6 +23,7 @@ from utils import saveJson from utils import undoAnnounceCollectionEntry from utils import updateAnnounceCollection from utils import localActorUrl +from utils import replaceUsersWithAt from posts import sendSignedJson from posts import getPersonBox from session import postJson @@ -307,7 +308,7 @@ def sendUndoAnnounceViaServer(baseDir: str, session, domainFull = getFullDomain(domain, port) actor = localActorUrl(httpPrefix, nickname, domainFull) - handle = actor.replace('/users/', '/@') + handle = replaceUsersWithAt(actor) statusNumber, published = getStatusNumber() unAnnounceJson = { diff --git a/daemon.py b/daemon.py index 0cd48196f..6183e7ff8 100644 --- a/daemon.py +++ b/daemon.py @@ -227,6 +227,7 @@ from categories import setHashtagCategory from categories import updateHashtagCategories from languages import getActorLanguages from languages import setActorLanguages +from utils import replaceUsersWithAt from utils import localActorUrl from utils import isfloat from utils import validPassword @@ -11558,7 +11559,7 @@ class PubServer(BaseHTTPRequestHandler): pinnedPostJson) messageJson['id'] = postId + '/activity' messageJson['object']['id'] = postId - messageJson['object']['url'] = postId.replace('/users/', '/@') + messageJson['object']['url'] = replaceUsersWithAt(postId) messageJson['object']['atomUri'] = postId msg = json.dumps(messageJson, ensure_ascii=False).encode('utf-8') diff --git a/person.py b/person.py index 985286d8e..742d62665 100644 --- a/person.py +++ b/person.py @@ -37,6 +37,7 @@ from roles import setRole from roles import setRolesFromList from roles import getActorRolesList from media import processMetaData +from utils import replaceUsersWithAt from utils import removeLineEndings from utils import removeDomainPort from utils import getStatusNumber @@ -702,7 +703,7 @@ def personUpgradeActor(baseDir: str, personJson: {}, # update domain/@nickname in actors cache actorCacheFilename = \ baseDir + '/accounts/cache/actors/' + \ - personJson['id'].replace('/users/', '/@').replace('/', '#') + \ + replaceUsersWithAt(personJson['id']).replace('/', '#') + \ '.json' if os.path.isfile(actorCacheFilename): saveJson(personJson, actorCacheFilename) diff --git a/pgp.py b/pgp.py index 401d002cb..345a0c5f3 100644 --- a/pgp.py +++ b/pgp.py @@ -16,6 +16,7 @@ from utils import isPGPEncrypted from utils import getFullDomain from utils import getStatusNumber from utils import localActorUrl +from utils import replaceUsersWithAt from webfinger import webfingerHandle from posts import getPersonBox from auth import createBasicAuthHeader @@ -491,7 +492,7 @@ def pgpPublicKeyUpload(baseDir: str, session, print('Actor for ' + handle + ' obtained') actor = localActorUrl(httpPrefix, nickname, domainFull) - handle = actor.replace('/users/', '/@') + handle = replaceUsersWithAt(actor) # check that this looks like the correct actor if not actorJson.get('id'): diff --git a/posts.py b/posts.py index 3593f7ed3..aa9ffde00 100644 --- a/posts.py +++ b/posts.py @@ -32,6 +32,7 @@ from webfinger import webfingerHandle from httpsig import createSignedHeader from siteactive import siteIsActive from languages import understoodPostLanguage +from utils import replaceUsersWithAt from utils import hasGroupType from utils import getBaseContentFromPost from utils import removeDomainPort @@ -1463,7 +1464,7 @@ def getPinnedPostAsJson(baseDir: str, httpPrefix: str, 'tag': [], 'to': ['https://www.w3.org/ns/activitystreams#Public'], 'type': 'Note', - 'url': actor.replace('/users/', '/@') + '/pinned' + 'url': replaceUsersWithAt(actor) + '/pinned' } return pinnedPostJson @@ -4440,7 +4441,7 @@ def sendMuteViaServer(baseDir: str, session, fromDomainFull = getFullDomain(fromDomain, fromPort) actor = localActorUrl(httpPrefix, fromNickname, fromDomainFull) - handle = actor.replace('/users/', '/@') + handle = replaceUsersWithAt(actor) newMuteJson = { "@context": "https://www.w3.org/ns/activitystreams", @@ -4516,7 +4517,7 @@ def sendUndoMuteViaServer(baseDir: str, session, fromDomainFull = getFullDomain(fromDomain, fromPort) actor = localActorUrl(httpPrefix, fromNickname, fromDomainFull) - handle = actor.replace('/users/', '/@') + handle = replaceUsersWithAt(actor) undoMuteJson = { "@context": "https://www.w3.org/ns/activitystreams", diff --git a/utils.py b/utils.py index 04ab3e8ba..795d4cadb 100644 --- a/utils.py +++ b/utils.py @@ -2907,3 +2907,14 @@ def getSharesFilesList() -> []: """Returns the possible shares files """ return ('shares', 'wanted') + + +def replaceUsersWithAt(actor: str) -> str: + """ https://domain/users/nick becomes https://domain/@nick + """ + uPaths = getUserPaths() + for path in uPaths: + if path in actor: + actor = actor.replace(path, '/@') + break + return actor diff --git a/webapp_calendar.py b/webapp_calendar.py index 81e4e65d8..26a0be727 100644 --- a/webapp_calendar.py +++ b/webapp_calendar.py @@ -22,6 +22,7 @@ from utils import getAltPath from utils import removeDomainPort from utils import acctDir from utils import localActorUrl +from utils import replaceUsersWithAt from happening import getTodaysEvents from happening import getCalendarEvents from webapp_utils import htmlHeaderWithExternalStyle @@ -175,7 +176,7 @@ def _htmlCalendarDay(personCache: {}, cssCache: {}, translate: {}, if senderName and eventDescription: # if the sender is also mentioned within the event # description then this is a reminder - senderActor2 = senderActor.replace('/users/', '/@') + senderActor2 = replaceUsersWithAt(senderActor) if senderActor not in eventDescription and \ senderActor2 not in eventDescription: eventDescription = senderName + eventDescription