mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 22:11:04 +08:00
FEATURE: warn the admin whenever we disable the download_remote_images_to_local site setting
This commit is contained in:
@ -1282,6 +1282,10 @@ en:
|
|||||||
|
|
||||||
[Please review them in the admin section](%{base_url}/admin/users/list/pending).
|
[Please review them in the admin section](%{base_url}/admin/users/list/pending).
|
||||||
|
|
||||||
|
download_remote_images_disabled:
|
||||||
|
subject_template: "Download remote images has been disabled"
|
||||||
|
text_body_template: "You previously had the `download_remote_images_to_local` setting enabled but the `download_remote_images_threshold` has been hit."
|
||||||
|
|
||||||
unsubscribe_link: "To unsubscribe from these emails, visit your [user preferences](%{user_preferences_url})."
|
unsubscribe_link: "To unsubscribe from these emails, visit your [user preferences](%{user_preferences_url})."
|
||||||
|
|
||||||
user_notifications:
|
user_notifications:
|
||||||
|
@ -236,6 +236,7 @@ class CookedPostProcessor
|
|||||||
def disable_if_low_on_disk_space
|
def disable_if_low_on_disk_space
|
||||||
if available_disk_space < SiteSetting.download_remote_images_threshold
|
if available_disk_space < SiteSetting.download_remote_images_threshold
|
||||||
SiteSetting.download_remote_images_to_local = false
|
SiteSetting.download_remote_images_to_local = false
|
||||||
|
SystemMessage.create(Discourse.site_contact_user, :download_remote_images_disabled)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
false
|
false
|
||||||
|
@ -295,20 +295,23 @@ describe CookedPostProcessor do
|
|||||||
|
|
||||||
before { SiteSetting.stubs(:download_remote_images_to_local).returns(true) }
|
before { SiteSetting.stubs(:download_remote_images_to_local).returns(true) }
|
||||||
|
|
||||||
it "runs only when a user updated the post" do
|
it "does not run when there is not enough disk space" do
|
||||||
|
cpp.expects(:disable_if_low_on_disk_space).returns(true)
|
||||||
|
Jobs.expects(:cancel_scheduled_job).never
|
||||||
|
cpp.pull_hotlinked_images
|
||||||
|
end
|
||||||
|
|
||||||
|
context "and there is enough disk space" do
|
||||||
|
|
||||||
|
before { cpp.expects(:disable_if_low_on_disk_space).returns(false) }
|
||||||
|
|
||||||
|
it "does not run when the system user updated the post" do
|
||||||
post.last_editor_id = Discourse.system_user.id
|
post.last_editor_id = Discourse.system_user.id
|
||||||
Jobs.expects(:cancel_scheduled_job).never
|
Jobs.expects(:cancel_scheduled_job).never
|
||||||
cpp.pull_hotlinked_images
|
cpp.pull_hotlinked_images
|
||||||
end
|
end
|
||||||
|
|
||||||
it "disables download when disk space is low" do
|
context "and the post has been updated by an actual user" do
|
||||||
SiteSetting.expects(:download_remote_images_threshold).returns(20)
|
|
||||||
cpp.expects(:available_disk_space).returns(10)
|
|
||||||
Jobs.expects(:cancel_scheduled_job).never
|
|
||||||
cpp.pull_hotlinked_images
|
|
||||||
end
|
|
||||||
|
|
||||||
context "and the post has been updated by a user" do
|
|
||||||
|
|
||||||
before { post.id = 42 }
|
before { post.id = 42 }
|
||||||
|
|
||||||
@ -327,6 +330,8 @@ describe CookedPostProcessor do
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
context ".disable_if_low_on_disk_space" do
|
context ".disable_if_low_on_disk_space" do
|
||||||
|
|
||||||
let(:post) { build(:post) }
|
let(:post) { build(:post) }
|
||||||
@ -340,14 +345,20 @@ describe CookedPostProcessor do
|
|||||||
cpp.disable_if_low_on_disk_space.should == false
|
cpp.disable_if_low_on_disk_space.should == false
|
||||||
end
|
end
|
||||||
|
|
||||||
it "disables download_remote_images_threshold when there's not enough disk space" do
|
context "when there's not enough disk space" do
|
||||||
SiteSetting.expects(:download_remote_images_threshold).returns(75)
|
|
||||||
|
before { SiteSetting.expects(:download_remote_images_threshold).returns(75) }
|
||||||
|
|
||||||
|
it "disables download_remote_images_threshold and send a notification to the admin" do
|
||||||
|
SystemMessage.expects(:create).with(Discourse.site_contact_user, :download_remote_images_disabled).once
|
||||||
cpp.disable_if_low_on_disk_space.should == true
|
cpp.disable_if_low_on_disk_space.should == true
|
||||||
SiteSetting.download_remote_images_to_local.should == false
|
SiteSetting.download_remote_images_to_local.should == false
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
context ".is_a_hyperlink?" do
|
context ".is_a_hyperlink?" do
|
||||||
|
|
||||||
let(:post) { build(:post) }
|
let(:post) { build(:post) }
|
||||||
|
Reference in New Issue
Block a user