fix: Allow removing guarantee from unreachable instance

pull/20/head
db0 2023-09-11 23:30:51 +02:00
parent 8a52289333
commit d824d9190e
2 changed files with 26 additions and 18 deletions

View File

@ -168,23 +168,31 @@ class Guarantees(Resource):
)
db.session.add(rejection)
db.session.commit()
activitypub_pm.pm_admins(
message=f"Attention! You guarantor instance {instance.domain} has withdrawn their [guarantee](https://fediseer.com/faq#what-is-a-guarantee).\n\n"
"IMPORTANT: The instances you vouched for are still considered guaranteed but cannot guarantee or endorse others"
"If you find a new guarantor then your guarantees will be reactivated!.\n\n"
"Note that if you do not find a guarantor within 7 days, all your guarantees and endorsements will be removed.",
domain=target_instance.domain,
software=target_instance.software,
instance=target_instance,
)
try:
activitypub_pm.pm_admins(
message=f"Attention! You guarantor instance {instance.domain} has withdrawn their [guarantee](https://fediseer.com/faq#what-is-a-guarantee).\n\n"
"IMPORTANT: The instances you vouched for are still considered guaranteed but cannot guarantee or endorse others"
"If you find a new guarantor then your guarantees will be reactivated!.\n\n"
"Note that if you do not find a guarantor within 7 days, all your guarantees and endorsements will be removed.",
domain=target_instance.domain,
software=target_instance.software,
instance=target_instance,
)
# We do not want a missing instance to prevent us from removing a guarantee
except:
pass
orphan_ids = database.get_guarantee_chain(target_instance.id)
for orphan in database.get_instances_by_ids(orphan_ids):
activitypub_pm.pm_admins(
message=f"Attention! You guarantor chain has been broken because {instance.domain} has withdrawn their backing from {domain}.\n\nIMPORTANT: All your guarantees will be deleted unless the chain is repaired or you find a new guarantor within 24hours!",
domain=orphan.domain,
software=orphan.software,
instance=orphan,
)
try:
activitypub_pm.pm_admins(
message=f"Attention! You guarantor chain has been broken because {instance.domain} has withdrawn their backing from {domain}.\n\nIMPORTANT: All your guarantees will be deleted unless the chain is repaired or you find a new guarantor within 24hours!",
domain=orphan.domain,
software=orphan.software,
instance=orphan,
)
# We do not want a missing instance to prevent us from removing a guarantee
except:
pass
orphan.set_as_oprhan()
logger.info(f"{instance.domain} Withdrew guarantee from {domain}")
return {"message":'Changed'}, 200

View File

@ -7,7 +7,7 @@ def get_lemmy_admins(domain):
requested_lemmy = Lemmy(f"https://{domain}")
site = requested_lemmy.site.get()
if not site:
logger.warning(f"Error retrieving mastodon site info for {domain}")
logger.error(f"Error retrieving mastodon site info for {domain}")
raise Exception(f"Error retrieving mastodon site info for {domain}")
return [a["person"]["name"] for a in site["admins"]]
@ -19,9 +19,9 @@ def get_mastodon_admins(domain):
return [site_json["contact"]["account"]["username"]]
except Exception as err:
if site is not None:
logger.warning(f"Error retrieving mastodon site info for {domain}: {err}. Request text: {site.text()}")
logger.error(f"Error retrieving mastodon site info for {domain}: {err}. Request text: {site.text()}")
else:
logger.warning(f"Error retrieving mastodon site info for {domain}: {err}")
logger.error(f"Error retrieving mastodon site info for {domain}: {err}")
raise Exception(f"Error retrieving mastodon site info for {domain}: {err}")
def get_unknown_admins(domain):