diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index feb2a76774..8203a630ff 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -83,4 +83,10 @@ def changing_css_class(version, *attrs) version.object_changes.to_h.slice(*attrs).any? && css_class end end + + def legal_document_types + types = LegalDocument::TYPES.dup + types.delete('ddoc') + ".#{types.join(',.')}" + end end diff --git a/app/helpers/default_form_builder.rb b/app/helpers/default_form_builder.rb new file mode 100644 index 0000000000..7353171981 --- /dev/null +++ b/app/helpers/default_form_builder.rb @@ -0,0 +1,6 @@ +class DefaultFormBuilder < ActionView::Helpers::FormBuilder + def legal_document_field(method, options = {}) + self.multipart = true + @template.legal_document_field(@object_name, method, objectify_options(options)) + end +end diff --git a/app/helpers/form_helper.rb b/app/helpers/form_helper.rb new file mode 100644 index 0000000000..a3a139e095 --- /dev/null +++ b/app/helpers/form_helper.rb @@ -0,0 +1,8 @@ +module FormHelper + def legal_document_field(object_name, method, options = {}) + options[:data] = { legal_document: true } + options[:accept] = legal_document_types unless options[:accept] + + file_field(object_name, method, options) + end +end diff --git a/app/helpers/form_tag_helper.rb b/app/helpers/form_tag_helper.rb new file mode 100644 index 0000000000..d19a59db52 --- /dev/null +++ b/app/helpers/form_tag_helper.rb @@ -0,0 +1,8 @@ +module FormTagHelper + def legal_document_field_tag(name, options = {}) + options[:data] = { legal_document: true } + options[:accept] = legal_document_types unless options[:accept] + + file_field_tag(name, options) + end +end diff --git a/app/views/registrar/contacts/_form.haml b/app/views/registrar/contacts/_form.haml index f826d06770..cf8217e13b 100644 --- a/app/views/registrar/contacts/_form.haml +++ b/app/views/registrar/contacts/_form.haml @@ -3,20 +3,20 @@ = f.hidden_field :password .row .col-md-8 - = render 'registrar/contacts/form_partials/general', f: f + = render 'registrar/contacts/form/general', f: f - if address_processing? .row .col-md-8 - = render 'registrar/contacts/form_partials/address', f: f + = render 'registrar/contacts/form/address', f: f - if !@contact.persisted? .row .col-md-8 - = render 'registrar/contacts/form_partials/code', f: f + = render 'registrar/contacts/form/code', f: f .row .col-md-8 - = render 'registrar/contacts/form_partials/legal_document', f: f + = render 'registrar/contacts/form/legal_document', f: f .row .col-md-8.text-right diff --git a/app/views/registrar/contacts/delete.haml b/app/views/registrar/contacts/delete.haml index 857c57cf8c..8662b738c8 100644 --- a/app/views/registrar/contacts/delete.haml +++ b/app/views/registrar/contacts/delete.haml @@ -10,7 +10,7 @@ .row .col-md-8 - = render 'registrar/contacts/form_partials/legal_document', f: f + = render 'registrar/contacts/form/legal_document', f: f %hr .row diff --git a/app/views/registrar/contacts/form_partials/_address.haml b/app/views/registrar/contacts/form/_address.haml similarity index 100% rename from app/views/registrar/contacts/form_partials/_address.haml rename to app/views/registrar/contacts/form/_address.haml diff --git a/app/views/registrar/contacts/form_partials/_code.haml b/app/views/registrar/contacts/form/_code.haml similarity index 100% rename from app/views/registrar/contacts/form_partials/_code.haml rename to app/views/registrar/contacts/form/_code.haml diff --git a/app/views/registrar/contacts/form_partials/_general.haml b/app/views/registrar/contacts/form/_general.haml similarity index 100% rename from app/views/registrar/contacts/form_partials/_general.haml rename to app/views/registrar/contacts/form/_general.haml diff --git a/app/views/registrar/contacts/form_partials/_legal_document.haml b/app/views/registrar/contacts/form/_legal_document.haml similarity index 77% rename from app/views/registrar/contacts/form_partials/_legal_document.haml rename to app/views/registrar/contacts/form/_legal_document.haml index bffa698311..6507da1d90 100644 --- a/app/views/registrar/contacts/form_partials/_legal_document.haml +++ b/app/views/registrar/contacts/form/_legal_document.haml @@ -10,4 +10,4 @@ = f.label :legal_document, t(:legal_document) %p.help-block= t(:legal_document_max_size) .col-md-7 - = f.file_field :legal_document, :value => '', data: {legal_document: true} + = f.legal_document_field :legal_document diff --git a/app/views/registrar/contacts/form_partials/_disclose.haml b/app/views/registrar/contacts/form_partials/_disclose.haml deleted file mode 100644 index 51f675c577..0000000000 --- a/app/views/registrar/contacts/form_partials/_disclose.haml +++ /dev/null @@ -1,41 +0,0 @@ -.panel.panel-default - .panel-heading.clearfix - .pull-left= t(:contact_disclosure) - - .panel-body - .form-group - = label_tag :contact_disclose_flag, t(:flag_type), class: 'col-md-2 control-label' - .col-md-10 - =# check_box_tag('contact[disclose][sv_policy]', @contact_params[:disclose][:sv_policy], class: 'form-control') - = select_tag('contact[disclose][flag]', options_for_select(Depp::Contact::DISCLOSURE_TYPES) ) - - .panel-body - .form-group - = label_tag :contact_disclose_name, t(:name), class: 'col-md-2 control-label' - .col-md-10 - = check_box_tag('contact[disclose][name]') - - .form-group - = label_tag :contact_disclose_email, t(:email), class: 'col-md-2 control-label' - .col-md-10 - = check_box_tag('contact[disclose][email]') - - .form-group - = label_tag :contact_disclose_org_name, t(:org_name), class: 'col-md-2 control-label' - .col-md-10 - = check_box_tag('contact[disclose][org_name]') - - .form-group - = label_tag :contact_disclose_address, t(:address), class: 'col-md-2 control-label' - .col-md-10 - = check_box_tag('contact[disclose][address]') - - .form-group - = label_tag :contact_disclose_voice, t(:voice), class: 'col-md-2 control-label' - .col-md-10 - = check_box_tag('contact[disclose][voice]') - - .form-group - = label_tag :contact_disclose_fax, t(:fax), class: 'col-md-2 control-label' - .col-md-10 - = check_box_tag('contact[disclose][fax]') diff --git a/app/views/registrar/contacts/partials/_disclose.haml b/app/views/registrar/contacts/partials/_disclose.haml deleted file mode 100644 index 734ca056d6..0000000000 --- a/app/views/registrar/contacts/partials/_disclose.haml +++ /dev/null @@ -1,10 +0,0 @@ -- @contact[:disclose].each do |flag, data| - - next if data.empty? - .panel.panel-default - .panel-heading - %h3.panel-title= t("disclosure-#{flag}") - .panel-body - %dl.dl-horizontal - - data.each do |k,v| - %dt= t(k) - diff --git a/app/views/registrar/contacts/partials/_domains.haml b/app/views/registrar/contacts/partials/_domains.haml index f580195672..d2943e8ef1 100644 --- a/app/views/registrar/contacts/partials/_domains.haml +++ b/app/views/registrar/contacts/partials/_domains.haml @@ -18,7 +18,7 @@ %th{class: 'col-xs-3'}=custom_sort_link t(:domain_name), :name %th{class: 'col-xs-3'}=custom_sort_link t(:registrar_name), :registrar_name %th{class: 'col-xs-3'}=custom_sort_link t(:valid_to), :valid_to - %th{class: 'col-xs-3'}= t(:roles) + %th{class: 'col-xs-3'}= t('.roles') %tbody - domains.each do |x| %tr diff --git a/app/views/registrar/domains/_form.haml b/app/views/registrar/domains/_form.haml index 83ad8add0f..d6428233b8 100644 --- a/app/views/registrar/domains/_form.haml +++ b/app/views/registrar/domains/_form.haml @@ -3,10 +3,10 @@ .row .col-md-8 #general-tab.tab-pane.active - = render 'registrar/domains/form_partials/general' - = render 'registrar/domains/form_partials/contacts' - = render 'registrar/domains/form_partials/nameservers' - = render 'registrar/domains/form_partials/dnskeys' + = render 'registrar/domains/form/general' + = render 'registrar/domains/form/contacts' + = render 'registrar/domains/form/nameservers' + = render 'registrar/domains/form/dnskeys' .panel.panel-default .panel-heading.clearfix @@ -18,7 +18,7 @@ = label_tag 'domain[legal_document]', t(:legal_document), class: c %p.help-block= t(:legal_document_max_size) .col-md-7 - = file_field_tag 'domain[legal_document]', required: fr, data: {legal_document: true} + = legal_document_field_tag 'domain[legal_document]', required: fr .col-md-4 %p.domain-general-help= t(:domain_general_help).html_safe %p.domain-admin-contact-help= t(:domain_admin_contact_help).html_safe @@ -26,9 +26,4 @@ .row .col-md-8.text-right - = button_tag(t('shared.save'), class: 'btn btn-warning') - -:javascript - $(function () { - $('#tabs a:first').tab('show') - }) + = button_tag(t('.save_btn'), class: 'btn btn-warning') diff --git a/app/views/registrar/domains/form_partials/_contacts.haml b/app/views/registrar/domains/form/_contacts.haml similarity index 100% rename from app/views/registrar/domains/form_partials/_contacts.haml rename to app/views/registrar/domains/form/_contacts.haml diff --git a/app/views/registrar/domains/form_partials/_dnskeys.haml b/app/views/registrar/domains/form/_dnskeys.haml similarity index 99% rename from app/views/registrar/domains/form_partials/_dnskeys.haml rename to app/views/registrar/domains/form/_dnskeys.haml index 818ea67a2c..7d41682f6f 100644 --- a/app/views/registrar/domains/form_partials/_dnskeys.haml +++ b/app/views/registrar/domains/form/_dnskeys.haml @@ -39,7 +39,7 @@ .form-group .col-md-3.control-label - = label_tag "domain_dnskeys_attributes_#{k}_flags", t(:flags) + = label_tag "domain_dnskeys_attributes_#{k}_flags", t('.flags') .col-md-7 = select_tag "domain[dnskeys_attributes][#{k}][flags]", options_for_select(Depp::Dnskey::FLAGS, v['flags']), @@ -55,7 +55,7 @@ .form-group .col-md-3.control-label - = label_tag "domain_dnskeys_attributes_#{k}_alg", t(:alg) + = label_tag "domain_dnskeys_attributes_#{k}_alg", t('.alg') .col-md-7 = select_tag "domain[dnskeys_attributes][#{k}][alg]", options_for_select(Depp::Dnskey::ALGORITHMS, v['alg']), { class: 'form-control' } diff --git a/app/views/registrar/domains/form_partials/_general.haml b/app/views/registrar/domains/form/_general.haml similarity index 100% rename from app/views/registrar/domains/form_partials/_general.haml rename to app/views/registrar/domains/form/_general.haml diff --git a/app/views/registrar/domains/form_partials/_nameservers.haml b/app/views/registrar/domains/form/_nameservers.haml similarity index 100% rename from app/views/registrar/domains/form_partials/_nameservers.haml rename to app/views/registrar/domains/form/_nameservers.haml diff --git a/app/views/registrar/domains/partials/_general.haml b/app/views/registrar/domains/partials/_general.haml index 0f1a2a831b..ca3dd99924 100644 --- a/app/views/registrar/domains/partials/_general.haml +++ b/app/views/registrar/domains/partials/_general.haml @@ -14,14 +14,14 @@ %dt= t(:registrant) %dd= "#{registrant.name} (#{@data.css('registrant').text})" - %dt= t(:registered) + %dt= t('.registered') %dd= @data.css('crDate').text %dt= t(:valid_to) %dd= @data.css('exDate').text - %dt= t(:created) + %dt= t('.created') %dd= @data.css('crDate').text - %dt= t(:updated) + %dt= t('.updated') %dd= @data.css('upDate').text diff --git a/config/application.rb b/config/application.rb index 109fa4d1ba..e946f5d115 100644 --- a/config/application.rb +++ b/config/application.rb @@ -78,6 +78,8 @@ class Application < Rails::Application domain: ENV['smtp_domain'], openssl_verify_mode: ENV['smtp_openssl_verify_mode'] } + + config.action_view.default_form_builder = 'DefaultFormBuilder' end end diff --git a/config/locales/registrar/contacts.en.yml b/config/locales/registrar/contacts.en.yml new file mode 100644 index 0000000000..2a3f5ba3e2 --- /dev/null +++ b/config/locales/registrar/contacts.en.yml @@ -0,0 +1,6 @@ +en: + registrar: + contacts: + partials: + domains: + roles: Roles diff --git a/config/locales/registrar/domains.en.yml b/config/locales/registrar/domains.en.yml index cdef2bd5ab..287704d29b 100644 --- a/config/locales/registrar/domains.en.yml +++ b/config/locales/registrar/domains.en.yml @@ -8,3 +8,15 @@ en: registrant_name: Registrant name registrant_code: Registrant code expire_time: Date of expiry + + form: + save_btn: Save + dnskeys: + flags: Flags + alg: Algorithm + + partials: + general: + registered: Registered + created: Created + updated: Updated diff --git a/spec/factories/api_user.rb b/spec/factories/api_user.rb index 01c2c70e05..a38fb8bf96 100644 --- a/spec/factories/api_user.rb +++ b/spec/factories/api_user.rb @@ -10,8 +10,13 @@ end factory :api_user_with_unlimited_balance do - after :build do |api_user| - api_user.registrar = create(:registrar_with_unlimited_balance) + transient do + registrar false + end + + after :build do |api_user, evaluator| + registrar = (evaluator.registrar || create(:registrar_with_unlimited_balance)) + api_user.registrar = registrar end end end diff --git a/spec/features/registrar/contacts/delete_spec.rb b/spec/features/registrar/contacts/delete_spec.rb new file mode 100644 index 0000000000..dd6305a109 --- /dev/null +++ b/spec/features/registrar/contacts/delete_spec.rb @@ -0,0 +1,52 @@ +require 'rails_helper' + +class FakeDeppContact + include ActiveModel::Model + + def id + 'test' + end + + def name + 'test' + end + + def persisted? + true + end + + def password + 'test' + end + + def delete + true + end +end + +RSpec.feature 'Contact deletion in registrar area' do + given!(:registrar) { create(:registrar) } + given!(:contact) { create(:contact, registrar: registrar) } + + background do + allow(Depp::Contact).to receive(:find_by_id).and_return(FakeDeppContact.new) + allow(Depp::Contact).to receive(:new).and_return(FakeDeppContact.new) + Setting.api_ip_whitelist_enabled = false + Setting.registrar_ip_whitelist_enabled = false + sign_in_to_registrar_area(user: create(:api_user_with_unlimited_balance, registrar: registrar)) + end + + it 'deletes contact' do + visit registrar_contacts_url + click_link_or_button 'Delete' + confirm + + expect(page).to have_text('Destroyed') + end + + private + + def confirm + click_link_or_button 'Delete' + end +end diff --git a/spec/views/registrar/contacts/_form.haml_spec.rb b/spec/views/registrar/contacts/_form.haml_spec.rb index 307c495e82..b1ecdf0cf3 100644 --- a/spec/views/registrar/contacts/_form.haml_spec.rb +++ b/spec/views/registrar/contacts/_form.haml_spec.rb @@ -8,10 +8,10 @@ assign(:contact, contact) stub_template 'registrar/shared/_error_messages' => '' - stub_template 'registrar/contacts/form_partials/_general' => '' - stub_template 'registrar/contacts/form_partials/_address' => 'address info' - stub_template 'registrar/contacts/form_partials/_code' => '' - stub_template 'registrar/contacts/form_partials/_legal_document' => '' + stub_template 'registrar/contacts/form/_general' => '' + stub_template 'registrar/contacts/form/_address' => 'address info' + stub_template 'registrar/contacts/form/_code' => '' + stub_template 'registrar/contacts/form/_legal_document' => '' end context 'when address processing is enabled' do diff --git a/spec/views/registrar/contacts/form/_legal_document.haml_spec.rb b/spec/views/registrar/contacts/form/_legal_document.haml_spec.rb new file mode 100644 index 0000000000..b5f428ca13 --- /dev/null +++ b/spec/views/registrar/contacts/form/_legal_document.haml_spec.rb @@ -0,0 +1,15 @@ +require 'rails_helper' + +RSpec.describe 'registrar/contacts/form/_legal_document' do + let(:contact) { instance_spy(Depp::Contact) } + + before :example do + allow(view).to receive(:f).and_return(DefaultFormBuilder.new(:depp_contact, contact, view, {})) + assign(:contact, contact) + end + + it 'has legal document' do + render + expect(rendered).to have_css('[name="depp_contact[legal_document]"]') + end +end diff --git a/spec/views/registrar/domains/_form.haml_spec.rb b/spec/views/registrar/domains/_form.haml_spec.rb new file mode 100644 index 0000000000..b7833f92af --- /dev/null +++ b/spec/views/registrar/domains/_form.haml_spec.rb @@ -0,0 +1,20 @@ +require 'rails_helper' + +RSpec.describe 'registrar/domains/_form' do + let(:domain) { instance_spy(Depp::Domain) } + + before :example do + allow(view).to receive(:f).and_return(DefaultFormBuilder.new(:domain, domain, view, {})) + assign(:domain, domain) + + stub_template 'registrar/domains/form/_general' => '' + stub_template 'registrar/domains/form/_contacts' => '' + stub_template 'registrar/domains/form/_nameservers' => '' + stub_template 'registrar/domains/form/_dnskeys' => '' + end + + it 'has legal document' do + render + expect(rendered).to have_css('[name="domain[legal_document]"]') + end +end