Fix request body handling

Signed-off-by: Tiago Garcia <tiago.rgarcia@ua.pt>
This commit is contained in:
Tiago Garcia 2024-11-20 01:14:10 +00:00
parent 11adcb21ba
commit 0dfb7d939d
Signed by: TiagoRG
GPG Key ID: DFCD48E3F420DB42
4 changed files with 17 additions and 0 deletions

View File

@ -1,3 +1,4 @@
cryptography
flask flask
flask_sqlalchemy flask_sqlalchemy
pytest pytest

View File

@ -1,3 +1,5 @@
import json
from flask import Blueprint, request, jsonify, send_file, Response from flask import Blueprint, request, jsonify, send_file, Response
import utils import utils
@ -44,6 +46,8 @@ def file_upload_metadata():
return session return session
data = request.json data = request.json
if type(data) is str:
data = json.loads(data)
if "document_name" not in data or "key" not in data or "alg" not in data: if "document_name" not in data or "key" not in data or "alg" not in data:
return jsonify({"error": "Missing required fields"}), 400 return jsonify({"error": "Missing required fields"}), 400
@ -98,6 +102,8 @@ def file_list():
data = request.json data = request.json
if type(data) is str:
data = json.loads(data)
org = OrganizationService.get_organization(session.org_id) org = OrganizationService.get_organization(session.org_id)
if not org: if not org:

View File

@ -1,3 +1,4 @@
import json
from flask import Blueprint, request, jsonify from flask import Blueprint, request, jsonify
from services import OrganizationService from services import OrganizationService
@ -6,6 +7,8 @@ org_bp = Blueprint("org", __name__)
@org_bp.route("/create", methods=["POST"]) @org_bp.route("/create", methods=["POST"])
def org_create(): def org_create():
data = request.json data = request.json
if type(data) is str:
data = json.loads(data)
if "name" not in data or "username" not in data or "full_name" not in data or "email" not in data or "public_key" not in data: if "name" not in data or "username" not in data or "full_name" not in data or "email" not in data or "public_key" not in data:
return jsonify({"error": "Missing required fields"}), 400 return jsonify({"error": "Missing required fields"}), 400

View File

@ -8,6 +8,8 @@ user_bp = Blueprint("user", __name__)
@user_bp.route("/login", methods=["POST"]) @user_bp.route("/login", methods=["POST"])
def user_login(): def user_login():
data = request.json data = request.json
if type(data) is str:
data = json.loads(data)
if "username" not in data or "org" not in data: if "username" not in data or "org" not in data:
return jsonify({"error": "Missing required fields"}), 400 return jsonify({"error": "Missing required fields"}), 400
@ -49,6 +51,8 @@ def user_list():
return session return session
data = request.json data = request.json
if type(data) is str:
data = json.loads(data)
org = OrganizationService.get_organization(session.org_id) org = OrganizationService.get_organization(session.org_id)
if not org: if not org:
@ -75,6 +79,9 @@ def user_create():
return session return session
data = request.json data = request.json
if type(data) is str:
data = json.loads(data)
if "username" not in data or "full_name" not in data or "email" not in data or "public_key" not in data: if "username" not in data or "full_name" not in data or "email" not in data or "public_key" not in data:
return jsonify({"error": "Missing required fields"}), 400 return jsonify({"error": "Missing required fields"}), 400