11import logging
2+ import uuid
23from typing import Any , Callable , Dict
34
45from django .http import HttpRequest , HttpResponseNotAllowed
@@ -56,6 +57,19 @@ def create_upload(
5657 else None
5758 )
5859 archive_service = ArchiveService (repository )
60+ # only Shelter requests are allowed to set their own `storage_path`
61+
62+ if not serializer .validated_data .get ("storage_path" ) or not is_shelter_request :
63+ serializer .validated_data ["external_id" ] = uuid .uuid4 ()
64+ path = MinioEndpoints .raw_with_upload_id .get_path (
65+ version = "v4" ,
66+ date = timezone .now ().strftime ("%Y-%m-%d" ),
67+ repo_hash = archive_service .storage_hash ,
68+ commit_sha = commit .commitid ,
69+ reportid = report .external_id ,
70+ uploadid = serializer .validated_data ["external_id" ],
71+ )
72+ serializer .validated_data ["storage_path" ] = path
5973 # Create upload record
6074 instance : ReportSession = serializer .save (
6175 report_id = report .id , upload_extras = {"format_version" : "v1" }, state = "started"
@@ -72,18 +86,6 @@ def create_upload(
7286 report_type = report .report_type ,
7387 )
7488
75- # only Shelter requests are allowed to set their own `storage_path`
76- if instance .storage_path is None or not is_shelter_request :
77- path = MinioEndpoints .raw_with_upload_id .get_path (
78- version = "v4" ,
79- date = timezone .now ().strftime ("%Y-%m-%d" ),
80- repo_hash = archive_service .storage_hash ,
81- commit_sha = commit .commitid ,
82- reportid = report .external_id ,
83- uploadid = instance .external_id ,
84- )
85- instance .storage_path = path
86- instance .save ()
8789 trigger_upload_task (repository , commit .commitid , instance , report )
8890 activate_repo (repository )
8991 send_analytics_data (commit , instance , version , analytics_token )
0 commit comments