mirror of
https://github.com/discourse/discourse.git
synced 2024-12-02 14:03:58 +08:00
8ebd5edd1e
This commit renames all secure_media related settings to secure_uploads_* along with the associated functionality. This is being done because "media" does not really cover it, we aren't just doing this for images and videos etc. but for all uploads in the site. Additionally, in future we want to secure more types of uploads, and enable a kind of "mixed mode" where some uploads are secure and some are not, so keeping media in the name is just confusing. This also keeps compatibility with the `secure-media-uploads` path, and changes new secure URLs to be `secure-uploads`. Deprecated settings: * secure_media -> secure_uploads * secure_media_allow_embed_images_in_emails -> secure_uploads_allow_embed_images_in_emails * secure_media_max_email_embed_image_size_kb -> secure_uploads_max_email_embed_image_size_kb
40 lines
1.2 KiB
Ruby
40 lines
1.2 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
module UploadsHelpers
|
|
def setup_s3
|
|
SiteSetting.enable_s3_uploads = true
|
|
|
|
SiteSetting.s3_region = 'us-west-1'
|
|
SiteSetting.s3_upload_bucket = "s3-upload-bucket"
|
|
|
|
SiteSetting.s3_access_key_id = "some key"
|
|
SiteSetting.s3_secret_access_key = "some secrets3_region key"
|
|
|
|
stub_request(:head, "https://#{SiteSetting.s3_upload_bucket}.s3.#{SiteSetting.s3_region}.amazonaws.com/")
|
|
end
|
|
|
|
# TODO (martin) Remove this alias once discourse-chat plugin has been
|
|
# updated to use secure_uploads instead.
|
|
def enable_secure_media
|
|
enable_secure_uploads
|
|
DiscourseEvent.trigger(:site_setting_changed, :secure_media, false, true)
|
|
end
|
|
|
|
def enable_secure_uploads
|
|
setup_s3
|
|
SiteSetting.secure_uploads = true
|
|
end
|
|
|
|
def stub_upload(upload)
|
|
url = %r{https://#{SiteSetting.s3_upload_bucket}.s3.#{SiteSetting.s3_region}.amazonaws.com/original/\d+X.*#{upload.sha1}.#{upload.extension}\?acl}
|
|
stub_request(:put, url)
|
|
end
|
|
|
|
def stub_s3_store
|
|
store = FileStore::S3Store.new
|
|
client = Aws::S3::Client.new(stub_responses: true)
|
|
store.s3_helper.stubs(:s3_client).returns(client)
|
|
Discourse.stubs(:store).returns(store)
|
|
end
|
|
end
|