add download_remote_images_to_local site setting

This commit is contained in:
Régis Hanol 2013-11-15 15:22:18 +01:00
parent 6a3000ffef
commit 16267e4887
5 changed files with 12 additions and 8 deletions

View File

@ -8,8 +8,7 @@ module Jobs
end
def execute(args)
# we don't want to run the job if we're not allowed to crawl images
return unless SiteSetting.crawl_images?
return unless SiteSetting.download_remote_images_to_local?
post_id = args[:post_id]
raise Discourse::InvalidParameters.new(:post_id) unless post_id.present?

View File

@ -500,6 +500,7 @@ en:
company_domain: "The domain name owned by the company that runs this site, used in legal documents like the /tos"
queue_jobs: "DEVELOPER ONLY! WARNING! By default, queue jobs in sidekiq. If disabled, your site will be broken."
crawl_images: "Enable retrieving images from third party sources to insert width and height dimensions"
download_remote_images_to_local: "Download a copy of all remote images"
ninja_edit_window: "Number of seconds after posting where edits do not create a new version"
edit_history_visible_to_public: "Allow everyone to see previous versions of an edited post. When disabled, only staff members can view edit history."
delete_removed_posts_after: "Number of hours after which posts removed by the author will be deleted."

View File

@ -249,6 +249,10 @@ files:
default: false
detect_custom_avatars: true
max_daily_gravatar_crawls: 500
download_remote_images_to_local:
default:
test: false
default: true
trust:
default_trust_level: 0

View File

@ -219,8 +219,8 @@ class CookedPostProcessor
end
def pull_hotlinked_images
# we don't want to run the job if we're not allowed to crawl images
return unless SiteSetting.crawl_images?
# is the job enabled?
return unless SiteSetting.download_remote_images_to_local?
# we only want to run the job whenever it's changed by a user
return if @post.updated_by == Discourse.system_user
# make sure no other job is scheduled

View File

@ -275,15 +275,15 @@ describe CookedPostProcessor do
let(:post) { build(:post) }
let(:cpp) { CookedPostProcessor.new(post) }
it "does not run when crawl images is disabled" do
SiteSetting.stubs(:crawl_images).returns(false)
it "does not run when download_remote_images_to_local is disabled" do
SiteSetting.stubs(:download_remote_images_to_local).returns(false)
Jobs.expects(:cancel_scheduled_job).never
cpp.pull_hotlinked_images
end
context "when crawl_images? is enabled" do
context "when download_remote_images_to_local? is enabled" do
before { SiteSetting.stubs(:crawl_images).returns(true) }
before { SiteSetting.stubs(:download_remote_images_to_local).returns(true) }
it "runs only when a user updated the post" do
post.updated_by = Discourse.system_user