mirror of
https://github.com/internetee/registry.git
synced 2025-05-18 18:29:40 +02:00
Refactor
This commit is contained in:
parent
168e6d2a01
commit
660eef414e
8 changed files with 55 additions and 18 deletions
|
@ -3,13 +3,20 @@ class Admin::DomainContactsController < ApplicationController
|
||||||
before_action :set_domain_contact, only: [:destroy]
|
before_action :set_domain_contact, only: [:destroy]
|
||||||
|
|
||||||
def new
|
def new
|
||||||
@domain_contact = @domain.domain_contacts.build
|
@domain_contact = @domain.domain_contacts.build(contact_type: params[:type])
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@domain.adding_admin_contact = true
|
|
||||||
@domain_contact = @domain.domain_contacts.build(domain_contact_params)
|
@domain_contact = @domain.domain_contacts.build(domain_contact_params)
|
||||||
|
|
||||||
|
unless @domain_contact.contact
|
||||||
|
flash.now[:alert] = I18n.t('shared.contact_was_not_found')
|
||||||
|
render 'new' and return
|
||||||
|
end
|
||||||
|
|
||||||
|
@domain.adding_admin_contact = true if @domain_contact.admin?
|
||||||
|
@domain.adding_admin_contact = true if @domain_contact.tech?
|
||||||
|
|
||||||
if @domain.save
|
if @domain.save
|
||||||
flash[:notice] = I18n.t('shared.contact_added')
|
flash[:notice] = I18n.t('shared.contact_added')
|
||||||
redirect_to [:admin, @domain]
|
redirect_to [:admin, @domain]
|
||||||
|
@ -20,13 +27,14 @@ class Admin::DomainContactsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
@domain.deleting_admin_contact = true
|
|
||||||
@domain.domain_contacts.select { |x| x == @domain_contact }[0].mark_for_destruction
|
@domain.domain_contacts.select { |x| x == @domain_contact }[0].mark_for_destruction
|
||||||
|
@domain.deleting_admin_contact = true if @domain_contact.admin?
|
||||||
|
@domain.deleting_tech_contact = true if @domain_contact.tech?
|
||||||
|
|
||||||
if @domain.save
|
if @domain.save
|
||||||
flash[:notice] = I18n.t('shared.contact_deleted')
|
flash[:notice] = I18n.t('shared.contact_deleted')
|
||||||
else
|
else
|
||||||
flash[:alert] = I18n.t('shared.fail')
|
flash[:alert] = @domain.errors.first[1]
|
||||||
end
|
end
|
||||||
|
|
||||||
redirect_to [:admin, @domain]
|
redirect_to [:admin, @domain]
|
||||||
|
|
|
@ -6,8 +6,6 @@ class Domain < ActiveRecord::Base
|
||||||
|
|
||||||
has_many :domain_contacts, dependent: :delete_all, autosave: true
|
has_many :domain_contacts, dependent: :delete_all, autosave: true
|
||||||
|
|
||||||
accepts_nested_attributes_for :domain_contacts, allow_destroy: true
|
|
||||||
|
|
||||||
has_many :tech_contacts, -> do
|
has_many :tech_contacts, -> do
|
||||||
where(domain_contacts: { contact_type: DomainContact::TECH })
|
where(domain_contacts: { contact_type: DomainContact::TECH })
|
||||||
end, through: :domain_contacts, source: :contact
|
end, through: :domain_contacts, source: :contact
|
||||||
|
@ -50,6 +48,9 @@ class Domain < ActiveRecord::Base
|
||||||
attr_accessor :deleting_nameserver
|
attr_accessor :deleting_nameserver
|
||||||
validate :validate_nameserver_min_count, if: :deleting_nameserver
|
validate :validate_nameserver_min_count, if: :deleting_nameserver
|
||||||
|
|
||||||
|
attr_accessor :adding_tech_contact
|
||||||
|
validate :validate_tech_contacts_max_count, if: :adding_tech_contact
|
||||||
|
|
||||||
def name=(value)
|
def name=(value)
|
||||||
value.strip!
|
value.strip!
|
||||||
write_attribute(:name, SimpleIDN.to_unicode(value))
|
write_attribute(:name, SimpleIDN.to_unicode(value))
|
||||||
|
|
|
@ -6,6 +6,17 @@ class DomainContact < ActiveRecord::Base
|
||||||
ADMIN = 'admin'
|
ADMIN = 'admin'
|
||||||
TYPES = [TECH, ADMIN]
|
TYPES = [TECH, ADMIN]
|
||||||
|
|
||||||
|
# TODO: Fix EPP problems
|
||||||
|
validates :contact, uniqueness: { scope: [:domain_id, :contact_type] }
|
||||||
|
|
||||||
scope :admin, -> { where(contact_type: ADMIN) }
|
scope :admin, -> { where(contact_type: ADMIN) }
|
||||||
scope :tech, -> { where(contact_type: TECH) }
|
scope :tech, -> { where(contact_type: TECH) }
|
||||||
|
|
||||||
|
def admin?
|
||||||
|
contact_type == ADMIN
|
||||||
|
end
|
||||||
|
|
||||||
|
def tech?
|
||||||
|
contact_type == TECH
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,6 +7,11 @@
|
||||||
= link_to(t('shared.back_to_domain'), [:admin, @domain], class: 'btn btn-default')
|
= link_to(t('shared.back_to_domain'), [:admin, @domain], class: 'btn btn-default')
|
||||||
%hr
|
%hr
|
||||||
= form_for([:admin, @domain, @domain_contact]) do |f|
|
= form_for([:admin, @domain, @domain_contact]) do |f|
|
||||||
|
= render 'admin/shared/errors', object: @domain
|
||||||
|
/ = render 'admin/shared/errors', object: f.object
|
||||||
|
|
||||||
|
- if @domain.errors.any?
|
||||||
|
%hr
|
||||||
.row
|
.row
|
||||||
.col-md-6
|
.col-md-6
|
||||||
.form-group
|
.form-group
|
||||||
|
@ -14,7 +19,7 @@
|
||||||
= f.select :contact_type, options_for_select(DomainContact::TYPES, @domain_contact.contact_type), {}, {class: 'form-control'}
|
= f.select :contact_type, options_for_select(DomainContact::TYPES, @domain_contact.contact_type), {}, {class: 'form-control'}
|
||||||
.col-md-6
|
.col-md-6
|
||||||
.form-group.has-feedback
|
.form-group.has-feedback
|
||||||
= f.label :contact
|
= label_tag :contact
|
||||||
= text_field_tag(:contact, params[:contact], class: 'form-control js-contact-typeahead', placeholder: t('shared.contact_code'), autocomplete: 'off')
|
= text_field_tag(:contact, params[:contact], class: 'form-control js-contact-typeahead', placeholder: t('shared.contact_code'), autocomplete: 'off')
|
||||||
%span.glyphicon.glyphicon-ok.form-control-feedback.js-typeahead-ok.hidden
|
%span.glyphicon.glyphicon-ok.form-control-feedback.js-typeahead-ok.hidden
|
||||||
%span.glyphicon.glyphicon-remove.form-control-feedback.js-typeahead-remove
|
%span.glyphicon.glyphicon-remove.form-control-feedback.js-typeahead-remove
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
.pull-left
|
.pull-left
|
||||||
= t('shared.admin_contacts')
|
= t('shared.admin_contacts')
|
||||||
.pull-right
|
.pull-right
|
||||||
= link_to(t('shared.add'), new_admin_domain_admin_contact_path(@domain), class: 'btn btn-primary btn-xs')
|
= link_to(t('shared.add'), new_admin_domain_domain_contact_path(@domain, type: DomainContact::ADMIN), class: 'btn btn-primary btn-xs')
|
||||||
.table-responsive
|
.table-responsive
|
||||||
%table.table.table-hover.table-bordered.table-condensed
|
%table.table.table-hover.table-bordered.table-condensed
|
||||||
%thead
|
%thead
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
.pull-left
|
.pull-left
|
||||||
= t('shared.tech_contacts')
|
= t('shared.tech_contacts')
|
||||||
.pull-right
|
.pull-right
|
||||||
= link_to(t('shared.add'), new_admin_domain_tech_contact_path(@domain), class: 'btn btn-primary btn-xs')
|
= link_to(t('shared.add'), new_admin_domain_domain_contact_path(@domain, type: DomainContact::TECH), class: 'btn btn-primary btn-xs')
|
||||||
.table-responsive
|
.table-responsive
|
||||||
%table.table.table-hover.table-bordered.table-condensed
|
%table.table.table-hover.table-bordered.table-condensed
|
||||||
%thead
|
%thead
|
||||||
|
@ -13,13 +13,13 @@
|
||||||
%th{class: 'col-xs-5'}= t('shared.email')
|
%th{class: 'col-xs-5'}= t('shared.email')
|
||||||
%th{class: 'col-xs-3'}= t('shared.action')
|
%th{class: 'col-xs-3'}= t('shared.action')
|
||||||
%tbody
|
%tbody
|
||||||
- @domain.tech_contacts.each do |x|
|
- @domain.domain_contacts.tech.each do |x|
|
||||||
%tr
|
%tr
|
||||||
%td= link_to(x, root_path)
|
%td= link_to(x.contact, root_path)
|
||||||
%td= x.email
|
%td= x.contact.email
|
||||||
%td
|
%td
|
||||||
= link_to(t('shared.edit'), root_path, class: 'btn btn-primary btn-xs')
|
= link_to(t('shared.edit'), root_path, class: 'btn btn-primary btn-xs')
|
||||||
= link_to(t('shared.detach'), admin_domain_tech_contact_path(@domain, x), method: :delete, data: { confirm: t('shared.are_you_sure') }, class: 'btn btn-warning btn-xs')
|
= link_to(t('shared.detach'), admin_domain_domain_contact_path(@domain, x), method: :delete, data: { confirm: t('shared.are_you_sure') }, class: 'btn btn-warning btn-xs')
|
||||||
- if @domain.errors.messages[:tech_contacts]
|
- if @domain.errors.messages[:tech_contacts]
|
||||||
%tfoot
|
%tfoot
|
||||||
- @domain.errors.messages[:tech_contacts].each do |x|
|
- @domain.errors.messages[:tech_contacts].each do |x|
|
||||||
|
|
|
@ -51,6 +51,7 @@ en:
|
||||||
activerecord:
|
activerecord:
|
||||||
errors:
|
errors:
|
||||||
models:
|
models:
|
||||||
|
|
||||||
contact:
|
contact:
|
||||||
attributes:
|
attributes:
|
||||||
code:
|
code:
|
||||||
|
@ -67,6 +68,7 @@ en:
|
||||||
blank: "Required parameter missing - ident"
|
blank: "Required parameter missing - ident"
|
||||||
domains:
|
domains:
|
||||||
exist: 'Object association prohibits operation'
|
exist: 'Object association prohibits operation'
|
||||||
|
|
||||||
epp_domain: &epp_domain_ar_attributes
|
epp_domain: &epp_domain_ar_attributes
|
||||||
attributes:
|
attributes:
|
||||||
name_dirty:
|
name_dirty:
|
||||||
|
@ -98,8 +100,10 @@ en:
|
||||||
invalid: 'Status is invalid'
|
invalid: 'Status is invalid'
|
||||||
not_found: 'Status was not found'
|
not_found: 'Status was not found'
|
||||||
taken: 'Status already exists on this domain'
|
taken: 'Status already exists on this domain'
|
||||||
|
|
||||||
domain:
|
domain:
|
||||||
<<: *epp_domain_ar_attributes
|
<<: *epp_domain_ar_attributes
|
||||||
|
|
||||||
nameserver:
|
nameserver:
|
||||||
attributes:
|
attributes:
|
||||||
hostname:
|
hostname:
|
||||||
|
@ -109,14 +113,22 @@ en:
|
||||||
invalid: 'IPv4 is invalid'
|
invalid: 'IPv4 is invalid'
|
||||||
ipv6:
|
ipv6:
|
||||||
invalid: 'IPv6 is invalid'
|
invalid: 'IPv6 is invalid'
|
||||||
|
|
||||||
|
domain_contact:
|
||||||
|
attributes:
|
||||||
|
contact:
|
||||||
|
taken: 'Contact already exists on this domain!'
|
||||||
|
|
||||||
setting:
|
setting:
|
||||||
attributes:
|
attributes:
|
||||||
code:
|
code:
|
||||||
taken: 'Code already exists'
|
taken: 'Code already exists'
|
||||||
|
|
||||||
domain_status:
|
domain_status:
|
||||||
attributes:
|
attributes:
|
||||||
setting_id:
|
setting_id:
|
||||||
taken: 'Status already exists on this domain'
|
taken: 'Status already exists on this domain'
|
||||||
|
|
||||||
attributes:
|
attributes:
|
||||||
epp_domain: &epp_domain_attributes
|
epp_domain: &epp_domain_attributes
|
||||||
name: 'Domain name'
|
name: 'Domain name'
|
||||||
|
@ -130,7 +142,7 @@ en:
|
||||||
|
|
||||||
errors:
|
errors:
|
||||||
messages:
|
messages:
|
||||||
taken: 'Status already exists on this domain'
|
#taken: 'Status already exists on this domain'
|
||||||
blank: 'is missing'
|
blank: 'is missing'
|
||||||
epp_domain_reserved: 'Domain name is reserved or restricted'
|
epp_domain_reserved: 'Domain name is reserved or restricted'
|
||||||
epp_obj_does_not_exist: 'Object does not exist'
|
epp_obj_does_not_exist: 'Object does not exist'
|
||||||
|
@ -211,9 +223,8 @@ en:
|
||||||
edit_domain: 'Edit domain'
|
edit_domain: 'Edit domain'
|
||||||
contact_was_not_found: 'Contact was not found!'
|
contact_was_not_found: 'Contact was not found!'
|
||||||
contact_already_exists: 'Contact already exists on this domain!'
|
contact_already_exists: 'Contact already exists on this domain!'
|
||||||
|
failed_to_add_contact: 'Failed to add contact!'
|
||||||
contact_added: 'Contact added!'
|
contact_added: 'Contact added!'
|
||||||
new_tech_contact: 'New tech contact'
|
|
||||||
new_admin_contact: 'New admin contact'
|
|
||||||
contact_detached: 'Contact detached!'
|
contact_detached: 'Contact detached!'
|
||||||
failed_to_detach_contact: 'Failed to detach contact!'
|
failed_to_detach_contact: 'Failed to detach contact!'
|
||||||
new_domain_status: 'New domain status'
|
new_domain_status: 'New domain status'
|
||||||
|
@ -225,3 +236,4 @@ en:
|
||||||
status_deleted: 'Status deleted!'
|
status_deleted: 'Status deleted!'
|
||||||
failed_to_delete_status: 'Failed to delete status!'
|
failed_to_delete_status: 'Failed to delete status!'
|
||||||
tech_contact: 'Tech contact'
|
tech_contact: 'Tech contact'
|
||||||
|
new_domain_contact: 'New contact'
|
||||||
|
|
|
@ -103,14 +103,14 @@ feature 'Domain management', type: :feature do
|
||||||
within('#tech_contacts') { click_on 'Add' }
|
within('#tech_contacts') { click_on 'Add' }
|
||||||
|
|
||||||
c = Contact.last
|
c = Contact.last
|
||||||
fill_in('Tech contact', with: c.code, fill_options: { blur: false })
|
fill_in('Contact', with: c.code, fill_options: { blur: false })
|
||||||
# TODO: Wait for poltergeist to support blur option, then uncomment these lines:
|
# TODO: Wait for poltergeist to support blur option, then uncomment these lines:
|
||||||
# expect(page).to have_text(c.code)
|
# expect(page).to have_text(c.code)
|
||||||
# click_on(c.code)
|
# click_on(c.code)
|
||||||
# expect(find_field('Tech contact').value).to eq(c.code)
|
# expect(find_field('Tech contact').value).to eq(c.code)
|
||||||
|
|
||||||
# temporary solution:
|
# temporary solution:
|
||||||
page.execute_script("$('#contact_id').val('#{c.id}')")
|
page.execute_script("$('#domain_contact_contact_id').val('#{c.id}')")
|
||||||
|
|
||||||
click_on 'Save'
|
click_on 'Save'
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue