mirror of
https://github.com/discourse/discourse.git
synced 2025-05-28 13:51:18 +08:00
FEATURE: Export chat messages to CSV file (#22113)
To export chat messages, go to `/admin/plugins/chat` and click the Create export button in the _Export chat messages_ section. You'll receive a direct message when the export is finished. Currently, this exports all messages from the last 6 months, but not more than 10000 messages. This exports all chat messages, including messages from private channels and users' direct conversations. This also exports messages that were deleted.
This commit is contained in:

committed by
GitHub

parent
720c0c6e4d
commit
3ea31f443c
40
plugins/chat/spec/requests/admin/export_controller_spec.rb
Normal file
40
plugins/chat/spec/requests/admin/export_controller_spec.rb
Normal file
@ -0,0 +1,40 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "rails_helper"
|
||||
|
||||
RSpec.describe Chat::ChatController do
|
||||
describe "#export_messages" do
|
||||
fab!(:user) { Fabricate(:user) }
|
||||
fab!(:moderator) { Fabricate(:moderator) }
|
||||
fab!(:admin) { Fabricate(:admin) }
|
||||
|
||||
it "enqueues the export job and logs into staff actions" do
|
||||
sign_in(admin)
|
||||
|
||||
post "/chat/admin/export/messages"
|
||||
|
||||
expect(response.status).to eq(204)
|
||||
|
||||
expect(Jobs::ExportCsvFile.jobs.size).to eq(1)
|
||||
job_data = Jobs::ExportCsvFile.jobs.first["args"].first
|
||||
expect(job_data["entity"]).to eq("chat_message")
|
||||
expect(job_data["user_id"]).to eq(admin.id)
|
||||
|
||||
staff_log_entry = UserHistory.last
|
||||
expect(staff_log_entry.acting_user_id).to eq(admin.id)
|
||||
expect(staff_log_entry.subject).to eq("chat_message")
|
||||
end
|
||||
|
||||
it "regular users don't have access" do
|
||||
sign_in(user)
|
||||
post "/chat/admin/export/messages"
|
||||
expect(response.status).to eq(403)
|
||||
end
|
||||
|
||||
it "moderators don't have access" do
|
||||
sign_in(moderator)
|
||||
post "/chat/admin/export/messages"
|
||||
expect(response.status).to eq(403)
|
||||
end
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user