add RequestStore gem, support universal only param for api endpoints (fixes #4068)
This commit is contained in:
1
Gemfile
1
Gemfile
@@ -52,6 +52,7 @@ gem 'jquery-rails'
|
|||||||
gem 'webpacker', '>= 4.0.x'
|
gem 'webpacker', '>= 4.0.x'
|
||||||
gem 'retriable'
|
gem 'retriable'
|
||||||
gem 'redis'
|
gem 'redis'
|
||||||
|
gem 'request_store'
|
||||||
|
|
||||||
# needed for looser jpeg header compat
|
# needed for looser jpeg header compat
|
||||||
gem 'ruby-imagespec', :require => "image_spec", :git => "https://github.com/r888888888/ruby-imagespec.git", :branch => "exif-fixes"
|
gem 'ruby-imagespec', :require => "image_spec", :git => "https://github.com/r888888888/ruby-imagespec.git", :branch => "exif-fixes"
|
||||||
|
|||||||
@@ -319,6 +319,8 @@ GEM
|
|||||||
ref (2.0.0)
|
ref (2.0.0)
|
||||||
representable (2.3.0)
|
representable (2.3.0)
|
||||||
uber (~> 0.0.7)
|
uber (~> 0.0.7)
|
||||||
|
request_store (1.4.1)
|
||||||
|
rack (>= 1.4)
|
||||||
responders (2.4.0)
|
responders (2.4.0)
|
||||||
actionpack (>= 4.2.0, < 5.3)
|
actionpack (>= 4.2.0, < 5.3)
|
||||||
railties (>= 4.2.0, < 5.3)
|
railties (>= 4.2.0, < 5.3)
|
||||||
@@ -492,6 +494,7 @@ DEPENDENCIES
|
|||||||
rakismet
|
rakismet
|
||||||
recaptcha
|
recaptcha
|
||||||
redis
|
redis
|
||||||
|
request_store
|
||||||
responders
|
responders
|
||||||
retriable
|
retriable
|
||||||
ruby-imagespec!
|
ruby-imagespec!
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ class ApplicationController < ActionController::Base
|
|||||||
before_action :api_check
|
before_action :api_check
|
||||||
before_action :set_safe_mode
|
before_action :set_safe_mode
|
||||||
before_action :set_variant
|
before_action :set_variant
|
||||||
|
before_action :track_only_param
|
||||||
# before_action :secure_cookies_check
|
# before_action :secure_cookies_check
|
||||||
layout "default"
|
layout "default"
|
||||||
helper_method :show_moderation_notice?
|
helper_method :show_moderation_notice?
|
||||||
@@ -48,6 +49,12 @@ class ApplicationController < ActionController::Base
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def track_only_param
|
||||||
|
if params[:only]
|
||||||
|
RequestStore[:only_param] = params[:only].split(/,/)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def api_check
|
def api_check
|
||||||
if !CurrentUser.is_anonymous? && !request.get? && !request.head?
|
if !CurrentUser.is_anonymous? && !request.get? && !request.head?
|
||||||
if CurrentUser.user.token_bucket.nil?
|
if CurrentUser.user.token_bucket.nil?
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ class PostVersionsController < ApplicationController
|
|||||||
@post_versions = PostArchive.includes(:updater, post: [:versions]).search(search_params).paginate(params[:page], :limit => params[:limit], :search_count => params[:search])
|
@post_versions = PostArchive.includes(:updater, post: [:versions]).search(search_params).paginate(params[:page], :limit => params[:limit], :search_count => params[:search])
|
||||||
respond_with(@post_versions) do |format|
|
respond_with(@post_versions) do |format|
|
||||||
format.xml do
|
format.xml do
|
||||||
render :xml => @post_versions.to_xml(:root => "post-versions")
|
render xml: @post_versions.to_xml(root: "post-versions")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ class PostsController < ApplicationController
|
|||||||
respond_with(@posts) do |format|
|
respond_with(@posts) do |format|
|
||||||
format.atom
|
format.atom
|
||||||
format.xml do
|
format.xml do
|
||||||
render :xml => @posts.to_xml(:root => "posts")
|
render xml: @posts.to_xml(root: "posts")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -149,12 +149,25 @@ class ApplicationRecord < ActiveRecord::Base
|
|||||||
|
|
||||||
def as_json(options = {})
|
def as_json(options = {})
|
||||||
options ||= {}
|
options ||= {}
|
||||||
|
|
||||||
options[:except] ||= []
|
options[:except] ||= []
|
||||||
options[:except] += hidden_attributes
|
options[:except] += hidden_attributes
|
||||||
|
|
||||||
options[:methods] ||= []
|
options[:methods] ||= []
|
||||||
options[:methods] += method_attributes
|
options[:methods] += method_attributes
|
||||||
|
|
||||||
|
if !options.key?(:only) && RequestStore.exist?(:only_param)
|
||||||
|
options[:only] = RequestStore[:only_param]
|
||||||
|
end
|
||||||
|
|
||||||
|
if options[:only].is_a?(String)
|
||||||
|
options[:only] = options[:only].split(/,/)
|
||||||
|
end
|
||||||
|
|
||||||
|
if options[:only]
|
||||||
|
options[:methods] = options[:methods] & options[:only]
|
||||||
|
end
|
||||||
|
|
||||||
super(options)
|
super(options)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -167,6 +180,18 @@ class ApplicationRecord < ActiveRecord::Base
|
|||||||
options[:methods] ||= []
|
options[:methods] ||= []
|
||||||
options[:methods] += method_attributes
|
options[:methods] += method_attributes
|
||||||
|
|
||||||
|
if !options.key?(:only) && RequestStore.exist?(:only_param)
|
||||||
|
options[:only] = RequestStore[:only_param]
|
||||||
|
end
|
||||||
|
|
||||||
|
if options[:only].is_a?(String)
|
||||||
|
options[:only] = options[:only].split(/,/)
|
||||||
|
end
|
||||||
|
|
||||||
|
if options[:only]
|
||||||
|
options[:methods] = options[:methods] & options[:only]
|
||||||
|
end
|
||||||
|
|
||||||
super(options, &block)
|
super(options, &block)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user