105842700-download_list_added

This commit is contained in:
Stas 2015-12-06 20:47:34 +02:00
parent da910bc660
commit 2748f3be55
11 changed files with 163 additions and 88 deletions

View file

@ -1,12 +1,9 @@
class Registrant::DomainsController < RegistrantController class Registrant::DomainsController < RegistrantController
def index def index
authorize! :view, :registrant_domains authorize! :view, :registrant_domains
params[:q] ||= {} params[:q] ||= {}
domains = current_user.domains domains = current_user.domains
normalize_search_parameters do normalize_search_parameters do
@q = domains.search(params[:q]) @q = domains.search(params[:q])
@domains = @q.result.page(params[:page]) @domains = @q.result.page(params[:page])
@ -16,15 +13,32 @@ class Registrant::DomainsController < RegistrantController
def show def show
@domain = Domain.find(params[:id]) @domain = Domain.find(params[:id])
@domain.valid? if !(current_user.domains.include?(@domain) || @domain.valid?)
redirect_to registrant_domains_path
end
authorize! :read, @domain
end end
def set_domain def set_domain
@domain = Domain.find(params[:id]) @domain = Domain.find(params[:id])
end end
def normalize_search_parameters def download_list
authorize! :view, :registrant_domains
params[:q] ||= {}
domains = current_user.domains
normalize_search_parameters do
@q = domains.search(params[:q])
@domains = @q
end
respond_to do |format|
format.html
format.csv { render text: @domains.to_csv }
end
end
def normalize_search_parameters
ca_cache = params[:q][:valid_to_lteq] ca_cache = params[:q][:valid_to_lteq]
begin begin
end_time = params[:q][:valid_to_lteq].try(:to_date) end_time = params[:q][:valid_to_lteq].try(:to_date)
@ -32,10 +46,7 @@ class Registrant::DomainsController < RegistrantController
rescue rescue
logger.warn('Invalid date') logger.warn('Invalid date')
end end
yield yield
params[:q][:valid_to_lteq] = ca_cache params[:q][:valid_to_lteq] = ca_cache
end end
end end

View file

@ -1,64 +1,8 @@
class Registrar::RegistrarsController < RegistrartController class Registrant::RegistrarsController < RegistrantController
load_and_authorize_resource
def show
def search
render json: Registrar.search_by_query(params[:q])
end
def index
@q = Registrar.ordered.search(params[:q])
@registrars = @q.result.page(params[:page])
end
def new
@registrar = Registrar.new
end
def create
@registrar = Registrar.new(registrar_params)
if @registrar.save
flash[:notice] = I18n.t('registrar_added')
redirect_to [:admin, @registrar]
else
flash.now[:alert] = I18n.t('failed_to_add_registrar')
render 'new'
end
end
def edit; end
def update
if @registrar.update(registrar_params)
flash[:notice] = I18n.t('registrar_updated')
redirect_to [:admin, @registrar]
else
flash.now[:alert] = I18n.t('failed_to_update_registrar')
render 'edit'
end
end
def destroy
if @registrar.destroy
flash[:notice] = I18n.t('registrar_deleted')
redirect_to admin_registrars_path
else
flash.now[:alert] = I18n.t('failed_to_delete_registrar')
render 'show'
end
end
private
def set_registrar
@registrar = Registrar.find(params[:id]) @registrar = Registrar.find(params[:id])
end authorize! :read, @registrar
@registrar.valid?
def registrar_params
params.require(:registrar).permit(
:name, :reg_no, :vat_no, :street, :city, :state, :zip, :billing_address,
:country_code, :email, :phone, :billing_email, :code
)
end end
end end

View file

@ -16,7 +16,7 @@ class Ability
@user.roles.each { |role| send(role) } if @user.roles @user.roles.each { |role| send(role) } if @user.roles
when 'ApiUser' when 'ApiUser'
@user.roles.each { |role| send(role) } if @user.roles @user.roles.each { |role| send(role) } if @user.roles
when 'RegistrantUser' when 'RegistrantUser'
static_registrant static_registrant
end end
@ -117,9 +117,11 @@ class Ability
end end
def static_registrant def static_registrant
customer_service
can :manage, :registrant_domains can :manage, :registrant_domains
can :manage, :registrant_whois can :manage, :registrant_whois
can :manage, Depp::Domain can :manage, Depp::Domain
can :manage, Domain
end end
def user def user

View file

@ -774,5 +774,14 @@ class Domain < ActiveRecord::Base
status_notes[status] = notes[i] status_notes[status] = notes[i]
end end
end end
def self.to_csv
CSV.generate do |csv|
csv << column_names
all.each do |domain|
csv << domain.attributes.values_at(*column_names)
end
end
end
end end
# rubocop: enable Metrics/ClassLength # rubocop: enable Metrics/ClassLength

View file

@ -12,10 +12,6 @@
.form-group .form-group
= f.label t(:registrant_ident) = f.label t(:registrant_ident)
= f.search_field :registrant_ident_eq, class: 'form-control', placeholder: t(:registrant_ident) = f.search_field :registrant_ident_eq, class: 'form-control', placeholder: t(:registrant_ident)
.col-md-3
.form-group
= f.label t(:nameserver_hostname)
= f.search_field :nameservers_hostname_eq, class: 'form-control', placeholder: t(:nameserver_hostname)
.row .row
.col-md-3 .col-md-3
.form-group .form-group
@ -36,6 +32,20 @@
&nbsp; &nbsp;
%button.btn.btn-default.js-reset-form %button.btn.btn-default.js-reset-form
= t(:clear_fields) = t(:clear_fields)
.row
.col-md-3
.btn-group{:role => "group"}
%button.btn.btn-default.dropdown-toggle{"aria-expanded" => "false", "aria-haspopup" => "true", "data-toggle" => "dropdown", :type => "button"}
Download
%span.caret
%ul.dropdown-menu
%li= link_to 'PDF', download_list_registrant_domain_path(params[:q], format: "pdf")
%li= link_to 'CSV', download_list_registrant_domain_path(params[:q], format: "csv")
.col-md-3
.col-md-3
.col-md-3
%hr %hr
.row .row
@ -58,7 +68,20 @@
%td= link_to(x, registrant_domain_path(x)) %td= link_to(x, registrant_domain_path(x))
%td %td
- if x.registrant - if x.registrant
= link_to(x.registrant, [:admin, x.registrant]) = link_to(x.registrant, [:registrant, x.registrant]) if x.registrant
%td= l(x.valid_to, format: :short) %td= l(x.valid_to, format: :short)
%td= link_to(x.registrar, admin_registrar_path(x.registrar)) if x.registrar %td= link_to(x.registrar, registrant_registrar_path(x.registrar)) if x.registrar
.row
.col-md-6
= paginate @domains
.col-md-6.text-right
.pagination
= t(:result_count, count: @domains.total_count)
:coffee
$(".js-reset-form").on "click", (e) ->
e.preventDefault();
window.location = "#{registrant_domains_path}"

View file

@ -1,24 +1,19 @@
- content_for :actions do - content_for :actions do
= link_to(t(:edit_statuses), edit_admin_domain_path(@domain), class: 'btn btn-primary') -#= link_to(t(:history), admin_domain_domain_versions_path(@domain.id), method: :get, class: 'btn btn-primary')
= link_to(t(:history), admin_domain_domain_versions_path(@domain.id), method: :get, class: 'btn btn-primary')
= render 'shared/title', name: @domain.name = render 'shared/title', name: @domain.name
.row .row
.col-md-6= render 'admin/domains/partials/general' .col-md-6= render 'registrant/domains/partials/general'
.col-md-6= render 'admin/domains/partials/owner'
.row .row
.col-md-12= render 'admin/domains/partials/tech_contacts' .col-md-12= render 'registrant/domains/partials/tech_contacts'
.row .row
.col-md-12= render 'admin/domains/partials/admin_contacts' .col-md-12= render 'registrant/domains/partials/admin_contacts'
.row .row
.col-md-12= render 'admin/domains/partials/statuses' .col-md-12= render 'registrant/domains/partials/statuses'
.row .row
.col-md-12= render 'admin/domains/partials/nameservers' .col-md-12= render 'registrant/domains/partials/nameservers'
.row .row
.col-md-12= render 'admin/domains/partials/dnskeys' .col-md-12= render 'registrant/domains/partials/dnskeys'
.row .row
.col-md-12= render 'admin/domains/partials/keyrelays' .col-md-12= render 'registrant/domains/partials/keyrelays'
.row
.col-md-12
= render 'admin/domains/partials/legal_documents', legal_documents: @domain.legal_documents

View file

@ -0,0 +1,22 @@
- content_for :actions do
= link_to(t(:new), new_admin_registrar_path, class: 'btn btn-primary')
= render 'shared/title', name: t(:registrars)
.row
.col-md-12
.table-responsive
%table.table.table-hover.table-bordered.table-condensed
%thead
%tr
%th{class: 'col-xs-6'}
= sort_link(@q, 'name')
%th{class: 'col-xs-6'}
= sort_link(@q, 'reg_no', t(:reg_no))
%tbody
- @registrars.each do |x|
%tr
%td= link_to(x, [:admin, x])
%td= x.reg_no
.row
.col-md-12
= paginate @registrars

View file

@ -0,0 +1,53 @@
= render 'shared/title', name: @registrar.name
- if @registrar.errors.any?
- @registrar.errors.each do |attr, err|
= err
%br
- if @registrar.errors.any?
%hr
.row
.col-md-6
.panel.panel-default
.panel-heading
%h3.panel-title= t(:general)
.panel-body
%dl.dl-horizontal
%dt= t(:name)
%dd= @registrar.name
%dt= t(:reg_no)
%dd= @registrar.reg_no
%dt= t(:vat_no)
%dd= @registrar.vat_no
%dt= t(:reference_no)
%dd= @registrar.reference_no
%dt= t(:id)
%dd= @registrar.code
.col-md-6
.panel.panel-default
.panel-heading
%h3.panel-title= t(:contact)
.panel-body
%dl.dl-horizontal
%dt= t(:country)
%dd= @registrar.country
%dt= t(:address)
%dd= @registrar.address
%dt= t(:contact_phone)
%dd= @registrar.phone
%dt= t(:contact_email)
%dd= @registrar.email
%dt= t(:billing_address)
%dd= @registrar.billing_address
%dt= t(:billing_email)
%dd= @registrar.billing_email

View file

@ -7,6 +7,8 @@ require 'action_controller/railtie'
require 'action_mailer/railtie' require 'action_mailer/railtie'
require 'action_view/railtie' require 'action_view/railtie'
require 'sprockets/railtie' require 'sprockets/railtie'
require 'csv'
require 'rails/all'
# require "rails/test_unit/railtie" # require "rails/test_unit/railtie"
# Require the gems listed in Gemfile, including any gems # Require the gems listed in Gemfile, including any gems

View file

@ -102,6 +102,12 @@ Rails.application.routes.draw do
namespace :registrant do namespace :registrant do
root 'domains#index' root 'domains#index'
resources :domains do
member do
get :download_list
end
end
# resources :invoices do # resources :invoices do
# member do # member do
# get 'download_pdf' # get 'download_pdf'
@ -140,6 +146,14 @@ Rails.application.routes.draw do
end end
end end
resources :registrars do
resources :api_users
resources :white_ips
collection do
get :search
end
end
resources :whois resources :whois
# resources :contacts do # resources :contacts do
# member do # member do