feat: Support for adding all fedi software but not claiming

pull/8/head
db0 2023-06-24 15:08:06 +02:00
parent a10524a35d
commit 2f5cdc1cab
5 changed files with 10 additions and 7 deletions

View File

@ -25,13 +25,14 @@ class Models:
'csv': fields.String(description="The suspicious domains as a csv."), 'csv': fields.String(description="The suspicious domains as a csv."),
}) })
self.response_model_instances = api.model('InstanceDetails', { self.response_model_instances = api.model('InstanceDetails', {
'id': fields.Integer(description="The instance id"), 'id': fields.Integer(description="The instance id", example=1),
'domain': fields.String(description="The instance domain"), 'domain': fields.String(description="The instance domain", example="lemmy.dbzer0.com"),
'software': fields.String(description="The fediverse software running in this instance", example="lemmy"),
'open_registrations': fields.Boolean(description="The instance uptime pct. 100% and thousand of users is unlikely"), 'open_registrations': fields.Boolean(description="The instance uptime pct. 100% and thousand of users is unlikely"),
'email_verify': fields.Boolean(description="The amount of local posts in that instance"), 'email_verify': fields.Boolean(description="The amount of local posts in that instance"),
'approvals': fields.Integer(description="The amount of endorsements this instance has given out"), 'approvals': fields.Integer(description="The amount of endorsements this instance has given out"),
'endorsements': fields.Integer(description="The amount of endorsements this instance has received"), 'endorsements': fields.Integer(description="The amount of endorsements this instance has received"),
'guarantor': fields.String(description="The domain of the instance which guaranteed this instance."), 'guarantor': fields.String(description="The domain of the instance which guaranteed this instance.", example="fediseer.com"),
}) })
self.response_model_model_Whitelist_get = api.model('WhitelistedInstances', { self.response_model_model_Whitelist_get = api.model('WhitelistedInstances', {
'instances': fields.List(fields.Nested(self.response_model_instances)), 'instances': fields.List(fields.Nested(self.response_model_instances)),

View File

@ -71,8 +71,6 @@ def ensure_instance_registered(domain):
if not nodeinfo: if not nodeinfo:
raise e.BadRequest(f"Error encountered while polling domain {domain}. Please check it's running correctly") raise e.BadRequest(f"Error encountered while polling domain {domain}. Please check it's running correctly")
software = nodeinfo["software"]["name"] software = nodeinfo["software"]["name"]
if software not in SUPPORTED_SOFTWARE:
raise e.BadRequest(f"Fediverse software {software} not supported at this time")
if software == "lemmy": if software == "lemmy":
requested_lemmy = Lemmy(f"https://{domain}") requested_lemmy = Lemmy(f"https://{domain}")
site = requested_lemmy.site.get() site = requested_lemmy.site.get()

View File

@ -69,7 +69,10 @@ class WhitelistDomain(Resource):
if not guarantor_instance: if not guarantor_instance:
raise e.BadRequest(f"Requested guarantor domain {self.args.guarantor} is not registered with the Fediseer yet!") raise e.BadRequest(f"Requested guarantor domain {self.args.guarantor} is not registered with the Fediseer yet!")
if self.args.admin not in admin_usernames: if self.args.admin not in admin_usernames:
raise e.Forbidden(f"Only admins of that {instance.software} are allowed to claim it.") if len(admin_usernames) == 0:
raise e.Unauthorized(f"We have not implemented admin lookup and messaging for this fediverse software at this point, so this instance cannot be claimed. Please consider sending a PR to add this functionality.")
else:
raise e.Forbidden(f"Only admins of that {instance.software} are allowed to claim it.")
existing_claim = database.find_claim(f"@{self.args.admin}@{domain}") existing_claim = database.find_claim(f"@{self.args.admin}@{domain}")
if existing_claim: if existing_claim:
raise e.Forbidden(f"You have already claimed this instance as this admin. Please use the PATCH method to reset your API key.") raise e.Forbidden(f"You have already claimed this instance as this admin. Please use the PATCH method to reset your API key.")

View File

@ -78,6 +78,7 @@ class Instance(db.Model):
ret_dict = { ret_dict = {
"id": self.id, "id": self.id,
"domain": self.domain, "domain": self.domain,
"software": self.software,
"open_registrations": self.open_registrations, "open_registrations": self.open_registrations,
"email_verify": self.email_verify, "email_verify": self.email_verify,
"endorsements": len(self.endorsements), "endorsements": len(self.endorsements),

View File

@ -25,7 +25,7 @@ def get_admin_for_software(software: str, domain: str):
"mastodon": get_mastodon_admins, "mastodon": get_mastodon_admins,
} }
if software not in software_map: if software not in software_map:
return None return []
return software_map[software](domain) return software_map[software](domain)