]> cat aescling's git repositories - mastodon.git/blob - app/controllers/stream_entries_controller.rb
Update AUTHORS.md (#9141)
[mastodon.git] / app / controllers / stream_entries_controller.rb
1 # frozen_string_literal: true
2
3 class StreamEntriesController < ApplicationController
4 include Authorization
5 include SignatureVerification
6
7 layout 'public'
8
9 before_action :set_account
10 before_action :set_stream_entry
11 before_action :set_link_headers
12 before_action :check_account_suspension
13 before_action :set_cache_headers
14
15 def show
16 respond_to do |format|
17 format.html do
18 redirect_to short_account_status_url(params[:account_username], @stream_entry.activity) if @type == 'status'
19 end
20
21 format.atom do
22 unless @stream_entry.hidden?
23 skip_session!
24 expires_in 3.minutes, public: true
25 end
26
27 render xml: OStatus::AtomSerializer.render(OStatus::AtomSerializer.new.entry(@stream_entry, true))
28 end
29 end
30 end
31
32 def embed
33 redirect_to embed_short_account_status_url(@account, @stream_entry.activity), status: 301
34 end
35
36 private
37
38 def set_account
39 @account = Account.find_local!(params[:account_username])
40 end
41
42 def set_link_headers
43 response.headers['Link'] = LinkHeader.new(
44 [
45 [account_stream_entry_url(@account, @stream_entry, format: 'atom'), [%w(rel alternate), %w(type application/atom+xml)]],
46 [ActivityPub::TagManager.instance.uri_for(@stream_entry.activity), [%w(rel alternate), %w(type application/activity+json)]],
47 ]
48 )
49 end
50
51 def set_stream_entry
52 @stream_entry = @account.stream_entries.where(activity_type: 'Status').find(params[:id])
53 @type = @stream_entry.activity_type.downcase
54
55 raise ActiveRecord::RecordNotFound if @stream_entry.activity.nil?
56 authorize @stream_entry.activity, :show? if @stream_entry.hidden?
57 rescue Mastodon::NotPermittedError
58 # Reraise in order to get a 404
59 raise ActiveRecord::RecordNotFound
60 end
61
62 def check_account_suspension
63 gone if @account.suspended?
64 end
65 end
This page took 0.084395 seconds and 4 git commands to generate.