mirror of https://gitlab.com/bashrc2/epicyon
Deletion of moderation reports
parent
1254dc1052
commit
cc332f316b
|
@ -312,12 +312,12 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
outboxUndoLike(self.server.baseDir,self.server.httpPrefix, \
|
outboxUndoLike(self.server.baseDir,self.server.httpPrefix, \
|
||||||
self.postToNickname,self.server.domain,self.server.port, \
|
self.postToNickname,self.server.domain,self.server.port, \
|
||||||
messageJson,self.server.debug)
|
messageJson,self.server.debug)
|
||||||
if self.server.allowDeletion:
|
|
||||||
if self.server.debug:
|
if self.server.debug:
|
||||||
print('DEBUG: handle delete requests')
|
print('DEBUG: handle delete requests')
|
||||||
outboxDelete(self.server.baseDir,self.server.httpPrefix, \
|
outboxDelete(self.server.baseDir,self.server.httpPrefix, \
|
||||||
self.postToNickname,self.server.domain, \
|
self.postToNickname,self.server.domain, \
|
||||||
messageJson,self.server.debug)
|
messageJson,self.server.debug, \
|
||||||
|
self.server.allowDeletion)
|
||||||
if self.server.debug:
|
if self.server.debug:
|
||||||
print('DEBUG: handle block requests')
|
print('DEBUG: handle block requests')
|
||||||
outboxBlock(self.server.baseDir,self.server.httpPrefix, \
|
outboxBlock(self.server.baseDir,self.server.httpPrefix, \
|
||||||
|
@ -894,9 +894,11 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
return
|
return
|
||||||
|
|
||||||
# delete a post from the web interface icon
|
# delete a post from the web interface icon
|
||||||
if authorized and self.server.allowDeletion and '?delete=' in self.path:
|
if authorized and '?delete=' in self.path:
|
||||||
deleteUrl=self.path.split('?delete=')[1]
|
deleteUrl=self.path.split('?delete=')[1]
|
||||||
actor=self.server.httpPrefix+'://'+self.server.domainFull+self.path.split('?delete=')[0]
|
actor=self.server.httpPrefix+'://'+self.server.domainFull+self.path.split('?delete=')[0]
|
||||||
|
if self.server.allowDeletion or \
|
||||||
|
deleteUrl.startswith(actor):
|
||||||
if self.server.debug:
|
if self.server.debug:
|
||||||
print('DEBUG: deleteUrl='+deleteUrl)
|
print('DEBUG: deleteUrl='+deleteUrl)
|
||||||
print('DEBUG: actor='+actor)
|
print('DEBUG: actor='+actor)
|
||||||
|
|
13
delete.py
13
delete.py
|
@ -16,6 +16,7 @@ from utils import getNicknameFromActor
|
||||||
from utils import getDomainFromActor
|
from utils import getDomainFromActor
|
||||||
from utils import locatePost
|
from utils import locatePost
|
||||||
from utils import deletePost
|
from utils import deletePost
|
||||||
|
from utils import removeModerationPostFromIndex
|
||||||
from posts import sendSignedJson
|
from posts import sendSignedJson
|
||||||
from session import postJson
|
from session import postJson
|
||||||
from webfinger import webfingerHandle
|
from webfinger import webfingerHandle
|
||||||
|
@ -195,7 +196,8 @@ def deletePostPub(session,baseDir: str,federationList: [], \
|
||||||
|
|
||||||
def outboxDelete(baseDir: str,httpPrefix: str, \
|
def outboxDelete(baseDir: str,httpPrefix: str, \
|
||||||
nickname: str,domain: str, \
|
nickname: str,domain: str, \
|
||||||
messageJson: {},debug: bool) -> None:
|
messageJson: {},debug: bool,
|
||||||
|
allowDeletion: bool) -> None:
|
||||||
""" When a delete request is received by the outbox from c2s
|
""" When a delete request is received by the outbox from c2s
|
||||||
"""
|
"""
|
||||||
if not messageJson.get('type'):
|
if not messageJson.get('type'):
|
||||||
|
@ -216,7 +218,13 @@ def outboxDelete(baseDir: str,httpPrefix: str, \
|
||||||
return
|
return
|
||||||
if debug:
|
if debug:
|
||||||
print('DEBUG: c2s delete request arrived in outbox')
|
print('DEBUG: c2s delete request arrived in outbox')
|
||||||
|
deletePrefix=httpPrefix+'://'+domain
|
||||||
|
if not allowDeletion and \
|
||||||
|
(not messageJson['object'].startswith(deletePrefix) or \
|
||||||
|
not messageJson['actor'].startswith(deletePrefix)):
|
||||||
|
if debug:
|
||||||
|
print('DEBUG: delete not permitted from other instances')
|
||||||
|
return
|
||||||
messageId=messageJson['object'].replace('/activity','')
|
messageId=messageJson['object'].replace('/activity','')
|
||||||
if '/statuses/' not in messageId:
|
if '/statuses/' not in messageId:
|
||||||
if debug:
|
if debug:
|
||||||
|
@ -238,6 +246,7 @@ def outboxDelete(baseDir: str,httpPrefix: str, \
|
||||||
if debug:
|
if debug:
|
||||||
print("DEBUG: you can't delete a post which wasn't created by you (domain does not match)")
|
print("DEBUG: you can't delete a post which wasn't created by you (domain does not match)")
|
||||||
return
|
return
|
||||||
|
removeModerationPostFromIndex(baseDir,messageId,debug)
|
||||||
postFilename=locatePost(baseDir,deleteNickname,deleteDomain,messageId)
|
postFilename=locatePost(baseDir,deleteNickname,deleteDomain,messageId)
|
||||||
if not postFilename:
|
if not postFilename:
|
||||||
if debug:
|
if debug:
|
||||||
|
|
18
inbox.py
18
inbox.py
|
@ -22,6 +22,7 @@ from utils import domainPermitted
|
||||||
from utils import locatePost
|
from utils import locatePost
|
||||||
from utils import deletePost
|
from utils import deletePost
|
||||||
from utils import removeAttachment
|
from utils import removeAttachment
|
||||||
|
from utils import removeModerationPostFromIndex
|
||||||
from httpsig import verifyPostHeaders
|
from httpsig import verifyPostHeaders
|
||||||
from session import createSession
|
from session import createSession
|
||||||
from session import getJson
|
from session import getJson
|
||||||
|
@ -661,7 +662,7 @@ def receiveDelete(session,handle: str,baseDir: str, \
|
||||||
httpPrefix: str,domain :str,port: int, \
|
httpPrefix: str,domain :str,port: int, \
|
||||||
sendThreads: [],postLog: [],cachedWebfingers: {}, \
|
sendThreads: [],postLog: [],cachedWebfingers: {}, \
|
||||||
personCache: {},messageJson: {},federationList: [], \
|
personCache: {},messageJson: {},federationList: [], \
|
||||||
debug : bool) -> bool:
|
debug : bool,allowDeletion: bool) -> bool:
|
||||||
"""Receives a Delete activity within the POST section of HTTPServer
|
"""Receives a Delete activity within the POST section of HTTPServer
|
||||||
"""
|
"""
|
||||||
if messageJson['type']!='Delete':
|
if messageJson['type']!='Delete':
|
||||||
|
@ -680,6 +681,17 @@ def receiveDelete(session,handle: str,baseDir: str, \
|
||||||
if debug:
|
if debug:
|
||||||
print('DEBUG: '+messageJson['type']+' object is not a string')
|
print('DEBUG: '+messageJson['type']+' object is not a string')
|
||||||
return False
|
return False
|
||||||
|
domainFull=domain
|
||||||
|
if port:
|
||||||
|
if port!=80 and port!=443:
|
||||||
|
domainFull=domain+':'+str(port)
|
||||||
|
deletePrefix=httpPrefix+'://'+domainFull+'/'
|
||||||
|
if not allowDeletion and \
|
||||||
|
(not messageJson['object'].startswith(deletePrefix) or \
|
||||||
|
not messageJson['actor'].startswith(deletePrefix)):
|
||||||
|
if debug:
|
||||||
|
print('DEBUG: delete not permitted from other instances')
|
||||||
|
return False
|
||||||
if not messageJson.get('to'):
|
if not messageJson.get('to'):
|
||||||
if debug:
|
if debug:
|
||||||
print('DEBUG: '+messageJson['type']+' has no "to" list')
|
print('DEBUG: '+messageJson['type']+' has no "to" list')
|
||||||
|
@ -699,6 +711,7 @@ def receiveDelete(session,handle: str,baseDir: str, \
|
||||||
print('DEBUG: unknown recipient of like - '+handle)
|
print('DEBUG: unknown recipient of like - '+handle)
|
||||||
# if this post in the outbox of the person?
|
# if this post in the outbox of the person?
|
||||||
messageId=messageJson['object'].replace('/activity','')
|
messageId=messageJson['object'].replace('/activity','')
|
||||||
|
removeModerationPostFromIndex(baseDir,messageId,debug)
|
||||||
postFilename=locatePost(baseDir,handle.split('@')[0],handle.split('@')[1],messageId)
|
postFilename=locatePost(baseDir,handle.split('@')[0],handle.split('@')[1],messageId)
|
||||||
if not postFilename:
|
if not postFilename:
|
||||||
if debug:
|
if debug:
|
||||||
|
@ -928,7 +941,6 @@ def inboxAfterCapabilities(session,keyId: str,handle: str,messageJson: {}, \
|
||||||
print('DEBUG: Undo announce accepted from '+keyId)
|
print('DEBUG: Undo announce accepted from '+keyId)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if allowDeletion:
|
|
||||||
if receiveDelete(session,handle, \
|
if receiveDelete(session,handle, \
|
||||||
baseDir,httpPrefix, \
|
baseDir,httpPrefix, \
|
||||||
domain,port, \
|
domain,port, \
|
||||||
|
@ -937,7 +949,7 @@ def inboxAfterCapabilities(session,keyId: str,handle: str,messageJson: {}, \
|
||||||
personCache, \
|
personCache, \
|
||||||
messageJson, \
|
messageJson, \
|
||||||
federationList, \
|
federationList, \
|
||||||
debug):
|
debug,allowDeletion):
|
||||||
if debug:
|
if debug:
|
||||||
print('DEBUG: Delete accepted from '+keyId)
|
print('DEBUG: Delete accepted from '+keyId)
|
||||||
return False
|
return False
|
||||||
|
|
29
utils.py
29
utils.py
|
@ -167,6 +167,24 @@ def removeAttachment(baseDir: str,httpPrefix: str,domain: str,postJson: {}):
|
||||||
os.remove(mediaFilename)
|
os.remove(mediaFilename)
|
||||||
postJson['attachment']=[]
|
postJson['attachment']=[]
|
||||||
|
|
||||||
|
def removeModerationPostFromIndex(baseDir: str,postUrl: str,debug: bool) -> None:
|
||||||
|
"""Removes a url from the moderation index
|
||||||
|
"""
|
||||||
|
moderationIndexFile=baseDir+'/accounts/moderation.txt'
|
||||||
|
if not os.path.isfile(moderationIndexFile):
|
||||||
|
return
|
||||||
|
postId=postUrl.replace('/activity','')
|
||||||
|
if postId in open(moderationIndexFile).read():
|
||||||
|
with open(moderationIndexFile, "r") as f:
|
||||||
|
lines = f.readlines()
|
||||||
|
with open(moderationIndexFile, "w+") as f:
|
||||||
|
for line in lines:
|
||||||
|
if line.strip("\n") != postId:
|
||||||
|
f.write(line)
|
||||||
|
else:
|
||||||
|
if debug:
|
||||||
|
print('DEBUG: removed '+postId+' from moderation index')
|
||||||
|
|
||||||
def deletePost(baseDir: str,httpPrefix: str,nickname: str,domain: str,postFilename: str,debug: bool):
|
def deletePost(baseDir: str,httpPrefix: str,nickname: str,domain: str,postFilename: str,debug: bool):
|
||||||
"""Recursively deletes a post and its replies and attachments
|
"""Recursively deletes a post and its replies and attachments
|
||||||
"""
|
"""
|
||||||
|
@ -178,20 +196,11 @@ def deletePost(baseDir: str,httpPrefix: str,nickname: str,domain: str,postFilena
|
||||||
|
|
||||||
# remove from moderation index file
|
# remove from moderation index file
|
||||||
if postJsonObject.get('moderationStatus'):
|
if postJsonObject.get('moderationStatus'):
|
||||||
moderationIndexFile=baseDir+'/accounts/moderation.txt'
|
|
||||||
if os.path.isfile(moderationIndexFile):
|
|
||||||
if postJsonObject.get('object'):
|
if postJsonObject.get('object'):
|
||||||
if isinstance(postJsonObject['object'], dict):
|
if isinstance(postJsonObject['object'], dict):
|
||||||
if postJsonObject['object'].get('id'):
|
if postJsonObject['object'].get('id'):
|
||||||
# get the id of the post
|
|
||||||
postId=postJsonObject['object']['id'].replace('/activity','')
|
postId=postJsonObject['object']['id'].replace('/activity','')
|
||||||
if postId in open(moderationIndexFile).read():
|
removeModerationPostFromIndex(baseDir,postId,debug)
|
||||||
with open(moderationIndexFile, "r") as f:
|
|
||||||
lines = f.readlines()
|
|
||||||
with open(moderationIndexFile, "w+") as f:
|
|
||||||
for line in lines:
|
|
||||||
if line.strip("\n") != postId:
|
|
||||||
f.write(line)
|
|
||||||
|
|
||||||
# remove any hashtags index entries
|
# remove any hashtags index entries
|
||||||
removeHashtagIndex=False
|
removeHashtagIndex=False
|
||||||
|
|
|
@ -921,7 +921,9 @@ def individualPostAsHtml(baseDir: str, \
|
||||||
'<img src="/icons/'+likeIcon+'"/></a>'
|
'<img src="/icons/'+likeIcon+'"/></a>'
|
||||||
|
|
||||||
deleteStr=''
|
deleteStr=''
|
||||||
if allowDeletion:
|
if allowDeletion or \
|
||||||
|
('/'+fullDomain+'/' in postJsonObject['actor'] and \
|
||||||
|
postJsonObject['object']['id'].startswith(postJsonObject['actor'])):
|
||||||
if '/users/'+nickname+'/' in postJsonObject['object']['id']:
|
if '/users/'+nickname+'/' in postJsonObject['object']['id']:
|
||||||
deleteStr= \
|
deleteStr= \
|
||||||
'<a href="/users/'+nickname+'?delete='+postJsonObject['object']['id']+'" title="Delete this post">' \
|
'<a href="/users/'+nickname+'?delete='+postJsonObject['object']['id']+'" title="Delete this post">' \
|
||||||
|
|
Loading…
Reference in New Issue