mirror of
https://github.com/internetee/registry.git
synced 2025-08-14 21:43:50 +02:00
Introduce BaseController for registrar area
This commit is contained in:
parent
955c7bcd6e
commit
92d8008c15
14 changed files with 785 additions and 746 deletions
|
@ -1,4 +1,5 @@
|
|||
class Registrar::AccountActivitiesController < RegistrarController
|
||||
class Registrar
|
||||
class AccountActivitiesController < BaseController
|
||||
load_and_authorize_resource
|
||||
|
||||
def index # rubocop: disable Metrics/AbcSize
|
||||
|
@ -26,3 +27,4 @@ class Registrar::AccountActivitiesController < RegistrarController
|
|||
params[:q][:created_at_lteq] = ca_cache
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
41
app/controllers/registrar/base_controller.rb
Normal file
41
app/controllers/registrar/base_controller.rb
Normal file
|
@ -0,0 +1,41 @@
|
|||
class Registrar
|
||||
class BaseController < ApplicationController
|
||||
before_action :authenticate_user!, :check_ip
|
||||
layout 'registrar/application'
|
||||
|
||||
include Registrar::ApplicationHelper
|
||||
|
||||
helper_method :depp_controller?
|
||||
|
||||
def depp_controller?
|
||||
false
|
||||
end
|
||||
|
||||
def check_ip
|
||||
return unless current_user
|
||||
unless current_user.is_a? ApiUser
|
||||
sign_out(current_user)
|
||||
return
|
||||
end
|
||||
return if Rails.env.development?
|
||||
registrar_ip_whitelisted = current_user.registrar.registrar_ip_white?(request.ip)
|
||||
|
||||
return if registrar_ip_whitelisted
|
||||
flash[:alert] = t('ip_is_not_whitelisted')
|
||||
sign_out(current_user)
|
||||
redirect_to registrar_login_path and return
|
||||
end
|
||||
|
||||
helper_method :head_title_sufix
|
||||
|
||||
def head_title_sufix
|
||||
t(:registrar_head_title_sufix)
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def current_ability
|
||||
@current_ability ||= Ability.new(current_user, request.remote_ip)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,4 +1,5 @@
|
|||
class Registrar::ContactsController < Registrar::DeppController # EPP controller
|
||||
class Registrar
|
||||
class ContactsController < DeppController
|
||||
before_action :init_epp_contact
|
||||
helper_method :address_processing?
|
||||
|
||||
|
@ -140,3 +141,4 @@ class Registrar::ContactsController < Registrar::DeppController # EPP controller
|
|||
Contact.address_processing?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
class Registrar::DashboardController < RegistrarController
|
||||
class Registrar
|
||||
class DashboardController < BaseController
|
||||
authorize_resource class: false
|
||||
|
||||
def show
|
||||
|
@ -9,3 +10,4 @@ class Registrar::DashboardController < RegistrarController
|
|||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
class Registrar::DepositsController < RegistrarController
|
||||
class Registrar
|
||||
class DepositsController < BaseController
|
||||
authorize_resource class: false
|
||||
|
||||
def new
|
||||
|
@ -24,3 +25,4 @@ class Registrar::DepositsController < RegistrarController
|
|||
params.require(:deposit).permit(:amount, :description)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
class Registrar::DeppController < RegistrarController # EPP controller
|
||||
class Registrar
|
||||
class DeppController < BaseController
|
||||
helper_method :depp_current_user
|
||||
|
||||
rescue_from(Errno::ECONNRESET, Errno::ECONNREFUSED) do |exception|
|
||||
|
@ -8,6 +9,7 @@ class Registrar::DeppController < RegistrarController # EPP controller
|
|||
end
|
||||
|
||||
before_action :authenticate_user
|
||||
|
||||
def authenticate_user
|
||||
redirect_to registrar_login_url and return unless depp_current_user
|
||||
end
|
||||
|
@ -32,3 +34,4 @@ class Registrar::DeppController < RegistrarController # EPP controller
|
|||
true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
class Registrar::DomainsController < Registrar::DeppController # EPP controller
|
||||
class Registrar
|
||||
class DomainsController < DeppController
|
||||
before_action :init_domain, except: :new
|
||||
helper_method :contacts
|
||||
|
||||
|
@ -55,6 +56,7 @@ class Registrar::DomainsController < Registrar::DeppController # EPP controller
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
# rubocop: enable Metrics/PerceivedComplexity
|
||||
# rubocop: enable Metrics/CyclomaticComplexity
|
||||
# rubocop: enable Metrics/AbcSize
|
||||
|
@ -189,3 +191,4 @@ class Registrar::DomainsController < Registrar::DeppController # EPP controller
|
|||
params[:q][:valid_to_lteq] = ca_cache
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
class Registrar::InvoicesController < RegistrarController
|
||||
class Registrar
|
||||
class InvoicesController < BaseController
|
||||
load_and_authorize_resource
|
||||
|
||||
before_action :set_invoice, only: [:show, :forward, :download_pdf]
|
||||
|
@ -14,7 +15,8 @@ class Registrar::InvoicesController < RegistrarController
|
|||
end
|
||||
end
|
||||
|
||||
def show; end
|
||||
def show;
|
||||
end
|
||||
|
||||
def forward
|
||||
@invoice.billing_email = @invoice.buyer.billing_email
|
||||
|
@ -69,3 +71,4 @@ class Registrar::InvoicesController < RegistrarController
|
|||
params[:q][:due_date_lteq] = ca_cache
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
class Registrar::KeyrelaysController < Registrar::DeppController # EPP controller
|
||||
class Registrar
|
||||
class KeyrelaysController < DeppController
|
||||
def show
|
||||
authorize! :view, Depp::Keyrelay
|
||||
end
|
||||
|
@ -16,3 +17,4 @@ class Registrar::KeyrelaysController < Registrar::DeppController # EPP controlle
|
|||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
class Registrar::PaymentsController < RegistrarController
|
||||
class Registrar
|
||||
class PaymentsController < BaseController
|
||||
protect_from_forgery except: :back
|
||||
|
||||
skip_authorization_check # actually anyone can pay, no problems at all
|
||||
|
@ -35,6 +36,7 @@ class Registrar::PaymentsController < RegistrarController
|
|||
end
|
||||
|
||||
private
|
||||
|
||||
def banks
|
||||
ENV['payments_banks'].split(",").map(&:strip)
|
||||
end
|
||||
|
@ -42,5 +44,5 @@ class Registrar::PaymentsController < RegistrarController
|
|||
def check_bank
|
||||
raise StandardError.new("Not Implemented bank") unless banks.include?(params[:bank])
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,11 +1,15 @@
|
|||
class Registrar::PollsController < Registrar::DeppController # EPP controller
|
||||
class Registrar
|
||||
class PollsController < DeppController
|
||||
authorize_resource class: false
|
||||
before_action :init_epp_xml
|
||||
|
||||
def show
|
||||
if Rails.env.test? # Stub for depp server request
|
||||
@data = Object.new
|
||||
def @data.css(key); []; end
|
||||
|
||||
def @data.css(key)
|
||||
; [];
|
||||
end
|
||||
else
|
||||
@data = depp_current_user.request(@ex.poll)
|
||||
end
|
||||
|
@ -54,3 +58,4 @@ class Registrar::PollsController < Registrar::DeppController # EPP controller
|
|||
@domain = Depp::Domain.new(current_user: depp_current_user)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
class Registrar::SessionsController < Devise::SessionsController
|
||||
class Registrar
|
||||
class SessionsController < Devise::SessionsController
|
||||
layout 'registrar/application'
|
||||
helper_method :depp_controller?
|
||||
|
||||
def depp_controller?
|
||||
false
|
||||
end
|
||||
|
@ -59,6 +61,7 @@ class Registrar::SessionsController < Devise::SessionsController
|
|||
render 'login'
|
||||
end
|
||||
end
|
||||
|
||||
# rubocop:enable Metrics/MethodLength
|
||||
# rubocop:enable Metrics/AbcSize
|
||||
|
||||
|
@ -76,6 +79,7 @@ class Registrar::SessionsController < Devise::SessionsController
|
|||
|
||||
redirect_to registrar_root_url
|
||||
end
|
||||
|
||||
# rubocop:enable Metrics/CyclomaticComplexity
|
||||
# rubocop:enable Metrics/PerceivedComplexity
|
||||
|
||||
|
@ -127,6 +131,7 @@ class Registrar::SessionsController < Devise::SessionsController
|
|||
render json: { message: t(:no_such_user) }, status: :unauthorized
|
||||
end
|
||||
end
|
||||
|
||||
# rubocop:enable Metrics/MethodLength
|
||||
|
||||
# rubocop: disable Metrics/AbcSize
|
||||
|
@ -167,6 +172,7 @@ class Registrar::SessionsController < Devise::SessionsController
|
|||
render json: { message: t(:internal_error) }, status: :bad_request
|
||||
end
|
||||
end
|
||||
|
||||
# rubocop: enable Metrics/AbcSize
|
||||
# rubocop: enable Metrics/CyclomaticComplexity
|
||||
# rubocop: enable Metrics/MethodLength
|
||||
|
@ -184,3 +190,4 @@ class Registrar::SessionsController < Devise::SessionsController
|
|||
render text: t('access_denied') and return
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
class Registrar::XmlConsolesController < Registrar::DeppController # EPP controller
|
||||
class Registrar
|
||||
class XmlConsolesController < DeppController
|
||||
authorize_resource class: false
|
||||
|
||||
def show
|
||||
|
@ -21,3 +22,4 @@ class Registrar::XmlConsolesController < Registrar::DeppController # EPP control
|
|||
render text: xml
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,37 +0,0 @@
|
|||
class RegistrarController < ApplicationController
|
||||
before_action :authenticate_user!, :check_ip
|
||||
layout 'registrar/application'
|
||||
|
||||
include Registrar::ApplicationHelper
|
||||
|
||||
helper_method :depp_controller?
|
||||
def depp_controller?
|
||||
false
|
||||
end
|
||||
|
||||
def check_ip
|
||||
return unless current_user
|
||||
unless current_user.is_a? ApiUser
|
||||
sign_out(current_user)
|
||||
return
|
||||
end
|
||||
return if Rails.env.development?
|
||||
registrar_ip_whitelisted = current_user.registrar.registrar_ip_white?(request.ip)
|
||||
|
||||
return if registrar_ip_whitelisted
|
||||
flash[:alert] = t('ip_is_not_whitelisted')
|
||||
sign_out(current_user)
|
||||
redirect_to registrar_login_path and return
|
||||
end
|
||||
|
||||
helper_method :head_title_sufix
|
||||
def head_title_sufix
|
||||
t(:registrar_head_title_sufix)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def current_ability
|
||||
@current_ability ||= Ability.new(current_user, request.remote_ip)
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue