mirror of
https://github.com/discourse/discourse.git
synced 2024-11-27 15:23:38 +08:00
7c32411881
### General Changes and Duplication * We now consider a post `with_secure_media?` if it is in a read-restricted category. * When uploading we now set an upload's secure status straight away. * When uploading if `SiteSetting.secure_media` is enabled, we do not check to see if the upload already exists using the `sha1` digest of the upload. The `sha1` column of the upload is filled with a `SecureRandom.hex(20)` value which is the same length as `Upload::SHA1_LENGTH`. The `original_sha1` column is filled with the _real_ sha1 digest of the file. * Whether an upload `should_be_secure?` is now determined by whether the `access_control_post` is `with_secure_media?` (if there is no access control post then we leave the secure status as is). * When serializing the upload, we now cook the URL if the upload is secure. This is so it shows up correctly in the composer preview, because we set secure status on upload. ### Viewing Secure Media * The secure-media-upload URL will take the post that the upload is attached to into account via `Guardian.can_see?` for access permissions * If there is no `access_control_post` then we just deliver the media. This should be a rare occurrance and shouldn't cause issues as the `access_control_post` is set when `link_post_uploads` is called via `CookedPostProcessor` ### Removed We no longer do any of these because we do not reuse uploads by sha1 if secure media is enabled. * We no longer have a way to prevent cross-posting of a secure upload from a private context to a public context. * We no longer have to set `secure: false` for uploads when uploading for a theme component.
54 lines
1.1 KiB
Ruby
54 lines
1.1 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
Fabricator(:upload) do
|
|
user
|
|
sha1 { sequence(:sha1) { |n| Digest::SHA1.hexdigest(n.to_s) } }
|
|
original_filename "logo.png"
|
|
filesize 1234
|
|
width 100
|
|
height 200
|
|
thumbnail_width 30
|
|
thumbnail_height 60
|
|
|
|
url do |attrs|
|
|
sequence(:url) do |n|
|
|
Discourse.store.get_path_for(
|
|
"original", n + 1, attrs[:sha1], ".#{attrs[:extension]}"
|
|
)
|
|
end
|
|
end
|
|
|
|
extension "png"
|
|
end
|
|
|
|
Fabricator(:video_upload, from: :upload) do
|
|
original_filename "video.mp4"
|
|
width nil
|
|
height nil
|
|
thumbnail_width nil
|
|
thumbnail_height nil
|
|
extension "mp4"
|
|
end
|
|
|
|
Fabricator(:secure_upload, from: :upload) do
|
|
secure { true }
|
|
sha1 { SecureRandom.hex(20) }
|
|
original_sha1 { sequence(:sha1) { |n| Digest::SHA1.hexdigest(n.to_s) } }
|
|
end
|
|
|
|
Fabricator(:upload_s3, from: :upload) do
|
|
url do |attrs|
|
|
sequence(:url) do |n|
|
|
path = +Discourse.store.get_path_for(
|
|
"original", n + 1, attrs[:sha1], ".#{attrs[:extension]}"
|
|
)
|
|
|
|
if Rails.configuration.multisite
|
|
path.prepend(File.join(Discourse.store.upload_path, "/"))
|
|
end
|
|
|
|
File.join(Discourse.store.absolute_base_url, path)
|
|
end
|
|
end
|
|
end
|