2017-04-18 20:09:07 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Admin
|
|
|
|
class InstancesController < BaseController
|
2019-07-30 10:10:46 +01:00
|
|
|
before_action :set_domain_block, only: :show
|
|
|
|
before_action :set_domain_allow, only: :show
|
|
|
|
before_action :set_instance, only: :show
|
|
|
|
|
2017-04-18 20:09:07 +01:00
|
|
|
def index
|
2017-11-11 19:23:33 +00:00
|
|
|
authorize :instance, :index?
|
2019-01-08 12:39:49 +00:00
|
|
|
|
2017-05-31 19:38:44 +01:00
|
|
|
@instances = ordered_instances
|
2017-04-18 20:09:07 +01:00
|
|
|
end
|
|
|
|
|
2019-01-08 12:39:49 +00:00
|
|
|
def show
|
|
|
|
authorize :instance, :show?
|
|
|
|
|
|
|
|
@following_count = Follow.where(account: Account.where(domain: params[:id])).count
|
|
|
|
@followers_count = Follow.where(target_account: Account.where(domain: params[:id])).count
|
|
|
|
@reports_count = Report.where(target_account: Account.where(domain: params[:id])).count
|
|
|
|
@blocks_count = Block.where(target_account: Account.where(domain: params[:id])).count
|
|
|
|
@available = DeliveryFailureTracker.available?(Account.select(:shared_inbox_url).where(domain: params[:id]).first&.shared_inbox_url)
|
|
|
|
@media_storage = MediaAttachment.where(account: Account.where(domain: params[:id])).sum(:file_file_size)
|
2017-07-20 22:07:13 +01:00
|
|
|
end
|
|
|
|
|
2017-04-18 20:09:07 +01:00
|
|
|
private
|
|
|
|
|
2019-07-30 10:10:46 +01:00
|
|
|
def set_domain_block
|
|
|
|
@domain_block = DomainBlock.rule_for(params[:id])
|
|
|
|
end
|
|
|
|
|
|
|
|
def set_domain_allow
|
|
|
|
@domain_allow = DomainAllow.rule_for(params[:id])
|
|
|
|
end
|
|
|
|
|
|
|
|
def set_instance
|
|
|
|
resource = Account.by_domain_accounts.find_by(domain: params[:id])
|
|
|
|
resource ||= @domain_block
|
|
|
|
resource ||= @domain_allow
|
|
|
|
|
|
|
|
if resource
|
|
|
|
@instance = Instance.new(resource)
|
|
|
|
else
|
|
|
|
not_found
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-09-13 11:30:07 +01:00
|
|
|
def filtered_instances
|
2019-07-30 10:10:46 +01:00
|
|
|
InstanceFilter.new(whitelist_mode? ? { allowed: true } : filter_params).results
|
2017-09-13 11:30:07 +01:00
|
|
|
end
|
|
|
|
|
2017-05-31 19:38:44 +01:00
|
|
|
def paginated_instances
|
2017-09-13 11:30:07 +01:00
|
|
|
filtered_instances.page(params[:page])
|
2017-05-31 19:38:44 +01:00
|
|
|
end
|
2017-07-20 22:07:13 +01:00
|
|
|
|
2017-05-31 19:38:44 +01:00
|
|
|
helper_method :paginated_instances
|
|
|
|
|
2017-04-18 20:09:07 +01:00
|
|
|
def ordered_instances
|
2019-01-08 12:39:49 +00:00
|
|
|
paginated_instances.map { |resource| Instance.new(resource) }
|
2017-07-20 22:07:13 +01:00
|
|
|
end
|
2017-09-13 11:30:07 +01:00
|
|
|
|
|
|
|
def filter_params
|
2019-02-18 13:59:19 +00:00
|
|
|
params.permit(:limited, :by_domain)
|
2017-09-13 11:30:07 +01:00
|
|
|
end
|
2017-04-18 20:09:07 +01:00
|
|
|
end
|
|
|
|
end
|