mirror of https://gitlab.com/bashrc2/epicyon
Only prevent remote DM deletions during archive
parent
ec82a20c2f
commit
ac8b86059f
10
daemon.py
10
daemon.py
|
@ -2363,7 +2363,8 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
nickname, domain,
|
nickname, domain,
|
||||||
post_filename,
|
post_filename,
|
||||||
debug,
|
debug,
|
||||||
self.server.recent_posts_cache)
|
self.server.recent_posts_cache,
|
||||||
|
True)
|
||||||
if nickname != 'news':
|
if nickname != 'news':
|
||||||
# if this is a local blog post then also remove it
|
# if this is a local blog post then also remove it
|
||||||
# from the news actor
|
# from the news actor
|
||||||
|
@ -2379,7 +2380,8 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
'news', domain,
|
'news', domain,
|
||||||
post_filename,
|
post_filename,
|
||||||
debug,
|
debug,
|
||||||
self.server.recent_posts_cache)
|
self.server.recent_posts_cache,
|
||||||
|
True)
|
||||||
|
|
||||||
self._redirect_headers(actor_str + '/moderation',
|
self._redirect_headers(actor_str + '/moderation',
|
||||||
cookie, calling_domain)
|
cookie, calling_domain)
|
||||||
|
@ -8655,7 +8657,7 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
if self.server.iconsCache.get('repeat_inactive.png'):
|
if self.server.iconsCache.get('repeat_inactive.png'):
|
||||||
del self.server.iconsCache['repeat_inactive.png']
|
del self.server.iconsCache['repeat_inactive.png']
|
||||||
|
|
||||||
# delete the announce post
|
# delete the announce post
|
||||||
if '?unannounce=' in path:
|
if '?unannounce=' in path:
|
||||||
announce_url = path.split('?unannounce=')[1]
|
announce_url = path.split('?unannounce=')[1]
|
||||||
if '?' in announce_url:
|
if '?' in announce_url:
|
||||||
|
@ -8669,7 +8671,7 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
if post_filename:
|
if post_filename:
|
||||||
delete_post(base_dir, http_prefix,
|
delete_post(base_dir, http_prefix,
|
||||||
nickname, domain, post_filename,
|
nickname, domain, post_filename,
|
||||||
debug, recent_posts_cache)
|
debug, recent_posts_cache, True)
|
||||||
|
|
||||||
self._post_to_outbox(new_undo_announce,
|
self._post_to_outbox(new_undo_announce,
|
||||||
self.server.project_version,
|
self.server.project_version,
|
||||||
|
|
|
@ -170,7 +170,7 @@ def outbox_delete(base_dir: str, http_prefix: str,
|
||||||
print(message_id)
|
print(message_id)
|
||||||
return True
|
return True
|
||||||
delete_post(base_dir, http_prefix, delete_nickname, delete_domain,
|
delete_post(base_dir, http_prefix, delete_nickname, delete_domain,
|
||||||
post_filename, debug, recent_posts_cache)
|
post_filename, debug, recent_posts_cache, True)
|
||||||
if debug:
|
if debug:
|
||||||
print('DEBUG: post deleted via c2s - ' + post_filename)
|
print('DEBUG: post deleted via c2s - ' + post_filename)
|
||||||
|
|
||||||
|
|
|
@ -1276,7 +1276,7 @@ def dav_delete_response(base_dir: str, nickname: str, domain: str,
|
||||||
token_post_id)
|
token_post_id)
|
||||||
delete_post(base_dir, http_prefix,
|
delete_post(base_dir, http_prefix,
|
||||||
nickname, domain, post_filename,
|
nickname, domain, post_filename,
|
||||||
debug, recent_posts_cache)
|
debug, recent_posts_cache, True)
|
||||||
return 'Ok'
|
return 'Ok'
|
||||||
|
|
||||||
|
|
||||||
|
|
6
inbox.py
6
inbox.py
|
@ -2058,7 +2058,7 @@ def _receive_delete(session, handle: str, is_group: bool, base_dir: str,
|
||||||
return True
|
return True
|
||||||
delete_post(base_dir, http_prefix, handle_nickname,
|
delete_post(base_dir, http_prefix, handle_nickname,
|
||||||
handle_domain, post_filename, debug,
|
handle_domain, post_filename, debug,
|
||||||
recent_posts_cache)
|
recent_posts_cache, True)
|
||||||
if debug:
|
if debug:
|
||||||
print('DEBUG: post deleted - ' + post_filename)
|
print('DEBUG: post deleted - ' + post_filename)
|
||||||
|
|
||||||
|
@ -2069,7 +2069,7 @@ def _receive_delete(session, handle: str, is_group: bool, base_dir: str,
|
||||||
if post_filename:
|
if post_filename:
|
||||||
delete_post(base_dir, http_prefix, 'news',
|
delete_post(base_dir, http_prefix, 'news',
|
||||||
handle_domain, post_filename, debug,
|
handle_domain, post_filename, debug,
|
||||||
recent_posts_cache)
|
recent_posts_cache, True)
|
||||||
if debug:
|
if debug:
|
||||||
print('DEBUG: blog post deleted - ' + post_filename)
|
print('DEBUG: blog post deleted - ' + post_filename)
|
||||||
return True
|
return True
|
||||||
|
@ -4094,7 +4094,7 @@ def _inbox_after_initial(server, inbox_start_time,
|
||||||
if edited_filename != destination_filename:
|
if edited_filename != destination_filename:
|
||||||
delete_post(base_dir, http_prefix,
|
delete_post(base_dir, http_prefix,
|
||||||
nickname, domain, edited_filename,
|
nickname, domain, edited_filename,
|
||||||
debug, recent_posts_cache)
|
debug, recent_posts_cache, True)
|
||||||
|
|
||||||
# update the indexes for different timelines
|
# update the indexes for different timelines
|
||||||
for boxname in update_index_list:
|
for boxname in update_index_list:
|
||||||
|
|
2
posts.py
2
posts.py
|
@ -4294,7 +4294,7 @@ def archive_posts_for_person(http_prefix: str, nickname: str, domain: str,
|
||||||
'.json.' + ext))
|
'.json.' + ext))
|
||||||
else:
|
else:
|
||||||
delete_post(base_dir, http_prefix, nickname, domain,
|
delete_post(base_dir, http_prefix, nickname, domain,
|
||||||
file_path, False, recent_posts_cache)
|
file_path, False, recent_posts_cache, False)
|
||||||
|
|
||||||
# remove cached html posts
|
# remove cached html posts
|
||||||
post_cache_filename = \
|
post_cache_filename = \
|
||||||
|
|
17
tests.py
17
tests.py
|
@ -3393,11 +3393,14 @@ def test_client_to_server(base_dir: str):
|
||||||
|
|
||||||
inbox_path = bob_dir + '/accounts/bob@' + bob_domain + '/inbox'
|
inbox_path = bob_dir + '/accounts/bob@' + bob_domain + '/inbox'
|
||||||
outbox_path = alice_dir + '/accounts/alice@' + alice_domain + '/outbox'
|
outbox_path = alice_dir + '/accounts/alice@' + alice_domain + '/outbox'
|
||||||
posts_before = \
|
bob_posts_before = \
|
||||||
len([name for name in os.listdir(inbox_path)
|
len([name for name in os.listdir(inbox_path)
|
||||||
if os.path.isfile(os.path.join(inbox_path, name))])
|
if os.path.isfile(os.path.join(inbox_path, name))])
|
||||||
|
alice_posts_before = \
|
||||||
|
len([name for name in os.listdir(outbox_path)
|
||||||
|
if os.path.isfile(os.path.join(outbox_path, name))])
|
||||||
print('\n\nEVENT: Alice deletes her post: ' + outbox_post_id + ' ' +
|
print('\n\nEVENT: Alice deletes her post: ' + outbox_post_id + ' ' +
|
||||||
str(posts_before))
|
str(alice_posts_before))
|
||||||
password = 'alicepass'
|
password = 'alicepass'
|
||||||
send_delete_via_server(alice_dir, session_alice, 'alice', password,
|
send_delete_via_server(alice_dir, session_alice, 'alice', password,
|
||||||
alice_domain, alice_port,
|
alice_domain, alice_port,
|
||||||
|
@ -3408,14 +3411,18 @@ def test_client_to_server(base_dir: str):
|
||||||
if os.path.isdir(inbox_path):
|
if os.path.isdir(inbox_path):
|
||||||
test = len([name for name in os.listdir(inbox_path)
|
test = len([name for name in os.listdir(inbox_path)
|
||||||
if os.path.isfile(os.path.join(inbox_path, name))])
|
if os.path.isfile(os.path.join(inbox_path, name))])
|
||||||
if test == posts_before-1:
|
if test == bob_posts_before-1:
|
||||||
break
|
break
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
test = len([name for name in os.listdir(inbox_path)
|
test = len([name for name in os.listdir(inbox_path)
|
||||||
if os.path.isfile(os.path.join(inbox_path, name))])
|
if os.path.isfile(os.path.join(inbox_path, name))])
|
||||||
assert test == posts_before - 1
|
assert test == bob_posts_before - 1
|
||||||
print(">>> post deleted from Alice's outbox and Bob's inbox")
|
print(">>> post was deleted from Bob's inbox")
|
||||||
|
# test = len([name for name in os.listdir(outbox_path)
|
||||||
|
# if os.path.isfile(os.path.join(outbox_path, name))])
|
||||||
|
# assert test == alice_posts_before - 1
|
||||||
|
# print(">>> post deleted from Alice's outbox")
|
||||||
assert valid_inbox(bob_dir, 'bob', bob_domain)
|
assert valid_inbox(bob_dir, 'bob', bob_domain)
|
||||||
assert valid_inbox_filenames(bob_dir, 'bob', bob_domain,
|
assert valid_inbox_filenames(bob_dir, 'bob', bob_domain,
|
||||||
alice_domain, alice_port)
|
alice_domain, alice_port)
|
||||||
|
|
20
utils.py
20
utils.py
|
@ -1619,7 +1619,8 @@ def _is_reply_to_blog_post(base_dir: str, nickname: str, domain: str,
|
||||||
|
|
||||||
def _delete_post_remove_replies(base_dir: str, nickname: str, domain: str,
|
def _delete_post_remove_replies(base_dir: str, nickname: str, domain: str,
|
||||||
http_prefix: str, post_filename: str,
|
http_prefix: str, post_filename: str,
|
||||||
recent_posts_cache: {}, debug: bool) -> None:
|
recent_posts_cache: {}, debug: bool,
|
||||||
|
manual: bool) -> None:
|
||||||
"""Removes replies when deleting a post
|
"""Removes replies when deleting a post
|
||||||
"""
|
"""
|
||||||
replies_filename = post_filename.replace('.json', '.replies')
|
replies_filename = post_filename.replace('.json', '.replies')
|
||||||
|
@ -1635,7 +1636,7 @@ def _delete_post_remove_replies(base_dir: str, nickname: str, domain: str,
|
||||||
if os.path.isfile(reply_file):
|
if os.path.isfile(reply_file):
|
||||||
delete_post(base_dir, http_prefix,
|
delete_post(base_dir, http_prefix,
|
||||||
nickname, domain, reply_file, debug,
|
nickname, domain, reply_file, debug,
|
||||||
recent_posts_cache)
|
recent_posts_cache, manual)
|
||||||
# remove the replies file
|
# remove the replies file
|
||||||
try:
|
try:
|
||||||
os.remove(replies_filename)
|
os.remove(replies_filename)
|
||||||
|
@ -1841,14 +1842,15 @@ def _is_remote_dm(domain_full: str, post_json_object: {}) -> bool:
|
||||||
this_post_json = post_json_object['object']
|
this_post_json = post_json_object['object']
|
||||||
if this_post_json.get('attributedTo'):
|
if this_post_json.get('attributedTo'):
|
||||||
if isinstance(this_post_json['attributedTo'], str):
|
if isinstance(this_post_json['attributedTo'], str):
|
||||||
if '://' + domain_full + '/' not in this_post_json['attributedTo']:
|
if '://' + domain_full not in this_post_json['attributedTo']:
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def delete_post(base_dir: str, http_prefix: str,
|
def delete_post(base_dir: str, http_prefix: str,
|
||||||
nickname: str, domain: str, post_filename: str,
|
nickname: str, domain: str, post_filename: str,
|
||||||
debug: bool, recent_posts_cache: {}) -> None:
|
debug: bool, recent_posts_cache: {},
|
||||||
|
manual: bool) -> None:
|
||||||
"""Recursively deletes a post and its replies and attachments
|
"""Recursively deletes a post and its replies and attachments
|
||||||
"""
|
"""
|
||||||
post_json_object = load_json(post_filename, 1)
|
post_json_object = load_json(post_filename, 1)
|
||||||
|
@ -1856,7 +1858,7 @@ def delete_post(base_dir: str, http_prefix: str,
|
||||||
# remove any replies
|
# remove any replies
|
||||||
_delete_post_remove_replies(base_dir, nickname, domain,
|
_delete_post_remove_replies(base_dir, nickname, domain,
|
||||||
http_prefix, post_filename,
|
http_prefix, post_filename,
|
||||||
recent_posts_cache, debug)
|
recent_posts_cache, debug, manual)
|
||||||
# finally, remove the post itself
|
# finally, remove the post itself
|
||||||
try:
|
try:
|
||||||
os.remove(post_filename)
|
os.remove(post_filename)
|
||||||
|
@ -1868,8 +1870,10 @@ def delete_post(base_dir: str, http_prefix: str,
|
||||||
|
|
||||||
# don't allow DMs to be deleted if they came from a different instance
|
# don't allow DMs to be deleted if they came from a different instance
|
||||||
# otherwise this breaks expectations about how DMs should operate
|
# otherwise this breaks expectations about how DMs should operate
|
||||||
if _is_remote_dm(domain, post_json_object):
|
# i.e. DMs should only be removed if they are manually deleted
|
||||||
return
|
if not manual:
|
||||||
|
if _is_remote_dm(domain, post_json_object):
|
||||||
|
return
|
||||||
|
|
||||||
# don't allow deletion of bookmarked posts
|
# don't allow deletion of bookmarked posts
|
||||||
if _is_bookmarked(base_dir, nickname, domain, post_filename):
|
if _is_bookmarked(base_dir, nickname, domain, post_filename):
|
||||||
|
@ -1931,7 +1935,7 @@ def delete_post(base_dir: str, http_prefix: str,
|
||||||
# remove any replies
|
# remove any replies
|
||||||
_delete_post_remove_replies(base_dir, nickname, domain,
|
_delete_post_remove_replies(base_dir, nickname, domain,
|
||||||
http_prefix, post_filename,
|
http_prefix, post_filename,
|
||||||
recent_posts_cache, debug)
|
recent_posts_cache, debug, manual)
|
||||||
# finally, remove the post itself
|
# finally, remove the post itself
|
||||||
try:
|
try:
|
||||||
os.remove(post_filename)
|
os.remove(post_filename)
|
||||||
|
|
Loading…
Reference in New Issue