Domain transfer approval

This commit is contained in:
Martin Lensment 2014-09-24 17:58:48 +03:00
parent f42a390968
commit c8e0a7f5e0
7 changed files with 48 additions and 8 deletions

View file

@ -1,5 +1,5 @@
class Client::DomainTransfersController < ClientController
before_action :set_domain_transfer, only: :show
before_action :set_domain_transfer, only: [:show, :approve]
before_action :set_domain, only: [:create]
def new
@ -12,11 +12,22 @@ class Client::DomainTransfersController < ClientController
flash[:notice] = I18n.t('shared.domain_transfer_requested')
redirect_to [:client, @domain_transfer]
else
flash[:alert] = I18n.t('shared.other_registrar_has_already_requested_to_transfer_this_domain')
flash.now[:alert] = I18n.t('shared.other_registrar_has_already_requested_to_transfer_this_domain')
render 'new'
end
end
def approve
if can? :approve_as_client, @domain_transfer
@domain_transfer.approve_as_client
flash[:notice] = I18n.t('shared.domain_transfer_approved')
else
flash[:alert] = I18n.t('shared.failed_to_approve_domain_transfer')
end
redirect_to [:client, @domain_transfer]
end
private
def set_domain_transfer
@ -45,11 +56,17 @@ class Client::DomainTransfersController < ClientController
@domain_transfer = DomainTransfer.new
@domain = Domain.find_by(name: params[:domain_name])
if @domain
return if @domain.auth_info == params[:domain_pw]
flash[:alert] = I18n.t('shared.password_invalid')
render 'new'
if @domain.auth_info != params[:domain_pw]
flash.now[:alert] = I18n.t('shared.password_invalid')
render 'new' and return
end
if @domain.registrar == current_user.registrar
flash.now[:alert] = I18n.t('shared.domain_already_belongs_to_the_querying_registrar')
render 'new' and return
end
else
flash[:alert] = I18n.t('shared.domain_was_not_found')
flash.now[:alert] = I18n.t('shared.domain_was_not_found')
render 'new'
end
end

View file

@ -1,5 +1,5 @@
class ClientController < ApplicationController
def current_user
EppUser.last
EppUser.first
end
end

View file

@ -6,6 +6,7 @@ class Ability
# user ||= EppUser.last
can :read, DomainTransfer, transfer_to_id: user.registrar.id
can :approve_as_client, DomainTransfer, transfer_from_id: user.registrar.id, status: DomainTransfer::PENDING
# Define abilities for the passed in user here. For example:
#
# user ||= User.new # guest user (not logged in)

View file

@ -15,4 +15,16 @@ class DomainTransfer < ActiveRecord::Base
wait_time = SettingGroup.domain_general.setting(:transfer_wait_time).value.to_i
transfer_requested_at + wait_time.hours
end
def approve_as_client
transaction do
self.status = DomainTransfer::CLIENT_APPROVED
self.transferred_at = Time.zone.now
save!
domain.generate_auth_info
domain.registrar = transfer_to
domain.save!
end
end
end

View file

@ -4,6 +4,8 @@
= "#{t('shared.domain_transfer')}"
.col-sm-6
%h2.text-right.text-center-xs
- if can? :approve_as_client, @domain_transfer
= button_to(t('shared.approve'), approve_client_domain_transfer_path, class: 'btn btn-primary')
%hr
.row

View file

@ -280,6 +280,10 @@ en:
status: 'Status'
eedirekt: 'EEDirekt'
domain_transfer_requested: 'Domain transfer requested!'
domain_transfer_approved: 'Domain transfer approved!'
failed_to_approve_domain_transfer: 'Failed to approve domain transfer'
approve: 'Approve'
domain_already_belongs_to_the_querying_registrar: 'Domain already belongs to the querying registrar'
other_registrar_has_already_requested_to_transfer_this_domain: 'Other registrar has already requested to transfer this domain.'
transfer: 'Transfer'
transfer_domain: 'Transfer domain'

View file

@ -23,7 +23,11 @@ Rails.application.routes.draw do
namespace(:client) do
resources :domains
resources :domain_transfers
resources :domain_transfers do
member do
post 'approve'
end
end
resources :contacts do
collection do