Cleanup various controllers (#10972)

* Remove skip_session! as it is not supported in Rails 5

* Minor cleanup in StreamEntriesController

* Remove redundant mark_cacheable! calls
remotes/1727458204337373841/tmp_refs/heads/signup-info-prompt
ThibG 2019-06-05 14:02:59 +02:00 committed by Eugen Rochko
parent 7fa23ec697
commit cac9110533
11 changed files with 8 additions and 46 deletions

View File

@ -46,8 +46,6 @@ class AccountsController < ApplicationController
end end
format.json do format.json do
mark_cacheable!
render_cached_json(['activitypub', 'actor', @account], content_type: 'application/activity+json') do render_cached_json(['activitypub', 'actor', @account], content_type: 'application/activity+json') do
ActiveModelSerializers::SerializableResource.new(@account, serializer: ActivityPub::ActorSerializer, adapter: ActivityPub::Adapter) ActiveModelSerializers::SerializableResource.new(@account, serializer: ActivityPub::ActorSerializer, adapter: ActivityPub::Adapter)
end end

View File

@ -9,8 +9,6 @@ class ActivityPub::CollectionsController < Api::BaseController
before_action :set_cache_headers before_action :set_cache_headers
def show def show
skip_session!
render_cached_json(['activitypub', 'collection', @account, params[:id]], content_type: 'application/activity+json') do render_cached_json(['activitypub', 'collection', @account, params[:id]], content_type: 'application/activity+json') do
ActiveModelSerializers::SerializableResource.new( ActiveModelSerializers::SerializableResource.new(
collection_presenter, collection_presenter,

View File

@ -10,10 +10,7 @@ class ActivityPub::OutboxesController < Api::BaseController
before_action :set_cache_headers before_action :set_cache_headers
def show def show
unless page_requested? expires_in 1.minute, public: true unless page_requested?
skip_session!
expires_in 1.minute, public: true
end
render json: outbox_presenter, serializer: ActivityPub::OutboxSerializer, adapter: ActivityPub::Adapter, content_type: 'application/activity+json' render json: outbox_presenter, serializer: ActivityPub::OutboxSerializer, adapter: ActivityPub::Adapter, content_type: 'application/activity+json'
end end

View File

@ -152,11 +152,6 @@ class ApplicationController < ActionController::Base
end end
def mark_cacheable! def mark_cacheable!
skip_session!
expires_in 0, public: true expires_in 0, public: true
end end
def skip_session!
request.session_options[:skip] = true
end
end end

View File

@ -70,7 +70,6 @@ module AccountControllerConcern
def check_account_suspension def check_account_suspension
if @account.suspended? if @account.suspended?
skip_session!
expires_in(3.minutes, public: true) expires_in(3.minutes, public: true)
gone gone
end end

View File

@ -4,7 +4,6 @@ class CustomCssController < ApplicationController
before_action :set_cache_headers before_action :set_cache_headers
def show def show
skip_session!
render plain: Setting.custom_css || '', content_type: 'text/css' render plain: Setting.custom_css || '', content_type: 'text/css'
end end
end end

View File

@ -7,8 +7,6 @@ class EmojisController < ApplicationController
def show def show
respond_to do |format| respond_to do |format|
format.json do format.json do
skip_session!
render_cached_json(['activitypub', 'emoji', @emoji], content_type: 'application/activity+json') do render_cached_json(['activitypub', 'emoji', @emoji], content_type: 'application/activity+json') do
ActiveModelSerializers::SerializableResource.new(@emoji, serializer: ActivityPub::EmojiSerializer, adapter: ActivityPub::Adapter) ActiveModelSerializers::SerializableResource.new(@emoji, serializer: ActivityPub::EmojiSerializer, adapter: ActivityPub::Adapter)
end end

View File

@ -19,10 +19,7 @@ class FollowerAccountsController < ApplicationController
format.json do format.json do
raise Mastodon::NotPermittedError if params[:page].present? && @account.user_hides_network? raise Mastodon::NotPermittedError if params[:page].present? && @account.user_hides_network?
if params[:page].blank? expires_in 3.minutes, public: true if params[:page].blank?
skip_session!
expires_in 3.minutes, public: true
end
render json: collection_presenter, render json: collection_presenter,
serializer: ActivityPub::CollectionSerializer, serializer: ActivityPub::CollectionSerializer,

View File

@ -19,10 +19,7 @@ class FollowingAccountsController < ApplicationController
format.json do format.json do
raise Mastodon::NotPermittedError if params[:page].present? && @account.user_hides_network? raise Mastodon::NotPermittedError if params[:page].present? && @account.user_hides_network?
if params[:page].blank? expires_in 3.minutes, public: true if params[:page].blank?
skip_session!
expires_in 3.minutes, public: true
end
render json: collection_presenter, render json: collection_presenter,
serializer: ActivityPub::CollectionSerializer, serializer: ActivityPub::CollectionSerializer,

View File

@ -27,10 +27,7 @@ class StatusesController < ApplicationController
def show def show
respond_to do |format| respond_to do |format|
format.html do format.html do
if current_account.nil? expires_in 10.seconds, public: true if current_account.nil?
skip_session!
expires_in 10.seconds, public: true
end
@body_classes = 'with-modals' @body_classes = 'with-modals'
@ -41,8 +38,6 @@ class StatusesController < ApplicationController
end end
format.json do format.json do
mark_cacheable! unless @stream_entry.hidden?
render_cached_json(['activitypub', 'note', @status], content_type: 'application/activity+json', public: !@stream_entry.hidden?) do render_cached_json(['activitypub', 'note', @status], content_type: 'application/activity+json', public: !@stream_entry.hidden?) do
ActiveModelSerializers::SerializableResource.new(@status, serializer: ActivityPub::NoteSerializer, adapter: ActivityPub::Adapter) ActiveModelSerializers::SerializableResource.new(@status, serializer: ActivityPub::NoteSerializer, adapter: ActivityPub::Adapter)
end end
@ -51,8 +46,6 @@ class StatusesController < ApplicationController
end end
def activity def activity
skip_session!
render_cached_json(['activitypub', 'activity', @status], content_type: 'application/activity+json', public: !@stream_entry.hidden?) do render_cached_json(['activitypub', 'activity', @status], content_type: 'application/activity+json', public: !@stream_entry.hidden?) do
ActiveModelSerializers::SerializableResource.new(@status, serializer: ActivityPub::ActivitySerializer, adapter: ActivityPub::Adapter) ActiveModelSerializers::SerializableResource.new(@status, serializer: ActivityPub::ActivitySerializer, adapter: ActivityPub::Adapter)
end end
@ -61,7 +54,6 @@ class StatusesController < ApplicationController
def embed def embed
raise ActiveRecord::RecordNotFound if @status.hidden? raise ActiveRecord::RecordNotFound if @status.hidden?
skip_session!
expires_in 180, public: true expires_in 180, public: true
response.headers['X-Frame-Options'] = 'ALLOWALL' response.headers['X-Frame-Options'] = 'ALLOWALL'
@autoplay = ActiveModel::Type::Boolean.new.cast(params[:autoplay]) @autoplay = ActiveModel::Type::Boolean.new.cast(params[:autoplay])
@ -70,8 +62,6 @@ class StatusesController < ApplicationController
end end
def replies def replies
skip_session!
render json: replies_collection_presenter, render json: replies_collection_presenter,
serializer: ActivityPub::CollectionSerializer, serializer: ActivityPub::CollectionSerializer,
adapter: ActivityPub::Adapter, adapter: ActivityPub::Adapter,

View File

@ -15,19 +15,13 @@ class StreamEntriesController < ApplicationController
def show def show
respond_to do |format| respond_to do |format|
format.html do format.html do
unless user_signed_in? expires_in 5.minutes, public: true unless @stream_entry.hidden?
skip_session!
expires_in 5.minutes, public: true
end
redirect_to short_account_status_url(params[:account_username], @stream_entry.activity) if @type == 'status' redirect_to short_account_status_url(params[:account_username], @stream_entry.activity)
end end
format.atom do format.atom do
unless @stream_entry.hidden? expires_in 3.minutes, public: true unless @stream_entry.hidden?
skip_session!
expires_in 3.minutes, public: true
end
render xml: OStatus::AtomSerializer.render(OStatus::AtomSerializer.new.entry(@stream_entry, true)) render xml: OStatus::AtomSerializer.render(OStatus::AtomSerializer.new.entry(@stream_entry, true))
end end
@ -55,7 +49,7 @@ class StreamEntriesController < ApplicationController
def set_stream_entry def set_stream_entry
@stream_entry = @account.stream_entries.where(activity_type: 'Status').find(params[:id]) @stream_entry = @account.stream_entries.where(activity_type: 'Status').find(params[:id])
@type = @stream_entry.activity_type.downcase @type = 'status'
raise ActiveRecord::RecordNotFound if @stream_entry.activity.nil? raise ActiveRecord::RecordNotFound if @stream_entry.activity.nil?
authorize @stream_entry.activity, :show? if @stream_entry.hidden? authorize @stream_entry.activity, :show? if @stream_entry.hidden?