Refactor Extension and Version: explicit constructors from File #191
@ -36,13 +36,6 @@ class UploadFileView(LoginRequiredMixin, CreateView):
|
|||||||
def form_valid(self, form):
|
def form_valid(self, form):
|
||||||
"""Create an extension and a version already, associated with the user."""
|
"""Create an extension and a version already, associated with the user."""
|
||||||
file = form.save()
|
file = form.save()
|
||||||
if file.user != self.request.user:
|
|
||||||
# this must never happen, but checking here to prevent misattributing the extension
|
|
||||||
# to a wrong user
|
|
||||||
raise Exception(
|
|
||||||
f'user {self.request.user} uploaded a file hash={file.hash} owned by {file.user}, '
|
|
||||||
f'this must never happen'
|
|
||||||
)
|
|
||||||
self.extension = Extension.create_from_file(file)
|
self.extension = Extension.create_from_file(file)
|
||||||
self.extension.create_version_from_file(file)
|
self.extension.create_version_from_file(file)
|
||||||
return super().form_valid(form)
|
return super().form_valid(form)
|
||||||
|
Loading…
Reference in New Issue
Block a user