Backtracking

main
Bob Mottram 2020-10-06 19:26:08 +01:00
parent 3f38f55297
commit 1d7a019217
3 changed files with 14 additions and 188 deletions

View File

@ -8688,21 +8688,21 @@ class PubServer(BaseHTTPRequestHandler):
'show announce done', 'show announce done',
'unannounce done') 'unannounce done')
# send a follow request approval from the web interface # send a newswire moderation approval from the web interface
if authorized and '/followapprove=' in self.path and \ if authorized and '/newswireapprove=' in self.path and \
self.path.startswith('/users/'): self.path.startswith('/users/'):
self._followApproveButton(callingDomain, self.path, self._moderationApproveButton(callingDomain, self.path,
cookie, cookie,
self.server.baseDir, self.server.baseDir,
self.server.httpPrefix, self.server.httpPrefix,
self.server.domain, self.server.domain,
self.server.domainFull, self.server.domainFull,
self.server.port, self.server.port,
self.server.onionDomain, self.server.onionDomain,
self.server.i2pDomain, self.server.i2pDomain,
GETstartTime, GETtimings, GETstartTime, GETtimings,
self.server.proxyType, self.server.proxyType,
self.server.debug) self.server.debug)
return return
self._benchmarkGETtimings(GETstartTime, GETtimings, self._benchmarkGETtimings(GETstartTime, GETtimings,

View File

@ -187,86 +187,6 @@ def isaBlogPost(postJsonObject: {}) -> bool:
return False return False
def updateNewswireModerationQueue(baseDir: str, handle: str,
maxBlogsPerAccount: int,
moderationDict: {}) -> None:
"""Puts new blog posts by untrusted accounts into a moderation queue
"""
accountDir = os.path.join(baseDir + '/accounts', handle)
indexFilename = accountDir + '/tlblogs.index'
if not os.path.isfile(indexFilename):
return
nickname = handle.split('@')[0]
domain = handle.split('@')[1]
with open(indexFilename, 'r') as indexFile:
postFilename = 'start'
ctr = 0
while postFilename:
postFilename = indexFile.readline()
if postFilename:
# if this is a full path then remove the directories
if '/' in postFilename:
postFilename = postFilename.split('/')[-1]
# filename of the post without any extension or path
# This should also correspond to any index entry in
# the posts cache
postUrl = \
postFilename.replace('\n', '').replace('\r', '')
postUrl = postUrl.replace('.json', '').strip()
# read the post from file
fullPostFilename = \
locatePost(baseDir, nickname,
domain, postUrl, False)
if not fullPostFilename:
print('Unable to locate post ' + postUrl)
ctr += 1
if ctr >= maxBlogsPerAccount:
break
continue
moderationStatusFilename = fullPostFilename + '.moderate'
moderationStatusStr = ''
if not os.path.isfile(moderationStatusFilename):
# create a file used to keep track of moderation status
moderationStatusStr = '[waiting]'
statusFile = open(moderationStatusFilename, "w+")
if statusFile:
statusFile.write(moderationStatusStr)
statusFile.close()
else:
# read the moderation status file
statusFile = open(moderationStatusFilename, "r")
if statusFile:
moderationStatusStr = statusFile.read()
statusFile.close()
# if the post is still in the moderation queue
if '[accepted]' not in \
open(moderationStatusFilename).read():
if '[rejected]' not in \
open(moderationStatusFilename).read():
# load the post and add its details to the
# moderation queue
postJsonObject = None
if fullPostFilename:
postJsonObject = loadJson(fullPostFilename)
if isaBlogPost(postJsonObject):
published = postJsonObject['object']['published']
published = published.replace('T', ' ')
published = published.replace('Z', '+00:00')
moderationDict[published] = \
[postJsonObject['object']['summary'],
postJsonObject['object']['url'],
nickname, moderationStatusStr,
fullPostFilename]
ctr += 1
if ctr >= maxBlogsPerAccount:
break
def addAccountBlogsToNewswire(baseDir: str, nickname: str, domain: str, def addAccountBlogsToNewswire(baseDir: str, nickname: str, domain: str,
newswire: {}, newswire: {},
maxBlogsPerAccount: int, maxBlogsPerAccount: int,
@ -359,8 +279,6 @@ def addBlogsToNewswire(baseDir: str, newswire: {},
# is this account trusted? # is this account trusted?
if not isTrustedByNewswire(baseDir, nickname): if not isTrustedByNewswire(baseDir, nickname):
updateNewswireModerationQueue(baseDir, handle, 5,
moderationDict)
continue continue
# is there a blogs timeline for this account? # is there a blogs timeline for this account?

View File

@ -1274,90 +1274,6 @@ def htmlEditLinks(translate: {}, baseDir: str, path: str,
return editLinksForm return editLinksForm
def htmlNewswireModeration(baseDir: str, path: str, translate: {}) -> str:
"""Get a list of newswire items to be moderated
"""
if '/users/' not in path:
return ''
# load the file containing newswire posts to be moderated
newswireModerationFilename = baseDir + '/accounts/newswiremoderation.txt'
moderateJson = loadJson(newswireModerationFilename)
if not moderateJson:
return ''
# get the nickname and actor path of the moderator
nickname = path.split('/users/')[1]
if '/' in nickname:
nickname = nickname.split('/')[0]
basePath = path.split('/users/')[0] + '/users/' + nickname
resultStr = ''
# for each post to be moderated
for dateStr, item in moderateJson.items():
# details of this post
title = item[0]
url = item[1]
nick = item[2]
status = item[3]
postFilename = item[4]
postLink = postFilename.replace(baseDir + '/accounts', '')
# create the html for this post
resultStr += '<div class="container">'
resultStr += \
'<a href="/users/' + nick + '">'
resultStr += \
'<span class="followRequestHandle">' + \
nick + '</span></a>:'
resultStr += \
'<a href="' + url + '">'
resultStr += \
'<span class="followRequestHandle">' + \
title + '</span></a>'
resultStr += \
'<a href="' + basePath + \
'/newswireapprove=' + postLink + '">'
if '[vote:' + nickname + ':approve]' in status:
resultStr += \
'<button class="followApprove">' + \
translate['Approve'] + '</button></a>'
else:
resultStr += \
'<button class="followDeny">' + \
translate['Approve'] + '</button></a>'
resultStr += \
'<a href="' + basePath + \
'/newswiredeny=' + postLink + '">'
if '[vote:' + nickname + ':deny]' in status:
resultStr += \
'<button class="followApprove">' + \
translate['Deny'] + '</button></a>'
else:
resultStr += \
'<button class="followDeny">' + \
translate['Deny'] + '</button></a>'
resultStr += \
'<a href="' + basePath + \
'/newswirediscuss=' + postLink + '">'
if os.path.isfile(postFilename + '.discuss'):
resultStr += \
'<button class="followApprove">' + \
translate['Discuss'] + '</button></a>'
else:
resultStr += \
'<button class="followDeny">' + \
translate['Discuss'] + '</button></a>'
resultStr += '</div>'
return resultStr
def htmlEditNewswire(translate: {}, baseDir: str, path: str, def htmlEditNewswire(translate: {}, baseDir: str, path: str,
domain: str, port: int, httpPrefix: str) -> str: domain: str, port: int, httpPrefix: str) -> str:
"""Shows the edit newswire screen """Shows the edit newswire screen
@ -1420,14 +1336,6 @@ def htmlEditNewswire(translate: {}, baseDir: str, path: str,
editNewswireForm += \ editNewswireForm += \
'<div class="container">' '<div class="container">'
newswireModerationFilename = baseDir + '/accounts/newswiremoderation.txt'
if os.path.isfile(newswireModerationFilename):
editNewswireForm += \
' ' + \
translate['Posts to be approved'] + ':<br>'
editNewswireForm += \
htmlNewswireModeration(baseDir, path, translate) + '<br>'
editNewswireForm += \ editNewswireForm += \
' ' + \ ' ' + \
translate['Add RSS feed links below.'] + \ translate['Add RSS feed links below.'] + \