Added csv export to registrar api_users and white_ips

This commit is contained in:
Sergei Tsoganov 2023-05-15 14:11:46 +03:00
parent 316f00cadc
commit 0f16ec77f5
11 changed files with 104 additions and 6 deletions

View file

@ -3,7 +3,7 @@ require 'net/http'
module Admin
class RegistrarsController < BaseController # rubocop:disable Metrics/ClassLength
load_and_authorize_resource
before_action :set_registrar, only: [:show, :edit, :update, :destroy]
before_action :set_registrar, only: %i[show edit update destroy]
before_action :set_registrar_status_filter, only: [:index]
helper_method :registry_vat_rate
helper_method :iban_max_length
@ -39,6 +39,11 @@ module Admin
def edit; end
def show
@result = @registrar.send(params[:records]) unless params[:records].blank?
render_by_format('admin/registrars/show', "#{@registrar.name.parameterize}_#{params[:records]}")
end
def update
if @registrar.update(registrar_params)
redirect_to [:admin, @registrar], notice: t('.updated')

View file

@ -91,6 +91,25 @@ class ApiUser < User
another_api_user.identity_code == identity_code
end
def as_csv_row
[
username,
plain_text_password,
identity_code,
roles.join(', '),
active,
accredited?,
accreditation_expire_date,
created_at,
updated_at
]
end
def self.csv_header
['Username', 'Password', 'Identity Code', 'Role', 'Active', 'Accredited',
'Accreditation Expire Date', 'Created', 'Updated']
end
private
def machine_readable_certificate(cert)

View file

@ -72,5 +72,19 @@ class WhiteIp < ApplicationRecord
rescue StandardError => _e
nil
end
def csv_header
%w[IPv4 IPv6 Interfaces Created Updated]
end
end
def as_csv_row
[
ipv4,
ipv6,
interfaces.join(', ').upcase,
created_at,
updated_at
]
end
end

View file

@ -22,7 +22,7 @@ class CsvGenerator
def custom_csv?(class_name)
[
Version::DomainVersion, Version::ContactVersion, Domain,
Contact, Invoice, Account, AccountActivity
Contact, Invoice, Account, AccountActivity, ApiUser, WhiteIp
].include?(class_name)
end
end

View file

@ -1,4 +1,4 @@
<div class="panel panel-default">
<div class="panel panel-default api_users">
<div class="panel-heading">
<%= t '.header' %>
</div>
@ -15,7 +15,7 @@
<tbody>
<% registrar.api_users.each do |api_user| %>
<tr>
<td><%= link_to api_user, admin_registrar_api_user_path(api_user.registrar, api_user) %></td>
<td><%= link_to api_user, admin_registrar_api_user_path(registrar, api_user) %></td>
<td><%= api_user.active %></td>
<td>
@ -37,5 +37,7 @@
<div class="panel-footer text-right">
<%= link_to t('.new_btn'), new_admin_registrar_api_user_path(registrar),
class: 'btn btn-default btn-xs' %>
<%= link_to 'Export to CSV', export_admin_registrar_path(registrar, records: 'api_users', format: :csv),
class: 'btn btn-default btn-xs' if registrar.api_users.any? %>
</div>
</div>

View file

@ -1,4 +1,4 @@
<div class="panel panel-default">
<div class="panel panel-default white_ips">
<div class="panel-heading">
<%= t '.header' %>
</div>
@ -34,5 +34,7 @@
<div class="panel-footer text-right">
<%= link_to t('.new_btn'), new_admin_registrar_white_ip_path(registrar),
class: 'btn btn-default btn-xs' %>
<%= link_to 'Export to CSV', export_admin_registrar_path(registrar, records: 'white_ips', format: :csv),
class: 'btn btn-default btn-xs' if registrar.white_ips.any? %>
</div>
</div>