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.

48 lines
958 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. before_action :set_pack
  10. def index
  11. render :index
  12. end
  13. def show
  14. render :index
  15. end
  16. private
  17. def set_pack
  18. use_pack 'share'
  19. end
  20. def check_enabled
  21. return not_found unless Setting.profile_directory
  22. end
  23. def set_tag
  24. @tag = Tag.discoverable.find_by!(name: params[:id].downcase)
  25. end
  26. def set_tags
  27. @tags = Tag.discoverable.limit(30).reject { |tag| tag.cached_sample_accounts.empty? }
  28. end
  29. def set_accounts
  30. @accounts = Account.discoverable.page(params[:page]).per(40).tap do |query|
  31. query.merge!(Account.tagged_with(@tag.id)) if @tag
  32. end
  33. end
  34. def set_instance_presenter
  35. @instance_presenter = InstancePresenter.new
  36. end
  37. end