Check that memorial accounts exist

main
Bob Mottram 2023-08-31 23:38:09 +01:00
parent 12dfeee1f7
commit c199b9cfc6
2 changed files with 14 additions and 3 deletions

View File

@ -6904,12 +6904,12 @@ class PubServer(BaseHTTPRequestHandler):
if fields.get('memorialAccounts'):
if fields['memorialAccounts'] != \
curr_memorial:
set_memorials(base_dir,
set_memorials(base_dir, self.server.domain,
fields['memorialAccounts'])
else:
if curr_memorial:
set_memorials(base_dir,
'memorialAccounts', '')
self.server.domain, '')
# change email address
current_email_address = get_email_address(actor_json)

View File

@ -757,9 +757,20 @@ def get_memorials(base_dir: str) -> str:
return memorial_str
def set_memorials(base_dir: str, memorial_str) -> None:
def set_memorials(base_dir: str, domain: str, memorial_str) -> None:
"""Sets the nicknames for memorial accounts
"""
# check that the accounts exist
memorial_list = memorial_str.split('\n')
new_memorial_str = ''
for memorial_item in memorial_list:
memorial_nick = memorial_item.strip()
check_dir = acct_dir(base_dir, memorial_nick, domain)
if os.path.isdir(check_dir):
new_memorial_str += memorial_nick + '\n'
memorial_str = new_memorial_str
# save the accounts
memorial_file = base_dir + '/accounts/memorial'
try:
with open(memorial_file, 'w+', encoding='utf-8') as fp_memorial: