diff --git a/app/assets/stylesheets/registrar.sass b/app/assets/stylesheets/registrar.sass index cd7867199..3d7f0aba7 100644 --- a/app/assets/stylesheets/registrar.sass +++ b/app/assets/stylesheets/registrar.sass @@ -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 diff --git a/app/controllers/registrar/deposits_controller.rb b/app/controllers/registrar/deposits_controller.rb new file mode 100644 index 000000000..6cf33f1c1 --- /dev/null +++ b/app/controllers/registrar/deposits_controller.rb @@ -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 diff --git a/app/models/ability.rb b/app/models/ability.rb index f2fe3f827..ecd4acc55 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -57,6 +57,7 @@ class Ability can :manage, Depp::Keyrelay can :confirm, :keyrelay can :confirm, :transfer + can :manage, :deposit end def user diff --git a/app/models/deposit.rb b/app/models/deposit.rb new file mode 100644 index 000000000..33c6502aa --- /dev/null +++ b/app/models/deposit.rb @@ -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 diff --git a/app/views/registrar/deposits/new.haml b/app/views/registrar/deposits/new.haml new file mode 100644 index 000000000..6557316f7 --- /dev/null +++ b/app/views/registrar/deposits/new.haml @@ -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') + + diff --git a/app/views/registrar/invoices/index.haml b/app/views/registrar/invoices/index.haml index b235cc182..56a5147fd 100644 --- a/app/views/registrar/invoices/index.haml +++ b/app/views/registrar/invoices/index.haml @@ -1 +1,2 @@ invoices index + diff --git a/app/views/shared/_full_errors.haml b/app/views/shared/_full_errors.haml new file mode 100644 index 000000000..aa3be8857 --- /dev/null +++ b/app/views/shared/_full_errors.haml @@ -0,0 +1,6 @@ +.errors + - if object.errors.any? + - object.errors.full_messages.each do |msg| + = msg + %br + %hr diff --git a/config/locales/en.yml b/config/locales/en.yml index 26aa09c88..350dcad4d 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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' diff --git a/config/routes.rb b/config/routes.rb index 75e6a57a6..f5cb5fca1 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -21,6 +21,7 @@ Rails.application.routes.draw do root 'polls#show' resources :invoices + resources :deposits devise_scope :user do get 'login' => 'sessions#login' diff --git a/db/seeds.rb b/db/seeds.rb index d5b022514..03dc6c18f 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -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!