chinwagsocial/app/controllers/admin/instances_controller.rb

69 lines
1.9 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
module Admin
class InstancesController < BaseController
2019-07-30 19:10:46 +10:00
before_action :set_domain_block, only: :show
before_action :set_domain_allow, only: :show
before_action :set_instance, only: :show
def index
authorize :instance, :index?
2019-01-08 23:39:49 +11:00
@instances = ordered_instances
end
2019-01-08 23:39:49 +11: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?(params[:id])
2019-01-08 23:39:49 +11:00
@media_storage = MediaAttachment.where(account: Account.where(domain: params[:id])).sum(:file_file_size)
@private_comment = @domain_block&.private_comment
@public_comment = @domain_block&.public_comment
end
private
2019-07-30 19:10:46 +10: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 20:30:07 +10:00
def filtered_instances
2019-07-30 19:10:46 +10:00
InstanceFilter.new(whitelist_mode? ? { allowed: true } : filter_params).results
2017-09-13 20:30:07 +10:00
end
def paginated_instances
2017-09-13 20:30:07 +10:00
filtered_instances.page(params[:page])
end
helper_method :paginated_instances
def ordered_instances
2019-01-08 23:39:49 +11:00
paginated_instances.map { |resource| Instance.new(resource) }
end
2017-09-13 20:30:07 +10:00
def filter_params
params.slice(*InstanceFilter::KEYS).permit(*InstanceFilter::KEYS)
2017-09-13 20:30:07 +10:00
end
end
end