epicyon/webapp_person_options.py

263 lines
10 KiB
Python
Raw Normal View History

2020-11-09 22:44:03 +00:00
__filename__ = "webapp_person_options.py"
__author__ = "Bob Mottram"
__license__ = "AGPL3+"
__version__ = "1.1.0"
__maintainer__ = "Bob Mottram"
__email__ = "bob@freedombone.net"
__status__ = "Production"
import os
from shutil import copyfile
from petnames import getPetName
from person import isPersonSnoozed
from posts import isModerator
2020-12-16 11:19:16 +00:00
from utils import getFullDomain
2020-12-17 09:50:04 +00:00
from utils import getConfigParam
from utils import isDormant
from utils import removeHtml
2020-11-09 22:44:03 +00:00
from utils import getDomainFromActor
from utils import getNicknameFromActor
from blocking import isBlocked
from follow import isFollowingActor
from followingCalendar import receivingCalendarEvents
2020-11-12 17:05:38 +00:00
from webapp_utils import htmlHeaderWithExternalStyle
2020-11-09 22:44:03 +00:00
from webapp_utils import htmlFooter
from webapp_utils import getBrokenLinkSubstitute
2020-11-09 22:44:03 +00:00
2020-11-10 20:44:38 +00:00
def htmlPersonOptions(defaultTimeline: str,
cssCache: {}, translate: {}, baseDir: str,
2020-11-09 22:44:03 +00:00
domain: str, domainFull: str,
originPathStr: str,
optionsActor: str,
optionsProfileUrl: str,
optionsLink: str,
pageNumber: int,
donateUrl: str,
xmppAddress: str,
matrixAddress: str,
ssbAddress: str,
blogAddress: str,
toxAddress: str,
2020-11-29 12:50:41 +00:00
jamiAddress: str,
2020-11-09 22:44:03 +00:00
PGPpubKey: str,
PGPfingerprint: str,
emailAddress: str,
dormantMonths: int) -> str:
2020-11-09 22:44:03 +00:00
"""Show options for a person: view/follow/block/report
"""
optionsDomain, optionsPort = getDomainFromActor(optionsActor)
2020-12-16 11:19:16 +00:00
optionsDomainFull = getFullDomain(optionsDomain, optionsPort)
2020-11-09 22:44:03 +00:00
if os.path.isfile(baseDir + '/accounts/options-background-custom.jpg'):
if not os.path.isfile(baseDir + '/accounts/options-background.jpg'):
copyfile(baseDir + '/accounts/options-background.jpg',
baseDir + '/accounts/options-background.jpg')
dormant = False
2020-11-09 22:44:03 +00:00
followStr = 'Follow'
blockStr = 'Block'
nickname = None
optionsNickname = None
if originPathStr.startswith('/users/'):
nickname = originPathStr.split('/users/')[1]
if '/' in nickname:
nickname = nickname.split('/')[0]
if '?' in nickname:
nickname = nickname.split('?')[0]
followerDomain, followerPort = getDomainFromActor(optionsActor)
if isFollowingActor(baseDir, nickname, domain, optionsActor):
followStr = 'Unfollow'
dormant = \
isDormant(baseDir, nickname, domain, optionsActor,
dormantMonths)
2020-11-09 22:44:03 +00:00
optionsNickname = getNicknameFromActor(optionsActor)
2020-12-16 11:19:16 +00:00
optionsDomainFull = getFullDomain(optionsDomain, optionsPort)
2020-11-09 22:44:03 +00:00
if isBlocked(baseDir, nickname, domain,
optionsNickname, optionsDomainFull):
blockStr = 'Block'
optionsLinkStr = ''
if optionsLink:
optionsLinkStr = \
' <input type="hidden" name="postUrl" value="' + \
optionsLink + '">\n'
cssFilename = baseDir + '/epicyon-options.css'
if os.path.isfile(baseDir + '/options.css'):
cssFilename = baseDir + '/options.css'
# To snooze, or not to snooze? That is the question
snoozeButtonStr = 'Snooze'
if nickname:
if isPersonSnoozed(baseDir, nickname, domain, optionsActor):
snoozeButtonStr = 'Unsnooze'
donateStr = ''
if donateUrl:
donateStr = \
' <a href="' + donateUrl + \
'"><button class="button" name="submitDonate">' + \
translate['Donate'] + '</button></a>\n'
2020-11-12 17:05:38 +00:00
optionsStr = htmlHeaderWithExternalStyle(cssFilename)
2020-11-09 22:44:03 +00:00
optionsStr += '<br><br>\n'
optionsStr += '<div class="options">\n'
optionsStr += ' <div class="optionsAvatar">\n'
optionsStr += ' <center>\n'
optionsStr += ' <a href="' + optionsActor + '">\n'
optionsStr += ' <img loading="lazy" src="' + optionsProfileUrl + \
'" ' + getBrokenLinkSubstitute() + '/></a>\n'
2020-11-09 22:44:03 +00:00
handle = getNicknameFromActor(optionsActor) + '@' + optionsDomain
handleShown = handle
if dormant:
2020-12-13 13:43:09 +00:00
handleShown += ' 💤'
2020-11-09 22:44:03 +00:00
optionsStr += \
' <p class="optionsText">' + translate['Options for'] + \
' @' + handleShown + '</p>\n'
2020-11-09 22:44:03 +00:00
if emailAddress:
optionsStr += \
'<p class="imText">' + translate['Email'] + \
': <a href="mailto:' + \
emailAddress + '">' + removeHtml(emailAddress) + '</a></p>\n'
2020-11-09 22:44:03 +00:00
if xmppAddress:
optionsStr += \
'<p class="imText">' + translate['XMPP'] + \
': <a href="xmpp:' + removeHtml(xmppAddress) + '">' + \
2020-11-09 22:44:03 +00:00
xmppAddress + '</a></p>\n'
if matrixAddress:
optionsStr += \
'<p class="imText">' + translate['Matrix'] + ': ' + \
removeHtml(matrixAddress) + '</p>\n'
2020-11-09 22:44:03 +00:00
if ssbAddress:
optionsStr += \
'<p class="imText">SSB: ' + removeHtml(ssbAddress) + '</p>\n'
2020-11-09 22:44:03 +00:00
if blogAddress:
optionsStr += \
'<p class="imText">Blog: <a href="' + \
removeHtml(blogAddress) + '">' + \
removeHtml(blogAddress) + '</a></p>\n'
2020-11-09 22:44:03 +00:00
if toxAddress:
optionsStr += \
'<p class="imText">Tox: ' + removeHtml(toxAddress) + '</p>\n'
2020-11-29 12:50:41 +00:00
if jamiAddress:
optionsStr += \
'<p class="imText">Jami: ' + removeHtml(jamiAddress) + '</p>\n'
2020-11-09 22:44:03 +00:00
if PGPfingerprint:
optionsStr += '<p class="pgp">PGP: ' + \
removeHtml(PGPfingerprint).replace('\n', '<br>') + '</p>\n'
2020-11-09 22:44:03 +00:00
if PGPpubKey:
optionsStr += '<p class="pgp">' + \
removeHtml(PGPpubKey).replace('\n', '<br>') + '</p>\n'
2020-11-09 22:44:03 +00:00
optionsStr += ' <form method="POST" action="' + \
originPathStr + '/personoptions">\n'
optionsStr += ' <input type="hidden" name="pageNumber" value="' + \
str(pageNumber) + '">\n'
optionsStr += ' <input type="hidden" name="actor" value="' + \
optionsActor + '">\n'
optionsStr += ' <input type="hidden" name="avatarUrl" value="' + \
optionsProfileUrl + '">\n'
if optionsNickname:
handle = optionsNickname + '@' + optionsDomainFull
petname = getPetName(baseDir, nickname, domain, handle)
optionsStr += \
' ' + translate['Petname'] + ': \n' + \
' <input type="text" name="optionpetname" value="' + \
petname + '">\n' \
' <button type="submit" class="buttonsmall" ' + \
'name="submitPetname">' + \
translate['Submit'] + '</button><br>\n'
# checkbox for receiving calendar events
if isFollowingActor(baseDir, nickname, domain, optionsActor):
checkboxStr = \
' <input type="checkbox" ' + \
'class="profilecheckbox" name="onCalendar" checked> ' + \
translate['Receive calendar events from this account'] + \
'\n <button type="submit" class="buttonsmall" ' + \
'name="submitOnCalendar">' + \
translate['Submit'] + '</button><br>\n'
if not receivingCalendarEvents(baseDir, nickname, domain,
optionsNickname, optionsDomainFull):
checkboxStr = checkboxStr.replace(' checked>', '>')
optionsStr += checkboxStr
# checkbox for permission to post to newswire
if optionsDomainFull == domainFull:
2020-12-17 09:50:04 +00:00
adminNickname = getConfigParam(baseDir, 'admin')
if (nickname == adminNickname or
(isModerator(baseDir, nickname) and
not isModerator(baseDir, optionsNickname))):
2020-11-09 22:44:03 +00:00
newswireBlockedFilename = \
baseDir + '/accounts/' + \
optionsNickname + '@' + optionsDomain + '/.nonewswire'
checkboxStr = \
' <input type="checkbox" ' + \
'class="profilecheckbox" name="postsToNews" checked> ' + \
translate['Allow news posts'] + \
'\n <button type="submit" class="buttonsmall" ' + \
'name="submitPostToNews">' + \
translate['Submit'] + '</button><br>\n'
if os.path.isfile(newswireBlockedFilename):
checkboxStr = checkboxStr.replace(' checked>', '>')
optionsStr += checkboxStr
optionsStr += optionsLinkStr
2020-11-10 20:40:19 +00:00
backPath = '/'
if nickname:
2020-11-10 20:44:38 +00:00
backPath = '/users/' + nickname + '/' + defaultTimeline
2020-11-09 22:44:03 +00:00
optionsStr += \
2020-11-10 20:40:19 +00:00
' <a href="' + backPath + '"><button type="button" ' + \
'class="buttonIcon" name="submitBack">' + translate['Go Back'] + \
2020-12-16 18:04:32 +00:00
'</button></a>\n'
2020-11-09 22:44:03 +00:00
optionsStr += \
' <button type="submit" class="button" name="submitView">' + \
2020-12-16 18:04:32 +00:00
translate['View'] + '</button>\n'
2020-11-09 22:44:03 +00:00
optionsStr += donateStr
optionsStr += \
' <button type="submit" class="button" name="submit' + \
2020-12-16 18:04:32 +00:00
followStr + '">' + translate[followStr] + '</button>\n'
2020-11-09 22:44:03 +00:00
optionsStr += \
' <button type="submit" class="button" name="submit' + \
2020-12-16 18:04:32 +00:00
blockStr + '">' + translate[blockStr] + '</button>\n'
2020-11-09 22:44:03 +00:00
optionsStr += \
' <button type="submit" class="button" name="submitDM">' + \
2020-12-16 18:04:32 +00:00
translate['DM'] + '</button>\n'
2020-11-09 22:44:03 +00:00
optionsStr += \
' <button type="submit" class="button" name="submit' + \
2020-12-16 18:04:32 +00:00
snoozeButtonStr + '">' + translate[snoozeButtonStr] + '</button>\n'
2020-11-09 22:44:03 +00:00
optionsStr += \
' <button type="submit" class="button" name="submitReport">' + \
2020-12-16 18:04:32 +00:00
translate['Report'] + '</button>\n'
if isModerator(baseDir, nickname):
optionsStr += \
2020-12-16 18:24:04 +00:00
' <button type="submit" class="button" ' + \
'name="submitPersonInfo">' + \
2020-12-16 18:04:32 +00:00
translate['Info'] + '</button>\n'
2020-11-09 22:44:03 +00:00
personNotes = ''
personNotesFilename = \
baseDir + '/accounts/' + nickname + '@' + domain + \
'/notes/' + handle + '.txt'
if os.path.isfile(personNotesFilename):
with open(personNotesFilename, 'r') as fp:
personNotes = fp.read()
optionsStr += \
' <br><br>' + translate['Notes'] + ': \n'
optionsStr += ' <button type="submit" class="buttonsmall" ' + \
'name="submitPersonNotes">' + \
translate['Submit'] + '</button><br>\n'
optionsStr += \
' <textarea id="message" ' + \
'name="optionnotes" style="height:400px">' + \
personNotes + '</textarea>\n'
optionsStr += ' </form>\n'
optionsStr += '</center>\n'
optionsStr += '</div>\n'
optionsStr += '</div>\n'
optionsStr += htmlFooter()
return optionsStr