Set shared item federation domains on edit profile screen

main
Bob Mottram 2021-07-26 22:01:48 +01:00
parent 50849490eb
commit 12011bfdd4
21 changed files with 157 additions and 19 deletions

View File

@ -203,6 +203,7 @@ from webapp_welcome import htmlWelcomeScreen
from webapp_welcome import isWelcomeScreenComplete from webapp_welcome import isWelcomeScreenComplete
from webapp_welcome_profile import htmlWelcomeProfile from webapp_welcome_profile import htmlWelcomeProfile
from webapp_welcome_final import htmlWelcomeFinal from webapp_welcome_final import htmlWelcomeFinal
from shares import mergeSharedItemTokens
from shares import runFederatedSharesDaemon from shares import runFederatedSharesDaemon
from shares import runFederatedSharesWatchdog from shares import runFederatedSharesWatchdog
from shares import updateSharedItemFederationToken from shares import updateSharedItemFederationToken
@ -4825,6 +4826,49 @@ class PubServer(BaseHTTPRequestHandler):
brochMode) brochMode)
setConfigParam(baseDir, "brochMode", brochMode) setConfigParam(baseDir, "brochMode", brochMode)
# shared item federation domains
siDomainUpdated = False
sharedItemsFederatedDomainsStr = \
getConfigParam(baseDir,
"sharedItemsFederatedDomains")
sharedItemsFormStr = ''
if sharedItemsFederatedDomainsStr and \
fields.get('shareDomainList'):
sharedItemsList = \
sharedItemsFederatedDomainsStr.split(',')
for sharedFederatedDomain in sharedItemsList:
sharedItemsFormStr += \
sharedFederatedDomain.strip() + '\n'
if fields.get('shareDomainList') != \
sharedItemsFormStr:
sharedItemsFormStr2 = \
sharedItemsFormStr.replace('\n', ',')
sharedItemsField = \
"sharedItemsFederatedDomains"
setConfigParam(baseDir, sharedItemsField,
sharedItemsFormStr2)
siDomainUpdated = True
else:
if not fields.get('shareDomainList') and \
sharedItemsFederatedDomainsStr:
sharedItemsField = \
"sharedItemsFederatedDomains"
setConfigParam(baseDir, sharedItemsField,
'')
siDomainUpdated = True
if siDomainUpdated:
siDomains = sharedItemsFormStr.split('\n')
siTokens = \
self.server.sharedItemFederationTokens
self.server.sharedItemsFederatedDomains = \
siDomains
self.server.sharedItemFederationTokens = \
mergeSharedItemTokens(self.server.baseDir,
self.server.domain,
siDomains,
siTokens)
# change moderators list # change moderators list
if fields.get('moderators'): if fields.get('moderators'):
if path.startswith('/users/' + if path.startswith('/users/' +

View File

@ -979,7 +979,7 @@ def generateSharedItemFederationTokens(sharedItemsFederatedDomains: [],
def updateSharedItemFederationToken(baseDir: str, def updateSharedItemFederationToken(baseDir: str,
tokenDomain: str, newToken: str, tokenDomain: str, newToken: str,
tokensJson: {} = None) -> {}: tokensJson: {} = None) -> {}:
"""Updates a token for shared item federation """Updates an individual token for shared item federation
""" """
if not tokensJson: if not tokensJson:
tokensJson = {} tokensJson = {}
@ -1003,10 +1003,44 @@ def updateSharedItemFederationToken(baseDir: str,
return tokensJson return tokensJson
def mergeSharedItemTokens(baseDir: str, domain: str,
newSharedItemsFederatedDomains: [],
tokensJson: {}) -> {}:
"""When the shared item federation domains list has changed, update
the tokens dict accordingly
"""
removals = []
changed = False
print('Test 46237')
for tokenDomain, tok in tokensJson.items():
print('tokenDomain: ' + tokenDomain)
if domain:
if tokenDomain.startswith(domain):
continue
if tokenDomain not in newSharedItemsFederatedDomains:
removals.append(tokenDomain)
print('remove ' + tokenDomain)
# remove domains no longer in the federation list
for tokenDomain in removals:
del tokensJson[tokenDomain]
print('removing ' + tokenDomain)
changed = True
# add new domains from the federation list
for tokenDomain in newSharedItemsFederatedDomains:
if tokenDomain not in tokensJson:
tokensJson[tokenDomain] = ''
changed = True
if baseDir and changed:
tokensFilename = \
baseDir + '/accounts/sharedItemsFederationTokens.json'
saveJson(tokensJson, tokensFilename)
return tokensJson
def createSharedItemFederationToken(baseDir: str, def createSharedItemFederationToken(baseDir: str,
tokenDomain: str, tokenDomain: str,
tokensJson: {} = None) -> {}: tokensJson: {} = None) -> {}:
"""Updates a token for shared item federation """Updates an individual token for shared item federation
""" """
if not tokensJson: if not tokensJson:
tokensJson = {} tokensJson = {}

View File

@ -132,6 +132,7 @@ from shares import authorizeSharedItems
from shares import generateSharedItemFederationTokens from shares import generateSharedItemFederationTokens
from shares import createSharedItemFederationToken from shares import createSharedItemFederationToken
from shares import updateSharedItemFederationToken from shares import updateSharedItemFederationToken
from shares import mergeSharedItemTokens
testServerAliceRunning = False testServerAliceRunning = False
testServerBobRunning = False testServerBobRunning = False
@ -3104,6 +3105,8 @@ def _testFunctions():
for sourceFile in files: for sourceFile in files:
if not sourceFile.endswith('.py'): if not sourceFile.endswith('.py'):
continue continue
if sourceFile.startswith('.#'):
continue
modName = sourceFile.replace('.py', '') modName = sourceFile.replace('.py', '')
modules[modName] = { modules[modName] = {
'functions': [] 'functions': []
@ -4300,6 +4303,20 @@ def _testAuthorizeSharedItems():
'dog.domain', 'testToken', tokensJson) 'dog.domain', 'testToken', tokensJson)
assert tokensJson['dog.domain'] == 'testToken' assert tokensJson['dog.domain'] == 'testToken'
# the shared item federation list changes
sharedItemsFederatedDomains = \
['possum.domain', 'cat.domain', 'birb.domain']
tokensJson = mergeSharedItemTokens(None, '',
sharedItemsFederatedDomains,
tokensJson)
assert 'dog.domain' not in tokensJson
assert 'cat.domain' in tokensJson
assert len(tokensJson['cat.domain']) >= 64
assert 'birb.domain' in tokensJson
assert 'possum.domain' in tokensJson
assert len(tokensJson['birb.domain']) == 0
assert len(tokensJson['possum.domain']) == 0
def runAllTests(): def runAllTests():
print('Running tests...') print('Running tests...')

View File

@ -456,5 +456,6 @@
"Quantity": "كمية", "Quantity": "كمية",
"food": "غذاء", "food": "غذاء",
"Price": "السعر", "Price": "السعر",
"Currency": "عملة" "Currency": "عملة",
"List of domains which can access the shared items catalog": "قائمة المجالات التي يمكن الوصول إلى كتالوج البنود المشتركة"
} }

View File

@ -456,5 +456,6 @@
"Quantity": "Quantitat", "Quantity": "Quantitat",
"food": "menjar", "food": "menjar",
"Price": "Preu", "Price": "Preu",
"Currency": "Moneda" "Currency": "Moneda",
"List of domains which can access the shared items catalog": "Llista de dominis que poden accedir al catàleg d'articles compartits"
} }

View File

@ -456,5 +456,6 @@
"Quantity": "Symiau", "Quantity": "Symiau",
"food": "bwyd", "food": "bwyd",
"Price": "Prisia", "Price": "Prisia",
"Currency": "Harian" "Currency": "Harian",
"List of domains which can access the shared items catalog": "Rhestr o barthau a all gael mynediad i'r catalog eitemau a rennir"
} }

View File

@ -456,5 +456,6 @@
"Quantity": "Menge", "Quantity": "Menge",
"food": "lebensmittel", "food": "lebensmittel",
"Price": "Preis", "Price": "Preis",
"Currency": "Währung" "Currency": "Währung",
"List of domains which can access the shared items catalog": "Liste der Domains, die auf den gemeinsam genutzten Artikelkatalog zugreifen können"
} }

View File

@ -456,5 +456,6 @@
"Quantity": "Quantity", "Quantity": "Quantity",
"food": "food", "food": "food",
"Price": "Price", "Price": "Price",
"Currency": "Currency" "Currency": "Currency",
"List of domains which can access the shared items catalog": "List of domains which can access the shared items catalog"
} }

View File

@ -456,5 +456,6 @@
"Quantity": "Cantidad", "Quantity": "Cantidad",
"food": "comida", "food": "comida",
"Price": "Precio", "Price": "Precio",
"Currency": "Divisa" "Currency": "Divisa",
"List of domains which can access the shared items catalog": "Lista de dominios que pueden acceder al catálogo de artículos compartidos"
} }

View File

@ -456,5 +456,6 @@
"Quantity": "Quantité", "Quantity": "Quantité",
"food": "aliments", "food": "aliments",
"Price": "Prix", "Price": "Prix",
"Currency": "Devise" "Currency": "Devise",
"List of domains which can access the shared items catalog": "Liste des domaines pouvant accéder au catalogue d'éléments partagés"
} }

View File

@ -456,5 +456,6 @@
"Quantity": "Cainníocht", "Quantity": "Cainníocht",
"food": "bia", "food": "bia",
"Price": "Praghas a chur ar", "Price": "Praghas a chur ar",
"Currency": "Airgeadra" "Currency": "Airgeadra",
"List of domains which can access the shared items catalog": "Liosta na bhfearann a fhéadann rochtain a fháil ar chatalóg na míreanna comhroinnte"
} }

View File

@ -456,5 +456,6 @@
"Quantity": "मात्रा", "Quantity": "मात्रा",
"food": "खाना", "food": "खाना",
"Price": "कीमत", "Price": "कीमत",
"Currency": "मुद्रा" "Currency": "मुद्रा",
"List of domains which can access the shared items catalog": "डोमेन की सूची जो साझा आइटम कैटलॉग तक पहुंच सकती है"
} }

View File

@ -456,5 +456,6 @@
"Quantity": "Quantità", "Quantity": "Quantità",
"food": "cibo", "food": "cibo",
"Price": "Prezzo", "Price": "Prezzo",
"Currency": "Moneta" "Currency": "Moneta",
"List of domains which can access the shared items catalog": "Elenco dei domini che possono accedere al catalogo articoli condivisi"
} }

View File

@ -456,5 +456,6 @@
"Quantity": "量", "Quantity": "量",
"food": "食物", "food": "食物",
"Price": "価格", "Price": "価格",
"Currency": "通貨" "Currency": "通貨",
"List of domains which can access the shared items catalog": "共有項目カタログにアクセスできるドメインのリスト"
} }

View File

@ -456,5 +456,6 @@
"Quantity": "Jimarî", "Quantity": "Jimarî",
"food": "xûrek", "food": "xûrek",
"Price": "Biha", "Price": "Biha",
"Currency": "Diravcins" "Currency": "Diravcins",
"List of domains which can access the shared items catalog": "Navnîşa domên ku dikarin bigihîjin kataloga tiştên parvekirî"
} }

View File

@ -452,5 +452,6 @@
"Quantity": "Quantity", "Quantity": "Quantity",
"food": "food", "food": "food",
"Price": "Price", "Price": "Price",
"Currency": "Currency" "Currency": "Currency",
"List of domains which can access the shared items catalog": "List of domains which can access the shared items catalog"
} }

View File

@ -456,5 +456,6 @@
"Quantity": "Quantidade", "Quantity": "Quantidade",
"food": "comida", "food": "comida",
"Price": "Preço", "Price": "Preço",
"Currency": "Moeda" "Currency": "Moeda",
"List of domains which can access the shared items catalog": "Lista de domínios que podem acessar o catálogo de itens compartilhados"
} }

View File

@ -456,5 +456,6 @@
"Quantity": "Количество", "Quantity": "Количество",
"food": "еда", "food": "еда",
"Price": "Цена", "Price": "Цена",
"Currency": "Валюта" "Currency": "Валюта",
"List of domains which can access the shared items catalog": "Список доменов, которые могут получить доступ к каталогу общих пунктов"
} }

View File

@ -456,5 +456,6 @@
"Quantity": "Wingi", "Quantity": "Wingi",
"food": "chakula", "food": "chakula",
"Price": "Bei", "Price": "Bei",
"Currency": "Fedha" "Currency": "Fedha",
"List of domains which can access the shared items catalog": "Orodha ya Domains ambayo inaweza kufikia orodha ya vitu vya pamoja"
} }

View File

@ -456,5 +456,6 @@
"Quantity": "数量", "Quantity": "数量",
"food": "食物", "food": "食物",
"Price": "价钱", "Price": "价钱",
"Currency": "货币" "Currency": "货币",
"List of domains which can access the shared items catalog": "可以访问共享项目目录的域名列表"
} }

View File

@ -1340,6 +1340,28 @@ def _htmlEditProfileGitProjects(baseDir: str, nickname: str, domain: str,
return editProfileForm return editProfileForm
def _htmlEditProfileSharedItems(baseDir: str, nickname: str, domain: str,
translate: {}) -> str:
"""shared items section of edit profile screen
"""
sharedItemsStr = ''
sharedItemsFederatedDomainsStr = \
getConfigParam(baseDir, 'sharedItemsFederatedDomains')
if sharedItemsFederatedDomainsStr:
sharedItemsFederatedDomainsList = \
sharedItemsFederatedDomainsStr.split(',')
for sharedFederatedDomain in sharedItemsFederatedDomainsList:
sharedItemsStr += sharedFederatedDomain.strip() + '\n'
editProfileForm = beginEditSection(translate['Shares'])
idx = 'List of domains which can access the shared items catalog'
editProfileForm += \
editTextArea(translate[idx], 'shareDomainList', sharedItemsStr,
200, '', False)
editProfileForm += endEditSection()
return editProfileForm
def _htmlEditProfileFiltering(baseDir: str, nickname: str, domain: str, def _htmlEditProfileFiltering(baseDir: str, nickname: str, domain: str,
userAgentsBlocked: str, translate: {}) -> str: userAgentsBlocked: str, translate: {}) -> str:
"""Filtering and blocking section of edit profile screen """Filtering and blocking section of edit profile screen
@ -1957,6 +1979,10 @@ def htmlEditProfile(cssCache: {}, translate: {}, baseDir: str, path: str,
editProfileForm += \ editProfileForm += \
_htmlEditProfileGitProjects(baseDir, nickname, domain, translate) _htmlEditProfileGitProjects(baseDir, nickname, domain, translate)
# shared items section
editProfileForm += \
_htmlEditProfileSharedItems(baseDir, nickname, domain, translate)
# Skills section # Skills section
editProfileForm += \ editProfileForm += \
_htmlEditProfileSkills(baseDir, nickname, domain, translate) _htmlEditProfileSkills(baseDir, nickname, domain, translate)