Ability to block announces from particular accounts or instances

main
Bob Mottram 2022-11-08 14:16:19 +00:00
parent 5f71654316
commit 6602908522
2 changed files with 51 additions and 0 deletions

View File

@ -432,6 +432,49 @@ def is_blocked(base_dir: str, nickname: str, domain: str,
return False
def allowed_announce(base_dir: str, nickname: str, domain: str,
block_nickname: str, block_domain: str,
announce_blocked_cache: [] = None) -> bool:
"""Is the given nickname allowed to send announces?
"""
block_handle = None
if block_nickname and block_domain:
block_handle = block_nickname + '@' + block_domain
# cached announce blocks
if announce_blocked_cache:
for blocked_str in announce_blocked_cache:
if '*@' + domain in blocked_str:
return False
if block_handle:
if blocked_str == block_handle:
return False
# non-cached instance level announce blocks
global_announce_blocks_filename = \
base_dir + '/accounts/noannounce.txt'
if os.path.isfile(global_announce_blocks_filename):
if text_in_file('*@' + block_domain,
global_announce_blocks_filename):
return False
if block_handle:
block_str = block_handle + '\n'
if text_in_file(block_str,
global_announce_blocks_filename):
return False
# non-cached account level announce blocks
account_dir = acct_dir(base_dir, nickname, domain)
blocking_filename = account_dir + '/noannounce.txt'
if os.path.isfile(blocking_filename):
if text_in_file('*@' + block_domain + '\n', blocking_filename):
return False
if block_handle:
if text_in_file(block_handle + '\n', blocking_filename):
return False
return True
def outbox_block(base_dir: str, nickname: str, domain: str,
message_json: {}, debug: bool) -> bool:
""" When a block request is received by the outbox from c2s

View File

@ -92,6 +92,7 @@ from acceptreject import receive_accept_reject
from bookmarks import update_bookmarks_collection
from bookmarks import undo_bookmarks_collection_entry
from blocking import is_blocked
from blocking import allowed_announce
from blocking import is_blocked_domain
from blocking import broch_modeLapses
from filters import is_filtered
@ -2473,6 +2474,13 @@ def _receive_announce(recent_posts_cache: {},
actor_nickname + '@' + actor_domain)
return False
# Are announces permitted from the given actor?
if not allowed_announce(base_dir, nickname, domain,
actor_nickname, actor_domain):
print('Announce not allowed for: ' +
actor_nickname + '@' + actor_domain)
return False
# also check the actor for the url being announced
announced_actor_nickname = get_nickname_from_actor(message_json['object'])
if not announced_actor_nickname: