mirror of
https://github.com/internetee/registry.git
synced 2025-07-29 05:56:20 +02:00
Merge pull request #2325 from internetee/499-admin-wildcard-search
Admin: missing wildcard and partial search
This commit is contained in:
commit
09d5d40640
14 changed files with 78 additions and 90 deletions
8
.github/workflows/build_deploy_staging.yml
vendored
8
.github/workflows/build_deploy_staging.yml
vendored
|
@ -67,7 +67,7 @@ jobs:
|
|||
|
||||
- name: Set EPP port
|
||||
run: echo "EPP_PORT=${PR_REF:(-3)}" >> $GITHUB_ENV
|
||||
|
||||
|
||||
- name: Set config files for build
|
||||
env:
|
||||
ST_APP: ${{ secrets.ST_APPLICATION_YML}}
|
||||
|
@ -101,7 +101,7 @@ jobs:
|
|||
sed -i -e 's/{certfile_path, "\/opt\/shared\/ca\/certs\/cert.pem"},/{certfile_path, "\/opt\/shared\/ca\/certs\/tls.crt"},/' sys.config
|
||||
sed -i -e 's/{keyfile_path, "\/opt\/shared\/ca\/certs\/key.pem"},/{keyfile_path, "\/opt\/shared\/ca\/certs\/tls.key"}]},/' sys.config
|
||||
sed -i -e 's/{crlfile_path, "\/opt\/shared\/ca\/certs\/key.pem"}]},//' sys.config
|
||||
|
||||
|
||||
- name: Build proxy image
|
||||
run: |
|
||||
cd epp_proxy
|
||||
|
@ -143,7 +143,9 @@ jobs:
|
|||
chmod 0600 kubeconfig
|
||||
|
||||
- name: Install Open VPN
|
||||
run: sudo apt-get install openvpn
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install openvpn
|
||||
|
||||
- name: Deploy from remote server
|
||||
timeout-minutes: 5
|
||||
|
|
|
@ -5,7 +5,7 @@ module Admin
|
|||
def index
|
||||
params[:q] ||= {}
|
||||
domains = BlockedDomain.all.order(:name)
|
||||
@q = domains.ransack(params[:q])
|
||||
@q = domains.ransack(PartialSearchFormatter.format(params[:q]))
|
||||
@domains = @q.result.page(params[:page])
|
||||
@domains = @domains.per(params[:results_per_page]) if params[:results_per_page].to_i.positive?
|
||||
|
||||
|
@ -13,13 +13,10 @@ module Admin
|
|||
end
|
||||
|
||||
def new
|
||||
|
||||
@domain = BlockedDomain.new
|
||||
|
||||
end
|
||||
|
||||
def create
|
||||
|
||||
@domain = BlockedDomain.new(blocked_domain_params)
|
||||
|
||||
if @domain.save
|
||||
|
@ -29,18 +26,16 @@ module Admin
|
|||
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
|
||||
|
||||
redirect_to admin_blocked_domains_path
|
||||
end
|
||||
|
||||
def blocked_domain_params
|
||||
|
|
|
@ -7,23 +7,9 @@ module Admin
|
|||
def index
|
||||
params[:q] ||= {}
|
||||
|
||||
search_params = params[:q].deep_dup.except(:created_at_gteq, :created_at_lteq)
|
||||
|
||||
where_s = '1=1'
|
||||
|
||||
search_params.each do |key, value|
|
||||
next if value.empty?
|
||||
|
||||
where_s += case key
|
||||
when 'event'
|
||||
" AND event = '#{value}'"
|
||||
else
|
||||
create_where_string(key, value)
|
||||
end
|
||||
end
|
||||
|
||||
versions = Version::ContactVersion.includes(:item).where(where_s).order(created_at: :desc, id: :desc)
|
||||
@q = versions.ransack(fix_date_params)
|
||||
search_params = PartialSearchFormatter.format(fix_date_params)
|
||||
versions = Version::ContactVersion.includes(:item).order(created_at: :desc, id: :desc)
|
||||
@q = versions.ransack(polymorphic_association(search_params))
|
||||
|
||||
@versions = @q.result.page(params[:page])
|
||||
@versions = @versions.per(params[:results_per_page]) if params[:results_per_page].to_i.positive?
|
||||
|
@ -53,12 +39,16 @@ module Admin
|
|||
render json: Version::ContactVersion.search_by_query(params[:q])
|
||||
end
|
||||
|
||||
def create_where_string(key, value)
|
||||
" AND object->>'#{key}' ~* '#{value}'"
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def polymorphic_association(search_params)
|
||||
record_type = {}
|
||||
fields = %w[name code ident]
|
||||
fields.each { |field| record_type[:"item_of_Contact_type_#{field}_matches"] = search_params[:"#{field}_matches"] }
|
||||
|
||||
record_type
|
||||
end
|
||||
|
||||
def fix_date_params
|
||||
params_copy = params[:q].deep_dup
|
||||
if params_copy['created_at_lteq'].present?
|
||||
|
|
|
@ -9,10 +9,8 @@ module Admin
|
|||
params[:q] ||= {}
|
||||
search_params = params[:q].deep_dup
|
||||
|
||||
if search_params[:domain_contacts_type_in].is_a?(Array) &&
|
||||
search_params[:domain_contacts_type_in].delete('registrant')
|
||||
search_params[:registrant_domains_id_not_null] = 1
|
||||
end
|
||||
search_params[:registrant_domains_id_not_null] = 1 if search_params[:domain_contacts_type_in].is_a?(Array) &&
|
||||
search_params[:domain_contacts_type_in].delete('registrant')
|
||||
|
||||
contacts = Contact.includes(:registrar).joins(:registrar)
|
||||
.select('contacts.*, registrars.name as registrars_name')
|
||||
|
@ -20,7 +18,7 @@ module Admin
|
|||
contacts = filter_by_flags(contacts)
|
||||
|
||||
normalize_search_parameters do
|
||||
@q = contacts.ransack(search_params)
|
||||
@q = contacts.ransack(PartialSearchFormatter.format(search_params))
|
||||
@contacts = @q.result.distinct.page(params[:page])
|
||||
end
|
||||
|
||||
|
@ -33,6 +31,7 @@ module Admin
|
|||
if params[:only_no_country_code].eql?('1')
|
||||
contacts = contacts.where("ident_country_code is null or ident_country_code=''")
|
||||
end
|
||||
|
||||
contacts = contacts.email_verification_failed if params[:email_verification_failed].eql?('1')
|
||||
contacts
|
||||
end
|
||||
|
@ -41,8 +40,7 @@ module Admin
|
|||
render json: Contact.search_by_query(params[:q])
|
||||
end
|
||||
|
||||
def edit
|
||||
end
|
||||
def edit; end
|
||||
|
||||
def update
|
||||
cp = ignore_empty_statuses
|
||||
|
|
|
@ -17,18 +17,10 @@ module Admin
|
|||
end
|
||||
|
||||
normalize_search_parameters do
|
||||
@q = domains.ransack(params[:q])
|
||||
@q = domains.ransack(PartialSearchFormatter.format(params[:q]))
|
||||
@domains = @q.result.page(params[:page])
|
||||
(redirect_to [:admin, @domains.first] and return if @domains.count == 1 && params[:q][:name_matches].present?)
|
||||
if @domains.count.zero? && params[:q][:name_matches] !~ /^%.+%$/
|
||||
# if we do not get any results, add wildcards to the name field and search again
|
||||
n_cache = params[:q][:name_matches]
|
||||
params[:q][:name_matches] = "%#{params[:q][:name_matches]}%"
|
||||
@q = domains.ransack(params[:q])
|
||||
@domains = @q.result.page(params[:page])
|
||||
params[:q][:name_matches] = n_cache # we don't want to show wildcards in search form
|
||||
end
|
||||
end
|
||||
|
||||
@domains = @domains.per(params[:results_per_page]) if params[:results_per_page].to_i.positive?
|
||||
|
||||
render_by_format('admin/domains/index', 'domains')
|
||||
|
@ -95,7 +87,7 @@ module Admin
|
|||
def build_associations
|
||||
@server_statuses = @domain.statuses.select { |x| DomainStatus::SERVER_STATUSES.include?(x) }
|
||||
@server_statuses = [nil] if @server_statuses.empty?
|
||||
@other_statuses = @domain.statuses.select { |x| !DomainStatus::SERVER_STATUSES.include?(x) }
|
||||
@other_statuses = @domain.statuses.reject { |x| DomainStatus::SERVER_STATUSES.include?(x) }
|
||||
end
|
||||
|
||||
def ignore_empty_statuses
|
||||
|
|
|
@ -5,7 +5,7 @@ module Admin
|
|||
|
||||
# rubocop:disable Metrics/MethodLength
|
||||
def index
|
||||
@q = ApiLog::EppLog.ransack(params[:q])
|
||||
@q = ApiLog::EppLog.ransack(PartialSearchFormatter.format(params[:q]))
|
||||
@q.sorts = 'id desc' if @q.sorts.empty?
|
||||
|
||||
@epp_logs = @q.result
|
||||
|
@ -29,16 +29,19 @@ module Admin
|
|||
|
||||
def set_default_dates
|
||||
params[:q] ||= {}
|
||||
return unless default_dates?
|
||||
|
||||
if params[:q][:created_at_gteq].nil? && params[:q][:created_at_lteq].nil? && params[:created_after].present?
|
||||
default_date = params[:created_after]
|
||||
default_date = params[:created_after]
|
||||
default_date = 'today' unless %w[today tomorrow yesterday].include?(default_date)
|
||||
|
||||
if !['today', 'tomorrow', 'yesterday'].include?(default_date)
|
||||
default_date = 'today'
|
||||
end
|
||||
params[:q][:created_at_gteq] = Date.send(default_date).strftime("%Y-%m-%d")
|
||||
end
|
||||
|
||||
params[:q][:created_at_gteq] = Date.send(default_date).strftime("%Y-%m-%d")
|
||||
end
|
||||
private
|
||||
|
||||
def default_dates?
|
||||
params[:q] ||= {}
|
||||
params[:q][:created_at_gteq].nil? && params[:q][:created_at_lteq].nil? && params[:created_after].present?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -5,7 +5,7 @@ module Admin
|
|||
|
||||
# rubocop:disable Metrics/MethodLength
|
||||
def index
|
||||
@q = ApiLog::ReppLog.ransack(params[:q])
|
||||
@q = ApiLog::ReppLog.ransack(PartialSearchFormatter.format(params[:q]))
|
||||
@q.sorts = 'id desc' if @q.sorts.empty?
|
||||
|
||||
@repp_logs = @q.result
|
||||
|
@ -31,17 +31,19 @@ module Admin
|
|||
|
||||
def set_default_dates
|
||||
params[:q] ||= {}
|
||||
return unless default_dates?
|
||||
|
||||
if params[:q][:created_at_gteq].nil? && params[:q][:created_at_lteq].nil? && params[:created_after].present?
|
||||
default_date = params[:created_after]
|
||||
default_date = 'today' unless %w[today tomorrow yesterday].include?(default_date)
|
||||
|
||||
default_date = params[:created_after]
|
||||
params[:q][:created_at_gteq] = Date.send(default_date).strftime("%Y-%m-%d")
|
||||
end
|
||||
|
||||
if !['today', 'tomorrow', 'yesterday'].include?(default_date)
|
||||
default_date = 'today'
|
||||
end
|
||||
private
|
||||
|
||||
params[:q][:created_at_gteq] = Date.send(default_date).strftime("%Y-%m-%d")
|
||||
end
|
||||
def default_dates?
|
||||
params[:q] ||= {}
|
||||
params[:q][:created_at_gteq].nil? && params[:q][:created_at_lteq].nil? && params[:created_after].present?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -6,7 +6,7 @@ module Admin
|
|||
def index
|
||||
params[:q] ||= {}
|
||||
domains = ReservedDomain.all.order(:name)
|
||||
@q = domains.ransack(params[:q])
|
||||
@q = domains.ransack(PartialSearchFormatter.format(params[:q]))
|
||||
@domains = @q.result.page(params[:page])
|
||||
@domains = @domains.per(params[:results_per_page]) if params[:results_per_page].to_i.positive?
|
||||
|
||||
|
@ -17,11 +17,9 @@ module Admin
|
|||
@domain = ReservedDomain.new
|
||||
end
|
||||
|
||||
def edit
|
||||
end
|
||||
def edit; end
|
||||
|
||||
def create
|
||||
|
||||
@domain = ReservedDomain.new(reserved_domain_params)
|
||||
|
||||
if @domain.save
|
||||
|
@ -31,30 +29,26 @@ module Admin
|
|||
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'
|
||||
|
||||
render 'edit'
|
||||
end
|
||||
|
||||
def delete
|
||||
|
||||
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
|
||||
|
||||
redirect_to admin_reserved_domains_path
|
||||
end
|
||||
|
||||
private
|
||||
|
|
13
app/services/partial_search_formatter.rb
Normal file
13
app/services/partial_search_formatter.rb
Normal file
|
@ -0,0 +1,13 @@
|
|||
class PartialSearchFormatter
|
||||
def self.format(params)
|
||||
search_params = params.deep_dup
|
||||
|
||||
search_params.each do |key, value|
|
||||
next unless key.include?('matches') && value.present?
|
||||
|
||||
value << '%'
|
||||
end
|
||||
|
||||
search_params
|
||||
end
|
||||
end
|
|
@ -7,15 +7,15 @@
|
|||
.col-md-3
|
||||
.form-group
|
||||
= f.label :name
|
||||
= f.search_field :name, value: params[:q][:name], class: 'form-control', placeholder: t(:name)
|
||||
= f.search_field :name_matches, value: params[:q][:name_matches], class: 'form-control', placeholder: t(:name)
|
||||
.col-md-3
|
||||
.form-group
|
||||
= f.label :id
|
||||
= f.search_field :code, value: params[:q][:code], class: 'form-control', placeholder: t(:id)
|
||||
= f.search_field :code_matches, value: params[:q][:code_matches], class: 'form-control', placeholder: t(:id)
|
||||
.col-md-3
|
||||
.form-group
|
||||
= f.label :ident
|
||||
= f.search_field :ident, value: params[:q][:ident], class: 'form-control', placeholder: t(:ident)
|
||||
= f.search_field :ident_matches, value: params[:q][:ident_matches], class: 'form-control', placeholder: t(:ident)
|
||||
.col-md-3
|
||||
.form-group
|
||||
= label_tag :action
|
||||
|
|
|
@ -11,11 +11,11 @@
|
|||
.col-md-3
|
||||
.form-group
|
||||
= f.label t(:id)
|
||||
= f.search_field :code_matches, class: 'form-control', placeholder: t(:id)
|
||||
= f.search_field :code_matches, value: params[:q][:code_matches], class: 'form-control', placeholder: t(:id)
|
||||
.col-md-3
|
||||
.form-group
|
||||
= f.label t(:ident)
|
||||
= f.search_field :ident_matches, class: 'form-control', placeholder: t(:ident)
|
||||
= f.search_field :ident_matches, value: params[:q][:ident_matches], class: 'form-control', placeholder: t(:ident)
|
||||
.col-md-3
|
||||
.form-group
|
||||
= label_tag t(:ident_type)
|
||||
|
@ -24,7 +24,7 @@
|
|||
.col-md-3
|
||||
.form-group
|
||||
= f.label t(:email)
|
||||
= f.search_field :email_matches, class: 'form-control', placeholder: t(:email)
|
||||
= f.search_field :email_matches, value: params[:q][:email_matches], class: 'form-control', placeholder: t(:email)
|
||||
.col-md-3
|
||||
.form-group
|
||||
= label_tag t(:country)
|
||||
|
|
|
@ -9,19 +9,19 @@
|
|||
<div class="col-md-2">
|
||||
<div class="form-group">
|
||||
<%= f.label :registrant_ident, for: nil %>
|
||||
<%= f.search_field :registrant_ident_eq, class: 'form-control', placeholder: t(:registrant_ident) %>
|
||||
<%= f.search_field :registrant_ident_matches, value: params[:q][:registrant_ident_matches], class: 'form-control', placeholder: t(:registrant_ident) %>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<div class="form-group">
|
||||
<%= f.label :contact_ident, for: nil %>
|
||||
<%= f.search_field :contacts_ident_eq, class: 'form-control', placeholder: t(:contact_ident) %>
|
||||
<%= f.search_field :contacts_ident_matches, value: params[:q][:contacts_ident_matches], class: 'form-control', placeholder: t(:contact_ident) %>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-4">
|
||||
<div class="form-group">
|
||||
<%= f.label :nameserver_hostname, for: nil %>
|
||||
<%= f.search_field :nameservers_hostname_eq, class: 'form-control', placeholder: t(:nameserver_hostname) %>
|
||||
<%= f.search_field :nameservers_hostname_matches, value: params[:q][:nameservers_hostname_matches], class: 'form-control', placeholder: t(:nameserver_hostname) %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -22,12 +22,12 @@
|
|||
.col-md-3
|
||||
.form-group
|
||||
= f.label :api_user
|
||||
= f.search_field :api_user_name_cont, class: 'form-control', placeholder: t(:api_user), autocomplete: 'off'
|
||||
= f.search_field :api_user_name_matches, value: params[:q][:api_user_name_matches], class: 'form-control', placeholder: t(:api_user), autocomplete: 'off'
|
||||
.row
|
||||
.col-md-3
|
||||
.form-group
|
||||
= f.label :registrar
|
||||
= f.select :api_user_registrar_cont, Registrar.all.map { |x| [x, x.name] }, { include_blank: true }, class: 'form-control', placeholder: t(:choose)
|
||||
= f.select :api_user_registrar_matches, Registrar.all.map { |x| [x, x.name] }, { include_blank: true }, class: 'form-control', placeholder: t(:choose)
|
||||
.col-md-3
|
||||
.form-group
|
||||
= f.label t(:created_after)
|
||||
|
|
|
@ -20,13 +20,12 @@
|
|||
.col-md-3
|
||||
.form-group
|
||||
= f.label :api_user
|
||||
= f.search_field :api_user_name_cont, class: 'form-control', placeholder: t(:api_user), autocomplete: 'off'
|
||||
= f.search_field :api_user_name_matches, value: params[:q][:api_user_name_matches], class: 'form-control', placeholder: t(:api_user), autocomplete: 'off'
|
||||
.row
|
||||
.col-md-3
|
||||
.form-group
|
||||
= f.label :registrar
|
||||
= f.select :api_user_registrar_cont, Registrar.all.map { |x| [x, x.name] }, { include_blank: true }, class: 'form-control', placeholder: t(:choose)
|
||||
-# = f.search_field :api_user_registrar_cont, class: 'form-control', placeholder: t(:registrar_name), autocomplete: 'off'
|
||||
= f.select :api_user_registrar_matches, Registrar.all.map { |x| [x, x.name] }, { include_blank: true }, class: 'form-control', placeholder: t(:choose)
|
||||
.col-md-3
|
||||
.form-group
|
||||
= f.label t(:created_after)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue