mirror of
https://github.com/internetee/registry.git
synced 2025-06-06 12:47:29 +02:00
added registrar credit changing functionality
This commit is contained in:
parent
4982aba97c
commit
2ff049707d
18 changed files with 271 additions and 2 deletions
46
app/controllers/admin/accounts_controller.rb
Normal file
46
app/controllers/admin/accounts_controller.rb
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
module Admin
|
||||||
|
class AccountsController < BaseController
|
||||||
|
load_and_authorize_resource
|
||||||
|
|
||||||
|
def index
|
||||||
|
@q = Account.includes(:registrar).search(params[:q])
|
||||||
|
@accounts = @q.result.page(params[:page])
|
||||||
|
@accounts = @accounts.per(params[:results_per_page]) if params[:results_per_page].to_i.positive?
|
||||||
|
|
||||||
|
render_by_format('admin/accounts/index', 'accounts')
|
||||||
|
end
|
||||||
|
|
||||||
|
def show; end
|
||||||
|
|
||||||
|
def edit; end
|
||||||
|
|
||||||
|
def update
|
||||||
|
if @account.valid?
|
||||||
|
@sum = params[:account][:balance].to_f - @account.balance
|
||||||
|
redirect_to admin_accounts_path, notice: t('.updated') if create_activity
|
||||||
|
else
|
||||||
|
render 'edit'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def create_activity
|
||||||
|
activity = AccountActivity.new(account: @account,
|
||||||
|
sum: @sum,
|
||||||
|
currency: @account.currency,
|
||||||
|
description: params[:description],
|
||||||
|
activity_type: AccountActivity::ADD_CREDIT)
|
||||||
|
|
||||||
|
if activity.save
|
||||||
|
true
|
||||||
|
else
|
||||||
|
false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def account_params
|
||||||
|
params.require(:account).permit(:id, :currency, :balance)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -101,6 +101,7 @@ class Ability
|
||||||
can :manage, BankTransaction
|
can :manage, BankTransaction
|
||||||
can :manage, Invoice
|
can :manage, Invoice
|
||||||
can :manage, WhiteIp
|
can :manage, WhiteIp
|
||||||
|
can :manage, Account
|
||||||
can :manage, AccountActivity
|
can :manage, AccountActivity
|
||||||
can :manage, Dispute
|
can :manage, Dispute
|
||||||
can :read, ApiLog::EppLog
|
can :read, ApiLog::EppLog
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
class Account < ApplicationRecord
|
class Account < ApplicationRecord
|
||||||
|
extend ToCsv
|
||||||
include Versions
|
include Versions
|
||||||
|
|
||||||
belongs_to :registrar, required: true
|
belongs_to :registrar, required: true
|
||||||
|
|
7
app/views/admin/accounts/_account.html.erb
Normal file
7
app/views/admin/accounts/_account.html.erb
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
<tr>
|
||||||
|
<td><%= account.id %></td>
|
||||||
|
<td><%= account.balance %></td>
|
||||||
|
<td><%= account.currency %></td>
|
||||||
|
<td><%= link_to account.registrar, admin_registrar_path(account.registrar) %></td>
|
||||||
|
<td><%= link_to(t(:edit_balance), edit_admin_account_path(account), class: 'btn btn-primary btn-xs') %></td>
|
||||||
|
</tr>
|
52
app/views/admin/accounts/_form.html.erb
Normal file
52
app/views/admin/accounts/_form.html.erb
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
<%= form_for([:admin, @account], html: { class: 'form-horizontal', autocomplete: 'off' }) do |f| %>
|
||||||
|
<%= render 'form_errors', target: @account %>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-8">
|
||||||
|
<div class="form-group">
|
||||||
|
<div class="col-md-4 control-label">
|
||||||
|
<%= f.label :id, nil, class: 'required' %>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-7">
|
||||||
|
<%= f.text_field :id, required: true, autofocus: true,
|
||||||
|
class: 'form-control', disabled: true %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<div class="col-md-4 control-label">
|
||||||
|
<%= f.label :currency, nil, class: 'required' %>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-7">
|
||||||
|
<%= f.text_field :currency, required: true, class: 'form-control', disabled: true %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<div class="col-md-4 control-label">
|
||||||
|
<%= f.label :balance %>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-7">
|
||||||
|
<%= f.text_field(:balance, class: 'form-control') %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<div class="col-md-4 control-label">
|
||||||
|
<%= f.label :description %>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-7">
|
||||||
|
<%= text_area_tag :description, params[:description], class: 'form-control' %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<hr>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-8 text-right">
|
||||||
|
<%= button_tag t('.save_btn'), class: 'btn btn-warning' %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
34
app/views/admin/accounts/_search_form.haml
Normal file
34
app/views/admin/accounts/_search_form.haml
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
.row
|
||||||
|
.col-md-12
|
||||||
|
= search_form_for [:admin, @q], html: { style: 'margin-bottom: 0;', class: 'js-form', autocomplete: 'off' } do |f|
|
||||||
|
.row
|
||||||
|
.col-md-3
|
||||||
|
.form-group
|
||||||
|
= label_tag :name
|
||||||
|
= f.search_field :name, value: params[:q][:name], class: 'form-control', placeholder: t(:name)
|
||||||
|
.col-md-3
|
||||||
|
.form-group
|
||||||
|
= label_tag :registrant
|
||||||
|
= f.search_field :registrant, value: params[:q][:registrant], class: 'form-control', placeholder: t('.registrant_placeholder')
|
||||||
|
.col-md-3
|
||||||
|
.form-group
|
||||||
|
= label_tag t(:registrar_name)
|
||||||
|
= select_tag '[q][registrar]', options_for_select(Registrar.all.map { |x| [x, x.name] }, selected: params[:q][:registrar]), { include_blank: true, class: 'form-control', placeholder: t('.registrant')}
|
||||||
|
.col-md-3
|
||||||
|
.form-group
|
||||||
|
= label_tag :action
|
||||||
|
= select_tag '[q][event]', options_for_select([['Update', 'update'], ['Destroy', 'destroy'], ['Create', 'create']], params[:q][:event]), { include_blank:true, multiple: false, placeholder: t(:choose), class: 'form-control js-combobox' }
|
||||||
|
.row
|
||||||
|
.col-md-3
|
||||||
|
.col-md-3
|
||||||
|
.col-md-3
|
||||||
|
.form-group
|
||||||
|
= label_tag t(:results_per_page)
|
||||||
|
= text_field_tag :results_per_page, params[:results_per_page], class: 'form-control', placeholder: t(:results_per_page)
|
||||||
|
.col-md-3{style: 'padding-top: 25px;'}
|
||||||
|
%button.btn.btn-primary
|
||||||
|
|
||||||
|
%span.glyphicon.glyphicon-search
|
||||||
|
|
||||||
|
= link_to(t('.reset_btn'), admin_domain_versions_path, class: 'btn btn-default')
|
||||||
|
%hr
|
32
app/views/admin/accounts/_search_form.html.erb
Normal file
32
app/views/admin/accounts/_search_form.html.erb
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-12">
|
||||||
|
<%= search_form_for @q, url: [:admin, :accounts], html: { style: 'margin-bottom: 0;' } do |f| %>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-3">
|
||||||
|
<div class="form-group">
|
||||||
|
<%= f.label t(:registrar_name) %>
|
||||||
|
<%= f.select :registrar_id_in, Registrar.all.map { |x| [x, x.id] }, {}, class: 'form-control js-combobox', placeholder: t(:choose), multiple: true %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-3">
|
||||||
|
<div class="form-group">
|
||||||
|
<%= label_tag t(:results_per_page) %>
|
||||||
|
<%= text_field_tag :results_per_page, params[:results_per_page], class: 'form-control', placeholder: t(:results_per_page) %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-md-6 text-right" style="padding-top: 25px;">
|
||||||
|
<button class="btn btn-default search">
|
||||||
|
|
||||||
|
<span class="glyphicon glyphicon-search"></span>
|
||||||
|
|
||||||
|
</button>
|
||||||
|
<%= button_tag t('.download_csv_btn'),
|
||||||
|
formaction: admin_accounts_path(format: 'csv'),
|
||||||
|
class: 'btn btn-default' %>
|
||||||
|
<%= link_to(t('.reset_btn'), admin_accounts_path, class: 'btn btn-default') %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
|
</div>
|
5
app/views/admin/accounts/edit.html.erb
Normal file
5
app/views/admin/accounts/edit.html.erb
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
<h1>Editing Account</h1>
|
||||||
|
|
||||||
|
<%= render 'form', account: @account %>
|
||||||
|
|
||||||
|
<%= link_to 'Back', admin_accounts_path %>
|
38
app/views/admin/accounts/index.html.erb
Normal file
38
app/views/admin/accounts/index.html.erb
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
<h1><%= t '.header' %></h1>
|
||||||
|
<%= render 'search_form', search: @search %>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-12">
|
||||||
|
<div class="table-responsive">
|
||||||
|
<table class="table table-hover table-bordered table-condensed">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th class="col-xs-2"><%= sort_link(@q, 'ID', t('.')) %></th>
|
||||||
|
<th class="col-xs-2"><%= sort_link(@q, 'Balance') %></th>
|
||||||
|
<th class="col-xs-2"><%= sort_link(@q, 'Currency') %></th>
|
||||||
|
<th class="col-xs-2"><%= sort_link(@q, 'registrar_name', Registrar.model_name.human) %></th>
|
||||||
|
<th class="col-xs-2">
|
||||||
|
<%= t(:actions) %>
|
||||||
|
</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
|
||||||
|
<tbody>
|
||||||
|
<%= render @accounts %>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<br>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-6">
|
||||||
|
<%= paginate @accounts %>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-6 text-right">
|
||||||
|
<div class="pagination">
|
||||||
|
<%= t(:result_count, count: @q.result.count) %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
5
app/views/admin/accounts/new.html.erb
Normal file
5
app/views/admin/accounts/new.html.erb
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
<h1>New Admin Account</h1>
|
||||||
|
|
||||||
|
<%= render 'form', admin_account: @admin_account %>
|
||||||
|
|
||||||
|
<%= link_to 'Back', admin_accounts_path %>
|
4
app/views/admin/accounts/show.html.erb
Normal file
4
app/views/admin/accounts/show.html.erb
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
<p id="notice"><%= notice %></p>
|
||||||
|
|
||||||
|
<%= link_to 'Edit', edit_admin_account_path(@account) %> |
|
||||||
|
<%= link_to 'Back', admin_accounts_path %>
|
|
@ -21,6 +21,7 @@
|
||||||
%li= link_to t('.prices'), admin_prices_path
|
%li= link_to t('.prices'), admin_prices_path
|
||||||
%li= link_to t(:bank_statements), admin_bank_statements_path
|
%li= link_to t(:bank_statements), admin_bank_statements_path
|
||||||
%li= link_to t(:invoices), admin_invoices_path
|
%li= link_to t(:invoices), admin_invoices_path
|
||||||
|
%li= link_to t(:accounts), admin_accounts_path
|
||||||
%li= link_to t(:account_activities), admin_account_activities_path(created_after: 'today')
|
%li= link_to t(:account_activities), admin_account_activities_path(created_after: 'today')
|
||||||
%li.divider
|
%li.divider
|
||||||
%li.dropdown-header= t('.archive')
|
%li.dropdown-header= t('.archive')
|
||||||
|
|
|
@ -45,7 +45,7 @@
|
||||||
<%= x.reg_no %>
|
<%= x.reg_no %>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<%= "#{x.balance}" %>
|
<%= link_to "#{x.balance}", edit_admin_account_path(x.cash_account) %>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<%= "#{x.test_registrar}" %>
|
<%= "#{x.test_registrar}" %>
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
<dd><%= registrar.code %></dd>
|
<dd><%= registrar.code %></dd>
|
||||||
|
|
||||||
<dt><%= Registrar.human_attribute_name :balance %></dt>
|
<dt><%= Registrar.human_attribute_name :balance %></dt>
|
||||||
<dd><%= number_to_currency registrar.balance %></dd>
|
<dd><%= link_to (number_to_currency registrar.balance), edit_admin_account_path(registrar.cash_account) %></dd>
|
||||||
|
|
||||||
<dt><%= Registrar.human_attribute_name :website %></dt>
|
<dt><%= Registrar.human_attribute_name :website %></dt>
|
||||||
<dd><%= registrar.website %></dd>
|
<dd><%= registrar.website %></dd>
|
||||||
|
|
21
config/locales/admin/accounts.en.yml
Normal file
21
config/locales/admin/accounts.en.yml
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
en:
|
||||||
|
admin:
|
||||||
|
accounts:
|
||||||
|
index:
|
||||||
|
header: Accounts
|
||||||
|
|
||||||
|
update:
|
||||||
|
updated: Account has been successfully updated
|
||||||
|
|
||||||
|
form:
|
||||||
|
update_btn: Update account
|
||||||
|
reset_btn: Reset
|
||||||
|
save_btn: Save
|
||||||
|
|
||||||
|
search_form:
|
||||||
|
registrar_name: Registrar
|
||||||
|
reset_btn: Reset
|
||||||
|
download_csv_btn: CSV
|
||||||
|
|
||||||
|
account:
|
||||||
|
edit_balance: Edit balance
|
|
@ -358,6 +358,7 @@ en:
|
||||||
contact_org_error: 'Parameter value policy error. Org must be blank'
|
contact_org_error: 'Parameter value policy error. Org must be blank'
|
||||||
contact_fax_error: 'Parameter value policy error. Fax must be blank'
|
contact_fax_error: 'Parameter value policy error. Fax must be blank'
|
||||||
invoices: 'Invoices'
|
invoices: 'Invoices'
|
||||||
|
accounts: 'Accounts'
|
||||||
no_such_user: 'No such user'
|
no_such_user: 'No such user'
|
||||||
phone_no: 'Phone number'
|
phone_no: 'Phone number'
|
||||||
confirmation_sms_was_sent_to_your_phone_verification_code_is: 'Confirmation sms was sent to your phone. Verification code is %{code}.'
|
confirmation_sms_was_sent_to_your_phone_verification_code_is: 'Confirmation sms was sent to your phone. Verification code is %{code}.'
|
||||||
|
|
|
@ -236,6 +236,7 @@ Rails.application.routes.draw do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
resources :accounts
|
||||||
resources :account_activities
|
resources :account_activities
|
||||||
|
|
||||||
resources :bank_statements do
|
resources :bank_statements do
|
||||||
|
|
20
test/system/admin_area/accounts_test.rb
Normal file
20
test/system/admin_area/accounts_test.rb
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
require 'application_system_test_case'
|
||||||
|
|
||||||
|
class AdminAccountsSystemTest < ApplicationSystemTestCase
|
||||||
|
setup do
|
||||||
|
sign_in users(:admin)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_download_accounts
|
||||||
|
now = Time.zone.parse('2010-07-05 08:00')
|
||||||
|
travel_to now
|
||||||
|
|
||||||
|
get admin_accounts_path(format: :csv)
|
||||||
|
|
||||||
|
assert_response :ok
|
||||||
|
assert_equal 'text/csv; charset=utf-8', response.headers['Content-Type']
|
||||||
|
assert_equal %(attachment; filename="accounts_#{Time.zone.now.to_formatted_s(:number)}.csv"; filename*=UTF-8''accounts_#{Time.zone.now.to_formatted_s(:number)}.csv),
|
||||||
|
response.headers['Content-Disposition']
|
||||||
|
assert_not_empty response.body
|
||||||
|
end
|
||||||
|
end
|
Loading…
Add table
Add a link
Reference in a new issue