make code climate a bit happier

This commit is contained in:
Sam
2013-08-06 06:25:44 +10:00
parent 1965cbcad6
commit 11dca1fd92
2 changed files with 42 additions and 30 deletions

View File

@ -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