Edit profile function for instance settings

main
Bob Mottram 2021-06-27 19:46:21 +01:00
parent 800d927d5b
commit 599cba6409
1 changed files with 249 additions and 230 deletions

View File

@ -1080,213 +1080,15 @@ def _htmlEditProfileGraphicDesign(baseDir: str, translate: {}) -> str:
return graphicsStr return graphicsStr
def htmlEditProfile(cssCache: {}, translate: {}, baseDir: str, path: str, def _htmlEditProfileInstance(baseDir: str, translate: {},
domain: str, port: int, httpPrefix: str,
defaultTimeline: str, theme: str,
peertubeInstances: [], peertubeInstances: [],
textModeBanner: str, city: str, mediaInstanceStr: str,
accessKeys: {}) -> str: blogsInstanceStr: str,
"""Shows the edit profile screen newsInstanceStr: str) -> (str, str, str):
"""Edit profile instance settings
""" """
imageFormats = getImageFormats() imageFormats = getImageFormats()
path = path.replace('/inbox', '').replace('/outbox', '')
path = path.replace('/shares', '')
nickname = getNicknameFromActor(path)
if not nickname:
return ''
domainFull = getFullDomain(domain, port)
actorFilename = \
baseDir + '/accounts/' + nickname + '@' + domain + '.json'
if not os.path.isfile(actorFilename):
return ''
# filename of the banner shown at the top
bannerFile, bannerFilename = \
getBannerFile(baseDir, nickname, domain, theme)
displayNickname = nickname
isBot = isGroup = followDMs = removeTwitter = ''
notifyLikes = hideLikeButton = mediaInstanceStr = ''
blogsInstanceStr = newsInstanceStr = movedTo = ''
bioStr = donateUrl = emailAddress = PGPpubKey = ''
PGPfingerprint = xmppAddress = matrixAddress = ''
ssbAddress = blogAddress = toxAddress = jamiAddress = ''
cwtchAddress = briarAddress = manuallyApprovesFollowers = ''
actorJson = loadJson(actorFilename)
if actorJson:
if actorJson.get('movedTo'):
movedTo = actorJson['movedTo']
donateUrl = getDonationUrl(actorJson)
xmppAddress = getXmppAddress(actorJson)
matrixAddress = getMatrixAddress(actorJson)
ssbAddress = getSSBAddress(actorJson)
blogAddress = getBlogAddress(actorJson)
toxAddress = getToxAddress(actorJson)
briarAddress = getBriarAddress(actorJson)
jamiAddress = getJamiAddress(actorJson)
cwtchAddress = getCwtchAddress(actorJson)
emailAddress = getEmailAddress(actorJson)
PGPpubKey = getPGPpubKey(actorJson)
PGPfingerprint = getPGPfingerprint(actorJson)
if actorJson.get('name'):
if not isFiltered(baseDir, nickname, domain, actorJson['name']):
displayNickname = actorJson['name']
if actorJson.get('summary'):
bioStr = \
actorJson['summary'].replace('<p>', '').replace('</p>', '')
if isFiltered(baseDir, nickname, domain, bioStr):
bioStr = ''
if actorJson.get('manuallyApprovesFollowers'):
if actorJson['manuallyApprovesFollowers']:
manuallyApprovesFollowers = 'checked'
else:
manuallyApprovesFollowers = ''
if actorJson.get('type'):
if actorJson['type'] == 'Service':
isBot = 'checked'
isGroup = ''
elif actorJson['type'] == 'Group':
isGroup = 'checked'
isBot = ''
if os.path.isfile(baseDir + '/accounts/' +
nickname + '@' + domain + '/.followDMs'):
followDMs = 'checked'
if os.path.isfile(baseDir + '/accounts/' +
nickname + '@' + domain + '/.removeTwitter'):
removeTwitter = 'checked'
if os.path.isfile(baseDir + '/accounts/' +
nickname + '@' + domain + '/.notifyLikes'):
notifyLikes = 'checked'
if os.path.isfile(baseDir + '/accounts/' +
nickname + '@' + domain + '/.hideLikeButton'):
hideLikeButton = 'checked'
mediaInstance = getConfigParam(baseDir, "mediaInstance")
if mediaInstance:
if mediaInstance is True:
mediaInstanceStr = 'checked'
blogsInstanceStr = newsInstanceStr = ''
newsInstance = getConfigParam(baseDir, "newsInstance")
if newsInstance:
if newsInstance is True:
newsInstanceStr = 'checked'
blogsInstanceStr = mediaInstanceStr = ''
blogsInstance = getConfigParam(baseDir, "blogsInstance")
if blogsInstance:
if blogsInstance is True:
blogsInstanceStr = 'checked'
mediaInstanceStr = newsInstanceStr = ''
filterStr = ''
filterFilename = \
baseDir + '/accounts/' + nickname + '@' + domain + '/filters.txt'
if os.path.isfile(filterFilename):
with open(filterFilename, 'r') as filterfile:
filterStr = filterfile.read()
switchStr = ''
switchFilename = \
baseDir + '/accounts/' + \
nickname + '@' + domain + '/replacewords.txt'
if os.path.isfile(switchFilename):
with open(switchFilename, 'r') as switchfile:
switchStr = switchfile.read()
autoTags = ''
autoTagsFilename = \
baseDir + '/accounts/' + \
nickname + '@' + domain + '/autotags.txt'
if os.path.isfile(autoTagsFilename):
with open(autoTagsFilename, 'r') as autoTagsFile:
autoTags = autoTagsFile.read()
autoCW = ''
autoCWFilename = \
baseDir + '/accounts/' + \
nickname + '@' + domain + '/autocw.txt'
if os.path.isfile(autoCWFilename):
with open(autoCWFilename, 'r') as autoCWFile:
autoCW = autoCWFile.read()
blockedStr = ''
blockedFilename = \
baseDir + '/accounts/' + \
nickname + '@' + domain + '/blocking.txt'
if os.path.isfile(blockedFilename):
with open(blockedFilename, 'r') as blockedfile:
blockedStr = blockedfile.read()
dmAllowedInstancesStr = ''
dmAllowedInstancesFilename = \
baseDir + '/accounts/' + \
nickname + '@' + domain + '/dmAllowedInstances.txt'
if os.path.isfile(dmAllowedInstancesFilename):
with open(dmAllowedInstancesFilename, 'r') as dmAllowedInstancesFile:
dmAllowedInstancesStr = dmAllowedInstancesFile.read()
allowedInstancesStr = ''
allowedInstancesFilename = \
baseDir + '/accounts/' + \
nickname + '@' + domain + '/allowedinstances.txt'
if os.path.isfile(allowedInstancesFilename):
with open(allowedInstancesFilename, 'r') as allowedInstancesFile:
allowedInstancesStr = allowedInstancesFile.read()
gitProjectsStr = ''
gitProjectsFilename = \
baseDir + '/accounts/' + \
nickname + '@' + domain + '/gitprojects.txt'
if os.path.isfile(gitProjectsFilename):
with open(gitProjectsFilename, 'r') as gitProjectsFile:
gitProjectsStr = gitProjectsFile.read()
skills = getSkills(baseDir, nickname, domain)
skillsStr = ''
skillCtr = 1
if skills:
for skillDesc, skillValue in skills.items():
if isFiltered(baseDir, nickname, domain, skillDesc):
continue
skillsStr += \
'<p><input type="text" placeholder="' + translate['Skill'] + \
' ' + str(skillCtr) + '" name="skillName' + str(skillCtr) + \
'" value="' + skillDesc + '" style="width:40%">'
skillsStr += \
'<input type="range" min="1" max="100" ' + \
'class="slider" name="skillValue' + \
str(skillCtr) + '" value="' + str(skillValue) + '"></p>'
skillCtr += 1
skillsStr += \
'<p><input type="text" placeholder="Skill ' + str(skillCtr) + \
'" name="skillName' + str(skillCtr) + \
'" value="" style="width:40%">'
skillsStr += \
'<input type="range" min="1" max="100" ' + \
'class="slider" name="skillValue' + \
str(skillCtr) + '" value="50"></p>'
skillsStr += ' </div></details>\n'
cssFilename = baseDir + '/epicyon-profile.css'
if os.path.isfile(baseDir + '/epicyon.css'):
cssFilename = baseDir + '/epicyon.css'
instanceStr = ''
roleAssignStr = ''
peertubeStr = ''
adminNickname = getConfigParam(baseDir, 'admin')
if isArtist(baseDir, nickname) or \
path.startswith('/users/' + str(adminNickname) + '/'):
graphicsStr = _htmlEditProfileGraphicDesign(baseDir, translate)
if adminNickname:
if path.startswith('/users/' + adminNickname + '/'):
# Instance details section # Instance details section
instanceDescription = \ instanceDescription = \
getConfigParam(baseDir, 'instanceDescription') getConfigParam(baseDir, 'instanceDescription')
@ -1518,6 +1320,223 @@ def htmlEditProfile(cssCache: {}, translate: {}, baseDir: str, path: str,
YTReplacementDomain + '">\n' YTReplacementDomain + '">\n'
peertubeStr += ' </div></details>\n' peertubeStr += ' </div></details>\n'
return instanceStr, roleAssignStr, peertubeStr
def htmlEditProfile(cssCache: {}, translate: {}, baseDir: str, path: str,
domain: str, port: int, httpPrefix: str,
defaultTimeline: str, theme: str,
peertubeInstances: [],
textModeBanner: str, city: str,
accessKeys: {}) -> str:
"""Shows the edit profile screen
"""
imageFormats = getImageFormats()
path = path.replace('/inbox', '').replace('/outbox', '')
path = path.replace('/shares', '')
nickname = getNicknameFromActor(path)
if not nickname:
return ''
domainFull = getFullDomain(domain, port)
actorFilename = \
baseDir + '/accounts/' + nickname + '@' + domain + '.json'
if not os.path.isfile(actorFilename):
return ''
# filename of the banner shown at the top
bannerFile, bannerFilename = \
getBannerFile(baseDir, nickname, domain, theme)
displayNickname = nickname
isBot = isGroup = followDMs = removeTwitter = ''
notifyLikes = hideLikeButton = mediaInstanceStr = ''
blogsInstanceStr = newsInstanceStr = movedTo = ''
bioStr = donateUrl = emailAddress = PGPpubKey = ''
PGPfingerprint = xmppAddress = matrixAddress = ''
ssbAddress = blogAddress = toxAddress = jamiAddress = ''
cwtchAddress = briarAddress = manuallyApprovesFollowers = ''
actorJson = loadJson(actorFilename)
if actorJson:
if actorJson.get('movedTo'):
movedTo = actorJson['movedTo']
donateUrl = getDonationUrl(actorJson)
xmppAddress = getXmppAddress(actorJson)
matrixAddress = getMatrixAddress(actorJson)
ssbAddress = getSSBAddress(actorJson)
blogAddress = getBlogAddress(actorJson)
toxAddress = getToxAddress(actorJson)
briarAddress = getBriarAddress(actorJson)
jamiAddress = getJamiAddress(actorJson)
cwtchAddress = getCwtchAddress(actorJson)
emailAddress = getEmailAddress(actorJson)
PGPpubKey = getPGPpubKey(actorJson)
PGPfingerprint = getPGPfingerprint(actorJson)
if actorJson.get('name'):
if not isFiltered(baseDir, nickname, domain, actorJson['name']):
displayNickname = actorJson['name']
if actorJson.get('summary'):
bioStr = \
actorJson['summary'].replace('<p>', '').replace('</p>', '')
if isFiltered(baseDir, nickname, domain, bioStr):
bioStr = ''
if actorJson.get('manuallyApprovesFollowers'):
if actorJson['manuallyApprovesFollowers']:
manuallyApprovesFollowers = 'checked'
else:
manuallyApprovesFollowers = ''
if actorJson.get('type'):
if actorJson['type'] == 'Service':
isBot = 'checked'
isGroup = ''
elif actorJson['type'] == 'Group':
isGroup = 'checked'
isBot = ''
if os.path.isfile(baseDir + '/accounts/' +
nickname + '@' + domain + '/.followDMs'):
followDMs = 'checked'
if os.path.isfile(baseDir + '/accounts/' +
nickname + '@' + domain + '/.removeTwitter'):
removeTwitter = 'checked'
if os.path.isfile(baseDir + '/accounts/' +
nickname + '@' + domain + '/.notifyLikes'):
notifyLikes = 'checked'
if os.path.isfile(baseDir + '/accounts/' +
nickname + '@' + domain + '/.hideLikeButton'):
hideLikeButton = 'checked'
mediaInstance = getConfigParam(baseDir, "mediaInstance")
if mediaInstance:
if mediaInstance is True:
mediaInstanceStr = 'checked'
blogsInstanceStr = newsInstanceStr = ''
newsInstance = getConfigParam(baseDir, "newsInstance")
if newsInstance:
if newsInstance is True:
newsInstanceStr = 'checked'
blogsInstanceStr = mediaInstanceStr = ''
blogsInstance = getConfigParam(baseDir, "blogsInstance")
if blogsInstance:
if blogsInstance is True:
blogsInstanceStr = 'checked'
mediaInstanceStr = newsInstanceStr = ''
filterStr = ''
filterFilename = \
baseDir + '/accounts/' + nickname + '@' + domain + '/filters.txt'
if os.path.isfile(filterFilename):
with open(filterFilename, 'r') as filterfile:
filterStr = filterfile.read()
switchStr = ''
switchFilename = \
baseDir + '/accounts/' + \
nickname + '@' + domain + '/replacewords.txt'
if os.path.isfile(switchFilename):
with open(switchFilename, 'r') as switchfile:
switchStr = switchfile.read()
autoTags = ''
autoTagsFilename = \
baseDir + '/accounts/' + \
nickname + '@' + domain + '/autotags.txt'
if os.path.isfile(autoTagsFilename):
with open(autoTagsFilename, 'r') as autoTagsFile:
autoTags = autoTagsFile.read()
autoCW = ''
autoCWFilename = \
baseDir + '/accounts/' + \
nickname + '@' + domain + '/autocw.txt'
if os.path.isfile(autoCWFilename):
with open(autoCWFilename, 'r') as autoCWFile:
autoCW = autoCWFile.read()
blockedStr = ''
blockedFilename = \
baseDir + '/accounts/' + \
nickname + '@' + domain + '/blocking.txt'
if os.path.isfile(blockedFilename):
with open(blockedFilename, 'r') as blockedfile:
blockedStr = blockedfile.read()
dmAllowedInstancesStr = ''
dmAllowedInstancesFilename = \
baseDir + '/accounts/' + \
nickname + '@' + domain + '/dmAllowedInstances.txt'
if os.path.isfile(dmAllowedInstancesFilename):
with open(dmAllowedInstancesFilename, 'r') as dmAllowedInstancesFile:
dmAllowedInstancesStr = dmAllowedInstancesFile.read()
allowedInstancesStr = ''
allowedInstancesFilename = \
baseDir + '/accounts/' + \
nickname + '@' + domain + '/allowedinstances.txt'
if os.path.isfile(allowedInstancesFilename):
with open(allowedInstancesFilename, 'r') as allowedInstancesFile:
allowedInstancesStr = allowedInstancesFile.read()
gitProjectsStr = ''
gitProjectsFilename = \
baseDir + '/accounts/' + \
nickname + '@' + domain + '/gitprojects.txt'
if os.path.isfile(gitProjectsFilename):
with open(gitProjectsFilename, 'r') as gitProjectsFile:
gitProjectsStr = gitProjectsFile.read()
skills = getSkills(baseDir, nickname, domain)
skillsStr = ''
skillCtr = 1
if skills:
for skillDesc, skillValue in skills.items():
if isFiltered(baseDir, nickname, domain, skillDesc):
continue
skillsStr += \
'<p><input type="text" placeholder="' + translate['Skill'] + \
' ' + str(skillCtr) + '" name="skillName' + str(skillCtr) + \
'" value="' + skillDesc + '" style="width:40%">'
skillsStr += \
'<input type="range" min="1" max="100" ' + \
'class="slider" name="skillValue' + \
str(skillCtr) + '" value="' + str(skillValue) + '"></p>'
skillCtr += 1
skillsStr += \
'<p><input type="text" placeholder="Skill ' + str(skillCtr) + \
'" name="skillName' + str(skillCtr) + \
'" value="" style="width:40%">'
skillsStr += \
'<input type="range" min="1" max="100" ' + \
'class="slider" name="skillValue' + \
str(skillCtr) + '" value="50"></p>'
skillsStr += ' </div></details>\n'
cssFilename = baseDir + '/epicyon-profile.css'
if os.path.isfile(baseDir + '/epicyon.css'):
cssFilename = baseDir + '/epicyon.css'
instanceStr = ''
roleAssignStr = ''
peertubeStr = ''
adminNickname = getConfigParam(baseDir, 'admin')
if isArtist(baseDir, nickname) or \
path.startswith('/users/' + str(adminNickname) + '/'):
graphicsStr = _htmlEditProfileGraphicDesign(baseDir, translate)
if adminNickname:
if path.startswith('/users/' + adminNickname + '/'):
instanceStr, roleAssignStr, peertubeStr = \
_htmlEditProfileInstance(baseDir, translate,
peertubeInstances,
mediaInstanceStr,
blogsInstanceStr,
newsInstanceStr)
instanceTitle = \ instanceTitle = \
getConfigParam(baseDir, 'instanceTitle') getConfigParam(baseDir, 'instanceTitle')
editProfileForm = htmlHeaderWithExternalStyle(cssFilename, instanceTitle) editProfileForm = htmlHeaderWithExternalStyle(cssFilename, instanceTitle)