where i deviate from standard mastodon assets
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

instances_controller.rb 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. # frozen_string_literal: true
  2. module Admin
  3. class InstancesController < BaseController
  4. before_action :set_domain_block, only: :show
  5. before_action :set_domain_allow, only: :show
  6. before_action :set_instance, only: :show
  7. def index
  8. authorize :instance, :index?
  9. @instances = ordered_instances
  10. end
  11. def show
  12. authorize :instance, :show?
  13. @following_count = Follow.where(account: Account.where(domain: params[:id])).count
  14. @followers_count = Follow.where(target_account: Account.where(domain: params[:id])).count
  15. @reports_count = Report.where(target_account: Account.where(domain: params[:id])).count
  16. @blocks_count = Block.where(target_account: Account.where(domain: params[:id])).count
  17. @available = DeliveryFailureTracker.available?(Account.select(:shared_inbox_url).where(domain: params[:id]).first&.shared_inbox_url)
  18. @media_storage = MediaAttachment.where(account: Account.where(domain: params[:id])).sum(:file_file_size)
  19. @private_comment = @domain_block&.private_comment
  20. @public_comment = @domain_block&.public_comment
  21. end
  22. private
  23. def set_domain_block
  24. @domain_block = DomainBlock.rule_for(params[:id])
  25. end
  26. def set_domain_allow
  27. @domain_allow = DomainAllow.rule_for(params[:id])
  28. end
  29. def set_instance
  30. resource = Account.by_domain_accounts.find_by(domain: params[:id])
  31. resource ||= @domain_block
  32. resource ||= @domain_allow
  33. if resource
  34. @instance = Instance.new(resource)
  35. else
  36. not_found
  37. end
  38. end
  39. def filtered_instances
  40. InstanceFilter.new(whitelist_mode? ? { allowed: true } : filter_params).results
  41. end
  42. def paginated_instances
  43. filtered_instances.page(params[:page])
  44. end
  45. helper_method :paginated_instances
  46. def ordered_instances
  47. paginated_instances.map { |resource| Instance.new(resource) }
  48. end
  49. def filter_params
  50. params.slice(*InstanceFilter::KEYS).permit(*InstanceFilter::KEYS)
  51. end
  52. end
  53. end