mirror of https://gitlab.com/bashrc2/epicyon
Check for allowed comments
parent
1983f8935e
commit
c64a8aadc1
|
@ -1765,7 +1765,8 @@ if args.testdata:
|
||||||
False, True, False, True, None, None, useBlurhash)
|
False, True, False, True, None, None, useBlurhash)
|
||||||
createPublicPost(baseDir, nickname, domain, port, httpPrefix,
|
createPublicPost(baseDir, nickname, domain, port, httpPrefix,
|
||||||
"Getting kinda spooky around here",
|
"Getting kinda spooky around here",
|
||||||
False, True, False, True, None, None, useBlurhash, 'someone')
|
False, True, False, True, None, None,
|
||||||
|
useBlurhash, 'someone')
|
||||||
createPublicPost(baseDir, nickname, domain, port, httpPrefix,
|
createPublicPost(baseDir, nickname, domain, port, httpPrefix,
|
||||||
"And they would have gotten away with it too" +
|
"And they would have gotten away with it too" +
|
||||||
"if it wasn't for those pesky hackers",
|
"if it wasn't for those pesky hackers",
|
||||||
|
|
36
inbox.py
36
inbox.py
|
@ -1585,6 +1585,28 @@ def receiveUndoAnnounce(recentPostsCache: {},
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def jsonPostAllowsComments(postJsonObject: {}) -> bool:
|
||||||
|
"""Returns true if the given post allows comments/replies
|
||||||
|
"""
|
||||||
|
if 'commentsEnabled' in postJsonObject:
|
||||||
|
return postJsonObject['commentsEnabled']
|
||||||
|
if postJsonObject.get('object'):
|
||||||
|
if not isinstance(postJsonObject['object'], dict):
|
||||||
|
return False
|
||||||
|
if 'commentsEnabled' in postJsonObject['object']:
|
||||||
|
return postJsonObject['object']['commentsEnabled']
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def postAllowsComments(postFilename: str) -> bool:
|
||||||
|
"""Returns true if the given post allows comments/replies
|
||||||
|
"""
|
||||||
|
postJsonObject = loadJson(postFilename)
|
||||||
|
if not postJsonObject:
|
||||||
|
return False
|
||||||
|
return jsonPostAllowsComments(postJsonObject)
|
||||||
|
|
||||||
|
|
||||||
def populateReplies(baseDir: str, httpPrefix: str, domain: str,
|
def populateReplies(baseDir: str, httpPrefix: str, domain: str,
|
||||||
messageJson: {}, maxReplies: int, debug: bool) -> bool:
|
messageJson: {}, maxReplies: int, debug: bool) -> bool:
|
||||||
"""Updates the list of replies for a post on this domain if
|
"""Updates the list of replies for a post on this domain if
|
||||||
|
@ -1625,6 +1647,10 @@ def populateReplies(baseDir: str, httpPrefix: str, domain: str,
|
||||||
if debug:
|
if debug:
|
||||||
print('DEBUG: post may have expired - ' + replyTo)
|
print('DEBUG: post may have expired - ' + replyTo)
|
||||||
return False
|
return False
|
||||||
|
if not postAllowsComments(postFilename):
|
||||||
|
if debug:
|
||||||
|
print('DEBUG: post does not allow comments - ' + replyTo)
|
||||||
|
return False
|
||||||
# populate a text file containing the ids of replies
|
# populate a text file containing the ids of replies
|
||||||
postRepliesFilename = postFilename.replace('.json', '.replies')
|
postRepliesFilename = postFilename.replace('.json', '.replies')
|
||||||
messageId = messageJson['id'].replace('/activity', '')
|
messageId = messageJson['id'].replace('/activity', '')
|
||||||
|
@ -1720,6 +1746,16 @@ def validPostContent(baseDir: str, nickname: str, domain: str,
|
||||||
messageJson['object']['content']):
|
messageJson['object']['content']):
|
||||||
print('REJECT: content filtered')
|
print('REJECT: content filtered')
|
||||||
return False
|
return False
|
||||||
|
if messageJson['object'].get('inReplyTo'):
|
||||||
|
if isinstance(messageJson['object']['inReplyTo'], str):
|
||||||
|
originalPostId = messageJson['object']['inReplyTo']
|
||||||
|
postPostFilename = locatePost(baseDir, nickname, domain,
|
||||||
|
originalPostId)
|
||||||
|
if postPostFilename:
|
||||||
|
if not postAllowsComments(postPostFilename):
|
||||||
|
print('REJECT: reply to post which does not ' +
|
||||||
|
'allow comments: ' + originalPostId)
|
||||||
|
return False
|
||||||
print('ACCEPT: post content is valid')
|
print('ACCEPT: post content is valid')
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
34
tests.py
34
tests.py
|
@ -62,6 +62,7 @@ from announce import sendAnnounceViaServer
|
||||||
from media import getMediaPath
|
from media import getMediaPath
|
||||||
from media import getAttachmentMediaType
|
from media import getAttachmentMediaType
|
||||||
from delete import sendDeleteViaServer
|
from delete import sendDeleteViaServer
|
||||||
|
from inbox import jsonPostAllowsComments
|
||||||
from inbox import validInbox
|
from inbox import validInbox
|
||||||
from inbox import validInboxFilenames
|
from inbox import validInboxFilenames
|
||||||
from content import htmlReplaceQuoteMarks
|
from content import htmlReplaceQuoteMarks
|
||||||
|
@ -1981,8 +1982,41 @@ def runHtmlReplaceQuoteMarks():
|
||||||
assert result == '“hello” <a href="somesite.html">“test” html</a>'
|
assert result == '“hello” <a href="somesite.html">“test” html</a>'
|
||||||
|
|
||||||
|
|
||||||
|
def testJsonPostAllowsComments():
|
||||||
|
print('testJsonPostAllowsComments')
|
||||||
|
postJsonObject = {
|
||||||
|
"id": "123"
|
||||||
|
}
|
||||||
|
assert jsonPostAllowsComments(postJsonObject)
|
||||||
|
postJsonObject = {
|
||||||
|
"id": "123",
|
||||||
|
"commentsEnabled": False
|
||||||
|
}
|
||||||
|
assert not jsonPostAllowsComments(postJsonObject)
|
||||||
|
postJsonObject = {
|
||||||
|
"id": "123",
|
||||||
|
"commentsEnabled": True
|
||||||
|
}
|
||||||
|
assert jsonPostAllowsComments(postJsonObject)
|
||||||
|
postJsonObject = {
|
||||||
|
"id": "123",
|
||||||
|
"object": {
|
||||||
|
"commentsEnabled": True
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assert jsonPostAllowsComments(postJsonObject)
|
||||||
|
postJsonObject = {
|
||||||
|
"id": "123",
|
||||||
|
"object": {
|
||||||
|
"commentsEnabled": False
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assert not jsonPostAllowsComments(postJsonObject)
|
||||||
|
|
||||||
|
|
||||||
def runAllTests():
|
def runAllTests():
|
||||||
print('Running tests...')
|
print('Running tests...')
|
||||||
|
testJsonPostAllowsComments()
|
||||||
runHtmlReplaceQuoteMarks()
|
runHtmlReplaceQuoteMarks()
|
||||||
testDangerousMarkup()
|
testDangerousMarkup()
|
||||||
testRemoveHtml()
|
testRemoveHtml()
|
||||||
|
|
Loading…
Reference in New Issue