fix a few api endpoints

This commit is contained in:
Izalia Mae 2024-02-11 15:59:59 -05:00
parent bd4790212e
commit 101c668173

View file

@ -284,13 +284,16 @@ class DomainBanSingle(View):
if not conn.get_domain_ban(domain): if not conn.get_domain_ban(domain):
return Response.new_error(404, 'Domain not banned', 'json') return Response.new_error(404, 'Domain not banned', 'json')
data = await self.get_api_data(['domain'], ['note', 'reason']) data = await self.get_api_data([], ['note', 'reason'])
if isinstance(data, Response): if isinstance(data, Response):
return data return data
if not any([data.get('note'), data.get('reason')]):
return Response.new_error(400, 'Must include note and/or reason parameters', 'json')
with conn.transaction(): with conn.transaction():
ban = conn.update_domain_ban(**data) ban = conn.update_domain_ban(domain, **data)
return Response.new(ban, ctype = 'json') return Response.new(ban, ctype = 'json')
@ -336,27 +339,30 @@ class SoftwareBanSingle(View):
return Response.new(ban, ctype = 'json') return Response.new(ban, ctype = 'json')
async def post(self, request: Request, conn: Connection, name: str) -> Response: async def patch(self, request: Request, conn: Connection, name: str) -> Response:
if not conn.get_software_ban(name): if not conn.get_software_ban(name):
return Response.new_error(404, 'Software not banned', 'json') return Response.new_error(404, 'Software not banned', 'json')
data = await self.get_api_data(['name'], ['note', 'reason']) data = await self.get_api_data([], ['note', 'reason'])
if isinstance(data, Response): if isinstance(data, Response):
return data return data
if not any([data.get('note'), data.get('reason')]):
return Response.new_error(400, 'Must include note and/or reason parameters', 'json')
with conn.transaction(): with conn.transaction():
ban = conn.update_software_ban(**data) ban = conn.update_software_ban(name, **data)
return Response.new(ban, ctype = 'json') return Response.new(ban, ctype = 'json')
async def delete(self, request: Request, conn: Connection, domain: str) -> Response: async def delete(self, request: Request, conn: Connection, name: str) -> Response:
if not conn.get_software_ban(domain): if not conn.get_software_ban(name):
return Response.new_error(404, 'Software not banned', 'json') return Response.new_error(404, 'Software not banned', 'json')
with conn.transaction(): with conn.transaction():
conn.del_software_ban(domain) conn.del_software_ban(name)
return Response.new({'message': 'Unbanned software'}, ctype = 'json') return Response.new({'message': 'Unbanned software'}, ctype = 'json')