Merge pull request #335 from internetee/registry-248

Registry 248
This commit is contained in:
Timo Võhmar 2017-01-24 14:31:20 +02:00 committed by GitHub
commit bd1d056b3d
15 changed files with 204 additions and 7 deletions

View file

@ -14,7 +14,7 @@ class Registrar::DomainsController < Registrar::DeppController # EPP controller
if params[:q].length == 1 && params[:q][:name_matches].present?
@domain = Domain.find_by(name: params[:q][:name_matches])
if @domain
redirect_to info_registrar_domains_path(domain_name: @domain.name) and return
redirect_to info_registrar_domains_url(domain_name: @domain.name) and return
end
end
@ -40,6 +40,20 @@ class Registrar::DomainsController < Registrar::DeppController # EPP controller
end
@domains = @domains.per(params[:results_per_page]) if params[:results_per_page].to_i > 0
respond_to do |format|
format.html
format.csv do
domain_presenters = []
@domains.find_each do |domain|
domain_presenters << ::DomainPresenter.new(domain: domain, view: view_context)
end
csv = Registrar::DomainListCSVPresenter.new(domains: domain_presenters, view: view_context).to_s
send_data(csv)
end
end
end
# rubocop: enable Metrics/PerceivedComplexity
# rubocop: enable Metrics/CyclomaticComplexity

View file

@ -3,7 +3,12 @@ class Registrar::PollsController < Registrar::DeppController # EPP controller
before_action :init_epp_xml
def show
@data = depp_current_user.request(@ex.poll)
if Rails.env.test? # Stub for depp server request
@data = Object.new
def @data.css(key); []; end
else
@data = depp_current_user.request(@ex.poll)
end
end
def destroy

View file

@ -11,12 +11,16 @@ class ApiUser < User
}
end
def self.min_password_length # Must precede .validates
6
end
# TODO: should have max request limit per day?
belongs_to :registrar
has_many :certificates
validates :username, :password, :registrar, :roles, presence: true
validates :password, length: { minimum: 6 }
validates :password, length: { minimum: min_password_length }
validates :username, uniqueness: true
# TODO: probably cache, because it's requested on every EPP

View file

@ -1,5 +1,5 @@
class DomainPresenter
delegate :name, :registrant_name, :registrant_id, to: :domain
delegate :name, :registrant_name, :registrant_id, :registrant_code, to: :domain
def initialize(domain:, view:)
@domain = domain

View file

@ -0,0 +1,45 @@
class Registrar::DomainListCSVPresenter
def initialize(domains:, view:)
@domains = domains
@view = view
end
def to_s
table = CSV::Table.new([header])
domains.each do |domain|
table << domain_to_row(domain: domain)
end
table.to_s
end
private
def header
columns = %w(
domain_name
registrant_name
registrant_code
expire_time
)
columns.map! { |column| view.t("registrar.domains.index.csv.#{column}") }
CSV::Row.new(columns, [], true)
end
def domain_to_row(domain:)
row = []
row[0] = domain.name
row[1] = domain.registrant_name
row[2] = domain.registrant_code
row[3] = domain.expire_date
row
CSV::Row.new([], row)
end
attr_reader :domains
attr_reader :view
end

View file

@ -52,6 +52,10 @@
&nbsp;
%button.btn.btn-default.js-reset-form
= t(:clear_fields)
.row
.col-md-2
= button_tag t('.export_csv_btn'), class: 'btn btn-primary export-domains-csv-btn',
formaction: registrar_domains_path(format: 'csv')
%hr
.row