mirror of
https://github.com/internetee/registry.git
synced 2025-07-03 01:33:36 +02:00
Add deposits controller
This commit is contained in:
parent
5c0e2be387
commit
13c94aeb1c
10 changed files with 88 additions and 4 deletions
|
@ -122,9 +122,7 @@ sub
|
|||
width: 860px
|
||||
body > .container
|
||||
background: #F8F8F8
|
||||
margin-bottom: 50px
|
||||
min-height: 600px
|
||||
padding: 30px 30px 56px 30px
|
||||
padding: 30px 30px 30px 30px
|
||||
|
||||
.container.version
|
||||
background: transparent
|
||||
|
|
26
app/controllers/registrar/deposits_controller.rb
Normal file
26
app/controllers/registrar/deposits_controller.rb
Normal file
|
@ -0,0 +1,26 @@
|
|||
class Registrar::DepositsController < RegistrarController
|
||||
authorize_resource class: false
|
||||
|
||||
def new
|
||||
@deposit = Deposit.new
|
||||
end
|
||||
|
||||
def create
|
||||
@deposit = Deposit.new(deposit_params.merge(registrar: current_user.registrar))
|
||||
@invoice = @deposit.issue_prepayment_invoice
|
||||
|
||||
if @invoice
|
||||
flash[:notice] = t('please_pay_the_following_invoice')
|
||||
redirect_to [:registrar, @invoice]
|
||||
else
|
||||
flash[:alert] = t('failed_to_create_record')
|
||||
render 'new'
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def deposit_params
|
||||
params.require(:deposit).permit(:amount, :description)
|
||||
end
|
||||
end
|
|
@ -57,6 +57,7 @@ class Ability
|
|||
can :manage, Depp::Keyrelay
|
||||
can :confirm, :keyrelay
|
||||
can :confirm, :transfer
|
||||
can :manage, :deposit
|
||||
end
|
||||
|
||||
def user
|
||||
|
|
23
app/models/deposit.rb
Normal file
23
app/models/deposit.rb
Normal file
|
@ -0,0 +1,23 @@
|
|||
class Deposit
|
||||
include ActiveModel::Validations
|
||||
include ActiveModel::Conversion
|
||||
extend ActiveModel::Naming
|
||||
|
||||
attr_accessor :amount, :description, :registrar
|
||||
|
||||
validates :amount, :registrar, presence: true
|
||||
|
||||
def initialize(attributes = {})
|
||||
attributes.each do |name, value|
|
||||
send("#{name}=", value)
|
||||
end
|
||||
end
|
||||
|
||||
def persisted?
|
||||
false
|
||||
end
|
||||
|
||||
def issue_prepayment_invoice
|
||||
valid? && registrar.issue_prepayment_invoice(amount, description)
|
||||
end
|
||||
end
|
22
app/views/registrar/deposits/new.haml
Normal file
22
app/views/registrar/deposits/new.haml
Normal file
|
@ -0,0 +1,22 @@
|
|||
%h1= t('add_deposit')
|
||||
%hr
|
||||
= form_for([:registrar, @deposit], method: :post) do |f|
|
||||
.row
|
||||
.col-md-4.col-md-offset-4
|
||||
= render 'shared/full_errors', object: @deposit
|
||||
.form-group
|
||||
= f.label :amount
|
||||
.input-group
|
||||
= f.text_field :amount, class: 'form-control'
|
||||
.input-group-addon
|
||||
EUR
|
||||
|
||||
.form-group
|
||||
= f.label :description
|
||||
= f.text_area :description, class: 'form-control'
|
||||
|
||||
.row
|
||||
.col-md-12.text-right
|
||||
= button_tag(t('save'), class: 'btn btn-primary')
|
||||
|
||||
|
|
@ -1 +1,2 @@
|
|||
invoices index
|
||||
|
||||
|
|
6
app/views/shared/_full_errors.haml
Normal file
6
app/views/shared/_full_errors.haml
Normal file
|
@ -0,0 +1,6 @@
|
|||
.errors
|
||||
- if object.errors.any?
|
||||
- object.errors.full_messages.each do |msg|
|
||||
= msg
|
||||
%br
|
||||
%hr
|
|
@ -222,6 +222,8 @@ en:
|
|||
phone: 'Contact phone'
|
||||
email: 'Contact e-mail'
|
||||
state: 'State / Province'
|
||||
deposit:
|
||||
amount: 'Amount'
|
||||
|
||||
errors:
|
||||
messages:
|
||||
|
@ -641,4 +643,6 @@ en:
|
|||
no_connection_to_registry: Connection issue to the registry server! Please try again later.
|
||||
domain_not_found: 'Domain was not found'
|
||||
new_contact: 'New contact'
|
||||
|
||||
add_deposit: 'Add deposit'
|
||||
amount: 'Amount'
|
||||
please_pay_the_following_invoice: 'Please pay the following invoice'
|
||||
|
|
|
@ -21,6 +21,7 @@ Rails.application.routes.draw do
|
|||
root 'polls#show'
|
||||
|
||||
resources :invoices
|
||||
resources :deposits
|
||||
|
||||
devise_scope :user do
|
||||
get 'login' => 'sessions#login'
|
||||
|
|
|
@ -15,6 +15,7 @@ registrar1 = Registrar.where(
|
|||
ApiUser.where(
|
||||
username: 'registrar1',
|
||||
password: 'test1',
|
||||
identity_code: '51001091072',
|
||||
active: true,
|
||||
registrar: registrar1
|
||||
).first_or_create!
|
||||
|
@ -33,6 +34,7 @@ registrar2 = Registrar.where(
|
|||
ApiUser.where(
|
||||
username: 'registrar2',
|
||||
password: 'test2',
|
||||
identity_code: '11412090004',
|
||||
active: true,
|
||||
registrar: registrar2
|
||||
).first_or_create!
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue