Merge branch '111396946-blocked_and_reserved_view' into staging

This commit is contained in:
Stas 2016-02-03 17:21:03 +02:00
commit 3178c13fd4
14 changed files with 208 additions and 54 deletions

View file

@ -2,46 +2,54 @@ class Admin::BlockedDomainsController < AdminController
load_and_authorize_resource
def index
bd = BlockedDomain.pluck(:name)
if bd
@blocked_domains = bd.to_yaml.gsub("---\n", '').gsub("-", '').gsub(" ", '')
end
params[:q] ||= {}
domains = BlockedDomain.all
@q = domains.search(params[:q])
@domains = @q.result.page(params[:page])
@domains = @domains.per(params[:results_per_page]) if params[:results_per_page].to_i > 0
end
def new
@domain = BlockedDomain.new
end
def create
@blocked_domains = params[:blocked_domains]
begin
params[:blocked_domains] = "---\n" if params[:blocked_domains].blank?
names = YAML.load(params[:blocked_domains])
fail if names == false
rescue
flash.now[:alert] = I18n.t('invalid_yaml')
logger.warn 'Invalid YAML'
render :index and return
end
@domain = BlockedDomain.new(blocked_domain_params)
names = names.split(' ')
result = true
BlockedDomain.transaction do
existing = BlockedDomain.any_of_domains(names).pluck(:id)
BlockedDomain.where.not(id: existing).destroy_all
names.each do |name|
rec = BlockedDomain.find_or_initialize_by(name: name)
unless rec.save
result = false
raise ActiveRecord::Rollback
end
end
end
if result
flash[:notice] = I18n.t('record_updated')
redirect_to :back
if @domain.save
flash[:notice] = I18n.t('domain_added')
redirect_to admin_blocked_domains_path
else
flash.now[:alert] = I18n.t('failed_to_update_record')
render :index
flash.now[:alert] = I18n.t('failed_to_add_domain')
render 'new'
end
end
def delete
if BlockedDomain.find(params[:id]).destroy
flash[:notice] = I18n.t('domain_deleted')
redirect_to admin_blocked_domains_path
else
flash.now[:alert] = I18n.t('failed_to_delete_domain')
redirect_to admin_blocked_domains_path
end
end
end
def blocked_domain_params
params.require(:blocked_domain).permit(:name)
end
private
def set_domain
@domain = BlockedDomain.find(params[:id])
end
end

View file

@ -1,5 +1,6 @@
class Admin::ReservedDomainsController < AdminController
load_and_authorize_resource
before_action :set_domain, only: [:edit, :update]
def index
@ -16,10 +17,52 @@ class Admin::ReservedDomainsController < AdminController
end
def edit
authorize! :update, ReservedDomain
end
def create
@domain = ReservedDomain.new(reserved_domain_params)
if @domain.save
flash[:notice] = I18n.t('domain_added')
redirect_to admin_reserved_domains_path
else
flash.now[:alert] = I18n.t('failed_to_add_domain')
render 'new'
end
end
def update
if @domain.update(reserved_domain_params)
flash[:notice] = I18n.t('domain_updated')
else
flash.now[:alert] = I18n.t('failed_to_update_domain')
end
render 'edit'
end
def delete
authorize! :delete, ReservedDomain
if ReservedDomain.find(params[:id]).destroy
flash[:notice] = I18n.t('domain_deleted')
redirect_to admin_reserved_domains_path
else
flash.now[:alert] = I18n.t('failed_to_delete_domain')
redirect_to admin_reserved_domains_path
end
end
private
def reserved_domain_params
params.require(:reserved_domain).permit(:name, :password)
end
def set_domain
@domain = ReservedDomain.find(params[:id])
end
end

View file

@ -2,6 +2,7 @@ class BlockedDomain < ActiveRecord::Base
include Versions
before_save :generate_data
before_destroy :remove_data
validates :name, domain_name: true, uniqueness: true
class << self

View file

@ -3,6 +3,9 @@ class ReservedDomain < ActiveRecord::Base
before_save :fill_empty_passwords
before_save :generate_data
before_destroy :remove_data
validates :name, domain_name: true, uniqueness: true
class << self
@ -22,7 +25,12 @@ class ReservedDomain < ActiveRecord::Base
def fill_empty_passwords
self.password = SecureRandom.hex unless self.password
if self.password.empty?
self.password = SecureRandom.hex
end
end
def name= val

View file

@ -0,0 +1,17 @@
= form_for([:admin, @domain], html: {class: 'form-horizontal'}) do |f|
= render 'shared/full_errors', object: @domain
.row
.col-md-8
.panel.panel-default
.panel-heading.clearfix
.pull-left= t(:general)
.panel-body
.form-group
.col-md-4.control-label
= f.label :name
.col-md-7
= f.text_field(:name, class: 'form-control')
.row
.col-md-8.text-right
= button_tag(t(:save), class: 'btn btn-primary')

View file

@ -0,0 +1,3 @@
= render 'shared/title', name: t(:edit_pw)
= render 'form'

View file

@ -1,10 +1,67 @@
- content_for :actions do
= link_to(t(:new), new_admin_blocked_domain_path, class: 'btn btn-primary')
= render 'shared/title', name: t(:blocked_domains)
= form_tag([:admin, :blocked_domains]) do |f|
.row
.col-md-12
= text_area_tag :blocked_domains, @blocked_domains, class: 'form-control', rows: 30
%hr
.row
.col-md-12.text-right
%button.btn.btn-warning=t(:save)
.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
= f.label :name
= f.search_field :name_matches, value: params[:q][:name_matches], class: 'form-control', placeholder: t(:name)
.col-md-3
.form-group
= f.label t(:created_at_from)
= f.search_field :created_at_gteq, value: params[:q][:created_at_gteq], class: 'form-control datepicker', placeholder: t(:created_at_from)
.col-md-3
.form-group
= f.label t(:created_at_until)
= f.search_field :created_at_lteq, value: params[:q][:created_at_lteq], class: 'form-control datepicker', placeholder: t(:created_at_until)
.row
.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
&nbsp;
%span.glyphicon.glyphicon-search
&nbsp;
%button.btn.btn-default.js-reset-form
= t(:clear_fields)
%hr
.row
.col-md-12
.table-responsive
%table.table.table-hover.table-bordered.table-condensed
%thead
%tr
%th{class: 'col-xs-2'}
= sort_link(@q, 'name')
%th{class: 'col-xs-2'}
= sort_link(@q, 'created_at', t(:created_at))
%th{class: 'col-xs-2'}
= sort_link(@q, 'updated_at', t(:updated_at))
%th{class: 'col-xs-2'}
= t(:actions)
%tbody
- @domains.each do |x|
%tr
%td= x.name
%td= l(x.created_at, format: :short)
%td= l(x.updated_at, format: :short)
%td
= link_to(t(:delete), delete_admin_blocked_domain_path(id: x.id),
data: { confirm: t(:are_you_sure) }, class: 'btn btn-danger btn-xs')
.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 = "#{admin_blocked_domains_path}"

View file

@ -0,0 +1,3 @@
= render 'shared/title', name: t(:add_blocked_domain)
= render 'form'

View file

@ -11,13 +11,12 @@
.col-md-4.control-label
= f.label :name
.col-md-7
= f.text_field(:name, class: 'form-control')
= f.text_field(:name, class: 'form-control', disabled: !f.object.new_record?)
.form-group
.col-md-4.control-label
= f.label :password
.col-md-7
= f.text_field(:password, class: 'form-control')
%hr
= f.text_field(:password, placeholder: t(:optional), class: 'form-control')
.row
.col-md-8.text-right
= button_tag(t(:save), class: 'btn btn-primary')

View file

@ -0,0 +1,3 @@
= render 'shared/title', name: t(:edit_pw)
= render 'form'

View file

@ -55,10 +55,10 @@
%td= l(x.created_at, format: :short)
%td= l(x.updated_at, format: :short)
%td
= link_to(t(:edit), edit_admin_reserved_domain_path(id: x.id),
= link_to(t(:edit_pw), edit_admin_reserved_domain_path(id: x.id),
class: 'btn btn-primary btn-xs')
= link_to(t(:delete), delete_admin_reserved_domain_path(id: x.id),
class: 'btn btn-primary btn-xs')
data: { confirm: t(:are_you_sure) }, class: 'btn btn-danger btn-xs')
.row
.col-md-6
= paginate @domains

View file

@ -1,3 +1,3 @@
= render 'shared/title', name: t(:new_reserved_domain)
= render 'shared/title', name: t(:add_reserved_domain)
= render 'form'

View file

@ -932,3 +932,7 @@ en:
if_auth_info_is_left_empty_it_will_be_auto_generated: 'If auth info is left empty, it will be auto generated.'
each_domain_name_must_end_with_colon_sign: 'Each domain name must end with colon (:) sign.'
expiration_remind_subject: 'The %{name} domain has expired'
add_reserved_domain: 'Add domain to reserved list'
add_blocked_domain: 'Add domain to blocked list'
edit_pw: 'Edit Pw'
optional: 'Optional'

View file

@ -221,8 +221,16 @@ Rails.application.routes.draw do
resources :settings
resources :blocked_domains
resources :reserved_domains
resources :blocked_domains do
member do
get 'delete'
end
end
resources :reserved_domains do
member do
get 'delete'
end
end
resources :registrars do
resources :api_users