diff --git a/Gemfile b/Gemfile index 5014e517f..99f257daa 100644 --- a/Gemfile +++ b/Gemfile @@ -67,6 +67,9 @@ gem 'selectize-rails', '~> 0.11.0' # See https://github.com/sstephenson/execjs#readme for more supported runtimes gem 'therubyracer', platforms: :ruby +# for settings +gem 'rails-settings-cached', '0.4.1' + group :development, :test do gem 'capybara', '~> 2.4.1' # For feature testing diff --git a/Gemfile.lock b/Gemfile.lock index 6a8fe5b70..f35d38ca6 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -200,6 +200,8 @@ GEM bundler (>= 1.3.0, < 2.0) railties (= 4.1.4) sprockets-rails (~> 2.0) + rails-settings-cached (0.4.1) + rails (>= 4.0.0) railties (4.1.4) actionpack (= 4.1.4) activesupport (= 4.1.4) @@ -376,6 +378,7 @@ DEPENDENCIES poltergeist (~> 1.5.1) pry (~> 0.10.1) rails (= 4.1.4) + rails-settings-cached (= 0.4.1) ransack (~> 1.3.0) rspec-rails (~> 3.0.2) rubocop (~> 0.26.1) diff --git a/Guardfile b/Guardfile index a915ec3ee..7f9b167e1 100644 --- a/Guardfile +++ b/Guardfile @@ -26,7 +26,7 @@ group :red_green_refactor, halt_on_fail: true do # Martin does not want rubocop unless Socket.gethostname == 'martin' - guard :rubocop, cli: '--display-cop-names -c .rubocop-guard.yml', notification: false do + guard :rubocop, cli: '--display-cop-names -c .rubocop-guard.yml -f fuubar', notification: false do watch(%r{.+\.rb$}) watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) } watch(%r{(?:.+/)?\.rubocop-guard\.yml$}) { |m| File.dirname(m[0]) } diff --git a/app/controllers/admin/domains_controller.rb b/app/controllers/admin/domains_controller.rb index fa3b29918..a5f50447e 100644 --- a/app/controllers/admin/domains_controller.rb +++ b/app/controllers/admin/domains_controller.rb @@ -2,7 +2,7 @@ class Admin::DomainsController < AdminController before_action :set_domain, only: [:show, :edit, :update] def index - @q = Domain.search(params[:q]) + @q = Domain.includes(:registrar, :owner_contact).search(params[:q]) @domains = @q.result.page(params[:page]) end diff --git a/app/controllers/admin/setting_groups_controller.rb b/app/controllers/admin/setting_groups_controller.rb deleted file mode 100644 index 994cfe531..000000000 --- a/app/controllers/admin/setting_groups_controller.rb +++ /dev/null @@ -1,30 +0,0 @@ -class Admin::SettingGroupsController < AdminController - before_action :set_setting_group, only: [:show, :update] - - def index - @q = SettingGroup.search(params[:q]) - @setting_groups = @q.result.page(params[:page]) - end - - def show; end - - def update - if @setting_group.update(setting_group_params) - flash[:notice] = I18n.t('shared.setting_updated') - redirect_to [:admin, @setting_group] - else - flash[:alert] = I18n.t('shared.failed_to_update_setting') - render 'show' - end - end - - private - - def set_setting_group - @setting_group = SettingGroup.find(params[:id]) - end - - def setting_group_params - params.require(:setting_group).permit(settings_attributes: [:value, :id]) - end -end diff --git a/app/controllers/admin/settings_controller.rb b/app/controllers/admin/settings_controller.rb new file mode 100644 index 000000000..b8e6048aa --- /dev/null +++ b/app/controllers/admin/settings_controller.rb @@ -0,0 +1,48 @@ +class Admin::SettingsController < AdminController + before_action :set_setting_group, only: [:show, :update] + + def index + @settings = Setting.unscoped + end + + def create + casted_settings.each do |k, v| + Setting[k] = v + end + + flash[:notice] = I18n.t('shared.records_updated') + redirect_to [:admin, :settings] + end + + def show; end + + def update + if @setting_group.update(setting_group_params) + flash[:notice] = I18n.t('shared.setting_updated') + redirect_to [:admin, @setting_group] + else + flash[:alert] = I18n.t('shared.failed_to_update_setting') + render 'show' + end + end + + private + + def set_setting_group + @setting_group = SettingGroup.find(params[:id]) + end + + def setting_group_params + params.require(:setting_group).permit(settings_attributes: [:value, :id]) + end + + def casted_settings + settings = {} + params[:settings].each do |k, v| + settings[k] = v.to_i if Setting[k].class == Fixnum + settings[k] = v.to_f if Setting[k].class == Float + settings[k] = (v == 'true' ? true : false) if [TrueClass, FalseClass].include?(Setting[k].class) + end + settings + end +end diff --git a/app/controllers/client/domains_controller.rb b/app/controllers/client/domains_controller.rb index 813fe7492..bc20dbc3a 100644 --- a/app/controllers/client/domains_controller.rb +++ b/app/controllers/client/domains_controller.rb @@ -4,7 +4,7 @@ class Client::DomainsController < ClientController before_action :verify_deletion, only: [:destroy] def index - @q = current_registrar.domains.search(params[:q]) + @q = current_registrar.domains.includes(:owner_contact).search(params[:q]) @domains = @q.result.page(params[:page]) end diff --git a/app/models/delegation_signer.rb b/app/models/delegation_signer.rb deleted file mode 100644 index 694feb870..000000000 --- a/app/models/delegation_signer.rb +++ /dev/null @@ -1,42 +0,0 @@ -class DelegationSigner < ActiveRecord::Base - include EppErrors - has_one :dnskeys - - validate :validate_dnskeys_uniqueness - validate :validate_dnskeys_count - - def epp_code_map - sg = SettingGroup.domain_validation - - { - '2004' => [ # Parameter value range error - [:dnskeys, :out_of_range, - { - min: sg.setting(Setting::DNSKEYS_MIN_COUNT).value, - max: sg.setting(Setting::DNSKEYS_MAX_COUNT).value - } - ] - ] - } - end - - def validate_dnskeys_count - sg = SettingGroup.domain_validation - min, max = sg.setting(:dnskeys_min_count).value.to_i, sg.setting(:dnskeys_max_count).value.to_i - return if dnskeys.reject(&:marked_for_destruction?).length.between?(min, max) - errors.add(:dnskeys, :out_of_range, { min: min, max: max }) - end - - def validate_dnskeys_uniqueness - validated = [] - list = dnskeys.reject(&:marked_for_destruction?) - list.each do |dnskey| - next if dnskey.public_key.blank? - existing = list.select { |x| x.public_key == dnskey.public_key } - next unless existing.length > 1 - validated << dnskey.public_key - errors.add(:dnskeys, :invalid) if errors[:dnskeys].blank? - dnskey.errors.add(:public_key, :taken) - end - end -end diff --git a/app/models/dnskey.rb b/app/models/dnskey.rb index 42a6bb77f..9a052e998 100644 --- a/app/models/dnskey.rb +++ b/app/models/dnskey.rb @@ -66,11 +66,9 @@ class Dnskey < ActiveRecord::Base hex = [domain.name_in_wire_format, flags_hex, protocol_hex, alg_hex, public_key_hex].join bin = self.class.hex_to_bin(hex) - sg = SettingGroup.dnskeys.setting(Setting::DS_ALGORITHM).value - - if sg == '1' + if Setting.ds_algorithm == 1 self.ds_digest = Digest::SHA1.hexdigest(bin).upcase - elsif sg == '2' + elsif Setting.ds_algorithm == 2 self.ds_digest = Digest::SHA256.hexdigest(bin).upcase end end diff --git a/app/models/domain.rb b/app/models/domain.rb index 43f0629bf..b5f898b45 100644 --- a/app/models/domain.rb +++ b/app/models/domain.rb @@ -103,9 +103,7 @@ class Domain < ActiveRecord::Base ### VALIDATIONS ### def validate_nameservers_count - sg = SettingGroup.domain_validation - min, max = sg.setting(:ns_min_count).value.to_i, sg.setting(:ns_max_count).value.to_i - + min, max = Setting.ns_min_count, Setting.ns_max_count return if nameservers.reject(&:marked_for_destruction?).length.between?(min, max) errors.add(:nameservers, :out_of_range, { min: min, max: max }) end @@ -115,8 +113,7 @@ class Domain < ActiveRecord::Base end def validate_dnskeys_count - sg = SettingGroup.domain_validation - min, max = sg.setting(:dnskeys_min_count).value.to_i, sg.setting(:dnskeys_max_count).value.to_i + min, max = Setting.dnskeys_min_count, Setting.dnskeys_max_count return if dnskeys.reject(&:marked_for_destruction?).length.between?(min, max) errors.add(:dnskeys, :out_of_range, { min: min, max: max }) end diff --git a/app/models/domain_transfer.rb b/app/models/domain_transfer.rb index 366b0872c..010d67046 100644 --- a/app/models/domain_transfer.rb +++ b/app/models/domain_transfer.rb @@ -14,7 +14,7 @@ class DomainTransfer < ActiveRecord::Base before_create :set_wait_until def set_wait_until - wait_time = SettingGroup.domain_general.setting(:transfer_wait_time).value.to_i + wait_time = Setting.transfer_wait_time return if wait_time == 0 self.wait_until = transfer_requested_at + wait_time.hours end diff --git a/app/models/epp/epp_domain.rb b/app/models/epp/epp_domain.rb index 950e6072e..1355b63c9 100644 --- a/app/models/epp/epp_domain.rb +++ b/app/models/epp/epp_domain.rb @@ -6,8 +6,6 @@ class Epp::EppDomain < Domain validate :validate_admin_contacts_count def epp_code_map # rubocop:disable Metrics/MethodLength - domain_validation_sg = SettingGroup.domain_validation - { '2002' => [ [:base, :domain_already_belongs_to_the_querying_registrar] @@ -29,15 +27,15 @@ class Epp::EppDomain < Domain '2004' => [ # Parameter value range error [:nameservers, :out_of_range, { - min: domain_validation_sg.setting(:ns_min_count).value, - max: domain_validation_sg.setting(:ns_max_count).value + min: Setting.ns_min_count, + max: Setting.ns_max_count } ], [:period, :out_of_range, { value: { obj: 'period', val: period } }], [:dnskeys, :out_of_range, { - min: domain_validation_sg.setting(Setting::DNSKEYS_MIN_COUNT).value, - max: domain_validation_sg.setting(Setting::DNSKEYS_MAX_COUNT).value + min: Setting.dnskeys_min_count, + max: Setting.dnskeys_max_count } ] ], @@ -189,8 +187,7 @@ class Epp::EppDomain < Domain end def attach_dnskeys(dnssec_data) - sg = SettingGroup.dnskeys - return false unless validate_dnssec_data(dnssec_data, sg) + return false unless validate_dnssec_data(dnssec_data) dnssec_data[:ds_data].each do |ds_data| dnskeys.build(ds_data) @@ -200,41 +197,35 @@ class Epp::EppDomain < Domain dnskeys.build({ ds_key_tag: SecureRandom.hex(5), ds_alg: 3, - ds_digest_type: sg.setting(Setting::DS_ALGORITHM).value + ds_digest_type: Setting.ds_algorithm }.merge(x)) end end - def validate_dnssec_data(dnssec_data, sg) - ds_data_allowed?(dnssec_data, sg) - ds_data_with_keys_allowed?(dnssec_data, sg) - key_data_allowed?(dnssec_data, sg) + def validate_dnssec_data(dnssec_data) + ds_data_allowed?(dnssec_data) + ds_data_with_keys_allowed?(dnssec_data) + key_data_allowed?(dnssec_data) errors.empty? end - def ds_data_allowed?(dnssec_data, sg) - ds_data_allowed = sg.setting(Setting::ALLOW_DS_DATA).value == '0' ? false : true - - return if (dnssec_data[:ds_data].any? && ds_data_allowed) || dnssec_data[:ds_data].empty? + def ds_data_allowed?(dnssec_data) + return if (dnssec_data[:ds_data].any? && Setting.ds_data_allowed) || dnssec_data[:ds_data].empty? errors.add(:base, :ds_data_not_allowed) end - def ds_data_with_keys_allowed?(dnssec_data, sg) - ds_data_with_keys_allowed = sg.setting(Setting::ALLOW_DS_DATA_WITH_KEYS).value == '0' ? false : true - + def ds_data_with_keys_allowed?(dnssec_data) dnssec_data[:ds_data].each do |ds_data| - if key_data?(ds_data) && !ds_data_with_keys_allowed + if key_data?(ds_data) && !Setting.ds_data_with_key_allowed errors.add(:base, :ds_data_with_key_not_allowed) return end end end - def key_data_allowed?(dnssec_data, sg) - key_data_allowed = sg.setting(Setting::ALLOW_KEY_DATA).value == '0' ? false : true - - return if (dnssec_data[:key_data].any? && key_data_allowed) || dnssec_data[:key_data].empty? + def key_data_allowed?(dnssec_data) + return if (dnssec_data[:key_data].any? && Setting.key_data_allowed) || dnssec_data[:key_data].empty? errors.add(:base, :key_data_not_allowed) end @@ -244,9 +235,7 @@ class Epp::EppDomain < Domain end def detach_dnskeys(dnssec_data) - sg = SettingGroup.dnskeys - - return false unless validate_dnssec_data(dnssec_data, sg) + return false unless validate_dnssec_data(dnssec_data) to_delete = [] dnssec_data[:ds_data].each do |x| @@ -305,9 +294,7 @@ class Epp::EppDomain < Domain return true if pt - wait_time = SettingGroup.domain_general.setting(:transfer_wait_time).value.to_i - - if wait_time > 0 + if Setting.transfer_wait_time > 0 domain_transfers.create( status: DomainTransfer::PENDING, transfer_requested_at: Time.zone.now, diff --git a/app/models/setting.rb b/app/models/setting.rb index 012fd31c7..50222cb11 100644 --- a/app/models/setting.rb +++ b/app/models/setting.rb @@ -1,14 +1,2 @@ -class Setting < ActiveRecord::Base - belongs_to :setting_group - has_many :domain_statuses - has_many :domains, through: :domain_statuses - validates :code, uniqueness: { scope: :setting_group_id } - - # dnskeys - DS_ALGORITHM = 'ds_algorithm' - ALLOW_DS_DATA = 'allow_ds_data' - ALLOW_DS_DATA_WITH_KEYS = 'allow_ds_data_with_keys' - ALLOW_KEY_DATA = 'allow_key_data' - DNSKEYS_MAX_COUNT = 'dnskeys_max_count' - DNSKEYS_MIN_COUNT = 'dnskeys_min_count' +class Setting < RailsSettings::CachedSettings end diff --git a/app/models/setting_group.rb b/app/models/setting_group.rb deleted file mode 100644 index be1656dd3..000000000 --- a/app/models/setting_group.rb +++ /dev/null @@ -1,25 +0,0 @@ -class SettingGroup < ActiveRecord::Base - has_many :settings - - accepts_nested_attributes_for :settings - - validates :code, uniqueness: true - - def setting(key) - settings.find_by(code: key.to_s) - end - - class << self - def domain_validation - find_by(code: 'domain_validation') - end - - def domain_general - find_by(code: 'domain_general') - end - - def dnskeys - find_by(code: 'dnskeys') - end - end -end diff --git a/app/views/admin/setting_groups/index.haml b/app/views/admin/setting_groups/index.haml deleted file mode 100644 index 1c97f56cb..000000000 --- a/app/views/admin/setting_groups/index.haml +++ /dev/null @@ -1,17 +0,0 @@ -%h2= t('shared.setting_groups') -%hr -.row - .col-md-12 - .table-responsive - %table.table.table-hover.table-bordered.table-condensed - %thead - %tr - %th{class: 'col-xs-9'} - = sort_link(@q, 'code', t('shared.setting_group')) - %th{class: 'col-xs-2'} - = t('shared.action') - %tbody - - @setting_groups.each do |x| - %tr - %td= t("setting_groups.codes.#{x.code}") - %td= link_to(t('shared.edit_settings'), admin_setting_group_path(x), class: 'btn btn-primary btn-xs') diff --git a/app/views/admin/setting_groups/show.haml b/app/views/admin/setting_groups/show.haml deleted file mode 100644 index 714d37407..000000000 --- a/app/views/admin/setting_groups/show.haml +++ /dev/null @@ -1,22 +0,0 @@ -%h2= t("setting_groups.codes.#{@setting_group.code}") -%hr -= form_for([:admin, @setting_group]) do |f| - .row - .col-md-12 - .table-responsive - %table.table.table-hover.table-bordered.table-condensed - %thead - %tr - %th{class: 'col-xs-9'} - = t('shared.setting') - %th{class: 'col-xs-2'} - = t('shared.value') - %tbody - - @setting_group.settings.order(:code).each do |setting| - = f.fields_for :settings, setting do |sf| - %tr - %td= sf.label :value, t("settings.codes.#{sf.object.code}") - %td= sf.text_field(:value, autocomplete: 'off') - .row - .col-md-12.text-right - %button.btn.btn-primary=t('shared.save') diff --git a/app/views/admin/settings/index.haml b/app/views/admin/settings/index.haml new file mode 100644 index 000000000..d3339c382 --- /dev/null +++ b/app/views/admin/settings/index.haml @@ -0,0 +1,26 @@ +%h2= t('shared.settings') +%hr += form_tag [:admin, :settings] do + .row + .col-md-12 + .table-responsive + %table.table.table-hover.table-bordered.table-condensed + %thead + %tr + %th{class: 'col-xs-9'} + = t('shared.setting') + %th{class: 'col-xs-2'} + = t('shared.value') + %tbody + - @settings.each do |x| + %tr + %td= t("shared.#{x.var}") + - if [TrueClass, FalseClass].include?(x.value.class) + %td + = hidden_field_tag("[settings][#{x.var}]", '') + = check_box_tag("[settings][#{x.var}]", true, x.value) + - else + %td= text_field_tag("[settings][#{x.var}]", x.value) + .row + .col-md-12.text-right + %button.btn.btn-primary=t('shared.save') diff --git a/app/views/layouts/application.haml b/app/views/layouts/application.haml index af4988ea7..0e027110f 100644 --- a/app/views/layouts/application.haml +++ b/app/views/layouts/application.haml @@ -36,7 +36,7 @@ %ul.dropdown-menu{role: "menu"} %li.dropdown-header= t('shared.system') %li - = link_to t('shared.setting_groups'), admin_setting_groups_path + = link_to t('shared.settings'), admin_settings_path %li.divider %li.dropdown-header= t('shared.users') %li diff --git a/config/locales/en.yml b/config/locales/en.yml index 5e5f6b8c3..5d7804b8f 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -139,11 +139,6 @@ en: blank: 'Contact was not found' taken: 'Contact already exists on this domain!' - setting: - attributes: - code: - taken: 'Code already exists' - domain_status: attributes: setting_id: @@ -249,27 +244,10 @@ en: domain_exists_but_belongs_to_other_registrar: 'Domain exists but belongs to other registrar' attribute_op_is_invalid: 'Attribute op is invalid' - setting_groups: - codes: - domain_validation: 'Domain validation' - domain_general: 'Domain general' - dnskeys: 'DNS keys' - - settings: - codes: - ns_min_count: 'Nameserver minimum count' - ns_max_count: 'Nameserver maximum count' - dnskeys_min_count: 'DNS keys minimum count' - dnskeys_max_count: 'DNS keys maximum count' - allow_ds_data: 'Allow DS data' - allow_ds_data_with_keys: 'Allow DS data with keys' - allow_key_data: 'Allow key data' - ds_algorithm: 'DS algorithm' shared: code: 'Code' value: 'Value' - setting_groups: 'Setting groups' action: 'Action' edit: 'Edit' save: 'Save' @@ -282,9 +260,6 @@ en: valid_to: 'Valid to' name: 'Name' transfer_can_be_approved_only_by_current_registrar: 'Transfer can be approved only by current domain registrar' - edit_settings: 'Edit settings' - setting_group: 'Setting group' - setting: 'Setting' registrar: 'Registrar' owner: 'Owner' domain_details: 'Domain details' @@ -357,8 +332,6 @@ en: contact_updated: 'Contact updated' search: 'Search' reg_no: 'Reg. no' - setting_updated: 'Setting updated!' - failed_to_update_setting: 'Failed to update setting' status: 'Status' eedirekt: 'EEDirekt' contact: 'Contact' @@ -428,6 +401,7 @@ en: record_created: 'Record created' failed_to_create_record: 'Failed to create record' record_updated: 'Record updated' + records_updated: 'Records updated' failed_to_update_record: 'Failed to update record' record_deleted: 'Record deleted' failed_to_delete_record: 'Failed to delete record' @@ -435,5 +409,15 @@ en: authentication_error: 'Authentication error' ds_data_and_key_data_must_not_exists_together: 'dsData and keyData objects must not exists together' + ns_min_count: 'Nameserver minimum count' + ns_max_count: 'Nameserver maximum count' + dnskeys_min_count: 'DNS keys minimum count' + dnskeys_max_count: 'DNS keys maximum count' + ds_data_allowed: 'DS data allowed' + ds_data_with_key_allowed: 'Allow DS data with key' + key_data_allowed: 'Allow key data' + ds_algorithm: 'DS algorithm' + setting: 'Setting' + registrar: Registrar diff --git a/config/routes.rb b/config/routes.rb index f0aed11b1..05316c6eb 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -8,7 +8,7 @@ Rails.application.routes.draw do ## ADMIN ROUTES namespace(:admin) do resources :domains - resources :setting_groups + resources :settings resources :registrars do collection do get :search diff --git a/db/migrate/20140815082916_create_settings.rb b/db/migrate/20140815082916_create_settings.rb deleted file mode 100644 index c8dff86c2..000000000 --- a/db/migrate/20140815082916_create_settings.rb +++ /dev/null @@ -1,9 +0,0 @@ -class CreateSettings < ActiveRecord::Migration - def change - create_table :settings do |t| - t.integer :setting_group_id - t.string :code - t.string :value - end - end -end diff --git a/db/migrate/20141015135255_create_settings.rb b/db/migrate/20141015135255_create_settings.rb new file mode 100644 index 000000000..07915811f --- /dev/null +++ b/db/migrate/20141015135255_create_settings.rb @@ -0,0 +1,18 @@ +class CreateSettings < ActiveRecord::Migration + def self.up + drop_table :settings + create_table :settings do |t| + t.string :var, :null => false + t.text :value, :null => true + t.integer :thing_id, :null => true + t.string :thing_type, :limit => 30, :null => true + t.timestamps + end + + add_index :settings, [ :thing_type, :thing_id, :var ], :unique => true + end + + def self.down + drop_table :settings + end +end diff --git a/db/migrate/20141015135742_correct_settings.rb b/db/migrate/20141015135742_correct_settings.rb new file mode 100644 index 000000000..f8675f851 --- /dev/null +++ b/db/migrate/20141015135742_correct_settings.rb @@ -0,0 +1,17 @@ +class CorrectSettings < ActiveRecord::Migration + def up + drop_table :setting_groups + + Setting.ds_algorithm = 2 + Setting.ds_data_allowed = true + Setting.ds_data_with_key_allowed = true + Setting.key_data_allowed = true + + Setting.dnskeys_min_count = 0 + Setting.dnskeys_max_count = 9 + Setting.ns_min_count = 2 + Setting.ns_max_count = 11 + + Setting.transfer_wait_time = 0 + end +end diff --git a/db/schema.rb b/db/schema.rb index 791379dc5..09125780b 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20141014073435) do +ActiveRecord::Schema.define(version: 20141015135742) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -253,15 +253,16 @@ ActiveRecord::Schema.define(version: 20141014073435) do t.datetime "updated_at" end - create_table "setting_groups", force: true do |t| - t.string "code" + create_table "settings", force: true do |t| + t.string "var", null: false + t.text "value" + t.integer "thing_id" + t.string "thing_type", limit: 30 + t.datetime "created_at" + t.datetime "updated_at" end - create_table "settings", force: true do |t| - t.integer "setting_group_id" - t.string "code" - t.string "value" - end + add_index "settings", ["thing_type", "thing_id", "var"], name: "index_settings_on_thing_type_and_thing_id_and_var", unique: true, using: :btree create_table "users", force: true do |t| t.string "username" diff --git a/db/seeds.rb b/db/seeds.rb index c180727ea..d0f1fbada 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -66,27 +66,14 @@ User.where( country: Country.where(name: 'Estonia').first ).first_or_create -sg = SettingGroup.where(code: 'domain_validation').first_or_create +Setting.ds_algorithm = 2 +Setting.ds_data_allowed = true +Setting.ds_data_with_key_allowed = true +Setting.key_data_allowed = true -s_1 = Setting.where(code: 'ns_min_count').first_or_create -s_1.value = 1 +Setting.dnskeys_min_count = 0 +Setting.dnskeys_max_count = 9 +Setting.ns_min_count = 2 +Setting.ns_max_count = 11 -s_2 = Setting.where(code: 'ns_max_count').first_or_create -s_2.value = 13 - -s_3 = Setting.where(code: 'dnskeys_min_count').first_or_create -s_3.value = 0 - -s_4 = Setting.where(code: 'dnskeys_max_count').first_or_create -s_4.value = 9 - -sg.settings = [s_1, s_2, s_3, s_4] -sg.save - -sg = SettingGroup.where(code: 'domain_general').first_or_create - -s_1 = Setting.where(code: 'transfer_wait_time').first_or_create -s_1.value = 0 - -sg.settings = [s_1] -sg.save +Setting.transfer_wait_time = 0 diff --git a/spec/epp/contact_spec.rb b/spec/epp/contact_spec.rb index 5acbccd4a..64fd34e78 100644 --- a/spec/epp/contact_spec.rb +++ b/spec/epp/contact_spec.rb @@ -11,8 +11,7 @@ describe 'EPP Contact', epp: true do Fabricate(:epp_user) Fabricate(:epp_user, username: 'zone', registrar: zone) Fabricate(:epp_user, username: 'elkdata', registrar: elkdata) - Fabricate(:domain_validation_setting_group) - Fabricate(:dnskeys_setting_group) + create_settings end context 'create command' do diff --git a/spec/epp/domain_spec.rb b/spec/epp/domain_spec.rb index 16b725ba8..2888e59f0 100644 --- a/spec/epp/domain_spec.rb +++ b/spec/epp/domain_spec.rb @@ -6,14 +6,12 @@ describe 'EPP Domain', epp: true do let(:elkdata) { Fabricate(:registrar, { name: 'Elkdata', reg_no: '123' }) } let(:zone) { Fabricate(:registrar) } + before(:each) { create_settings } + context 'with valid user' do before(:each) do Fabricate(:epp_user, username: 'zone', registrar: zone) Fabricate(:epp_user, username: 'elkdata', registrar: elkdata) - - Fabricate(:domain_validation_setting_group) - Fabricate(:domain_statuses_setting_group) - Fabricate(:dnskeys_setting_group) end it 'returns error if contact does not exists' do @@ -36,7 +34,6 @@ describe 'EPP Domain', epp: true do let(:domain) { Domain.first } before(:each) do - Fabricate(:domain_general_setting_group) Fabricate(:domain, name: 'example.ee', registrar: zone) end @@ -65,8 +62,7 @@ describe 'EPP Domain', epp: true do expect(domain.registrar).to eq(elkdata) - s = Setting.find_by(code: 'transfer_wait_time') - s.update(value: 1) + Setting.transfer_wait_time = 1 domain.reload pw = domain.auth_info @@ -209,8 +205,8 @@ describe 'EPP Domain', epp: true do expect(key.ds_alg).to eq(3) expect(key.ds_key_tag).to_not be_blank - sg = SettingGroup.dnskeys - expect(key.ds_digest_type).to eq(sg.setting(Setting::DS_ALGORITHM).value.to_i) + + expect(key.ds_digest_type).to eq(Setting.ds_algorithm) expect(key.flags).to eq(257) expect(key.protocol).to eq(3) expect(key.alg).to eq(5) @@ -297,7 +293,7 @@ describe 'EPP Domain', epp: true do response = epp_request(xml, :xml) expect(response[:result_code]).to eq('2004') - expect(response[:msg]).to eq('Nameservers count must be between 1-13') + expect(response[:msg]).to eq('Nameservers count must be between 2-11') end it 'returns error when invalid nameservers are present' do @@ -391,7 +387,7 @@ describe 'EPP Domain', epp: true do key_1 = d.dnskeys[0] expect(key_1.ds_key_tag).to_not be_blank expect(key_1.ds_alg).to eq(3) - expect(key_1.ds_digest_type).to eq(SettingGroup.dnskeys.setting(Setting::DS_ALGORITHM).value.to_i) + expect(key_1.ds_digest_type).to eq(Setting.ds_algorithm) expect(d.dnskeys.pluck(:flags)).to match_array([257, 0, 256]) expect(d.dnskeys.pluck(:protocol)).to match_array([3, 3, 3]) @@ -484,9 +480,7 @@ describe 'EPP Domain', epp: true do end it 'validated dnskeys count' do - s = Setting.find_by(code: 'dnskeys_max_count') - s.value = 1 - s.save + Setting.dnskeys_max_count = 1 xml = domain_create_xml({}, { _other: [ @@ -572,10 +566,7 @@ describe 'EPP Domain', epp: true do end it 'prohibits dsData with key' do - sg = SettingGroup.dnskeys - s = sg.setting(Setting::ALLOW_DS_DATA_WITH_KEYS) - s.value = 0 - s.save + Setting.ds_data_with_key_allowed = false xml = domain_create_xml({}, { _other: [ @@ -600,10 +591,7 @@ describe 'EPP Domain', epp: true do end it 'prohibits dsData' do - sg = SettingGroup.dnskeys - s = sg.setting(Setting::ALLOW_DS_DATA) - s.value = 0 - s.save + Setting.ds_data_allowed = false xml = domain_create_xml({}, { _other: [ @@ -628,10 +616,7 @@ describe 'EPP Domain', epp: true do end it 'prohibits keyData' do - sg = SettingGroup.dnskeys - s = sg.setting(Setting::ALLOW_KEY_DATA) - s.value = 0 - s.save + Setting.key_data_allowed = false xml = domain_create_xml({}, { _other: [ diff --git a/spec/fabricators/setting_fabricator.rb b/spec/fabricators/setting_fabricator.rb deleted file mode 100644 index 415280d09..000000000 --- a/spec/fabricators/setting_fabricator.rb +++ /dev/null @@ -1,3 +0,0 @@ -Fabricator(:setting) do - code 'ns_min_count' -end diff --git a/spec/fabricators/setting_group_fabricator.rb b/spec/fabricators/setting_group_fabricator.rb deleted file mode 100644 index 13129a6bf..000000000 --- a/spec/fabricators/setting_group_fabricator.rb +++ /dev/null @@ -1,52 +0,0 @@ -Fabricator(:setting_group) do - code 'domain_validation' - settings do - [ - Fabricate(:setting, code: 'ns_min_count', value: 1), - Fabricate(:setting, code: 'ns_max_count', value: 13) - ] - end -end - -Fabricator(:domain_validation_setting_group, from: :setting_group) do - code 'domain_validation' - settings do - [ - Fabricate(:setting, code: 'ns_min_count', value: 1), - Fabricate(:setting, code: 'ns_max_count', value: 13), - Fabricate(:setting, code: 'dnskeys_min_count', value: 0), - Fabricate(:setting, code: 'dnskeys_max_count', value: 9) - ] - end -end - -Fabricator(:domain_statuses_setting_group, from: :setting_group) do - code 'domain_statuses' - settings do - [ - Fabricate(:setting, code: 'client_hold', value: 'clientHold'), - Fabricate(:setting, code: 'client_update_prohibited', value: 'clientUpdateProhibited') - ] - end -end - -Fabricator(:domain_general_setting_group, from: :setting_group) do - code 'domain_general' - settings do - [ - Fabricate(:setting, code: 'transfer_wait_time', value: '0') - ] - end -end - -Fabricator(:dnskeys_setting_group, from: :setting_group) do - code 'dnskeys' - settings do - [ - Fabricate(:setting, code: Setting::DS_ALGORITHM, value: 2), - Fabricate(:setting, code: Setting::ALLOW_DS_DATA, value: 1), - Fabricate(:setting, code: Setting::ALLOW_DS_DATA_WITH_KEYS, value: 1), - Fabricate(:setting, code: Setting::ALLOW_KEY_DATA, value: 1) - ] - end -end diff --git a/spec/features/client_contact_spec.rb b/spec/features/client_contact_spec.rb deleted file mode 100644 index 81b5971dd..000000000 --- a/spec/features/client_contact_spec.rb +++ /dev/null @@ -1,38 +0,0 @@ -require 'rails_helper' - -feature 'Contact management', type: :feature do - # background do - # end - - before(:each) do - Fabricate(:user, country: Fabricate(:country, iso: 'EE'), admin: false, username: 'zone') - visit login_path - click_on 'ID card (zone)' - end - - scenario 'User sees contacts', js: true do - Fabricate(:contact, registrar: Registrar.first) - Fabricate(:contact, registrar: Registrar.first) - visit client_contacts_path - expect(page).to have_text(Contact.first.name) - expect(page).to have_text(Contact.second.name) - end - - scenario 'User creates contact', js: true do - visit client_contacts_path - click_on 'Create new contact' - fill_in('Name', with: 'John Doe The Third') - fill_in('Email', with: 'john@doe.eu') - fill_in('Phone', with: '+123.3213123') - fill_in('Ident', with: '312313') - click_on 'Save' - - expect(current_path).to eq client_contact_path(Contact.first) - - expect(page).to have_text('Contact added!') - expect(page).to have_text('Contact details') - expect(page).to have_text('John Doe The Third') - - expect(Contact.first.registrar).to eq Registrar.first - end -end diff --git a/spec/features/domain_management_spec.rb b/spec/features/domain_management_spec.rb deleted file mode 100644 index 0a48079ae..000000000 --- a/spec/features/domain_management_spec.rb +++ /dev/null @@ -1,124 +0,0 @@ -require 'rails_helper' - -feature 'Domain management', type: :feature do - background do - Fabricate(:registrar) - Fabricate(:domain_validation_setting_group) - Fabricate.times(4, :domain) - end - - scenario 'User sees domains', js: true do - visit root_path - click_on 'Domains' - - Domain.all.each do |x| - expect(page).to have_link(x) - expect(page).to have_link(x.registrar) - expect(page).to have_link(x.owner_contact) - end - end - - scenario 'User adds a domain', js: true do - visit admin_domains_path - click_on 'Add' - fill_in('Domain name', with: 'example.ee') - fill_in('Period', with: 1) - fill_in('Registrar', with: 'zone', fill_options: { blur: false }) - # TODO: Wait for poltergeist to support blur option, then uncomment these lines: - # expect(page).to have_text('Zone Media OÜ (10577829)') - # click_on('Zone Media OÜ (10577829)') - # expect(find_field('Registrar').value).to eq('Zone Media OÜ (10577829)') - - # temporary solution: - - page.execute_script("$('#domain_registrar_id').val('1')") - - c = Contact.first - - fill_in('Registrant', with: c.code, fill_options: { blur: false }) - # TODO: Wait for poltergeist to support blur option, then uncomment these lines: - # expect(page).to have_text(c.code) - # click_on(c.code) - # expect(find_field('Registrar').value).to eq(c.code) - - # temporary solution: - page.execute_script("$('#domain_owner_contact_id').val('1')") - - click_on('Save') - - expect(page).to have_text('Domain details') - expect(page).to have_text('example.ee') - expect(page).to have_link('Zone Media OÜ') - expect(page).to have_link(c.name, count: 3) - expect(page).to have_text(c.code) - expect(page).to have_text(c.ident) - expect(page).to have_text(c.email) - expect(page).to have_text(c.phone) - expect(page).to have_text('Nameservers count must be between 1-13') - end - - scenario 'User adds nameserver to domain' do - d = Domain.first - visit admin_domain_path(d) - - within('#nameservers') { click_on 'Add' } - - fill_in('Hostname', with: 'ns1.example.ee') - fill_in('Ipv4', with: '192.168.1.1') - fill_in('Ipv6', with: 'FE80:0000:0000:0000:0202:B3FF:FE1E:8329') - - click_on 'Save' - - expect(page).to have_text('Nameserver added!') - - within('#nameservers') do - expect(page).to have_link('ns1.example.ee') - expect(page).to have_text('192.168.1.1') - expect(page).to have_text('FE80:0000:0000:0000:0202:B3FF:FE1E:8329') - end - end - - scenario 'User adds status to domain' do - d = Domain.first - visit admin_domain_path(d) - - within('#domain_statuses') { click_on 'Add' } - - fill_in('Description', with: 'All is well.') - - click_on 'Save' - - expect(page).to have_text('Status added!') - - within('#domain_statuses') do - expect(page).to have_text('ok') - expect(page).to have_text('All is well.') - end - end - - scenario 'User adds technical contact', js: true do - d = Domain.first - visit admin_domain_path(d) - - within('#tech_contacts') { click_on 'Add' } - - c = Contact.last - fill_in('Contact', with: c.code, fill_options: { blur: false }) - # TODO: Wait for poltergeist to support blur option, then uncomment these lines: - # expect(page).to have_text(c.code) - # click_on(c.code) - # expect(find_field('Tech contact').value).to eq(c.code) - - # temporary solution: - page.execute_script("$('#domain_contact_contact_id').val('#{c.id}')") - - click_on 'Save' - - expect(page).to have_text('Contact added!') - - within('#tech_contacts') do - expect(page).to have_link(c.name) - expect(page).to have_text(c.email) - end - end -end diff --git a/spec/features/domain_transfer_spec.rb b/spec/features/domain_transfer_spec.rb deleted file mode 100644 index 3447edeca..000000000 --- a/spec/features/domain_transfer_spec.rb +++ /dev/null @@ -1,126 +0,0 @@ -require 'rails_helper' - -feature 'Domain transfer', type: :feature do - let(:elkdata) { Fabricate(:registrar, { name: 'Elkdata', reg_no: '123' }) } - let(:zone) { Fabricate(:registrar) } - let(:zone_user) { Fabricate(:user, registrar: zone, username: 'zone', admin: false, identity_code: '37810013087') } - let(:elkdata_user) do - Fabricate(:user, registrar: elkdata, username: 'elkdata', admin: false, identity_code: '37810013261') - end - - background do - Fabricate(:domain_validation_setting_group) - Fabricate(:domain_general_setting_group) - Fabricate(:dnskeys_setting_group) - Fabricate(:domain, registrar: zone) - end - - scenario 'Registrar requests transfer on own domain', js: true do - sign_in zone_user - click_on 'Domains' - click_on 'Domain transfers list' - click_on 'Request domain transfer' - - fill_in 'Domain name', with: 'false' - click_on 'Request domain transfer' - expect(page).to have_text('Domain was not found!') - - d = Domain.first - fill_in 'Domain name', with: d.name - click_on 'Request domain transfer' - expect(page).to have_text('Password invalid!') - - fill_in 'Domain password', with: d.auth_info - click_on 'Request domain transfer' - - expect(page).to have_text('Domain already belongs to the querying registrar') - end - - scenario 'Other registrar requests transfer with 0 wait time' do - sign_in elkdata_user - d = Domain.first - visit client_domains_path - expect(page).to_not have_link(d.name) - - visit new_client_domain_transfer_path - fill_in 'Domain name', with: d.name - fill_in 'Domain password', with: d.auth_info - click_on 'Request domain transfer' - - expect(page).to have_text('Domain transfer approved!') - expect(page).to have_text('serverApproved') - - visit client_domains_path - expect(page).to have_link(d.name) - end - - scenario 'Other registrar requests transfer with 1 wait time' do - s = Setting.find_by(code: 'transfer_wait_time') - s.value = 1 - s.save - - sign_in elkdata_user - d = Domain.first - visit client_domains_path - expect(page).to_not have_link(d.name) - - visit new_client_domain_transfer_path - fill_in 'Domain name', with: d.name - fill_in 'Domain password', with: d.auth_info - click_on 'Request domain transfer' - - expect(page).to have_text('Domain transfer requested!') - expect(page).to have_text('pending') - - visit new_client_domain_transfer_path - fill_in 'Domain name', with: d.name - fill_in 'Domain password', with: d.auth_info - click_on 'Request domain transfer' - - expect(page).to have_text('Domain transfer requested!') - expect(page).to have_text('pending') - - visit client_domains_path - expect(page).to_not have_link(d.name) - end - - scenario 'Domain owner approves request' do - s = Setting.find_by(code: 'transfer_wait_time') - s.value = 1 - s.save - - d = Domain.first - d.domain_transfers.create( - status: DomainTransfer::PENDING, - transfer_requested_at: Time.zone.now, - transfer_to: elkdata, - transfer_from: zone - ) - - sign_in elkdata_user - visit new_client_domain_transfer_path - fill_in 'Domain name', with: d.name - fill_in 'Domain password', with: d.auth_info - click_on 'Request domain transfer' - - expect(page).to have_text('Domain transfer requested!') - expect(page).to_not have_button('Approve') - - sign_in zone_user - - visit new_client_domain_transfer_path - fill_in 'Domain name', with: d.name - fill_in 'Domain password', with: d.auth_info - click_on 'Request domain transfer' - - expect(page).to have_link('Approve') - - click_on 'Approve' - expect(page).to have_text('Domain transfer approved!') - expect(page).to have_text('clientApproved') - - sign_in elkdata_user - visit client_domains_path - expect(page).to have_link(d.name) - end -end diff --git a/spec/features/sessions_spec.rb b/spec/features/sessions_spec.rb index 8c12c2032..9ce6ccea4 100644 --- a/spec/features/sessions_spec.rb +++ b/spec/features/sessions_spec.rb @@ -5,9 +5,9 @@ feature 'Sessions', type: :feature do let(:zone) { Fabricate(:registrar) } background do - Fabricate(:user, registrar: zone, username: 'elkdata', identity_code: '37810013261') + create_settings + Fabricate(:user, registrar: nil, identity_code: '37810013261') Fabricate(:user, registrar: zone, username: 'zone', admin: false, identity_code: '37810013087') - Fabricate(:domain_validation_setting_group) Fabricate.times(2, :domain, registrar: zone) Fabricate.times(2, :domain, registrar: elkdata) end diff --git a/spec/features/setting_management_spec.rb b/spec/features/setting_management_spec.rb index 6b4fdd4bc..a8e082f13 100644 --- a/spec/features/setting_management_spec.rb +++ b/spec/features/setting_management_spec.rb @@ -1,37 +1,30 @@ require 'rails_helper' feature 'Setting management', type: :feature do - background { Fabricate(:domain_validation_setting_group) } + let(:zone) { Fabricate(:registrar) } + let(:zone_user) { Fabricate(:user, registrar: zone, username: 'zone', admin: true, identity_code: '37810013087') } - scenario 'User changes a setting', js: true do - visit root_path + background { create_settings } - # This ensures javascript works correctly - expect(page).to have_no_link 'Setting groups' - click_on 'Settings' - expect(page).to have_link 'Setting groups' + scenario 'User changes a setting' do + sign_in zone_user + visit admin_settings_path - click_on 'Setting groups' - expect(page).to have_text('Domain validation') - click_on 'Edit settings' - expect(page).to have_text('Nameserver minimum count') - expect(page).to have_text('Nameserver maximum count') + val_min = find_field('_settings_ns_min_count').value + val_max = find_field('_settings_ns_max_count').value - val_min = find_field('Nameserver minimum count').value - val_max = find_field('Nameserver maximum count').value + expect(val_min).to eq('2') + expect(val_max).to eq('11') - expect(val_min).to eq('1') - expect(val_max).to eq('13') + fill_in '_settings_ns_min_count', with: 0 + fill_in '_settings_ns_max_count', with: 10 - fill_in('Nameserver minimum count', with: '3') - fill_in('Nameserver maximum count', with: '10') + click_button 'Save' - click_on 'Save' + val_min = find_field('_settings_ns_min_count').value + val_max = find_field('_settings_ns_max_count').value - val_min = find_field('Nameserver minimum count').value - val_max = find_field('Nameserver maximum count').value - - expect(val_min).to eq('3') + expect(val_min).to eq('0') expect(val_max).to eq('10') end end diff --git a/spec/models/address_spec.rb b/spec/models/address_spec.rb index 2238c6a33..7009b48c4 100644 --- a/spec/models/address_spec.rb +++ b/spec/models/address_spec.rb @@ -11,8 +11,8 @@ describe Address, '.extract_params' do ph = { postalInfo: { name: 'fred', addr: { cc: 'EE', city: 'Village', street: %w(street1 street2) } } } expect(Address.extract_attributes(ph[:postalInfo])).to eq({ address_attributes: { - city: 'Village', country_id: 1, + city: 'Village', street: 'street1', street2: 'street2' } diff --git a/spec/models/contact_spec.rb b/spec/models/contact_spec.rb index 44a6d23a0..b50f9e2c3 100644 --- a/spec/models/contact_spec.rb +++ b/spec/models/contact_spec.rb @@ -50,8 +50,7 @@ describe Contact, '#relations_with_domain?' do context 'with relation' do before(:each) do - Fabricate(:domain_validation_setting_group) - Fabricate(:dnskeys_setting_group) + create_settings Fabricate(:domain) end diff --git a/spec/models/dnskey_spec.rb b/spec/models/dnskey_spec.rb index 6663f148a..116b5ebbf 100644 --- a/spec/models/dnskey_spec.rb +++ b/spec/models/dnskey_spec.rb @@ -2,8 +2,7 @@ require 'rails_helper' describe Dnskey do before(:each) do - Fabricate(:domain_validation_setting_group) - Fabricate(:dnskeys_setting_group) + create_settings end it { should belong_to(:domain) } diff --git a/spec/models/domain_spec.rb b/spec/models/domain_spec.rb index edef63e71..ce0966ba7 100644 --- a/spec/models/domain_spec.rb +++ b/spec/models/domain_spec.rb @@ -11,8 +11,7 @@ describe Domain do context 'with sufficient settings' do before(:each) do - Fabricate(:domain_validation_setting_group) - Fabricate(:dnskeys_setting_group) + create_settings end it 'validates domain name' do @@ -51,20 +50,13 @@ describe Domain do period: ['is not a number'], owner_contact: ['Registrant is missing'], admin_contacts: ['Admin contacts count must be between 1 - infinity'], - nameservers: ['Nameservers count must be between 1-13'], + nameservers: ['Nameservers count must be between 2-11'], registrar: ['Registrar is missing'], period: ['Period is not a number'] }) - sg = SettingGroup.domain_validation - min = sg.setting(:ns_min_count) - max = sg.setting(:ns_max_count) - - min.value = 2 - min.save - - max.value = 7 - max.save + Setting.ns_min_count = 2 + Setting.ns_max_count = 7 expect(d.valid?).to be false expect(d.errors.messages[:nameservers]).to eq(['Nameservers count must be between 2-7']) diff --git a/spec/models/setting_group_spec.rb b/spec/models/setting_group_spec.rb deleted file mode 100644 index cea1f03a6..000000000 --- a/spec/models/setting_group_spec.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'rails_helper' - -describe SettingGroup do - it { should have_many(:settings) } -end diff --git a/spec/models/setting_spec.rb b/spec/models/setting_spec.rb index 09ae4cd49..9459fc999 100644 --- a/spec/models/setting_spec.rb +++ b/spec/models/setting_spec.rb @@ -1,21 +1,12 @@ require 'rails_helper' describe Setting do - it { should belong_to(:setting_group) } - - it 'validates code uniqueness' do - sg = Fabricate(:setting_group) - sg.settings.build(code: 'this_is_code') - expect(sg.save).to be true - - sg.settings.build(code: 'this_is_code') - expect(sg.save).to be false - err = sg.settings.last.errors[:code].first - expect(err).to eq('Code already exists') - - sg_2 = Fabricate(:setting_group, code: 'domain_statuses') - - sg_2.settings.build(code: 'this_is_code') - expect(sg_2.save).to be true + it 'returns value' do + create_settings + expect(Setting.ns_min_count).to eq(2) + Setting.ns_min_count = '2' + expect(Setting.ns_min_count).to eq('2') + Setting.ns_min_count = true + expect(Setting.ns_min_count).to eq(true) end end diff --git a/spec/support/general.rb b/spec/support/general.rb new file mode 100644 index 000000000..3c646e2e4 --- /dev/null +++ b/spec/support/general.rb @@ -0,0 +1,20 @@ +module General + def create_settings + Setting.ds_algorithm = 2 + Setting.ds_data_allowed = true + Setting.ds_data_with_key_allowed = true + Setting.key_data_allowed = true + + Setting.dnskeys_min_count = 0 + Setting.dnskeys_max_count = 9 + Setting.ns_min_count = 2 + Setting.ns_max_count = 11 + + Setting.transfer_wait_time = 0 + end +end + + +RSpec.configure do |c| + c.include General +end