FIX: Use attachment format in user export system post take 2.
This commit is contained in:
parent
a112259c66
commit
9d0fba64c0
|
@ -63,9 +63,8 @@ module Jobs
|
|||
system('gzip', '-5', absolute_path)
|
||||
|
||||
# create upload
|
||||
download_link = nil
|
||||
upload = nil
|
||||
compressed_file_path = "#{absolute_path}.gz"
|
||||
file_size = number_to_human_size(File.size(compressed_file_path))
|
||||
|
||||
if File.exist?(compressed_file_path)
|
||||
File.open(compressed_file_path) do |file|
|
||||
|
@ -78,16 +77,16 @@ module Jobs
|
|||
|
||||
if upload.persisted?
|
||||
user_export.update_columns(upload_id: upload.id)
|
||||
download_link = upload.url
|
||||
else
|
||||
Rails.logger.warn("Failed to upload the file #{Discourse.base_uri}/export_csv/#{file_name}.gz")
|
||||
end
|
||||
end
|
||||
|
||||
File.delete(compressed_file_path)
|
||||
end
|
||||
|
||||
ensure
|
||||
post = notify_user(download_link, file_name, file_size, export_title)
|
||||
post = notify_user(upload, export_title)
|
||||
|
||||
if user_export.present? && post.present?
|
||||
topic = post.topic
|
||||
user_export.update_columns(topic_id: topic.id)
|
||||
|
@ -388,22 +387,22 @@ module Jobs
|
|||
screened_url_array
|
||||
end
|
||||
|
||||
def notify_user(download_link, file_name, file_size, export_title)
|
||||
def notify_user(upload, export_title)
|
||||
post = nil
|
||||
|
||||
if @current_user
|
||||
post = if download_link.present?
|
||||
post = if upload
|
||||
SystemMessage.create_from_system_user(
|
||||
@current_user,
|
||||
:csv_export_succeeded,
|
||||
download_link: download_link,
|
||||
file_name: "#{file_name}.gz",
|
||||
file_size: file_size,
|
||||
download_link: "[#{upload.original_filename}|attachment](#{upload.short_url}) (#{number_to_human_size(upload.filesize)})",
|
||||
export_title: export_title
|
||||
)
|
||||
else
|
||||
SystemMessage.create_from_system_user(@current_user, :csv_export_failed)
|
||||
end
|
||||
end
|
||||
|
||||
post
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2347,7 +2347,7 @@ de:
|
|||
text_body_template: |
|
||||
Deine Daten wurden erfolgreich exportiert! :dvd:
|
||||
|
||||
![%{file_name}|attachment](%{download_link}) (%{file_size})
|
||||
%{download_link}
|
||||
|
||||
Der obenstehende Download-Link wird 48 Stunden gültig sein.
|
||||
|
||||
|
|
|
@ -2657,7 +2657,7 @@ en:
|
|||
text_body_template: |
|
||||
Your data export was successful! :dvd:
|
||||
|
||||
![%{file_name}|attachment](%{download_link}) (%{file_size})
|
||||
%{download_link}
|
||||
|
||||
The above download link will be valid for 48 hours.
|
||||
|
||||
|
|
|
@ -2369,7 +2369,7 @@ es:
|
|||
text_body_template: |
|
||||
¡La exportación de los datos ha finalizado correctamente! :dvd:
|
||||
|
||||
![%{file_name}|attachment](%{download_link}) (%{file_size})
|
||||
%{download_link}
|
||||
|
||||
El enlace de arriba funcionará durante las próximas 48 horas.
|
||||
|
||||
|
|
|
@ -2258,7 +2258,7 @@ fi:
|
|||
text_body_template: |
|
||||
Tietojen vienti onnistui! :dvd:
|
||||
|
||||
![%{file_name}|attachment](%{download_link}) (%{file_size})
|
||||
%{download_link}
|
||||
|
||||
Yllä oleva latauslinkki toimii 48 tunnin ajan.
|
||||
|
||||
|
|
|
@ -2322,7 +2322,7 @@ fr:
|
|||
text_body_template: |
|
||||
L'exportation de vos données a réussi ! :dvd:
|
||||
|
||||
![%{file_name}|attachment](%{download_link}) (%{file_size})
|
||||
%{download_link}
|
||||
|
||||
Le lien de téléchargement ci-dessus est valide 48 heures.
|
||||
|
||||
|
|
|
@ -2185,7 +2185,7 @@ hy:
|
|||
text_body_template: |
|
||||
Ձեր տվյալների արտահանումը հաջող էր! :dvd:
|
||||
|
||||
![%{file_name}|attachment](%{download_link}) (%{file_size})
|
||||
%{download_link}
|
||||
|
||||
Վերևի ներբեռնման հղումը վավեր կլինի 8 ժամ:
|
||||
|
||||
|
|
|
@ -1113,7 +1113,7 @@ sl:
|
|||
text_body_template: |
|
||||
Vaš izvoz podatkov je končan! :dvd:
|
||||
|
||||
![%{file_name}|attachment](%{download_link}) (%{file_size})
|
||||
%{download_link}
|
||||
|
||||
Zgornja povezava za prenos bo aktivna naslednjih 48 ur.
|
||||
|
||||
|
|
|
@ -2367,7 +2367,7 @@ ur:
|
|||
text_body_template: |
|
||||
آپ کا ڈَیٹا ایکسپورٹ کامیاب ہو گیا! :dvd:
|
||||
|
||||
![%{file_name}|attachment](%{download_link}) (%{file_size})
|
||||
%{download_link}
|
||||
|
||||
درجہ بالا ڈاؤن لوڈ لِنک 48 گھنٹے تک درست رہے گا۔
|
||||
|
||||
|
|
|
@ -2299,7 +2299,7 @@ zh_CN:
|
|||
text_body_template: |
|
||||
数据成功出成功!:dvd:
|
||||
|
||||
![%{file_name}|attachment](%{download_link}) (%{file_size})
|
||||
%{download_link}
|
||||
|
||||
以上的下载链接将在48小时后失效。
|
||||
|
||||
|
|
|
@ -2266,7 +2266,7 @@ zh_TW:
|
|||
text_body_template: |
|
||||
資料成功匯出了!:dvd:
|
||||
|
||||
![%{file_name}|attachment](%{download_link}) (%{file_size})
|
||||
%{download_link}
|
||||
|
||||
以上的下載連結將在 48 小時後失效。
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ require 'rails_helper'
|
|||
|
||||
describe Jobs::ExportCsvFile do
|
||||
|
||||
context '.execute' do
|
||||
context '#execute' do
|
||||
fab!(:user) { Fabricate(:user, username: "john_doe") }
|
||||
|
||||
it 'raises an error when the entity is missing' do
|
||||
|
@ -13,14 +13,27 @@ describe Jobs::ExportCsvFile do
|
|||
|
||||
it 'works' do
|
||||
begin
|
||||
Jobs::ExportCsvFile.new.execute(user_id: user.id, entity: "user_archive")
|
||||
expect do
|
||||
Jobs::ExportCsvFile.new.execute(
|
||||
user_id: user.id,
|
||||
entity: "user_archive"
|
||||
)
|
||||
end.to change { Upload.count }.by(1)
|
||||
|
||||
system_message = user.topics_allowed.last
|
||||
|
||||
expect(system_message.title).to eq(I18n.t(
|
||||
"system_messages.csv_export_succeeded.subject_template",
|
||||
export_title: "User Archive"
|
||||
))
|
||||
expect(system_message.first_post.raw).to include("user-archive-john_doe-")
|
||||
|
||||
upload = system_message.first_post.uploads.first
|
||||
|
||||
expect(system_message.first_post.raw).to eq(I18n.t(
|
||||
"system_messages.csv_export_succeeded.text_body_template",
|
||||
download_link: "[#{upload.original_filename}|attachment](#{upload.short_url}) (#{upload.filesize} Bytes)"
|
||||
).chomp)
|
||||
|
||||
expect(system_message.id).to eq(UserExport.last.topic_id)
|
||||
expect(system_message.closed).to eq(true)
|
||||
ensure
|
||||
|
|
Loading…
Reference in New Issue