2013-08-07 16:04:12 -04:00
|
|
|
class Admin::StaffActionLogsController < Admin::AdminController
|
|
|
|
|
|
|
|
def index
|
2015-02-05 14:34:57 -05:00
|
|
|
filters = params.slice(*UserHistory.staff_filters)
|
2017-05-30 11:25:42 -04:00
|
|
|
|
2015-02-05 14:34:57 -05:00
|
|
|
staff_action_logs = UserHistory.staff_action_records(current_user, filters).to_a
|
2017-05-30 11:25:42 -04:00
|
|
|
render json: StaffActionLogsSerializer.new({
|
|
|
|
staff_action_logs: staff_action_logs,
|
2019-04-10 08:53:17 -04:00
|
|
|
user_history_actions: staff_available_actions
|
2017-05-30 11:25:42 -04:00
|
|
|
}, root: false)
|
2013-08-07 16:04:12 -04:00
|
|
|
end
|
|
|
|
|
2017-04-12 10:52:52 -04:00
|
|
|
def diff
|
|
|
|
require_dependency "discourse_diff"
|
|
|
|
|
|
|
|
@history = UserHistory.find(params[:id])
|
|
|
|
prev = @history.previous_value
|
|
|
|
cur = @history.new_value
|
|
|
|
|
|
|
|
prev = JSON.parse(prev) if prev
|
|
|
|
cur = JSON.parse(cur) if cur
|
|
|
|
|
|
|
|
diff_fields = {}
|
|
|
|
|
|
|
|
output = "<h2>#{CGI.escapeHTML(cur["name"].to_s)}</h2><p></p>"
|
|
|
|
|
|
|
|
diff_fields["name"] = {
|
|
|
|
prev: prev["name"].to_s,
|
|
|
|
cur: cur["name"].to_s,
|
|
|
|
}
|
|
|
|
|
|
|
|
["default", "user_selectable"].each do |f|
|
|
|
|
diff_fields[f] = {
|
|
|
|
prev: (!!prev[f]).to_s,
|
|
|
|
cur: (!!cur[f]).to_s
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
diff_fields["color scheme"] = {
|
|
|
|
prev: prev["color_scheme"]&.fetch("name").to_s,
|
|
|
|
cur: cur["color_scheme"]&.fetch("name").to_s,
|
|
|
|
}
|
|
|
|
|
|
|
|
diff_fields["included themes"] = {
|
|
|
|
prev: child_themes(prev),
|
|
|
|
cur: child_themes(cur)
|
|
|
|
}
|
|
|
|
|
|
|
|
load_diff(diff_fields, :cur, cur)
|
|
|
|
load_diff(diff_fields, :prev, prev)
|
|
|
|
|
2017-07-27 21:20:09 -04:00
|
|
|
diff_fields.delete_if { |k, v| v[:cur] == v[:prev] }
|
2017-04-12 10:52:52 -04:00
|
|
|
|
2017-07-27 21:20:09 -04:00
|
|
|
diff_fields.each do |k, v|
|
2017-04-12 10:52:52 -04:00
|
|
|
output << "<h3>#{k}</h3><p></p>"
|
|
|
|
diff = DiscourseDiff.new(v[:prev] || "", v[:cur] || "")
|
|
|
|
output << diff.side_by_side_markdown
|
|
|
|
end
|
|
|
|
|
2017-07-27 21:20:09 -04:00
|
|
|
render json: { side_by_side: output }
|
2017-04-12 10:52:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
def child_themes(theme)
|
|
|
|
return "" unless children = theme["child_themes"]
|
|
|
|
|
2017-07-27 21:20:09 -04:00
|
|
|
children.map { |row| row["name"] }.join(" ").to_s
|
2017-04-12 10:52:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def load_diff(hash, key, val)
|
2017-07-27 21:20:09 -04:00
|
|
|
if f = val["theme_fields"]
|
2017-04-12 10:52:52 -04:00
|
|
|
f.each do |row|
|
|
|
|
entry = hash[row["target"] + " " + row["name"]] ||= {}
|
|
|
|
entry[key] = row["value"]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-04-10 08:53:17 -04:00
|
|
|
private
|
|
|
|
|
|
|
|
def staff_available_actions
|
|
|
|
UserHistory.staff_actions.sort.map do |name|
|
|
|
|
{
|
|
|
|
id: name,
|
|
|
|
action_id: UserHistory.actions[name] || UserHistory.actions[:custom_staff],
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
2013-08-07 16:04:12 -04:00
|
|
|
end
|