fix: mastodon admin pull

pull/8/head
db0 2023-06-24 14:56:09 +02:00
parent 1b8cfe08b1
commit a10524a35d
5 changed files with 8 additions and 9 deletions

View File

@ -88,7 +88,7 @@ def ensure_instance_registered(domain):
admin_usernames = get_admin_for_software(software, domain)
instance = database.find_instance_by_domain(domain)
if instance:
return instance, nodeinfo, site, admin_usernames
return instance, nodeinfo, admin_usernames
new_instance = Instance(
domain=domain,
open_registrations=open_registrations,
@ -96,4 +96,4 @@ def ensure_instance_registered(domain):
software=software,
)
new_instance.create()
return new_instance, nodeinfo, site, admin_usernames
return new_instance, nodeinfo, admin_usernames

View File

@ -81,7 +81,7 @@ class Endorsements(Resource):
unbroken_chain, chainbreaker = database.has_unbroken_chain(instance.id)
if not unbroken_chain:
raise e.Forbidden(f"Guarantee chain for this instance has been broken. Chain ends at {chainbreaker.domain}!")
target_instance, nodeinfo, site, admin_usernames = ensure_instance_registered(domain)
target_instance, nodeinfo, admin_usernames = ensure_instance_registered(domain)
if not target_instance:
raise e.NotFound(f"Something went wrong trying to register this instance.")
if len(target_instance.guarantors) == 0:

View File

@ -84,7 +84,7 @@ class Guarantees(Resource):
unbroken_chain, chainbreaker = database.has_unbroken_chain(instance.id)
if not unbroken_chain:
raise e.Forbidden(f"Guarantee chain for this instance has been broken. Chain ends at {chainbreaker.domain}!")
target_instance, nodeinfo, site, admin_usernames = ensure_instance_registered(domain)
target_instance, nodeinfo, admin_usernames = ensure_instance_registered(domain)
if not target_instance:
raise e.NotFound(f"Something went wrong trying to register this instance.")
if database.get_guarantee(target_instance.id,instance.id):

View File

@ -39,7 +39,7 @@ class WhitelistDomain(Resource):
'''Display info about a specific instance
'''
self.args = self.get_parser.parse_args()
instance, nodeinfo, site, admin_usernames = ensure_instance_registered(domain)
instance, nodeinfo, admin_usernames = ensure_instance_registered(domain)
if not instance:
raise e.NotFound(f"Something went wrong trying to register this instance.")
return instance.get_details(),200
@ -62,7 +62,7 @@ class WhitelistDomain(Resource):
self.args = self.put_parser.parse_args()
if '@' in self.args.admin:
raise e.BadRequest("Please send the username without any @ signs or domains")
instance, nodeinfo, site, admin_usernames = ensure_instance_registered(domain)
instance, nodeinfo, admin_usernames = ensure_instance_registered(domain)
guarantor_instance = None
if self.args.guarantor:
guarantor_instance = database.find_instance_by_domain(self.args.guarantor)

View File

@ -13,10 +13,10 @@ def get_lemmy_admins(domain):
def get_mastodon_admins(domain):
try:
site = requests(f"https://{domain}/api/v2/instance").json()
site = requests.get(f"https://{domain}/api/v2/instance").json()
return [site["contact"]["account"]["username"]]
except Exception as err:
logger.warning(f"Error retrieving mastodon site info for {domain}")
logger.warning(f"Error retrieving mastodon site info for {domain}: {err}")
return None
def get_admin_for_software(software: str, domain: str):
@ -44,5 +44,4 @@ def get_nodeinfo(domain):
nodeinfo = requests.get(wellknown['links'][0]['href'], headers=headers, timeout=3).json()
return nodeinfo
except Exception as err:
logger.debug(err)
return None