discourse/spec/serializers/user_export_serializer_spec.rb
Gary Pendergast 7fc8d74f3e
FEATURE: Allow admins to export users (#30918)
The GDPR requires all users to be able to export their data, or request an export of their data. This is fine for active users as we have a data export button on user profiles, but suspended users have no way of accessing the data export function, and the workaround for admins to export data for suspended users involves temporarily unsuspending them, then impersonating the user to export the data as them.

Since suspended users no longer have access to their account, we can safely assume that the export request will be coming via a medium outside of Discourse (eg, email). This change is built with this workflow in mind.

This change adds a new "User exports" section to the admin user page, allowing admins to start a new export, and to download the latest export file.
2025-01-24 08:13:25 +11:00

32 lines
1.1 KiB
Ruby

# frozen_string_literal: true
RSpec.describe UserExportSerializer do
subject(:serializer) { UserExportSerializer.new(user_export, root: false) }
fab!(:user_export) do
user = Fabricate(:user)
csv_file_1 = Fabricate(:upload, created_at: 1.day.ago)
topic_1 = Fabricate(:topic, created_at: 1.day.ago)
Fabricate(:post, topic: topic_1)
UserExport.create!(
file_name: "test",
user: user,
upload_id: csv_file_1.id,
topic_id: topic_1.id,
created_at: 1.day.ago,
)
end
it "should render without errors" do
json_data = JSON.parse(serializer.to_json)
expect(json_data["id"]).to eql user_export.id
expect(json_data["filename"]).to eql user_export.upload.original_filename
expect(json_data["uri"]).to eql user_export.upload.short_path
expect(json_data["filesize"]).to eql user_export.upload.filesize
expect(json_data["extension"]).to eql user_export.upload.extension
expect(json_data["retain_hours"]).to eql user_export.retain_hours
expect(json_data["human_filesize"]).to eql user_export.upload.human_filesize
end
end