From 1d7a0192170725dfc662b35c016fa1ec26da74e6 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Tue, 6 Oct 2020 19:26:08 +0100 Subject: [PATCH] Backtracking --- daemon.py | 28 +++++++-------- newswire.py | 82 ------------------------------------------- webinterface.py | 92 ------------------------------------------------- 3 files changed, 14 insertions(+), 188 deletions(-) diff --git a/daemon.py b/daemon.py index b9e32a5dd..1de1cef12 100644 --- a/daemon.py +++ b/daemon.py @@ -8688,21 +8688,21 @@ class PubServer(BaseHTTPRequestHandler): 'show announce done', 'unannounce done') - # send a follow request approval from the web interface - if authorized and '/followapprove=' in self.path and \ + # send a newswire moderation approval from the web interface + if authorized and '/newswireapprove=' in self.path and \ self.path.startswith('/users/'): - self._followApproveButton(callingDomain, self.path, - cookie, - self.server.baseDir, - self.server.httpPrefix, - self.server.domain, - self.server.domainFull, - self.server.port, - self.server.onionDomain, - self.server.i2pDomain, - GETstartTime, GETtimings, - self.server.proxyType, - self.server.debug) + self._moderationApproveButton(callingDomain, self.path, + cookie, + self.server.baseDir, + self.server.httpPrefix, + self.server.domain, + self.server.domainFull, + self.server.port, + self.server.onionDomain, + self.server.i2pDomain, + GETstartTime, GETtimings, + self.server.proxyType, + self.server.debug) return self._benchmarkGETtimings(GETstartTime, GETtimings, diff --git a/newswire.py b/newswire.py index 3a9f044f4..0b0e9ffa8 100644 --- a/newswire.py +++ b/newswire.py @@ -187,86 +187,6 @@ def isaBlogPost(postJsonObject: {}) -> bool: 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, newswire: {}, maxBlogsPerAccount: int, @@ -359,8 +279,6 @@ def addBlogsToNewswire(baseDir: str, newswire: {}, # is this account trusted? if not isTrustedByNewswire(baseDir, nickname): - updateNewswireModerationQueue(baseDir, handle, 5, - moderationDict) continue # is there a blogs timeline for this account? diff --git a/webinterface.py b/webinterface.py index 0cc17ee84..de5087003 100644 --- a/webinterface.py +++ b/webinterface.py @@ -1274,90 +1274,6 @@ def htmlEditLinks(translate: {}, baseDir: str, path: str, 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 += '
' - - resultStr += \ - '' - resultStr += \ - '' + \ - nick + ':' - - resultStr += \ - '' - resultStr += \ - '' + \ - title + '' - - resultStr += \ - '' - if '[vote:' + nickname + ':approve]' in status: - resultStr += \ - '' - else: - resultStr += \ - '' - - resultStr += \ - '' - if '[vote:' + nickname + ':deny]' in status: - resultStr += \ - '' - else: - resultStr += \ - '' - - resultStr += \ - '' - if os.path.isfile(postFilename + '.discuss'): - resultStr += \ - '' - else: - resultStr += \ - '' - resultStr += '
' - return resultStr - - def htmlEditNewswire(translate: {}, baseDir: str, path: str, domain: str, port: int, httpPrefix: str) -> str: """Shows the edit newswire screen @@ -1420,14 +1336,6 @@ def htmlEditNewswire(translate: {}, baseDir: str, path: str, editNewswireForm += \ '
' - newswireModerationFilename = baseDir + '/accounts/newswiremoderation.txt' - if os.path.isfile(newswireModerationFilename): - editNewswireForm += \ - ' ' + \ - translate['Posts to be approved'] + ':
' - editNewswireForm += \ - htmlNewswireModeration(baseDir, path, translate) + '
' - editNewswireForm += \ ' ' + \ translate['Add RSS feed links below.'] + \