From 101c668173844e55b7ccdd8e24815bbec2938bad Mon Sep 17 00:00:00 2001 From: Izalia Mae Date: Sun, 11 Feb 2024 15:59:59 -0500 Subject: [PATCH] fix a few api endpoints --- relay/views/api.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/relay/views/api.py b/relay/views/api.py index 2fcbc6c..56b5ed7 100644 --- a/relay/views/api.py +++ b/relay/views/api.py @@ -284,13 +284,16 @@ class DomainBanSingle(View): if not conn.get_domain_ban(domain): 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): 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(): - ban = conn.update_domain_ban(**data) + ban = conn.update_domain_ban(domain, **data) return Response.new(ban, ctype = 'json') @@ -336,27 +339,30 @@ class SoftwareBanSingle(View): 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): 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): 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(): - ban = conn.update_software_ban(**data) + ban = conn.update_software_ban(name, **data) return Response.new(ban, ctype = 'json') - async def delete(self, request: Request, conn: Connection, domain: str) -> Response: - if not conn.get_software_ban(domain): + async def delete(self, request: Request, conn: Connection, name: str) -> Response: + if not conn.get_software_ban(name): return Response.new_error(404, 'Software not banned', 'json') with conn.transaction(): - conn.del_software_ban(domain) + conn.del_software_ban(name) return Response.new({'message': 'Unbanned software'}, ctype = 'json')