FEATURE: Log entity export in staff logs

This commit is contained in:
Vinoth Kannan 2018-09-19 03:16:45 +05:30
parent e95d6a12c5
commit 9281b72308
5 changed files with 32 additions and 2 deletions

View File

@ -5,6 +5,7 @@ class ExportCsvController < ApplicationController
def export_entity
guardian.ensure_can_export_entity!(export_params[:entity])
Jobs.enqueue(:export_csv_file, entity: export_params[:entity], user_id: current_user.id, args: export_params[:args])
StaffActionLogger.new(current_user).log_entity_export(export_params[:entity])
render json: success_json
end

View File

@ -81,7 +81,8 @@ class UserHistory < ActiveRecord::Base
removed_unsilence_user: 62,
removed_unsuspend_user: 63,
post_rejected: 64,
merge_user: 65
merge_user: 65,
entity_export: 66
)
end
@ -141,7 +142,8 @@ class UserHistory < ActiveRecord::Base
:change_badge,
:delete_badge,
:post_rejected,
:merge_user
:merge_user,
:entity_export
]
end

View File

@ -459,6 +459,14 @@ class StaffActionLogger
))
end
def log_entity_export(entity, opts = {})
UserHistory.create!(params(opts).merge(
action: UserHistory.actions[:entity_export],
ip_address: @admin.ip_address.to_s,
subject: entity
))
end
def log_backup_download(backup, opts = {})
raise Discourse::InvalidParameters.new(:backup) unless backup
UserHistory.create!(params(opts).merge(

View File

@ -3522,6 +3522,7 @@ en:
change_badge: "change badge"
delete_badge: "delete badge"
merge_user: "merge user"
entity_export: "export entity"
screened_emails:
title: "Screened Emails"
description: "When someone tries to create a new account, the following email addresses will be checked and the registration will be blocked, or some other action performed."

View File

@ -30,6 +30,15 @@ describe ExportCsvController do
expect(response).to be_forbidden
expect(Jobs::ExportCsvFile.jobs.size).to eq(0)
end
it "correctly logs the entity export" do
post "/export_csv/export_entity.json", params: { entity: "user_archive" }
log_entry = UserHistory.last
expect(log_entry.action).to eq(UserHistory.actions[:entity_export])
expect(log_entry.acting_user_id).to eq(user.id)
expect(log_entry.subject).to eq("user_archive")
end
end
end
@ -58,6 +67,15 @@ describe ExportCsvController do
expect(job_data["entity"]).to eq("staff_action")
expect(job_data["user_id"]).to eq(admin.id)
end
it "correctly logs the entity export" do
post "/export_csv/export_entity.json", params: { entity: "user_list" }
log_entry = UserHistory.last
expect(log_entry.action).to eq(UserHistory.actions[:entity_export])
expect(log_entry.acting_user_id).to eq(admin.id)
expect(log_entry.subject).to eq("user_list")
end
end
end
end