mirror of https://gitlab.com/bashrc2/epicyon
Remove global block reasons
parent
7c561a309d
commit
738a3faf3c
45
blocking.py
45
blocking.py
|
@ -83,7 +83,7 @@ def _add_global_block_reason(base_dir: str,
|
||||||
if not line.startswith(block_id + ' '):
|
if not line.startswith(block_id + ' '):
|
||||||
new_reasons_str += line + '\n'
|
new_reasons_str += line + '\n'
|
||||||
continue
|
continue
|
||||||
new_reasons_str = reason_line
|
new_reasons_str += reason_line
|
||||||
try:
|
try:
|
||||||
with open(blocking_reasons_filename, 'w+',
|
with open(blocking_reasons_filename, 'w+',
|
||||||
encoding='utf-8') as reas_file:
|
encoding='utf-8') as reas_file:
|
||||||
|
@ -214,11 +214,54 @@ def add_block(base_dir: str, nickname: str, domain: str,
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def _remove_global_block_reason(base_dir: str,
|
||||||
|
unblock_nickname: str,
|
||||||
|
unblock_domain: str) -> bool:
|
||||||
|
"""Remove a globla block reason
|
||||||
|
"""
|
||||||
|
unblocking_filename = base_dir + '/accounts/blocking_reasons.txt'
|
||||||
|
if not os.path.isfile(unblocking_filename):
|
||||||
|
return False
|
||||||
|
|
||||||
|
if not unblock_nickname.startswith('#'):
|
||||||
|
unblock_id = unblock_nickname + '@' + unblock_domain
|
||||||
|
else:
|
||||||
|
unblock_id = unblock_nickname
|
||||||
|
|
||||||
|
if not text_in_file(unblock_id + ' ', unblocking_filename):
|
||||||
|
return False
|
||||||
|
|
||||||
|
reasons_str = ''
|
||||||
|
try:
|
||||||
|
with open(unblocking_filename, 'r',
|
||||||
|
encoding='utf-8') as reas_file:
|
||||||
|
reasons_str = reas_file.read()
|
||||||
|
except OSError:
|
||||||
|
print('EX: unable to read blocking reasons 2')
|
||||||
|
reasons_lines = reasons_str.split('\n')
|
||||||
|
new_reasons_str = ''
|
||||||
|
for line in reasons_lines:
|
||||||
|
if line.startswith(unblock_id + ' '):
|
||||||
|
continue
|
||||||
|
new_reasons_str += line + '\n'
|
||||||
|
try:
|
||||||
|
with open(unblocking_filename, 'w+',
|
||||||
|
encoding='utf-8') as reas_file:
|
||||||
|
reas_file.write(new_reasons_str)
|
||||||
|
except OSError:
|
||||||
|
print('EX: unable to save blocking reasons 2' +
|
||||||
|
unblocking_filename)
|
||||||
|
|
||||||
|
|
||||||
def remove_global_block(base_dir: str,
|
def remove_global_block(base_dir: str,
|
||||||
unblock_nickname: str,
|
unblock_nickname: str,
|
||||||
unblock_domain: str) -> bool:
|
unblock_domain: str) -> bool:
|
||||||
"""Unblock the given global block
|
"""Unblock the given global block
|
||||||
"""
|
"""
|
||||||
|
_remove_global_block_reason(base_dir,
|
||||||
|
unblock_nickname,
|
||||||
|
unblock_domain)
|
||||||
|
|
||||||
unblocking_filename = base_dir + '/accounts/blocking.txt'
|
unblocking_filename = base_dir + '/accounts/blocking.txt'
|
||||||
if not unblock_nickname.startswith('#'):
|
if not unblock_nickname.startswith('#'):
|
||||||
unblock_handle = unblock_nickname + '@' + unblock_domain
|
unblock_handle = unblock_nickname + '@' + unblock_domain
|
||||||
|
|
22
daemon.py
22
daemon.py
|
@ -2642,23 +2642,27 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
full_block_domain, moderation_reason)
|
full_block_domain, moderation_reason)
|
||||||
if moderation_button == 'unblock':
|
if moderation_button == 'unblock':
|
||||||
full_block_domain = None
|
full_block_domain = None
|
||||||
if moderation_text.startswith('http') or \
|
if ' ' in moderation_text:
|
||||||
moderation_text.startswith('ipfs') or \
|
moderation_domain = moderation_text.split(' ', 1)[0]
|
||||||
moderation_text.startswith('ipns') or \
|
else:
|
||||||
moderation_text.startswith('hyper'):
|
moderation_domain = moderation_text
|
||||||
|
if moderation_domain.startswith('http') or \
|
||||||
|
moderation_domain.startswith('ipfs') or \
|
||||||
|
moderation_domain.startswith('ipns') or \
|
||||||
|
moderation_domain.startswith('hyper'):
|
||||||
# https://domain
|
# https://domain
|
||||||
block_domain, block_port = \
|
block_domain, block_port = \
|
||||||
get_domain_from_actor(moderation_text)
|
get_domain_from_actor(moderation_domain)
|
||||||
full_block_domain = \
|
full_block_domain = \
|
||||||
get_full_domain(block_domain, block_port)
|
get_full_domain(block_domain, block_port)
|
||||||
if '@' in moderation_text:
|
if '@' in moderation_domain:
|
||||||
# nick@domain or *@domain
|
# nick@domain or *@domain
|
||||||
full_block_domain = moderation_text.split('@')[1]
|
full_block_domain = moderation_domain.split('@')[1]
|
||||||
else:
|
else:
|
||||||
# assume the text is a domain name
|
# assume the text is a domain name
|
||||||
if not full_block_domain and '.' in moderation_text:
|
if not full_block_domain and '.' in moderation_domain:
|
||||||
nickname = '*'
|
nickname = '*'
|
||||||
full_block_domain = moderation_text.strip()
|
full_block_domain = moderation_domain.strip()
|
||||||
if full_block_domain or nickname.startswith('#'):
|
if full_block_domain or nickname.startswith('#'):
|
||||||
remove_global_block(base_dir, nickname,
|
remove_global_block(base_dir, nickname,
|
||||||
full_block_domain)
|
full_block_domain)
|
||||||
|
|
Loading…
Reference in New Issue