List of accounts on moderator info screen

merge-requests/30/head
Bob Mottram 2020-12-20 11:00:17 +00:00
parent 99374a63dc
commit fba6679b21
4 changed files with 95 additions and 36 deletions

View File

@ -950,6 +950,14 @@ div.container {
font-size: var(--font-size); font-size: var(--font-size);
color: var(--title-color); color: var(--title-color);
} }
.accountsTable {
width: 100%;
border: 0;
}
.accountsTableCol {
width: 20%;
text-align: center;
}
.containerHeader { .containerHeader {
border: var(--border-width-header) solid var(--border-color); border: var(--border-width-header) solid var(--border-color);
background-color: var(--header-bg-color); background-color: var(--header-bg-color);
@ -1601,6 +1609,14 @@ div.container {
font-size: var(--font-size-mobile); font-size: var(--font-size-mobile);
color: var(--title-color); color: var(--title-color);
} }
.accountsTable {
width: 100%;
border: 0;
}
.accountsTableCol {
width: 20%;
text-align: center;
}
.containerHeader { .containerHeader {
border: var(--border-width-header) solid var(--border-color); border: var(--border-width-header) solid var(--border-color);
background-color: var(--header-bg-color); background-color: var(--header-bg-color);

View File

@ -7,10 +7,12 @@ __email__ = "bob@freedombone.net"
__status__ = "Production" __status__ = "Production"
import os import os
from utils import loadJson
from utils import getNicknameFromActor from utils import getNicknameFromActor
from utils import getDomainFromActor from utils import getDomainFromActor
from posts import getPublicPostInfo from posts import getPublicPostInfo
from webapp_timeline import htmlTimeline from webapp_timeline import htmlTimeline
# from webapp_utils import getPersonAvatarUrl
from webapp_utils import getContentWarningButton from webapp_utils import getContentWarningButton
from webapp_utils import htmlHeaderWithExternalStyle from webapp_utils import htmlHeaderWithExternalStyle
from webapp_utils import htmlFooter from webapp_utils import htmlFooter
@ -152,11 +154,51 @@ def htmlModerationInfo(cssCache: {}, translate: {},
'</a></h1></center><br>' '</a></h1></center><br>'
infoShown = False infoShown = False
cols = 5
infoForm += '<div class="container">\n'
infoForm += '<table class="accountsTable">\n'
infoForm += ' <colgroup>\n'
for col in range(cols):
infoForm += ' <col span="1" class="accountsTableCol">\n'
infoForm += ' </colgroup>\n'
infoForm += '<tr>\n'
col = 0
for subdir, dirs, files in os.walk(baseDir + '/accounts'):
for acct in dirs:
if '@' not in acct:
continue
if 'inbox@' in acct or 'news@' in acct:
continue
accountDir = os.path.join(baseDir + '/accounts', acct)
acctNickname = acct.split('@')[0]
actorJson = loadJson(accountDir + '.json')
if not actorJson:
continue
actor = actorJson['id']
avatarUrl = ''
if actorJson.get('icon'):
if actorJson['icon'].get('url'):
avatarUrl = actorJson['icon']['url']
acctUrl = \
'/users/' + nickname + '?options=' + actor + ';1;' + \
avatarUrl.replace('/', '-')
infoForm += '<td>\n<a href="' + acctUrl + '">'
infoForm += '<img src="' + avatarUrl + '" />'
infoForm += '<br>' + acctNickname + '</a>\n</td>\n'
col += 1
if col == cols:
# new row of accounts
infoForm += '</tr>\n<tr>\n'
break
infoForm += '</tr>\n</table>\n'
infoForm += '</div>\n'
suspendedFilename = baseDir + '/accounts/suspended.txt' suspendedFilename = baseDir + '/accounts/suspended.txt'
if os.path.isfile(suspendedFilename): if os.path.isfile(suspendedFilename):
with open(suspendedFilename, "r") as f: with open(suspendedFilename, "r") as f:
suspendedStr = f.read() suspendedStr = f.read()
infoForm += '<div class="container">' infoForm += '<div class="container">\n'
infoForm += ' <br><b>' + \ infoForm += ' <br><b>' + \
translate['Suspended accounts'] + '</b>' translate['Suspended accounts'] + '</b>'
infoForm += ' <br>' + \ infoForm += ' <br>' + \
@ -164,15 +206,15 @@ def htmlModerationInfo(cssCache: {}, translate: {},
infoForm += \ infoForm += \
' <textarea id="message" ' + \ ' <textarea id="message" ' + \
'name="suspended" style="height:200px">' + \ 'name="suspended" style="height:200px">' + \
suspendedStr + '</textarea>' suspendedStr + '</textarea>\n'
infoForm += '</div>' infoForm += '</div>\n'
infoShown = True infoShown = True
blockingFilename = baseDir + '/accounts/blocking.txt' blockingFilename = baseDir + '/accounts/blocking.txt'
if os.path.isfile(blockingFilename): if os.path.isfile(blockingFilename):
with open(blockingFilename, "r") as f: with open(blockingFilename, "r") as f:
blockedStr = f.read() blockedStr = f.read()
infoForm += '<div class="container">' infoForm += '<div class="container">\n'
infoForm += \ infoForm += \
' <br><b>' + \ ' <br><b>' + \
translate['Blocked accounts and hashtags'] + '</b>' translate['Blocked accounts and hashtags'] + '</b>'
@ -182,29 +224,29 @@ def htmlModerationInfo(cssCache: {}, translate: {},
infoForm += \ infoForm += \
' <textarea id="message" ' + \ ' <textarea id="message" ' + \
'name="blocked" style="height:700px">' + \ 'name="blocked" style="height:700px">' + \
blockedStr + '</textarea>' blockedStr + '</textarea>\n'
infoForm += '</div>' infoForm += '</div>\n'
infoShown = True infoShown = True
filtersFilename = baseDir + '/accounts/filters.txt' filtersFilename = baseDir + '/accounts/filters.txt'
if os.path.isfile(filtersFilename): if os.path.isfile(filtersFilename):
with open(filtersFilename, "r") as f: with open(filtersFilename, "r") as f:
filteredStr = f.read() filteredStr = f.read()
infoForm += '<div class="container">' infoForm += '<div class="container">\n'
infoForm += \ infoForm += \
' <br><b>' + \ ' <br><b>' + \
translate['Filtered words'] + '</b>' translate['Filtered words'] + '</b>'
infoForm += \ infoForm += \
' <textarea id="message" ' + \ ' <textarea id="message" ' + \
'name="filtered" style="height:700px">' + \ 'name="filtered" style="height:700px">' + \
filteredStr + '</textarea>' filteredStr + '</textarea>\n'
infoForm += '</div>' infoForm += '</div>\n'
infoShown = True infoShown = True
if not infoShown: if not infoShown:
infoForm += \ infoForm += \
'<center><p>' + \ '<center><p>' + \
translate[msgStr2] + \ translate[msgStr2] + \
'</p></center>' '</p></center>\n'
infoForm += htmlFooter() infoForm += htmlFooter()
return infoForm return infoForm

View File

@ -47,6 +47,7 @@ from content import getMentionsFromHtml
from content import switchWords from content import switchWords
from person import isPersonSnoozed from person import isPersonSnoozed
from announce import announcedByPerson from announce import announcedByPerson
from webapp_utils import getAvatarImageUrl
from webapp_utils import getPersonAvatarUrl from webapp_utils import getPersonAvatarUrl
from webapp_utils import updateAvatarImageCache from webapp_utils import updateAvatarImageCache
from webapp_utils import loadIndividualPostAsHtmlFromCache from webapp_utils import loadIndividualPostAsHtmlFromCache
@ -177,32 +178,6 @@ def getPostFromRecentCache(session,
return postHtml return postHtml
def getAvatarImageUrl(session,
baseDir: str, httpPrefix: str,
postActor: str, personCache: {},
avatarUrl: str, allowDownloads: bool) -> str:
"""Returns the avatar image url
"""
# get the avatar image url for the post actor
if not avatarUrl:
avatarUrl = \
getPersonAvatarUrl(baseDir, postActor, personCache,
allowDownloads)
avatarUrl = \
updateAvatarImageCache(session, baseDir, httpPrefix,
postActor, avatarUrl, personCache,
allowDownloads)
else:
updateAvatarImageCache(session, baseDir, httpPrefix,
postActor, avatarUrl, personCache,
allowDownloads)
if not avatarUrl:
avatarUrl = postActor + '/avatar.png'
return avatarUrl
def getAvatarImageHtml(showAvatarOptions: bool, def getAvatarImageHtml(showAvatarOptions: bool,
nickname: str, domainFull: str, nickname: str, domainFull: str,
avatarUrl: str, postActor: str, avatarUrl: str, postActor: str,

View File

@ -850,3 +850,29 @@ def htmlHighlightLabel(label: str, highlight: bool) -> str:
if not highlight: if not highlight:
return label return label
return '*' + str(label) + '*' return '*' + str(label) + '*'
def getAvatarImageUrl(session,
baseDir: str, httpPrefix: str,
postActor: str, personCache: {},
avatarUrl: str, allowDownloads: bool) -> str:
"""Returns the avatar image url
"""
# get the avatar image url for the post actor
if not avatarUrl:
avatarUrl = \
getPersonAvatarUrl(baseDir, postActor, personCache,
allowDownloads)
avatarUrl = \
updateAvatarImageCache(session, baseDir, httpPrefix,
postActor, avatarUrl, personCache,
allowDownloads)
else:
updateAvatarImageCache(session, baseDir, httpPrefix,
postActor, avatarUrl, personCache,
allowDownloads)
if not avatarUrl:
avatarUrl = postActor + '/avatar.png'
return avatarUrl