From c7ccb1743376ad9efc73502ca2d63ecce9f7132d Mon Sep 17 00:00:00 2001 From: Selase Krakani <849886+s3lase@users.noreply.github.com> Date: Fri, 11 Nov 2022 11:07:32 +0000 Subject: [PATCH] FEATURE: Add cooked post to user archive exports (#18979) This change allows easily accessible secure media URLs to be available in the exported data. --- app/jobs/regular/export_user_archive.rb | 14 +++++++++++--- spec/jobs/export_user_archive_spec.rb | 10 +++++++--- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/app/jobs/regular/export_user_archive.rb b/app/jobs/regular/export_user_archive.rb index 256b8a3d4d7..657cc4aafec 100644 --- a/app/jobs/regular/export_user_archive.rb +++ b/app/jobs/regular/export_user_archive.rb @@ -26,7 +26,7 @@ module Jobs ) HEADER_ATTRS_FOR ||= HashWithIndifferentAccess.new( - user_archive: ['topic_title', 'categories', 'is_pm', 'post', 'like_count', 'reply_count', 'url', 'created_at'], + user_archive: ['topic_title', 'categories', 'is_pm', 'post_raw', 'post_cooked', 'like_count', 'reply_count', 'url', 'created_at'], user_archive_profile: ['location', 'website', 'bio', 'views'], auth_tokens: ['id', 'auth_token_hash', 'prev_auth_token_hash', 'auth_token_seen', 'client_ip', 'user_agent', 'seen_at', 'rotated_at', 'created_at', 'updated_at'], auth_token_logs: ['id', 'action', 'user_auth_token_id', 'client_ip', 'auth_token_hash', 'created_at', 'path', 'user_agent'], @@ -134,7 +134,7 @@ module Jobs Post.includes(topic: :category) .where(user_id: @current_user.id) - .select(:topic_id, :post_number, :raw, :like_count, :reply_count, :created_at) + .select(:topic_id, :post_number, :raw, :cooked, :like_count, :reply_count, :created_at) .order(:created_at) .with_deleted .each do |user_archive| @@ -441,7 +441,15 @@ module Jobs is_pm = topic_data.archetype == "private_message" ? I18n.t("csv_export.boolean_yes") : I18n.t("csv_export.boolean_no") url = "#{Discourse.base_url}/t/#{topic_data.slug}/#{topic_data.id}/#{user_archive['post_number']}" - topic_hash = { "post" => user_archive['raw'], "topic_title" => topic_data.title, "categories" => categories, "is_pm" => is_pm, "url" => url } + topic_hash = { + "post_raw" => user_archive['raw'], + "post_cooked" => user_archive["cooked"], + "topic_title" => topic_data.title, + "categories" => categories, + "is_pm" => is_pm, + "url" => url + } + user_archive.merge!(topic_hash) HEADER_ATTRS_FOR['user_archive'].each do |attr| diff --git a/spec/jobs/export_user_archive_spec.rb b/spec/jobs/export_user_archive_spec.rb index 09f86a331fe..2c047791b26 100644 --- a/spec/jobs/export_user_archive_spec.rb +++ b/spec/jobs/export_user_archive_spec.rb @@ -146,9 +146,13 @@ RSpec.describe Jobs::ExportUserArchive do expect(post2["is_pm"]).to eq(I18n.t("csv_export.boolean_no")) expect(post3["is_pm"]).to eq(I18n.t("csv_export.boolean_yes")) - expect(post1["post"]).to eq(normal_post.raw) - expect(post2["post"]).to eq(subsubpost.raw) - expect(post3["post"]).to eq(message_post.raw) + expect(post1["post_raw"]).to eq(normal_post.raw) + expect(post2["post_raw"]).to eq(subsubpost.raw) + expect(post3["post_raw"]).to eq(message_post.raw) + + expect(post1["post_cooked"]).to eq(normal_post.cooked) + expect(post2["post_cooked"]).to eq(subsubpost.cooked) + expect(post3["post_cooked"]).to eq(message_post.cooked) expect(post1['like_count']).to eq(1) expect(post2['like_count']).to eq(0)