mirror of
https://github.com/discourse/discourse.git
synced 2024-11-26 17:53:44 +08:00
FIX: don't delete uploads referenced in drafts or queued posts when using the short_url
This commit is contained in:
parent
38c103c75e
commit
7370adeae3
|
@ -50,8 +50,9 @@ module Jobs
|
|||
result = result.where("uploads.url NOT IN (?)", ignore_urls) if ignore_urls.present?
|
||||
|
||||
result.find_each do |upload|
|
||||
next if QueuedPost.where("raw LIKE '%#{upload.sha1}%'").exists?
|
||||
next if Draft.where("data LIKE '%#{upload.sha1}%'").exists?
|
||||
encoded_sha = Base62.encode(upload.sha1.hex)
|
||||
next if QueuedPost.where("raw LIKE '%#{upload.sha1}%' OR raw LIKE '%#{encoded_sha}%'").exists?
|
||||
next if Draft.where("data LIKE '%#{upload.sha1}%' OR data LIKE '%#{encoded_sha}%'").exists?
|
||||
upload.destroy
|
||||
end
|
||||
end
|
||||
|
|
|
@ -127,12 +127,13 @@ describe Jobs::CleanUpUploads do
|
|||
|
||||
it "does not delete uploads in a queued post" do
|
||||
upload = fabricate_upload
|
||||
upload2 = fabricate_upload
|
||||
|
||||
QueuedPost.create(
|
||||
queue: "uploads",
|
||||
state: QueuedPost.states[:new],
|
||||
user_id: Fabricate(:user).id,
|
||||
raw: upload.sha1,
|
||||
raw: "#{upload.sha1}\n#{upload2.short_url}",
|
||||
post_options: {}
|
||||
)
|
||||
|
||||
|
@ -140,16 +141,20 @@ describe Jobs::CleanUpUploads do
|
|||
|
||||
expect(Upload.find_by(id: @upload.id)).to eq(nil)
|
||||
expect(Upload.find_by(id: upload.id)).to eq(upload)
|
||||
expect(Upload.find_by(id: upload2.id)).to eq(upload2)
|
||||
end
|
||||
|
||||
it "does not delete uploads in a draft" do
|
||||
upload = fabricate_upload
|
||||
Draft.set(Fabricate(:user), "test", 0, upload.sha1)
|
||||
upload2 = fabricate_upload
|
||||
|
||||
Draft.set(Fabricate(:user), "test", 0, "#{upload.sha1}\n#{upload2.short_url}")
|
||||
|
||||
Jobs::CleanUpUploads.new.execute(nil)
|
||||
|
||||
expect(Upload.find_by(id: @upload.id)).to eq(nil)
|
||||
expect(Upload.find_by(id: upload.id)).to eq(upload)
|
||||
expect(Upload.find_by(id: upload2.id)).to eq(upload2)
|
||||
end
|
||||
|
||||
it "does not delete custom emojis" do
|
||||
|
|
Loading…
Reference in New Issue
Block a user