summaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
authorerdgeist <erdgeist@erdgeist.org>2026-07-21 21:01:30 +0200
committererdgeist <erdgeist@erdgeist.org>2026-07-21 21:01:30 +0200
commit1791d8067d00dc1381b9cdc3cc4ad44c1f6c7197 (patch)
tree7046ee2744b42a7f0fc710a50fb36f4ab2bf0d19 /app/models
parent65da515e27939c90a66ec3b063b5e58943d3dcea (diff)
Add storage isolation for tests, preventing live data destruction
Diffstat (limited to 'app/models')
-rw-r--r--app/models/concerns/file_attachment.rb20
1 files changed, 14 insertions, 6 deletions
diff --git a/app/models/concerns/file_attachment.rb b/app/models/concerns/file_attachment.rb
index e7a33c5..548531f 100644
--- a/app/models/concerns/file_attachment.rb
+++ b/app/models/concerns/file_attachment.rb
@@ -66,12 +66,23 @@ module FileAttachment
66 @upload = UploadProxy.new(self) 66 @upload = UploadProxy.new(self)
67 end 67 end
68 68
69 class_methods do
70 def upload_root
71 Rails.env.test? ? Rails.root.join("tmp", "test_uploads") : Rails.root.join("public", "system", "uploads")
72 end
73 end
74
75 def upload_root
76 self.class.upload_root
77 end
78
69 def process_upload 79 def process_upload
70 return unless @pending_upload 80 return unless @pending_upload
71 uploaded_file = @pending_upload 81 uploaded_file = @pending_upload
72 @pending_upload = nil 82 @pending_upload = nil
73 83
74 old_dir = Rails.root.join("public", "system", "uploads", id.to_s) 84 old_dir = upload_root.join(id.to_s)
85
75 FileUtils.rm_rf(old_dir) if Dir.exist?(old_dir) 86 FileUtils.rm_rf(old_dir) if Dir.exist?(old_dir)
76 87
77 original_path = file_path(:original) 88 original_path = file_path(:original)
@@ -102,15 +113,12 @@ module FileAttachment
102 end 113 end
103 114
104 def delete_upload_files 115 def delete_upload_files
105 dir = Rails.root.join("public", "system", "uploads", id.to_s) 116 dir = upload_root.join(id.to_s)
106 FileUtils.rm_rf(dir) if Dir.exist?(dir) 117 FileUtils.rm_rf(dir) if Dir.exist?(dir)
107 end 118 end
108 119
109 def file_path(style) 120 def file_path(style)
110 Rails.root.join( 121 upload_root.join(id.to_s, style.to_s, variant_filename(style)).to_s
111 "public", "system", "uploads",
112 id.to_s, style.to_s, upload_file_name
113 ).to_s
114 end 122 end
115 123
116 def sanitize_filename(filename) 124 def sanitize_filename(filename)