mirror of
https://github.com/internetee/registry.git
synced 2025-07-21 02:05:57 +02:00
Merge pull request #2159 from internetee/2156-admin-changes-for-registrars-filter
Admin: changes for active/inactive registrars filtration
This commit is contained in:
commit
01d5254688
1 changed files with 19 additions and 3 deletions
|
@ -1,11 +1,13 @@
|
||||||
module Admin
|
module Admin
|
||||||
class RegistrarsController < BaseController
|
class RegistrarsController < BaseController # rubocop:disable Metrics/ClassLength
|
||||||
load_and_authorize_resource
|
load_and_authorize_resource
|
||||||
before_action :set_registrar, only: [:show, :edit, :update, :destroy]
|
before_action :set_registrar, only: [:show, :edit, :update, :destroy]
|
||||||
before_action :set_registrar_status_filter, only: [:index]
|
before_action :set_registrar_status_filter, only: [:index]
|
||||||
helper_method :registry_vat_rate
|
helper_method :registry_vat_rate
|
||||||
helper_method :iban_max_length
|
helper_method :iban_max_length
|
||||||
|
|
||||||
|
SQL_SUM_STR = 'sum(case active when TRUE then 1 else 0 end)'.freeze
|
||||||
|
|
||||||
def index
|
def index
|
||||||
registrars = filter_by_status
|
registrars = filter_by_status
|
||||||
@q = registrars.ransack(params[:q])
|
@q = registrars.ransack(params[:q])
|
||||||
|
@ -58,14 +60,28 @@ module Admin
|
||||||
def filter_by_status
|
def filter_by_status
|
||||||
case params[:status]
|
case params[:status]
|
||||||
when 'Active'
|
when 'Active'
|
||||||
Registrar.includes(:accounts, :api_users).where.not(api_users: { id: nil }).ordered
|
active_registrars
|
||||||
when 'Inactive'
|
when 'Inactive'
|
||||||
Registrar.includes(:accounts, :api_users).where(api_users: { id: nil }).ordered
|
inactive_registrars
|
||||||
else
|
else
|
||||||
Registrar.includes(:accounts, :api_users).ordered
|
Registrar.includes(:accounts, :api_users).ordered
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def active_registrars
|
||||||
|
Registrar.includes(:accounts, :api_users).where(
|
||||||
|
id: ApiUser.having("#{SQL_SUM_STR} > 0").group(:registrar_id).pluck(:registrar_id)
|
||||||
|
).ordered
|
||||||
|
end
|
||||||
|
|
||||||
|
def inactive_registrars
|
||||||
|
Registrar.includes(:accounts, :api_users).where(api_users: { id: nil }).or(
|
||||||
|
Registrar.includes(:accounts, :api_users).where(
|
||||||
|
id: ApiUser.having("#{SQL_SUM_STR} = 0").group(:registrar_id).pluck(:registrar_id)
|
||||||
|
)
|
||||||
|
).ordered
|
||||||
|
end
|
||||||
|
|
||||||
def set_registrar_status_filter
|
def set_registrar_status_filter
|
||||||
params[:status] ||= 'Active'
|
params[:status] ||= 'Active'
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue