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.

43 lines
906 B

  1. # frozen_string_literal: true
  2. class DirectoriesController < ApplicationController
  3. layout 'public'
  4. before_action :check_enabled
  5. before_action :set_instance_presenter
  6. before_action :set_tag, only: :show
  7. before_action :set_tags
  8. before_action :set_accounts
  9. def index
  10. render :index
  11. end
  12. def show
  13. render :index
  14. end
  15. private
  16. def check_enabled
  17. return not_found unless Setting.profile_directory
  18. end
  19. def set_tag
  20. @tag = Tag.discoverable.find_by!(name: params[:id].downcase)
  21. end
  22. def set_tags
  23. @tags = Tag.discoverable.limit(30).reject { |tag| tag.cached_sample_accounts.empty? }
  24. end
  25. def set_accounts
  26. @accounts = Account.discoverable.by_recent_status.page(params[:page]).per(40).tap do |query|
  27. query.merge!(Account.tagged_with(@tag.id)) if @tag
  28. end
  29. end
  30. def set_instance_presenter
  31. @instance_presenter = InstancePresenter.new
  32. end
  33. end