2017-04-19 04:52:37 -07:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module AccountControllerConcern
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
FOLLOW_PER_PAGE = 12
|
|
|
|
|
|
|
|
included do
|
|
|
|
layout 'public'
|
2019-03-13 21:28:30 -07:00
|
|
|
|
2017-04-19 04:52:37 -07:00
|
|
|
before_action :set_account
|
2019-03-13 21:28:30 -07:00
|
|
|
before_action :check_account_approval
|
|
|
|
before_action :check_account_suspension
|
2018-07-28 10:25:33 -07:00
|
|
|
before_action :set_instance_presenter
|
2017-04-19 04:52:37 -07:00
|
|
|
before_action :set_link_headers
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def set_account
|
2019-03-13 21:28:30 -07:00
|
|
|
@account = Account.find_local!(username_param)
|
2017-04-19 04:52:37 -07:00
|
|
|
end
|
|
|
|
|
2018-07-28 10:25:33 -07:00
|
|
|
def set_instance_presenter
|
|
|
|
@instance_presenter = InstancePresenter.new
|
|
|
|
end
|
|
|
|
|
2017-04-19 04:52:37 -07:00
|
|
|
def set_link_headers
|
|
|
|
response.headers['Link'] = LinkHeader.new(
|
|
|
|
[
|
|
|
|
webfinger_account_link,
|
|
|
|
atom_account_url_link,
|
2017-08-12 15:45:04 -07:00
|
|
|
actor_url_link,
|
2017-04-19 04:52:37 -07:00
|
|
|
]
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2019-03-13 21:28:30 -07:00
|
|
|
def username_param
|
|
|
|
params[:account_username]
|
|
|
|
end
|
|
|
|
|
2017-04-19 04:52:37 -07:00
|
|
|
def webfinger_account_link
|
|
|
|
[
|
|
|
|
webfinger_account_url,
|
|
|
|
[%w(rel lrdd), %w(type application/xrd+xml)],
|
|
|
|
]
|
|
|
|
end
|
|
|
|
|
|
|
|
def atom_account_url_link
|
|
|
|
[
|
|
|
|
account_url(@account, format: 'atom'),
|
|
|
|
[%w(rel alternate), %w(type application/atom+xml)],
|
|
|
|
]
|
|
|
|
end
|
|
|
|
|
2017-08-12 15:45:04 -07:00
|
|
|
def actor_url_link
|
|
|
|
[
|
|
|
|
ActivityPub::TagManager.instance.uri_for(@account),
|
|
|
|
[%w(rel alternate), %w(type application/activity+json)],
|
|
|
|
]
|
|
|
|
end
|
|
|
|
|
2017-04-19 04:52:37 -07:00
|
|
|
def webfinger_account_url
|
|
|
|
webfinger_url(resource: @account.to_webfinger_s)
|
|
|
|
end
|
|
|
|
|
2019-03-13 21:28:30 -07:00
|
|
|
def check_account_approval
|
|
|
|
not_found if @account.user_pending?
|
|
|
|
end
|
|
|
|
|
2017-04-19 04:52:37 -07:00
|
|
|
def check_account_suspension
|
2019-03-21 15:33:18 -07:00
|
|
|
if @account.suspended?
|
|
|
|
skip_session!
|
|
|
|
expires_in(3.minutes, public: true)
|
|
|
|
gone
|
|
|
|
end
|
2017-04-19 04:52:37 -07:00
|
|
|
end
|
|
|
|
end
|