Update shared item tokens from inbox posts

main
Bob Mottram 2021-07-26 15:41:06 +01:00
parent 84ad6d9f4f
commit c194c3996b
2 changed files with 28 additions and 3 deletions

View File

@ -203,6 +203,7 @@ from webapp_welcome import htmlWelcomeScreen
from webapp_welcome import isWelcomeScreenComplete
from webapp_welcome_profile import htmlWelcomeProfile
from webapp_welcome_final import htmlWelcomeFinal
from shares import updateSharedItemFederationToken
from shares import createSharedItemFederationToken
from shares import authorizeSharedItems
from shares import generateSharedItemFederationTokens
@ -14692,6 +14693,23 @@ class PubServer(BaseHTTPRequestHandler):
self._benchmarkPOSTtimings(POSTstartTime, POSTtimings, 23)
# update the shared item federation token for the calling domain
# if it is within the permitted federation
if self.headers.get('SharesCatalog') and \
callingDomain != self.server.domain and \
callingDomain != self.server.domainFull and \
callingDomain in self.server.sharedItemsFederatedDomains:
if self.server.debug:
print('DEBUG: ' +
'POST updating shared item federation token for ' +
callingDomain)
sharedItemTokens = self.server.sharedItemFederationTokens
self.server.sharedItemFederationTokens = \
updateSharedItemFederationToken(self.server.baseDir,
callingDomain,
self.headers['SharesCatalog'],
sharedItemTokens)
if self.server.debug:
print('DEBUG: POST saving to inbox queue')
if usersInPath:

View File

@ -987,9 +987,16 @@ def updateSharedItemFederationToken(baseDir: str,
tokensJson = loadJson(tokensFilename, 1, 2)
if tokensJson is None:
tokensJson = {}
tokensJson[tokenDomain] = newToken
if baseDir:
saveJson(tokensJson, tokensFilename)
updateRequired = False
if tokensJson.get(tokenDomain):
if tokensJson[tokenDomain] != newToken:
updateRequired = True
else:
updateRequired = True
if updateRequired:
tokensJson[tokenDomain] = newToken
if baseDir:
saveJson(tokensJson, tokensFilename)
return tokensJson