Refactor namesrvers controller, WIP with domain contacts

This commit is contained in:
Martin Lensment 2014-09-16 16:28:08 +03:00
parent 4c4c65d431
commit 168e6d2a01
8 changed files with 122 additions and 30 deletions

View file

@ -0,0 +1,48 @@
class Admin::DomainContactsController < ApplicationController
before_action :set_domain
before_action :set_domain_contact, only: [:destroy]
def new
@domain_contact = @domain.domain_contacts.build
end
def create
@domain.adding_admin_contact = true
@domain_contact = @domain.domain_contacts.build(domain_contact_params)
if @domain.save
flash[:notice] = I18n.t('shared.contact_added')
redirect_to [:admin, @domain]
else
flash.now[:alert] = I18n.t('shared.failed_to_add_contact')
render 'new'
end
end
def destroy
@domain.deleting_admin_contact = true
@domain.domain_contacts.select { |x| x == @domain_contact }[0].mark_for_destruction
if @domain.save
flash[:notice] = I18n.t('shared.contact_deleted')
else
flash[:alert] = I18n.t('shared.fail')
end
redirect_to [:admin, @domain]
end
private
def set_domain
@domain = Domain.find(params[:domain_id])
end
def set_domain_contact
@domain_contact = DomainContact.find(params[:id])
end
def domain_contact_params
params.require(:domain_contact).permit(:contact_id, :contact_type)
end
end

View file

@ -2,7 +2,6 @@ class Admin::DomainStatusesController < ApplicationController
before_action :set_domain
before_action :set_domain_status, only: [:edit, :update, :destroy]
def new
@domain_status = @domain.domain_statuses.build(value: DomainStatus::OK)
end

View file

@ -7,13 +7,8 @@ class Admin::NameserversController < ApplicationController
end
def create
unless @domain.can_add_nameserver?
@nameserver = @domain.nameservers.build(nameserver_params)
flash.now[:alert] = I18n.t('shared.failed_to_add_nameserver')
render 'new' and return
end
@domain.nameservers.build(nameserver_params)
@domain.adding_nameserver = true
@nameserver = @domain.nameservers.build(nameserver_params)
if @domain.save
flash[:notice] = I18n.t('shared.nameserver_added')
@ -29,7 +24,7 @@ class Admin::NameserversController < ApplicationController
end
def update
if @nameserver.update(nameserver_params) && @domain.valid?
if @nameserver.update(nameserver_params)
redirect_to [:admin, @domain]
else
render 'edit'
@ -37,12 +32,11 @@ class Admin::NameserversController < ApplicationController
end
def destroy
if @domain.can_remove_nameserver?
if @nameserver.destroy
flash[:notice] = I18n.t('shared.nameserver_deleted')
else
flash[:alert] = I18n.t('shared.failed_to_delete_nameserver')
end
@domain.deleting_nameserver = true
@domain.nameservers.select { |x| x == @nameserver }[0].mark_for_destruction
if @domain.save
flash[:notice] = I18n.t('shared.nameserver_deleted')
else
flash[:alert] = @domain.errors[:nameservers].first
end