From 7fd5f1bcd83919a164ad4bc13439aa1dbedc5fe9 Mon Sep 17 00:00:00 2001 From: Tiago Garcia Date: Wed, 20 Nov 2024 14:58:14 +0000 Subject: [PATCH] Add nonce Signed-off-by: Tiago Garcia --- delivery1/server/models/file.py | 2 ++ delivery1/server/models/org.py | 1 - delivery1/server/models/user.py | 1 - delivery1/server/routes/file.py | 4 ++-- delivery1/server/services/files.py | 3 ++- 5 files changed, 6 insertions(+), 5 deletions(-) diff --git a/delivery1/server/models/file.py b/delivery1/server/models/file.py index 8288403..a7fc99f 100644 --- a/delivery1/server/models/file.py +++ b/delivery1/server/models/file.py @@ -11,6 +11,7 @@ class File(db_connection.Model): created_at = db_connection.Column(db_connection.Integer, nullable=False) key = db_connection.Column(db_connection.String, nullable=False) alg = db_connection.Column(db_connection.String, nullable=False) + nonce = db_connection.Column(db_connection.String, nullable=False) org_id = db_connection.Column(db_connection.Integer, db_connection.ForeignKey('organizations.id'), nullable=False) creator_id = db_connection.Column(db_connection.Integer, db_connection.ForeignKey('users.id'), nullable=False) org = db_connection.relationship('Organization', backref=db_connection.backref('org_files', uselist=False)) @@ -25,6 +26,7 @@ class File(db_connection.Model): "created_at": self.created_at, "key": self.key, "alg": self.alg, + "nonce": self.nonce, "org": {"id": self.org.id, "name": self.org.name}, "creator": {"id": self.creator.id, "username": self.creator.username} } \ No newline at end of file diff --git a/delivery1/server/models/org.py b/delivery1/server/models/org.py index 1a9b356..2374eec 100644 --- a/delivery1/server/models/org.py +++ b/delivery1/server/models/org.py @@ -20,5 +20,4 @@ class Organization(db_connection.Model): "email": user_data["email"], "status": user_data["status"] }} for user_id, user_data in self.users.items()], - # "files": [{"id": file.id, "name": file.name, "file_handle": file.file_handle} for file in self.files] } \ No newline at end of file diff --git a/delivery1/server/models/user.py b/delivery1/server/models/user.py index 0e019eb..3325839 100644 --- a/delivery1/server/models/user.py +++ b/delivery1/server/models/user.py @@ -19,5 +19,4 @@ class User(db_connection.Model): "full_name": self.full_name, "email": self.email, "orgs": [{"id": org_id, "name": org_data["name"], "status": org_data["status"]} for org_id, org_data in self.orgs.items()], - # "files": [{"id": file.id, "name": file.name, "file_handle": file.file_handle} for file in self.files] } \ No newline at end of file diff --git a/delivery1/server/routes/file.py b/delivery1/server/routes/file.py index 8c70a5b..0c489bb 100644 --- a/delivery1/server/routes/file.py +++ b/delivery1/server/routes/file.py @@ -48,7 +48,7 @@ def file_upload_metadata(): 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 or "nonce" not in data: return jsonify({"error": "Missing required fields"}), 400 org = OrganizationService.get_organization(session.org_id) @@ -59,7 +59,7 @@ def file_upload_metadata(): if not user: return jsonify({"error": "User not found"}), 404 - file = upload_service.create_file(session.token, org, user, data["document_name"], data["key"], data["alg"]) + file = upload_service.create_file(session.token, org, user, data["document_name"], data["key"], data["alg"], data["nonce"]) return jsonify(file.to_dict()), 201 diff --git a/delivery1/server/services/files.py b/delivery1/server/services/files.py index 28498a1..a39ee11 100644 --- a/delivery1/server/services/files.py +++ b/delivery1/server/services/files.py @@ -13,7 +13,7 @@ class FileService: def __init__(self): self.current_requests = {} - def create_file(self, session_token: str, org: Organization, user: User, file_name: str, key: str, alg: str) -> File: + def create_file(self, session_token: str, org: Organization, user: User, file_name: str, key: str, alg: str, nonce: str) -> File: file = File( file_handle = None, document_handle = get_hash(file_name), @@ -21,6 +21,7 @@ class FileService: created_at = int(datetime.now().timestamp()), key = key, alg = alg, + nonce = nonce, org_id = org.id, creator_id = user.id, org = org,