mirror of
https://github.com/internetee/registry.git
synced 2025-07-22 02:35:57 +02:00
parent
19f9a4eb71
commit
62c38d1f99
29 changed files with 660 additions and 16 deletions
|
@ -2,6 +2,7 @@ class Registrar
|
|||
class AccountController < BaseController
|
||||
skip_authorization_check
|
||||
helper_method :iban_max_length
|
||||
helper_method :balance_auto_reload_setting
|
||||
|
||||
def show; end
|
||||
|
||||
|
@ -25,5 +26,9 @@ class Registrar
|
|||
def iban_max_length
|
||||
Iban.max_length
|
||||
end
|
||||
|
||||
def balance_auto_reload_setting
|
||||
current_registrar_user.registrar.settings['balance_auto_reload']
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,52 @@
|
|||
class Registrar
|
||||
module Settings
|
||||
class BalanceAutoReloadController < BaseController
|
||||
before_action :authorize
|
||||
|
||||
def edit
|
||||
@type = if current_registrar.settings['balance_auto_reload']
|
||||
type_params = current_registrar.settings['balance_auto_reload']['type']
|
||||
.except('name')
|
||||
BalanceAutoReloadTypes::Threshold.new(type_params)
|
||||
else
|
||||
BalanceAutoReloadTypes::Threshold.new
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
type = BalanceAutoReloadTypes::Threshold.new(type_params)
|
||||
current_registrar.update!(settings: { balance_auto_reload: { type: type } })
|
||||
|
||||
redirect_to registrar_account_path, notice: t('.saved')
|
||||
end
|
||||
|
||||
def destroy
|
||||
current_registrar.settings.delete('balance_auto_reload')
|
||||
current_registrar.save!
|
||||
|
||||
redirect_to registrar_account_path, notice: t('.disabled')
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def type_params
|
||||
permitted_params = params.require(:type).permit(:amount, :threshold)
|
||||
normalize_params(permitted_params)
|
||||
end
|
||||
|
||||
def normalize_params(params)
|
||||
params[:amount] = params[:amount].to_f
|
||||
params[:threshold] = params[:threshold].to_f
|
||||
params
|
||||
end
|
||||
|
||||
def authorize
|
||||
authorize!(:manage, :balance_auto_reload)
|
||||
end
|
||||
|
||||
def current_registrar
|
||||
current_registrar_user.registrar
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue