mirror of
https://github.com/discourse/discourse.git
synced 2025-05-21 18:12:32 +08:00
make code climate a bit happier
This commit is contained in:
@ -106,23 +106,15 @@ class ApplicationController < ActionController::Base
|
||||
|
||||
# If we are rendering HTML, preload the session data
|
||||
def preload_json
|
||||
|
||||
# We don't preload JSON on xhr or JSON request
|
||||
return if request.xhr?
|
||||
|
||||
if guardian.current_user
|
||||
guardian.current_user.sync_notification_channel_position
|
||||
preload_anonymous_data
|
||||
|
||||
if current_user
|
||||
preload_current_user_data
|
||||
current_user.sync_notification_channel_position
|
||||
end
|
||||
|
||||
store_preloaded("site", Site.cached_json(guardian))
|
||||
|
||||
if current_user.present?
|
||||
store_preloaded("currentUser", MultiJson.dump(CurrentUserSerializer.new(current_user, root: false)))
|
||||
|
||||
serializer = ActiveModel::ArraySerializer.new(TopicTrackingState.report([current_user.id]), each_serializer: TopicTrackingStateSerializer)
|
||||
store_preloaded("topicTrackingStates", MultiJson.dump(serializer))
|
||||
end
|
||||
store_preloaded("siteSettings", SiteSetting.client_settings_json)
|
||||
end
|
||||
|
||||
|
||||
@ -201,6 +193,17 @@ class ApplicationController < ActionController::Base
|
||||
|
||||
private
|
||||
|
||||
def preload_anonymous_data
|
||||
store_preloaded("site", Site.cached_json(guardian))
|
||||
store_preloaded("siteSettings", SiteSetting.client_settings_json)
|
||||
end
|
||||
|
||||
def preload_current_user_data
|
||||
store_preloaded("currentUser", MultiJson.dump(CurrentUserSerializer.new(current_user, root: false)))
|
||||
serializer = ActiveModel::ArraySerializer.new(TopicTrackingState.report([current_user.id]), each_serializer: TopicTrackingStateSerializer)
|
||||
store_preloaded("topicTrackingStates", MultiJson.dump(serializer))
|
||||
end
|
||||
|
||||
def render_json_error(obj)
|
||||
if obj.present?
|
||||
render json: MultiJson.dump(errors: obj.errors.full_messages), status: 422
|
||||
@ -257,11 +260,9 @@ class ApplicationController < ActionController::Base
|
||||
end
|
||||
|
||||
def check_xhr
|
||||
unless (controller_name == 'forums' || controller_name == 'user_open_ids')
|
||||
# bypass xhr check on PUT / POST / DELETE provided api key is there, otherwise calling api is annoying
|
||||
return if !request.get? && api_key_valid?
|
||||
raise RenderEmpty.new unless ((request.format && request.format.json?) || request.xhr?)
|
||||
end
|
||||
# bypass xhr check on PUT / POST / DELETE provided api key is there, otherwise calling api is annoying
|
||||
return if !request.get? && api_key_valid?
|
||||
raise RenderEmpty.new unless ((request.format && request.format.json?) || request.xhr?)
|
||||
end
|
||||
|
||||
def ensure_logged_in
|
||||
|
Reference in New Issue
Block a user