mirror of https://gitlab.com/bashrc2/epicyon
Update announces allowed
parent
9b93eeb5d1
commit
8ce0cfcbe1
54
blocking.py
54
blocking.py
|
@ -475,6 +475,60 @@ def allowed_announce(base_dir: str, nickname: str, domain: str,
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
def allowed_announce_add(base_dir: str, nickname: str, domain: str,
|
||||||
|
following_nickname: str,
|
||||||
|
following_domain: str) -> None:
|
||||||
|
"""Allow announces for a handle
|
||||||
|
"""
|
||||||
|
account_dir = acct_dir(base_dir, nickname, domain)
|
||||||
|
blocking_filename = account_dir + '/noannounce.txt'
|
||||||
|
handle = following_nickname + '@' + following_domain
|
||||||
|
if text_in_file(handle + '\n', blocking_filename):
|
||||||
|
file_text = ''
|
||||||
|
try:
|
||||||
|
with open(blocking_filename, 'r',
|
||||||
|
encoding='utf-8') as fp_noannounce:
|
||||||
|
file_text = fp_noannounce.read()
|
||||||
|
file_text = file_text.replace(handle + '\n', '')
|
||||||
|
except OSError:
|
||||||
|
print('EX: unable to read noannounce: ' +
|
||||||
|
blocking_filename + ' ' + handle)
|
||||||
|
try:
|
||||||
|
with open(blocking_filename, 'w+',
|
||||||
|
encoding='utf-8') as fp_noannounce:
|
||||||
|
fp_noannounce.write(file_text)
|
||||||
|
except OSError:
|
||||||
|
print('EX: unable to write noannounce: ' +
|
||||||
|
blocking_filename + ' ' + handle)
|
||||||
|
|
||||||
|
|
||||||
|
def allowed_announce_remove(base_dir: str, nickname: str, domain: str,
|
||||||
|
following_nickname: str,
|
||||||
|
following_domain: str) -> None:
|
||||||
|
"""Don't allow announces from a handle
|
||||||
|
"""
|
||||||
|
account_dir = acct_dir(base_dir, nickname, domain)
|
||||||
|
blocking_filename = account_dir + '/noannounce.txt'
|
||||||
|
handle = following_nickname + '@' + following_domain
|
||||||
|
file_text = ''
|
||||||
|
if not text_in_file(handle + '\n', blocking_filename):
|
||||||
|
try:
|
||||||
|
with open(blocking_filename, 'r',
|
||||||
|
encoding='utf-8') as fp_noannounce:
|
||||||
|
file_text = fp_noannounce.read()
|
||||||
|
except OSError:
|
||||||
|
print('EX: unable to read noannounce: ' +
|
||||||
|
blocking_filename + ' ' + handle)
|
||||||
|
file_text += handle + '\n'
|
||||||
|
try:
|
||||||
|
with open(blocking_filename, 'w+',
|
||||||
|
encoding='utf-8') as fp_noannounce:
|
||||||
|
fp_noannounce.write(file_text)
|
||||||
|
except OSError:
|
||||||
|
print('EX: unable to write noannounce: ' +
|
||||||
|
blocking_filename + ' ' + handle)
|
||||||
|
|
||||||
|
|
||||||
def outbox_block(base_dir: str, nickname: str, domain: str,
|
def outbox_block(base_dir: str, nickname: str, domain: str,
|
||||||
message_json: {}, debug: bool) -> bool:
|
message_json: {}, debug: bool) -> bool:
|
||||||
""" When a block request is received by the outbox from c2s
|
""" When a block request is received by the outbox from c2s
|
||||||
|
|
31
daemon.py
31
daemon.py
|
@ -154,6 +154,8 @@ from blocking import remove_global_block
|
||||||
from blocking import is_blocked_hashtag
|
from blocking import is_blocked_hashtag
|
||||||
from blocking import is_blocked_domain
|
from blocking import is_blocked_domain
|
||||||
from blocking import get_domain_blocklist
|
from blocking import get_domain_blocklist
|
||||||
|
from blocking import allowed_announce_add
|
||||||
|
from blocking import allowed_announce_remove
|
||||||
from roles import set_roles_from_list
|
from roles import set_roles_from_list
|
||||||
from roles import get_actor_roles_list
|
from roles import get_actor_roles_list
|
||||||
from blog import path_contains_blog_link
|
from blog import path_contains_blog_link
|
||||||
|
@ -3046,6 +3048,35 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
self.server.postreq_busy = False
|
self.server.postreq_busy = False
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# person options screen, allow announces checkbox
|
||||||
|
# See html_person_options
|
||||||
|
if '&submitAllowAnnounce=' in options_confirm_params:
|
||||||
|
allow_announce = None
|
||||||
|
if 'allowAnnounce=' in options_confirm_params:
|
||||||
|
allow_announce = \
|
||||||
|
options_confirm_params.split('allowAnnounce=')[1]
|
||||||
|
if '&' in allow_announce:
|
||||||
|
allow_announce = allow_announce.split('&')[0]
|
||||||
|
if allow_announce == 'on':
|
||||||
|
allowed_announce_add(base_dir,
|
||||||
|
chooser_nickname,
|
||||||
|
domain,
|
||||||
|
options_nickname,
|
||||||
|
options_domain_full)
|
||||||
|
else:
|
||||||
|
allowed_announce_remove(base_dir,
|
||||||
|
chooser_nickname,
|
||||||
|
domain,
|
||||||
|
options_nickname,
|
||||||
|
options_domain_full)
|
||||||
|
users_path_str = \
|
||||||
|
users_path + '/' + self.server.default_timeline + \
|
||||||
|
'?page=' + str(page_number)
|
||||||
|
self._redirect_headers(users_path_str, cookie,
|
||||||
|
calling_domain)
|
||||||
|
self.server.postreq_busy = False
|
||||||
|
return
|
||||||
|
|
||||||
# person options screen, on notify checkbox
|
# person options screen, on notify checkbox
|
||||||
# See html_person_options
|
# See html_person_options
|
||||||
if '&submitNotifyOnPost=' in options_confirm_params:
|
if '&submitNotifyOnPost=' in options_confirm_params:
|
||||||
|
|
|
@ -421,7 +421,7 @@ def html_person_options(default_timeline: str,
|
||||||
'name="allowAnnounce" checked> 🔁' + \
|
'name="allowAnnounce" checked> 🔁' + \
|
||||||
translate['Allow announces'] + \
|
translate['Allow announces'] + \
|
||||||
'\n <button type="submit" class="buttonsmall" ' + \
|
'\n <button type="submit" class="buttonsmall" ' + \
|
||||||
'name="submitAllowAnnounces">' + \
|
'name="submitAllowAnnounce">' + \
|
||||||
translate['Save'] + '</button><br>\n'
|
translate['Save'] + '</button><br>\n'
|
||||||
if not allowed_announce(base_dir, nickname, domain,
|
if not allowed_announce(base_dir, nickname, domain,
|
||||||
options_nickname, options_domain_full):
|
options_nickname, options_domain_full):
|
||||||
|
|
Loading…
Reference in New Issue