2017-03-22 18:26:22 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class StatusesController < ApplicationController
|
2019-07-08 10:03:45 +00:00
|
|
|
include StatusControllerConcern
|
2018-02-02 09:19:59 +00:00
|
|
|
include SignatureAuthentication
|
2017-05-29 16:22:22 +00:00
|
|
|
include Authorization
|
2019-07-08 10:03:45 +00:00
|
|
|
include AccountOwnedConcern
|
2018-04-11 10:35:09 +00:00
|
|
|
|
2017-03-22 18:26:22 +00:00
|
|
|
layout 'public'
|
|
|
|
|
2021-01-19 05:47:36 +00:00
|
|
|
before_action :require_signature!, only: [:show, :activity], if: -> { request.format == :json && authorized_fetch_mode? }
|
2017-03-22 18:26:22 +00:00
|
|
|
before_action :set_status
|
2018-07-28 17:25:33 +00:00
|
|
|
before_action :set_instance_presenter
|
2017-03-22 18:26:22 +00:00
|
|
|
before_action :set_link_headers
|
2022-03-17 14:25:16 +00:00
|
|
|
before_action :redirect_to_original, only: [:show, :references]
|
|
|
|
before_action :set_referrer_policy_header, only: [:show, :references]
|
2018-01-04 00:21:38 +00:00
|
|
|
before_action :set_cache_headers
|
2019-07-08 10:03:45 +00:00
|
|
|
before_action :set_body_classes
|
2017-03-22 18:26:22 +00:00
|
|
|
|
2019-08-11 20:59:40 +00:00
|
|
|
skip_around_action :set_locale, if: -> { request.format == :json }
|
2022-03-17 14:25:16 +00:00
|
|
|
skip_before_action :require_functional!, only: [:show, :references, :embed], unless: :whitelist_mode?
|
2019-08-11 20:59:40 +00:00
|
|
|
|
2018-10-11 18:35:46 +00:00
|
|
|
content_security_policy only: :embed do |p|
|
|
|
|
p.frame_ancestors(false)
|
|
|
|
end
|
|
|
|
|
2017-03-22 18:26:22 +00:00
|
|
|
def show
|
2017-07-15 01:01:39 +00:00
|
|
|
respond_to do |format|
|
|
|
|
format.html do
|
2019-06-05 12:02:59 +00:00
|
|
|
expires_in 10.seconds, public: true if current_account.nil?
|
2018-04-23 17:27:35 +00:00
|
|
|
set_ancestors
|
|
|
|
set_descendants
|
2017-07-15 01:01:39 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
format.json do
|
2019-07-11 18:11:09 +00:00
|
|
|
expires_in 3.minutes, public: @status.distributable? && public_fetch_mode?
|
2019-07-21 20:32:16 +00:00
|
|
|
render_with_cache json: @status, content_type: 'application/activity+json', serializer: ActivityPub::NoteSerializer, adapter: ActivityPub::Adapter
|
2017-07-15 01:01:39 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-03-22 18:26:22 +00:00
|
|
|
|
2022-03-17 14:25:16 +00:00
|
|
|
def references
|
|
|
|
respond_to do |format|
|
|
|
|
format.html do
|
|
|
|
expires_in 10.seconds, public: true if current_account.nil?
|
|
|
|
set_references
|
|
|
|
return not_found unless @references.present?
|
|
|
|
end
|
|
|
|
|
|
|
|
format.json do
|
|
|
|
redirect_to account_status_references_url(@account, @status)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-07-15 01:01:39 +00:00
|
|
|
def activity
|
2019-07-11 18:11:09 +00:00
|
|
|
expires_in 3.minutes, public: @status.distributable? && public_fetch_mode?
|
2020-06-02 17:24:53 +00:00
|
|
|
render_with_cache json: ActivityPub::ActivityPresenter.from_status(@status), content_type: 'application/activity+json', serializer: ActivityPub::ActivitySerializer, adapter: ActivityPub::Adapter
|
2017-03-22 18:26:22 +00:00
|
|
|
end
|
|
|
|
|
2017-08-30 08:23:43 +00:00
|
|
|
def embed
|
2020-05-03 14:30:36 +00:00
|
|
|
return not_found if @status.hidden? || @status.reblog?
|
2018-07-01 02:12:34 +00:00
|
|
|
|
|
|
|
expires_in 180, public: true
|
2017-08-30 08:23:43 +00:00
|
|
|
response.headers['X-Frame-Options'] = 'ALLOWALL'
|
2018-07-01 02:12:34 +00:00
|
|
|
|
2019-07-07 14:16:51 +00:00
|
|
|
render layout: 'embedded'
|
2017-08-30 08:23:43 +00:00
|
|
|
end
|
|
|
|
|
2017-03-22 18:26:22 +00:00
|
|
|
private
|
|
|
|
|
2019-07-08 10:03:45 +00:00
|
|
|
def set_body_classes
|
|
|
|
@body_classes = 'with-modals'
|
2018-04-23 17:27:35 +00:00
|
|
|
end
|
|
|
|
|
2017-03-22 18:26:22 +00:00
|
|
|
def set_link_headers
|
2019-07-07 14:16:51 +00:00
|
|
|
response.headers['Link'] = LinkHeader.new([[ActivityPub::TagManager.instance.uri_for(@status), [%w(rel alternate), %w(type application/activity+json)]]])
|
2017-03-22 18:26:22 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def set_status
|
2019-07-07 14:16:51 +00:00
|
|
|
@status = @account.statuses.find(params[:id])
|
2020-09-05 07:33:17 +00:00
|
|
|
|
|
|
|
if request.authorization.present? && request.authorization.match(/^Bearer /i)
|
|
|
|
raise Mastodon::NotPermittedError unless @status.capability_tokens.find_by(token: request.authorization.gsub(/^Bearer /i, ''))
|
|
|
|
else
|
|
|
|
authorize @status, :show?
|
|
|
|
end
|
2017-05-29 16:22:22 +00:00
|
|
|
rescue Mastodon::NotPermittedError
|
2020-01-23 23:20:51 +00:00
|
|
|
not_found
|
2017-03-22 18:26:22 +00:00
|
|
|
end
|
|
|
|
|
2018-07-28 17:25:33 +00:00
|
|
|
def set_instance_presenter
|
|
|
|
@instance_presenter = InstancePresenter.new
|
|
|
|
end
|
|
|
|
|
2017-08-24 14:21:42 +00:00
|
|
|
def redirect_to_original
|
2019-07-07 14:16:51 +00:00
|
|
|
redirect_to ActivityPub::TagManager.instance.url_for(@status.reblog) if @status.reblog?
|
2017-08-24 14:21:42 +00:00
|
|
|
end
|
2018-04-17 11:51:01 +00:00
|
|
|
|
|
|
|
def set_referrer_policy_header
|
2019-07-08 10:03:45 +00:00
|
|
|
response.headers['Referrer-Policy'] = 'origin' unless @status.distributable?
|
2019-02-28 17:16:34 +00:00
|
|
|
end
|
2017-03-22 18:26:22 +00:00
|
|
|
end
|