FIX: Use attachment format in user export system post take 2.

FIX: Use attachment format in user export system post take 2.

diff --git a/app/jobs/regular/export_csv_file.rb b/app/jobs/regular/export_csv_file.rb
index c3af9fd..8101b10 100644
--- a/app/jobs/regular/export_csv_file.rb
+++ b/app/jobs/regular/export_csv_file.rb
@@ -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
diff --git a/config/locales/server.de.yml b/config/locales/server.de.yml
index 5407547..0c502bf 100644
--- a/config/locales/server.de.yml
+++ b/config/locales/server.de.yml
@@ -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.
 
diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml
index 6d316e4..cea98cf 100644
--- a/config/locales/server.en.yml
+++ b/config/locales/server.en.yml
@@ -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.
 
diff --git a/config/locales/server.es.yml b/config/locales/server.es.yml
index a6ec7ef..7658249 100644
--- a/config/locales/server.es.yml
+++ b/config/locales/server.es.yml
@@ -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.
 
diff --git a/config/locales/server.fi.yml b/config/locales/server.fi.yml
index 8a649f3..b0eeb48 100644
--- a/config/locales/server.fi.yml
+++ b/config/locales/server.fi.yml
@@ -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.
 
diff --git a/config/locales/server.fr.yml b/config/locales/server.fr.yml
index a25a367..61ced97 100644
--- a/config/locales/server.fr.yml
+++ b/config/locales/server.fr.yml
@@ -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.
 
diff --git a/config/locales/server.hy.yml b/config/locales/server.hy.yml
index 3caac1a..1c83e48 100644
--- a/config/locales/server.hy.yml
+++ b/config/locales/server.hy.yml
@@ -2185,7 +2185,7 @@ hy:
       text_body_template: |
         Ձեր տվյալների արտահանումը հաջող էր! :dvd:
 
-        ![%{file_name}|attachment](%{download_link}) (%{file_size})
+        %{download_link}
 
         Վերևի ներբեռնման հղումը վավեր կլինի 8 ժամ:
 
diff --git a/config/locales/server.sl.yml b/config/locales/server.sl.yml
index 4bd5656..a58a180 100644
--- a/config/locales/server.sl.yml
+++ b/config/locales/server.sl.yml
@@ -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.
 
diff --git a/config/locales/server.ur.yml b/config/locales/server.ur.yml
index 75bcd56..7df4c1e 100644
--- a/config/locales/server.ur.yml
+++ b/config/locales/server.ur.yml
@@ -2367,7 +2367,7 @@ ur:
       text_body_template: |
         آپ کا ڈَیٹا ایکسپورٹ کامیاب ہو گیا! :dvd:
 
-        ![%{file_name}|attachment](%{download_link}) (%{file_size})
+        %{download_link}
 
         درجہ بالا ڈاؤن لوڈ لِنک 48 گھنٹے تک درست رہے گا۔
 
diff --git a/config/locales/server.zh_CN.yml b/config/locales/server.zh_CN.yml
index 1fe425e..b9a4fa1 100644
--- a/config/locales/server.zh_CN.yml
+++ b/config/locales/server.zh_CN.yml
@@ -2299,7 +2299,7 @@ zh_CN:
       text_body_template: |
         数据成功出成功!:dvd:
 
-        ![%{file_name}|attachment](%{download_link}) (%{file_size})
+        %{download_link}
 
         以上的下载链接将在48小时后失效。
 
diff --git a/config/locales/server.zh_TW.yml b/config/locales/server.zh_TW.yml
index 0a47e3c..f787b16 100644
--- a/config/locales/server.zh_TW.yml
+++ b/config/locales/server.zh_TW.yml
@@ -2266,7 +2266,7 @@ zh_TW:
       text_body_template: |
         資料成功匯出了!:dvd:
 
-         ![%{file_name}|attachment](%{download_link}) (%{file_size})
+         %{download_link}
 
         以上的下載連結將在 48 小時後失效。
 
diff --git a/spec/jobs/export_csv_file_spec.rb b/spec/jobs/export_csv_file_spec.rb
index 941c864..61b8b10 100644
--- a/spec/jobs/export_csv_file_spec.rb
+++ b/spec/jobs/export_csv_file_spec.rb
@@ -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

GitHub sha: 9d0fba64

1 Like