diff --git a/app/assets/javascripts/admin/models/export_csv.js b/app/assets/javascripts/admin/models/export_csv.js
index 3afe84a1ce6..9994db97d89 100644
--- a/app/assets/javascripts/admin/models/export_csv.js
+++ b/app/assets/javascripts/admin/models/export_csv.js
@@ -22,5 +22,14 @@ Discourse.ExportCsv.reopenClass({
bootbox.alert(I18n.t("admin.export_csv.failed"));
}
});
+ },
+
+ /**
+ Exports screened IPs list
+
+ @method export_screened_ips_list
+ **/
+ exportScreenedIpsList: function() {
+ return Discourse.ajax("/admin/export_csv/screened_ips.json");
}
});
diff --git a/app/assets/javascripts/admin/routes/admin-logs.js.es6 b/app/assets/javascripts/admin/routes/admin-logs.js.es6
new file mode 100644
index 00000000000..a16a9f1a6bf
--- /dev/null
+++ b/app/assets/javascripts/admin/routes/admin-logs.js.es6
@@ -0,0 +1,15 @@
+export default Discourse.Route.extend({
+
+ actions: {
+ exportScreenedIps: function() {
+ Discourse.ExportCsv.exportScreenedIpsList().then(function(result) {
+ if (result.success) {
+ bootbox.alert(I18n.t("admin.export_csv.success"));
+ } else {
+ bootbox.alert(I18n.t("admin.export_csv.failed"));
+ }
+ });
+ }
+ }
+
+});
diff --git a/app/assets/javascripts/admin/templates/logs.hbs b/app/assets/javascripts/admin/templates/logs.hbs
index fc194af0359..35321dd463f 100644
--- a/app/assets/javascripts/admin/templates/logs.hbs
+++ b/app/assets/javascripts/admin/templates/logs.hbs
@@ -8,6 +8,9 @@
{{i18n admin.logs.logster.title}}
+
+
+
diff --git a/app/controllers/admin/export_csv_controller.rb b/app/controllers/admin/export_csv_controller.rb
index 82fec5d09e4..2a5d53a00f6 100644
--- a/app/controllers/admin/export_csv_controller.rb
+++ b/app/controllers/admin/export_csv_controller.rb
@@ -8,6 +8,12 @@ class Admin::ExportCsvController < Admin::AdminController
render json: success_json
end
+ def export_screened_ips_list
+ # export csv file in a background thread
+ Jobs.enqueue(:export_csv_file, entity: 'screened_ips', user_id: current_user.id)
+ render json: success_json
+ end
+
# download
def show
filename = params.fetch(:id)
diff --git a/app/jobs/regular/export_csv_file.rb b/app/jobs/regular/export_csv_file.rb
index 79f9ea38a6d..f3cbadec057 100644
--- a/app/jobs/regular/export_csv_file.rb
+++ b/app/jobs/regular/export_csv_file.rb
@@ -6,6 +6,7 @@ module Jobs
class ExportCsvFile < Jobs::Base
CSV_USER_ATTRS = ['id','name','username','email','title','created_at','trust_level','active','admin','moderator','ip_address']
CSV_USER_STATS = ['topics_entered','posts_read_count','time_read','topic_count','post_count','likes_given','likes_received']
+ SCREENED_IP_ATTRS = ['ip_address','action_type','match_count','last_match_at','created_at']
sidekiq_options retry: false
attr_accessor :current_user
@@ -24,20 +25,26 @@ module Jobs
when 'user'
query = ::AdminUserIndexQuery.new
user_data = query.find_users_query.to_a
- data = Array.new
-
+ data = []
user_data.each do |user|
- user_array = Array.new
group_names = get_group_names(user).join(';')
user_array = get_user_fields(user)
user_array.push(group_names) if group_names != ''
data.push(user_array)
end
+ when 'screened_ips'
+ screened_ips_data = ScreenedIpAddress.order('id desc').to_a
+ data = []
+ screened_ips_data.each do |screened_ip|
+ screened_ip_array = get_screened_ip_fields(screened_ip)
+ data.push(screened_ip_array)
+ end
end
if data && data.length > 0
set_file_path
- write_csv_file(data)
+ header = get_header(entity)
+ write_csv_file(data, header)
end
notify_user
@@ -46,7 +53,7 @@ module Jobs
private
def get_group_names(user)
- group_names = Array.new
+ group_names = []
groups = user.groups
groups.each do |group|
group_names.push(group.name)
@@ -55,7 +62,7 @@ module Jobs
end
def get_user_fields(user)
- user_array = Array.new
+ user_array = []
CSV_USER_ATTRS.each do |attr|
user_array.push(user.attributes[attr])
@@ -74,16 +81,31 @@ module Jobs
return user_array
end
- def get_header
- header_array = CSV_USER_ATTRS + CSV_USER_STATS
+ def get_screened_ip_fields(screened_ip)
+ screened_ip_array = []
- user_custom_fields = UserField.all
- if user_custom_fields.present?
- user_custom_fields.each do |custom_field|
- header_array.push("#{custom_field.name} (custom user field)")
- end
+ SCREENED_IP_ATTRS.each do |attr|
+ screened_ip_array.push(screened_ip.attributes[attr])
+ end
+
+ return screened_ip_array
+ end
+
+ def get_header(entity)
+
+ case entity
+ when 'user'
+ header_array = CSV_USER_ATTRS + CSV_USER_STATS
+ user_custom_fields = UserField.all
+ if user_custom_fields.present?
+ user_custom_fields.each do |custom_field|
+ header_array.push("#{custom_field.name} (custom user field)")
+ end
+ end
+ header_array.push("group_names")
+ when 'screened_ips'
+ header_array = SCREENED_IP_ATTRS
end
- header_array.push("group_names")
return header_array
end
@@ -95,10 +117,10 @@ module Jobs
FileUtils.mkdir_p(dir) unless Dir.exists?(dir)
end
- def write_csv_file(data)
+ def write_csv_file(data, header)
# write to CSV file
CSV.open(File.expand_path("#{ExportCsv.base_directory}/#{@file_name}", __FILE__), "w") do |csv|
- csv << get_header
+ csv << header
data.each do |value|
csv << value
end
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index f33e0d720de..05b18c4f818 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -1686,6 +1686,9 @@ en:
users:
text: "Export Users"
title: "Export user list in a CSV file."
+ screened_ips:
+ text: "Export Screened IPs"
+ title: "Export screened IPs list in a CSV file."
success: "Export has been initiated, you will be notified shortly with progress."
failed: "Export failed. Please check the logs."
diff --git a/config/routes.rb b/config/routes.rb
index fd8c3e357ac..c417eeb8cdc 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -159,6 +159,7 @@ Discourse::Application.routes.draw do
resources :export_csv, constraints: AdminConstraint.new do
collection do
get "users" => "export_csv#export_user_list"
+ get "screened_ips" => "export_csv#export_screened_ips_list"
end
member do
get "" => "export_csv#show", constraints: { id: /[^\/]+/ }