added csv download

This commit is contained in:
dinsmol 2021-08-11 22:28:20 +03:00
parent c7e92452af
commit 7f8eee52f4
41 changed files with 259 additions and 35 deletions

View file

@ -8,6 +8,18 @@ module Admin
@q = domains.search(params[:q])
@domains = @q.result.page(params[:page])
@domains = @domains.per(params[:results_per_page]) if params[:results_per_page].to_i.positive?
respond_to do |format|
format.html do
render 'admin/blocked_domains/index'
end
format.csv do
raw_csv = @q.result.to_csv
send_data raw_csv,
filename: "blocked_domains_#{Time.zone.now.to_formatted_s(:number)}.csv",
type: "#{Mime[:csv]}; charset=utf-8"
end
end
end
def new

View file

@ -28,6 +28,17 @@ module Admin
@versions = @q.result.page(params[:page])
@versions = @versions.per(params[:results_per_page]) if params[:results_per_page].to_i.positive?
respond_to do |format|
format.html do
render 'admin/contact_versions/index'
end
format.csv do
raw_csv = @q.result.to_csv
send_data raw_csv,
filename: "contact_history_#{Time.zone.now.to_formatted_s(:number)}.csv",
type: "#{Mime[:csv]}; charset=utf-8"
end
end
end
def show

View file

@ -24,6 +24,18 @@ module Admin
end
@contacts = @contacts.per(params[:results_per_page]) if params[:results_per_page].to_i.positive?
respond_to do |format|
format.html do
@contacts
end
format.csv do
raw_csv = @q.result.distinct.to_csv
send_data raw_csv,
filename: "contacts_#{Time.zone.now.to_formatted_s(:number)}.csv",
type: "#{Mime[:csv]}; charset=utf-8"
end
end
end
def filter_by_flags(contacts)

View file

@ -10,6 +10,18 @@ module Admin
params[:q] ||= {}
@disputes = sortable_dispute_query_for(Dispute.active.all, params[:q])
@closed_disputes = sortable_dispute_query_for(Dispute.closed.all, params[:q], closed: true)
respond_to do |format|
format.html do
render 'admin/disputes/index'
end
format.csv do
raw_csv = @q.result.to_csv
send_data raw_csv,
filename: "disputes_#{Time.zone.now.to_formatted_s(:number)}.csv",
type: "#{Mime[:csv]}; charset=utf-8"
end
end
end
# GET /admin/disputes/1

View file

@ -44,7 +44,18 @@ module Admin
@q = versions.search(params[:q])
@versions = @q.result.page(params[:page])
@versions = @versions.per(params[:results_per_page]) if params[:results_per_page].to_i.positive?
render "admin/domain_versions/archive"
respond_to do |format|
format.html do
render 'admin/domain_versions/archive'
end
format.csv do
raw_csv = @q.result.to_csv
send_data raw_csv,
filename: "domain_history_#{Time.zone.now.to_formatted_s(:number)}.csv",
type: "#{Mime[:csv]}; charset=utf-8"
end
end
end
def show

View file

@ -13,6 +13,18 @@ module Admin
@epp_logs = @epp_logs.page(params[:page])
@count = @q.result.count
@epp_logs = @epp_logs.per(params[:results_per_page]) if paginate?
respond_to do |format|
format.html do
render 'admin/epp_logs/index'
end
format.csv do
raw_csv = @q.result.to_csv
send_data raw_csv,
filename: "epp_logs_#{Time.zone.now.to_formatted_s(:number)}.csv",
type: "#{Mime[:csv]}; charset=utf-8"
end
end
end
def show

View file

@ -13,6 +13,18 @@ module Admin
@repp_logs = @repp_logs.page(params[:page])
@count = @q.result.count
@repp_logs = @repp_logs.per(params[:results_per_page]) if paginate?
respond_to do |format|
format.html do
render 'admin/repp_logs/index'
end
format.csv do
raw_csv = @q.result.to_csv
send_data raw_csv,
filename: "repp_logs_#{Time.zone.now.to_formatted_s(:number)}.csv",
type: "#{Mime[:csv]}; charset=utf-8"
end
end
end
def show

View file

@ -9,6 +9,18 @@ module Admin
@q = domains.search(params[:q])
@domains = @q.result.page(params[:page])
@domains = @domains.per(params[:results_per_page]) if params[:results_per_page].to_i.positive?
respond_to do |format|
format.html do
render 'admin/reserved_domains/index'
end
format.csv do
raw_csv = @q.result.to_csv
send_data raw_csv,
filename: "reserved_domains_#{Time.zone.now.to_formatted_s(:number)}.csv",
type: "#{Mime[:csv]}; charset=utf-8"
end
end
end
def new

View file

@ -0,0 +1,10 @@
module CsvReportHelper
def to_csv
CSV.generate do |csv|
csv << column_names
all.each do |item|
csv << item.attributes.values_at(*column_names)
end
end
end
end

View file

@ -1,4 +1,5 @@
module ApiLog
class EppLog < Db
extend CsvReportHelper
end
end

View file

@ -1,4 +1,5 @@
module ApiLog
class ReppLog < Db
extend CsvReportHelper
end
end

View file

@ -1,5 +1,6 @@
class BlockedDomain < ApplicationRecord
include Versions
extend CsvReportHelper
before_save :generate_data
after_destroy :remove_data

View file

@ -1,4 +1,5 @@
class Dispute < ApplicationRecord
extend CsvReportHelper
include WhoisStatusPopulate
validates :domain_name, :password, :starts_at, :expires_at, presence: true
before_validation :fill_empty_passwords, :set_expiry_date

View file

@ -1,4 +1,5 @@
class Domain < ApplicationRecord
extend CsvReportHelper
include UserEvents
include Roids
include Versions # version/domain_version.rb
@ -720,15 +721,6 @@ class Domain < ApplicationRecord
contacts.select(&:email_verification_failed?)&.map(&:email)&.uniq
end
def self.to_csv
CSV.generate do |csv|
csv << column_names
all.each do |domain|
csv << domain.attributes.values_at(*column_names)
end
end
end
def self.pdf(html)
kit = PDFKit.new(html)
kit.to_pdf

View file

@ -1,4 +1,5 @@
class ReservedDomain < ApplicationRecord
extend CsvReportHelper
include Versions # version/reserved_domain_version.rb
include WhoisStatusPopulate
before_save :fill_empty_passwords

View file

@ -1,7 +1,7 @@
class Version::ContactVersion < PaperTrail::Version
extend CsvReportHelper
include VersionSession
self.table_name = :log_contacts
self.sequence_name = :log_contacts_id_seq
# scope :deleted, -> { where(event: 'destroy') }
end

View file

@ -1,4 +1,5 @@
class Version::DomainVersion < PaperTrail::Version
extend CsvReportHelper
include VersionSession
self.table_name = :log_domains

View file

@ -23,11 +23,12 @@
.form-group
= label_tag t(:results_per_page)
= text_field_tag :results_per_page, params[:results_per_page], class: 'form-control', placeholder: t(:results_per_page)
.col-md-3{style: 'padding-top: 25px;'}
.col-md-4{style: 'padding-top: 25px;'}
%button.btn.btn-primary
&nbsp;
%span.glyphicon.glyphicon-search
&nbsp;
= link_to(t('.csv_btn'), admin_blocked_domains_path(format: :csv, params: params.permit!), class: 'btn btn-default')
= link_to(t('.reset_btn'), admin_blocked_domains_path, class: 'btn btn-default')
%hr
.row

View file

@ -21,18 +21,19 @@
= label_tag :action
= select_tag '[q][event]', options_for_select([['Update', 'update'], ['Destroy', 'destroy'], ['Create', 'create']], params[:q][:event]), { include_blank:true, multiple: false, placeholder: t(:choose), class: 'form-control js-combobox' }
.row
.col-md-3
.col-md-3
.col-md-3
.form-group
= label_tag t(:results_per_page)
= text_field_tag :results_per_page, params[:results_per_page], class: 'form-control', placeholder: t(:results_per_page)
.col-md-3{style: 'padding-top: 25px;'}
%button.btn.btn-primary
&nbsp;
%span.glyphicon.glyphicon-search
&nbsp;
= link_to(t('.reset_btn'), admin_contact_versions_path, class: 'btn btn-default')
.col-md-3
.col-md-3
.col-md-3
.form-group
= label_tag t(:results_per_page)
= text_field_tag :results_per_page, params[:results_per_page], class: 'form-control', placeholder: t(:results_per_page)
.col-md-3{style: 'padding-top: 25px;float:right;padding-right: 0px;'}
%button.btn.btn-primary
&nbsp;
%span.glyphicon.glyphicon-search
&nbsp;
= link_to(t('.csv_btn'), admin_contact_versions_path(format: :csv, params: params.permit!), class: 'btn btn-default')
= link_to(t('.reset_btn'), admin_contact_versions_path, class: 'btn btn-default')
%hr

View file

@ -69,11 +69,12 @@
= check_box_tag :email_verification_failed, '1',params[:email_verification_failed].eql?('1'), style: 'width:auto;height:auto;float:right'
.row
.col-md-3{style: 'padding-top: 25px;float:right;'}
.col-md-3{style: 'padding-top: 25px;float:right;padding-right: 0px'}
%button.btn.btn-primary
&nbsp;
%span.glyphicon.glyphicon-search
&nbsp;
= link_to(t('.csv_btn'), admin_contacts_path(format: :csv, params: params.permit!), class: 'btn btn-default')
= link_to(t('.reset_btn'), admin_contacts_path, class: 'btn btn-default')
%hr
.row

View file

@ -32,12 +32,13 @@
<%= text_field_tag :results_per_page, params[:results_per_page], class: 'form-control', placeholder: t(:results_per_page) %>
</div>
</div>
<div class="col-md-3" style="padding-top: 25px;">
<div class="col-md-4" style="padding-top: 25px;">
<button class="btn btn-primary">
&nbsp;
<span class="glyphicon glyphicon-search"></span>
&nbsp;
</button>
<%= link_to(t('.csv_btn'), admin_disputes_path(format: :csv, params: params.permit!), class: 'btn btn-default') %>
<%= link_to(t('.reset_btn'), admin_disputes_path, class: 'btn btn-default') %>
</div>
</div>

View file

@ -27,11 +27,12 @@
.form-group
= label_tag t(:results_per_page)
= text_field_tag :results_per_page, params[:results_per_page], class: 'form-control', placeholder: t(:results_per_page)
.col-md-3{style: 'padding-top: 25px;'}
.col-md-3{style: 'padding-top: 25px;float:right;padding-right: 0px;'}
%button.btn.btn-primary
&nbsp;
%span.glyphicon.glyphicon-search
&nbsp;
= link_to(t('.csv_btn'), admin_domain_versions_path(format: :csv, params: params.permit!), class: 'btn btn-default')
= link_to(t('.reset_btn'), admin_domain_versions_path, class: 'btn btn-default')
%hr

View file

@ -36,11 +36,12 @@
.form-group
= f.label t(:created_before)
= f.search_field :created_at_lteq, value: params[:q][:created_at_lteq], class: 'form-control js-datepicker', placeholder: t(:created_before)
.col-md-3{style: 'padding-top: 25px;'}
.col-md-3{style: 'padding-top: 25px;float:right;padding-right: 0px;'}
%button.btn.btn-primary
&nbsp;
%span.glyphicon.glyphicon-search
&nbsp;
= link_to(t('.csv_btn'), admin_epp_logs_path(format: :csv, params: params.permit!), class: 'btn btn-default')
= link_to(t('.reset_btn'), admin_epp_logs_path, class: 'btn btn-default')
.row
.col-md-12
@ -49,6 +50,7 @@
.pull-right
.pagination
= t(:result_count, count: @count) if @count > 0
.row
.table-responsive
%table.table.table-hover.table-bordered.table-condensed
%thead

View file

@ -35,11 +35,12 @@
.form-group
= f.label t(:created_before)
= f.search_field :created_at_lteq, value: params[:q][:created_at_lteq], class: 'form-control js-datepicker', placeholder: t(:created_before)
.col-md-3{style: 'padding-top: 25px;'}
.col-md-3{style: 'padding-top: 25px;float:right;padding-right: 0px;'}
%button.btn.btn-primary
&nbsp;
%span.glyphicon.glyphicon-search
&nbsp;
= link_to(t('.csv_btn'), admin_repp_logs_path(format: :csv, params: params.permit!), class: 'btn btn-default')
= link_to(t('.reset_btn'), admin_repp_logs_path, class: 'btn btn-default')
%hr
.row
@ -48,6 +49,7 @@
.pull-right
.pagination
= t(:result_count, count: @count) if @count > 0
.row
.table-responsive
%table.table.table-hover.table-bordered.table-condensed
%thead

View file

@ -23,11 +23,12 @@
.form-group
= label_tag t(:results_per_page)
= text_field_tag :results_per_page, params[:results_per_page], class: 'form-control', placeholder: t(:results_per_page)
.col-md-3{style: 'padding-top: 25px;'}
.col-md-4{style: 'padding-top: 25px;'}
%button.btn.btn-primary
&nbsp;
%span.glyphicon.glyphicon-search
&nbsp;
= link_to(t('.csv_btn'), admin_reserved_domains_path(format: :csv, params: params.permit!), class: 'btn btn-default')
= link_to(t('.reset_btn'), admin_reserved_domains_path, class: 'btn btn-default')
%hr
.row

View file

@ -5,3 +5,4 @@ en:
title: Blocked domains
new_btn: New blocked domain
reset_btn: Reset
csv_btn: CSV

View file

@ -3,3 +3,4 @@ en:
contact_versions:
index:
reset_btn: Reset
csv_btn: CSV

View file

@ -3,6 +3,7 @@ en:
contacts:
index:
reset_btn: Reset
csv_btn: CSV
edit:
new_status_btn: Add new status

View file

@ -12,6 +12,7 @@ en:
title: Disputed domains
new_btn: New disputed domain
reset_btn: Reset
csv_btn: CSV
form:
password_hint: Generated automatically if left blank

View file

@ -3,6 +3,7 @@ en:
domain_versions:
archive:
reset_btn: Reset
csv_btn: CSV
registrant_placeholder: Registrant
registrant: Registrant

View file

@ -4,5 +4,6 @@ en:
index:
title: EPP log
reset_btn: Reset
csv_btn: CSV
show:
title: EPP log

View file

@ -4,6 +4,7 @@ en:
index:
title: REPP log
reset_btn: Reset
csv_btn: CSV
show:
title: REPP log

View file

@ -5,6 +5,7 @@ en:
title: Reserved domains
new_btn: New reserved domain
reset_btn: Reset
csv_btn: CSV
form:
password_hint: Generated automatically if left blank

View file

@ -48,6 +48,19 @@ class AdminAreaBlockedDomainsIntegrationTest < JavaScriptApplicationSystemTestCa
assert_text @domain.name
end
def test_download_blocked_domains
now = Time.zone.parse('2010-07-05 08:00')
travel_to now
get admin_blocked_domains_path(format: :csv)
assert_response :ok
assert_equal 'text/csv; charset=utf-8', response.headers['Content-Type']
assert_equal %(attachment; filename="blocked_domains_#{Time.zone.now.to_formatted_s(:number)}.csv"; filename*=UTF-8''blocked_domains_#{Time.zone.now.to_formatted_s(:number)}.csv),
response.headers['Content-Disposition']
assert_not_empty response.body
end
private
def visit_admin_blocked_domains_path

View file

@ -70,4 +70,17 @@ class AdminDisputesSystemTest < ApplicationSystemTestCase
assert_text 'Dispute already exists for this domain at given timeframe'
end
def test_download_disputes
now = Time.zone.parse('2010-07-05 08:00')
travel_to now
get admin_disputes_path(format: :csv)
assert_response :ok
assert_equal 'text/csv; charset=utf-8', response.headers['Content-Type']
assert_equal %(attachment; filename="disputes_#{Time.zone.now.to_formatted_s(:number)}.csv"; filename*=UTF-8''disputes_#{Time.zone.now.to_formatted_s(:number)}.csv),
response.headers['Content-Disposition']
assert_not_empty response.body
end
end

View file

@ -36,6 +36,19 @@ class AdminEppLogsIntegrationTest < ApplicationSystemTestCase
assert_match /#{date_now}/, epp_log_date
end
def test_download_epp_logs
now = Time.zone.parse('2010-07-05 08:00')
travel_to now
get admin_epp_logs_path(format: :csv)
assert_response :ok
assert_equal 'text/csv; charset=utf-8', response.headers['Content-Type']
assert_equal %(attachment; filename="epp_logs_#{Time.zone.now.to_formatted_s(:number)}.csv"; filename*=UTF-8''epp_logs_#{Time.zone.now.to_formatted_s(:number)}.csv),
response.headers['Content-Disposition']
assert_not_empty response.body
end
private
def send_epp_request_hello

View file

@ -20,4 +20,17 @@ class AdminAreaReppLogsIntegrationTest < ApplicationSystemTestCase
assert_text 'REPP log'
end
def test_download_repp_logs
now = Time.zone.parse('2010-07-05 08:00')
travel_to now
get admin_repp_logs_path(format: :csv)
assert_response :ok
assert_equal 'text/csv; charset=utf-8', response.headers['Content-Type']
assert_equal %(attachment; filename="repp_logs_#{Time.zone.now.to_formatted_s(:number)}.csv"; filename*=UTF-8''repp_logs_#{Time.zone.now.to_formatted_s(:number)}.csv),
response.headers['Content-Disposition']
assert_not_empty response.body
end
end

View file

@ -36,4 +36,17 @@ class AdminAreaReservedDomainsIntegrationTest < JavaScriptApplicationSystemTestC
assert_text 'Domain updated!'
end
def test_download_reserved_domains
now = Time.zone.parse('2010-07-05 08:00')
travel_to now
get admin_reserved_domains_path(format: :csv)
assert_response :ok
assert_equal 'text/csv; charset=utf-8', response.headers['Content-Type']
assert_equal %(attachment; filename="reserved_domains_#{Time.zone.now.to_formatted_s(:number)}.csv"; filename*=UTF-8''reserved_domains_#{Time.zone.now.to_formatted_s(:number)}.csv),
response.headers['Content-Disposition']
assert_not_empty response.body
end
end

View file

@ -56,4 +56,17 @@ class ContactVersionsTest < ApplicationSystemTestCase
assert_text 'Best Names'
assert_text '23.04.18, 18:50 update 1-AdminUser'
end
def test_download_contact_history
now = Time.zone.parse('2010-07-05 08:00')
travel_to now
get admin_contact_versions_path(format: :csv)
assert_response :ok
assert_equal 'text/csv; charset=utf-8', response.headers['Content-Type']
assert_equal %(attachment; filename="contact_history_#{Time.zone.now.to_formatted_s(:number)}.csv"; filename*=UTF-8''contact_history_#{Time.zone.now.to_formatted_s(:number)}.csv),
response.headers['Content-Disposition']
assert_not_empty response.body
end
end

View file

@ -39,4 +39,17 @@ class AdminContactsTest < ApplicationSystemTestCase
assert_text('Street Main Street City New York Postcode 12345 ' \
'State New York State Country United States of America')
end
def test_download_contacts
now = Time.zone.parse('2010-07-05 08:00')
travel_to now
get admin_contacts_path(format: :csv)
assert_response :ok
assert_equal 'text/csv; charset=utf-8', response.headers['Content-Type']
assert_equal %(attachment; filename="contacts_#{Time.zone.now.to_formatted_s(:number)}.csv"; filename*=UTF-8''contacts_#{Time.zone.now.to_formatted_s(:number)}.csv),
response.headers['Content-Disposition']
assert_not_empty response.body
end
end

View file

@ -88,6 +88,19 @@ class DomainVersionsTest < ApplicationSystemTestCase
'http://www.example.com/admin/domain_versions?q[name]=shop.test&q[registrant]=&q[registrar]=&q[event]=&results_per_page='
end
def test_download_domain_history
now = Time.zone.parse('2010-07-05 08:00')
travel_to now
get admin_domain_versions_path(format: :csv)
assert_response :ok
assert_equal 'text/csv; charset=utf-8', response.headers['Content-Type']
assert_equal %(attachment; filename="domain_history_#{Time.zone.now.to_formatted_s(:number)}.csv"; filename*=UTF-8''domain_history_#{Time.zone.now.to_formatted_s(:number)}.csv),
response.headers['Content-Disposition']
assert_not_empty response.body
end
def test_search_event_param
# TODO
end