mirror of
https://github.com/internetee/registry.git
synced 2025-05-17 01:47:18 +02:00
commit
bd1d056b3d
15 changed files with 204 additions and 7 deletions
|
@ -14,7 +14,7 @@ class Registrar::DomainsController < Registrar::DeppController # EPP controller
|
||||||
if params[:q].length == 1 && params[:q][:name_matches].present?
|
if params[:q].length == 1 && params[:q][:name_matches].present?
|
||||||
@domain = Domain.find_by(name: params[:q][:name_matches])
|
@domain = Domain.find_by(name: params[:q][:name_matches])
|
||||||
if @domain
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -40,6 +40,20 @@ class Registrar::DomainsController < Registrar::DeppController # EPP controller
|
||||||
end
|
end
|
||||||
|
|
||||||
@domains = @domains.per(params[:results_per_page]) if params[:results_per_page].to_i > 0
|
@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
|
end
|
||||||
# rubocop: enable Metrics/PerceivedComplexity
|
# rubocop: enable Metrics/PerceivedComplexity
|
||||||
# rubocop: enable Metrics/CyclomaticComplexity
|
# rubocop: enable Metrics/CyclomaticComplexity
|
||||||
|
|
|
@ -3,8 +3,13 @@ class Registrar::PollsController < Registrar::DeppController # EPP controller
|
||||||
before_action :init_epp_xml
|
before_action :init_epp_xml
|
||||||
|
|
||||||
def show
|
def show
|
||||||
|
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)
|
@data = depp_current_user.request(@ex.poll)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
@data = depp_current_user.request(@ex.poll(poll: {
|
@data = depp_current_user.request(@ex.poll(poll: {
|
||||||
|
|
|
@ -11,12 +11,16 @@ class ApiUser < User
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.min_password_length # Must precede .validates
|
||||||
|
6
|
||||||
|
end
|
||||||
|
|
||||||
# TODO: should have max request limit per day?
|
# TODO: should have max request limit per day?
|
||||||
belongs_to :registrar
|
belongs_to :registrar
|
||||||
has_many :certificates
|
has_many :certificates
|
||||||
|
|
||||||
validates :username, :password, :registrar, :roles, presence: true
|
validates :username, :password, :registrar, :roles, presence: true
|
||||||
validates :password, length: { minimum: 6 }
|
validates :password, length: { minimum: min_password_length }
|
||||||
validates :username, uniqueness: true
|
validates :username, uniqueness: true
|
||||||
|
|
||||||
# TODO: probably cache, because it's requested on every EPP
|
# TODO: probably cache, because it's requested on every EPP
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
class DomainPresenter
|
class DomainPresenter
|
||||||
delegate :name, :registrant_name, :registrant_id, to: :domain
|
delegate :name, :registrant_name, :registrant_id, :registrant_code, to: :domain
|
||||||
|
|
||||||
def initialize(domain:, view:)
|
def initialize(domain:, view:)
|
||||||
@domain = domain
|
@domain = domain
|
||||||
|
|
45
app/presenters/registrar/domain_list_csv_presenter.rb
Normal file
45
app/presenters/registrar/domain_list_csv_presenter.rb
Normal 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
|
|
@ -52,6 +52,10 @@
|
||||||
|
|
||||||
%button.btn.btn-default.js-reset-form
|
%button.btn.btn-default.js-reset-form
|
||||||
= t(:clear_fields)
|
= 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
|
%hr
|
||||||
|
|
||||||
.row
|
.row
|
||||||
|
|
10
config/locales/registrar/domains.en.yml
Normal file
10
config/locales/registrar/domains.en.yml
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
en:
|
||||||
|
registrar:
|
||||||
|
domains:
|
||||||
|
index:
|
||||||
|
export_csv_btn: Export CSV
|
||||||
|
csv:
|
||||||
|
domain_name: Domain
|
||||||
|
registrant_name: Registrant name
|
||||||
|
registrant_code: Registrant code
|
||||||
|
expire_time: Date of expiry
|
|
@ -1,12 +1,18 @@
|
||||||
FactoryGirl.define do
|
FactoryGirl.define do
|
||||||
factory :api_user do
|
factory :api_user do
|
||||||
sequence(:username) { |n| "test#{n}" }
|
sequence(:username) { |n| "test#{n}" }
|
||||||
password 'a' * 6
|
password 'a' * ApiUser.min_password_length
|
||||||
roles ['super']
|
roles ['super']
|
||||||
registrar
|
registrar
|
||||||
|
|
||||||
factory :api_user_epp do
|
factory :api_user_epp do
|
||||||
roles %w(epp static_registrant)
|
roles %w(epp static_registrant)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
factory :api_user_with_unlimited_balance do
|
||||||
|
after :build do |api_user|
|
||||||
|
api_user.registrar = create(:registrar_with_unlimited_balance)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -9,5 +9,11 @@ FactoryGirl.define do
|
||||||
zip 'test'
|
zip 'test'
|
||||||
email 'test@test.com'
|
email 'test@test.com'
|
||||||
country_code 'EE'
|
country_code 'EE'
|
||||||
|
|
||||||
|
factory :registrar_with_unlimited_balance do
|
||||||
|
after :create do |registrar|
|
||||||
|
create(:account, registrar: registrar, balance: 1_000_000)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
14
spec/features/registrar/domains/csv_export_spec.rb
Normal file
14
spec/features/registrar/domains/csv_export_spec.rb
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.feature 'CSV Export' do
|
||||||
|
background do
|
||||||
|
Setting.api_ip_whitelist_enabled = false
|
||||||
|
Setting.registrar_ip_whitelist_enabled = false
|
||||||
|
sign_in_to_registrar_area(user: create(:api_user_with_unlimited_balance))
|
||||||
|
end
|
||||||
|
|
||||||
|
scenario 'exports csv' do
|
||||||
|
visit registrar_domains_url
|
||||||
|
click_button t('registrar.domains.index.export_csv_btn')
|
||||||
|
end
|
||||||
|
end
|
|
@ -1,6 +1,6 @@
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
describe ApiUser do
|
RSpec.describe ApiUser do
|
||||||
context 'class methods' do
|
context 'class methods' do
|
||||||
before do
|
before do
|
||||||
Fabricate(:api_user, identity_code: '')
|
Fabricate(:api_user, identity_code: '')
|
||||||
|
@ -26,7 +26,7 @@ describe ApiUser do
|
||||||
@api_user.valid?
|
@api_user.valid?
|
||||||
@api_user.errors.full_messages.should match_array([
|
@api_user.errors.full_messages.should match_array([
|
||||||
"Password Password is missing",
|
"Password Password is missing",
|
||||||
"Password is too short (minimum is 6 characters)",
|
"Password is too short (minimum is #{ApiUser.min_password_length} characters)",
|
||||||
"Registrar Registrar is missing",
|
"Registrar Registrar is missing",
|
||||||
"Username Username is missing",
|
"Username Username is missing",
|
||||||
"Roles is missing"
|
"Roles is missing"
|
||||||
|
@ -68,4 +68,10 @@ describe ApiUser do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '::min_password_length', db: false do
|
||||||
|
it 'returns minimum password length' do
|
||||||
|
expect(described_class.min_password_length).to eq(6)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -153,6 +153,7 @@ RSpec.describe DomainPresenter do
|
||||||
name
|
name
|
||||||
registrant_name
|
registrant_name
|
||||||
registrant_id
|
registrant_id
|
||||||
|
registrant_code
|
||||||
)
|
)
|
||||||
|
|
||||||
domain_delegatable_attributes.each do |attribute_name|
|
domain_delegatable_attributes.each do |attribute_name|
|
||||||
|
|
45
spec/presenters/registrar/domain_list_csv_presenter_spec.rb
Normal file
45
spec/presenters/registrar/domain_list_csv_presenter_spec.rb
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe Registrar::DomainListCSVPresenter do
|
||||||
|
let(:domain) { instance_spy(DomainPresenter) }
|
||||||
|
let(:csv) { CSV.parse(described_class.new(domains: [domain], view: view).to_s, converters: :all) }
|
||||||
|
|
||||||
|
describe 'header' do
|
||||||
|
subject(:header) { csv.first }
|
||||||
|
|
||||||
|
it 'is present' do
|
||||||
|
columns = []
|
||||||
|
columns[0] = 'Domain'
|
||||||
|
columns[1] = 'Registrant name'
|
||||||
|
columns[2] = 'Registrant code'
|
||||||
|
columns[3] = 'Date of expiry'
|
||||||
|
columns
|
||||||
|
|
||||||
|
expect(header).to eq(columns)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe 'row' do
|
||||||
|
subject(:row) { csv.second }
|
||||||
|
|
||||||
|
it 'has domain name' do
|
||||||
|
expect(domain).to receive(:name).and_return('test name')
|
||||||
|
expect(row[0]).to eq('test name')
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'has registrant name' do
|
||||||
|
expect(domain).to receive(:registrant_name).and_return('test registrant name')
|
||||||
|
expect(row[1]).to eq('test registrant name')
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'has registrant code' do
|
||||||
|
expect(domain).to receive(:registrant_code).and_return('test registrant code')
|
||||||
|
expect(row[2]).to eq('test registrant code')
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'has expire date' do
|
||||||
|
expect(domain).to receive(:expire_date).and_return('expire date')
|
||||||
|
expect(row[3]).to eq('expire date')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
28
spec/requests/registrar/domains_controller_spec.rb
Normal file
28
spec/requests/registrar/domains_controller_spec.rb
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe Registrar::DomainsController, db: true do
|
||||||
|
describe '#index' do
|
||||||
|
before do
|
||||||
|
sign_in_to_registrar_area
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'responds with success' do
|
||||||
|
csv_presenter = instance_double(Registrar::DomainListCSVPresenter, to_s: 'csv')
|
||||||
|
expect(Registrar::DomainListCSVPresenter).to receive(:new).and_return(csv_presenter)
|
||||||
|
|
||||||
|
get registrar_domains_url(format: 'csv')
|
||||||
|
|
||||||
|
expect(response.body).to eq('csv')
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns csv' do
|
||||||
|
get registrar_domains_url(format: 'csv')
|
||||||
|
|
||||||
|
expect(response).to have_http_status(:success)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def sign_in_to_registrar_area(user: FactoryGirl.create(:api_user))
|
||||||
|
post registrar_sessions_path, { depp_user: { tag: user.username, password: user.password } }
|
||||||
|
end
|
||||||
|
end
|
9
spec/routing/registrar/domains_routing_spec.rb
Normal file
9
spec/routing/registrar/domains_routing_spec.rb
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe Registrar::DomainsController do
|
||||||
|
describe 'routing' do
|
||||||
|
it 'routes to #index' do
|
||||||
|
expect(get: '/registrar/domains').to route_to('registrar/domains#index')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Add table
Add a link
Reference in a new issue