Merge pull request #6413 from vinothkannans/log-entity-export
FEATURE: Log entity export in staff logs
This commit is contained in:
commit
4383afb769
|
@ -5,6 +5,7 @@ class ExportCsvController < ApplicationController
|
||||||
def export_entity
|
def export_entity
|
||||||
guardian.ensure_can_export_entity!(export_params[: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])
|
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
|
render json: success_json
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -81,7 +81,8 @@ class UserHistory < ActiveRecord::Base
|
||||||
removed_unsilence_user: 62,
|
removed_unsilence_user: 62,
|
||||||
removed_unsuspend_user: 63,
|
removed_unsuspend_user: 63,
|
||||||
post_rejected: 64,
|
post_rejected: 64,
|
||||||
merge_user: 65
|
merge_user: 65,
|
||||||
|
entity_export: 66
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -141,7 +142,8 @@ class UserHistory < ActiveRecord::Base
|
||||||
:change_badge,
|
:change_badge,
|
||||||
:delete_badge,
|
:delete_badge,
|
||||||
:post_rejected,
|
:post_rejected,
|
||||||
:merge_user
|
:merge_user,
|
||||||
|
:entity_export
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -459,6 +459,14 @@ class StaffActionLogger
|
||||||
))
|
))
|
||||||
end
|
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 = {})
|
def log_backup_download(backup, opts = {})
|
||||||
raise Discourse::InvalidParameters.new(:backup) unless backup
|
raise Discourse::InvalidParameters.new(:backup) unless backup
|
||||||
UserHistory.create!(params(opts).merge(
|
UserHistory.create!(params(opts).merge(
|
||||||
|
|
|
@ -3520,6 +3520,7 @@ en:
|
||||||
change_badge: "change badge"
|
change_badge: "change badge"
|
||||||
delete_badge: "delete badge"
|
delete_badge: "delete badge"
|
||||||
merge_user: "merge user"
|
merge_user: "merge user"
|
||||||
|
entity_export: "export entity"
|
||||||
screened_emails:
|
screened_emails:
|
||||||
title: "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."
|
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."
|
||||||
|
|
|
@ -30,6 +30,15 @@ describe ExportCsvController do
|
||||||
expect(response).to be_forbidden
|
expect(response).to be_forbidden
|
||||||
expect(Jobs::ExportCsvFile.jobs.size).to eq(0)
|
expect(Jobs::ExportCsvFile.jobs.size).to eq(0)
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -58,6 +67,15 @@ describe ExportCsvController do
|
||||||
expect(job_data["entity"]).to eq("staff_action")
|
expect(job_data["entity"]).to eq("staff_action")
|
||||||
expect(job_data["user_id"]).to eq(admin.id)
|
expect(job_data["user_id"]).to eq(admin.id)
|
||||||
end
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue