domain_blocks_controller.rb 955 B

123456789101112131415161718192021222324252627282930
  1. # frozen_string_literal: true
  2. class Api::V1::Instances::DomainBlocksController < Api::BaseController
  3. skip_before_action :require_authenticated_user!, unless: :limited_federation_mode?
  4. before_action :require_enabled_api!
  5. before_action :set_domain_blocks
  6. vary_by '', if: -> { Setting.show_domain_blocks == 'all' }
  7. def index
  8. if Setting.show_domain_blocks == 'all'
  9. cache_even_if_authenticated!
  10. else
  11. cache_if_unauthenticated!
  12. end
  13. render json: @domain_blocks, each_serializer: REST::DomainBlockSerializer, with_comment: (Setting.show_domain_blocks_rationale == 'all' || (Setting.show_domain_blocks_rationale == 'users' && user_signed_in?))
  14. end
  15. private
  16. def require_enabled_api!
  17. head 404 unless Setting.show_domain_blocks == 'all' || (Setting.show_domain_blocks == 'users' && user_signed_in?)
  18. end
  19. def set_domain_blocks
  20. @domain_blocks = DomainBlock.with_user_facing_limitations.by_severity
  21. end
  22. end