mirror of
https://github.com/discourse/discourse.git
synced 2025-05-21 18:12:32 +08:00
Reduced complexity of admin flags controller, split up into methods, moved reports into model.
This commit is contained in:
@ -122,21 +122,24 @@ class ApplicationController < ActionController::Base
|
||||
@guardian ||= Guardian.new(current_user)
|
||||
end
|
||||
|
||||
|
||||
def serialize_data(obj, serializer, opts={})
|
||||
# If it's an array, apply the serializer as an each_serializer to the elements
|
||||
serializer_opts = {scope: guardian}.merge!(opts)
|
||||
if obj.is_a?(Array)
|
||||
serializer_opts[:each_serializer] = serializer
|
||||
ActiveModel::ArraySerializer.new(obj, serializer_opts).as_json
|
||||
else
|
||||
serializer.new(obj, serializer_opts).as_json
|
||||
end
|
||||
end
|
||||
|
||||
# This is odd, but it seems that in Rails `render json: obj` is about
|
||||
# 20% slower than calling MultiJSON.dump ourselves. I'm not sure why
|
||||
# Rails doesn't call MultiJson.dump when you pass it json: obj but
|
||||
# it seems we don't need whatever Rails is doing.
|
||||
def render_serialized(obj, serializer, opts={})
|
||||
|
||||
# If it's an array, apply the serializer as an each_serializer to the elements
|
||||
serializer_opts = {scope: guardian}.merge!(opts)
|
||||
if obj.is_a?(Array)
|
||||
serializer_opts[:each_serializer] = serializer
|
||||
render_json_dump(ActiveModel::ArraySerializer.new(obj, serializer_opts).as_json)
|
||||
else
|
||||
render_json_dump(serializer.new(obj, serializer_opts).as_json)
|
||||
end
|
||||
|
||||
render_json_dump(serialize_data(obj, serializer, opts))
|
||||
end
|
||||
|
||||
def render_json_dump(obj)
|
||||
|
Reference in New Issue
Block a user