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.

77 lines
1.5 KiB

  1. # frozen_string_literal: true
  2. module AccountControllerConcern
  3. extend ActiveSupport::Concern
  4. FOLLOW_PER_PAGE = 12
  5. included do
  6. layout 'public'
  7. before_action :set_account
  8. before_action :check_account_approval
  9. before_action :check_account_suspension
  10. before_action :set_instance_presenter
  11. before_action :set_link_headers
  12. end
  13. private
  14. def set_account
  15. @account = Account.find_local!(username_param)
  16. end
  17. def set_instance_presenter
  18. @instance_presenter = InstancePresenter.new
  19. end
  20. def set_link_headers
  21. response.headers['Link'] = LinkHeader.new(
  22. [
  23. webfinger_account_link,
  24. atom_account_url_link,
  25. actor_url_link,
  26. ]
  27. )
  28. end
  29. def username_param
  30. params[:account_username]
  31. end
  32. def webfinger_account_link
  33. [
  34. webfinger_account_url,
  35. [%w(rel lrdd), %w(type application/xrd+xml)],
  36. ]
  37. end
  38. def atom_account_url_link
  39. [
  40. account_url(@account, format: 'atom'),
  41. [%w(rel alternate), %w(type application/atom+xml)],
  42. ]
  43. end
  44. def actor_url_link
  45. [
  46. ActivityPub::TagManager.instance.uri_for(@account),
  47. [%w(rel alternate), %w(type application/activity+json)],
  48. ]
  49. end
  50. def webfinger_account_url
  51. webfinger_url(resource: @account.to_webfinger_s)
  52. end
  53. def check_account_approval
  54. not_found if @account.user_pending?
  55. end
  56. def check_account_suspension
  57. if @account.suspended?
  58. expires_in(3.minutes, public: true)
  59. gone
  60. end
  61. end
  62. end