mirror of https://gitlab.com/bashrc2/epicyon
Set shared item federation domains on edit profile screen
parent
50849490eb
commit
12011bfdd4
44
daemon.py
44
daemon.py
|
@ -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 mergeSharedItemTokens
|
||||
from shares import runFederatedSharesDaemon
|
||||
from shares import runFederatedSharesWatchdog
|
||||
from shares import updateSharedItemFederationToken
|
||||
|
@ -4825,6 +4826,49 @@ class PubServer(BaseHTTPRequestHandler):
|
|||
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
|
||||
if fields.get('moderators'):
|
||||
if path.startswith('/users/' +
|
||||
|
|
38
shares.py
38
shares.py
|
@ -979,7 +979,7 @@ def generateSharedItemFederationTokens(sharedItemsFederatedDomains: [],
|
|||
def updateSharedItemFederationToken(baseDir: str,
|
||||
tokenDomain: str, newToken: str,
|
||||
tokensJson: {} = None) -> {}:
|
||||
"""Updates a token for shared item federation
|
||||
"""Updates an individual token for shared item federation
|
||||
"""
|
||||
if not tokensJson:
|
||||
tokensJson = {}
|
||||
|
@ -1003,10 +1003,44 @@ def updateSharedItemFederationToken(baseDir: str,
|
|||
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,
|
||||
tokenDomain: str,
|
||||
tokensJson: {} = None) -> {}:
|
||||
"""Updates a token for shared item federation
|
||||
"""Updates an individual token for shared item federation
|
||||
"""
|
||||
if not tokensJson:
|
||||
tokensJson = {}
|
||||
|
|
17
tests.py
17
tests.py
|
@ -132,6 +132,7 @@ from shares import authorizeSharedItems
|
|||
from shares import generateSharedItemFederationTokens
|
||||
from shares import createSharedItemFederationToken
|
||||
from shares import updateSharedItemFederationToken
|
||||
from shares import mergeSharedItemTokens
|
||||
|
||||
testServerAliceRunning = False
|
||||
testServerBobRunning = False
|
||||
|
@ -3104,6 +3105,8 @@ def _testFunctions():
|
|||
for sourceFile in files:
|
||||
if not sourceFile.endswith('.py'):
|
||||
continue
|
||||
if sourceFile.startswith('.#'):
|
||||
continue
|
||||
modName = sourceFile.replace('.py', '')
|
||||
modules[modName] = {
|
||||
'functions': []
|
||||
|
@ -4300,6 +4303,20 @@ def _testAuthorizeSharedItems():
|
|||
'dog.domain', 'testToken', tokensJson)
|
||||
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():
|
||||
print('Running tests...')
|
||||
|
|
|
@ -456,5 +456,6 @@
|
|||
"Quantity": "كمية",
|
||||
"food": "غذاء",
|
||||
"Price": "السعر",
|
||||
"Currency": "عملة"
|
||||
"Currency": "عملة",
|
||||
"List of domains which can access the shared items catalog": "قائمة المجالات التي يمكن الوصول إلى كتالوج البنود المشتركة"
|
||||
}
|
||||
|
|
|
@ -456,5 +456,6 @@
|
|||
"Quantity": "Quantitat",
|
||||
"food": "menjar",
|
||||
"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"
|
||||
}
|
||||
|
|
|
@ -456,5 +456,6 @@
|
|||
"Quantity": "Symiau",
|
||||
"food": "bwyd",
|
||||
"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"
|
||||
}
|
||||
|
|
|
@ -456,5 +456,6 @@
|
|||
"Quantity": "Menge",
|
||||
"food": "lebensmittel",
|
||||
"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"
|
||||
}
|
||||
|
|
|
@ -456,5 +456,6 @@
|
|||
"Quantity": "Quantity",
|
||||
"food": "food",
|
||||
"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"
|
||||
}
|
||||
|
|
|
@ -456,5 +456,6 @@
|
|||
"Quantity": "Cantidad",
|
||||
"food": "comida",
|
||||
"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"
|
||||
}
|
||||
|
|
|
@ -456,5 +456,6 @@
|
|||
"Quantity": "Quantité",
|
||||
"food": "aliments",
|
||||
"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"
|
||||
}
|
||||
|
|
|
@ -456,5 +456,6 @@
|
|||
"Quantity": "Cainníocht",
|
||||
"food": "bia",
|
||||
"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"
|
||||
}
|
||||
|
|
|
@ -456,5 +456,6 @@
|
|||
"Quantity": "मात्रा",
|
||||
"food": "खाना",
|
||||
"Price": "कीमत",
|
||||
"Currency": "मुद्रा"
|
||||
"Currency": "मुद्रा",
|
||||
"List of domains which can access the shared items catalog": "डोमेन की सूची जो साझा आइटम कैटलॉग तक पहुंच सकती है"
|
||||
}
|
||||
|
|
|
@ -456,5 +456,6 @@
|
|||
"Quantity": "Quantità",
|
||||
"food": "cibo",
|
||||
"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"
|
||||
}
|
||||
|
|
|
@ -456,5 +456,6 @@
|
|||
"Quantity": "量",
|
||||
"food": "食物",
|
||||
"Price": "価格",
|
||||
"Currency": "通貨"
|
||||
"Currency": "通貨",
|
||||
"List of domains which can access the shared items catalog": "共有項目カタログにアクセスできるドメインのリスト"
|
||||
}
|
||||
|
|
|
@ -456,5 +456,6 @@
|
|||
"Quantity": "Jimarî",
|
||||
"food": "xûrek",
|
||||
"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î"
|
||||
}
|
||||
|
|
|
@ -452,5 +452,6 @@
|
|||
"Quantity": "Quantity",
|
||||
"food": "food",
|
||||
"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"
|
||||
}
|
||||
|
|
|
@ -456,5 +456,6 @@
|
|||
"Quantity": "Quantidade",
|
||||
"food": "comida",
|
||||
"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"
|
||||
}
|
||||
|
|
|
@ -456,5 +456,6 @@
|
|||
"Quantity": "Количество",
|
||||
"food": "еда",
|
||||
"Price": "Цена",
|
||||
"Currency": "Валюта"
|
||||
"Currency": "Валюта",
|
||||
"List of domains which can access the shared items catalog": "Список доменов, которые могут получить доступ к каталогу общих пунктов"
|
||||
}
|
||||
|
|
|
@ -456,5 +456,6 @@
|
|||
"Quantity": "Wingi",
|
||||
"food": "chakula",
|
||||
"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"
|
||||
}
|
||||
|
|
|
@ -456,5 +456,6 @@
|
|||
"Quantity": "数量",
|
||||
"food": "食物",
|
||||
"Price": "价钱",
|
||||
"Currency": "货币"
|
||||
"Currency": "货币",
|
||||
"List of domains which can access the shared items catalog": "可以访问共享项目目录的域名列表"
|
||||
}
|
||||
|
|
|
@ -1340,6 +1340,28 @@ def _htmlEditProfileGitProjects(baseDir: str, nickname: str, domain: str,
|
|||
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,
|
||||
userAgentsBlocked: str, translate: {}) -> str:
|
||||
"""Filtering and blocking section of edit profile screen
|
||||
|
@ -1957,6 +1979,10 @@ def htmlEditProfile(cssCache: {}, translate: {}, baseDir: str, path: str,
|
|||
editProfileForm += \
|
||||
_htmlEditProfileGitProjects(baseDir, nickname, domain, translate)
|
||||
|
||||
# shared items section
|
||||
editProfileForm += \
|
||||
_htmlEditProfileSharedItems(baseDir, nickname, domain, translate)
|
||||
|
||||
# Skills section
|
||||
editProfileForm += \
|
||||
_htmlEditProfileSkills(baseDir, nickname, domain, translate)
|
||||
|
|
Loading…
Reference in New Issue