2019-05-03 06:17:27 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-01-04 01:03:01 +08:00
|
|
|
require_dependency 'reviewable_score_type_serializer'
|
|
|
|
|
|
|
|
class ReviewableScoreSerializer < ApplicationSerializer
|
|
|
|
|
2019-04-11 23:11:35 +08:00
|
|
|
attributes :id, :score, :agree_stats, :status, :reason, :created_at, :reviewed_at
|
2019-01-04 01:03:01 +08:00
|
|
|
has_one :user, serializer: BasicUserSerializer, root: 'users'
|
|
|
|
has_one :score_type, serializer: ReviewableScoreTypeSerializer
|
|
|
|
has_one :reviewable_conversation, serializer: ReviewableConversationSerializer
|
2019-04-10 04:43:08 +08:00
|
|
|
has_one :reviewed_by, serializer: BasicUserSerializer, root: 'users'
|
2019-01-04 01:03:01 +08:00
|
|
|
|
|
|
|
def agree_stats
|
|
|
|
{
|
|
|
|
agreed: user.user_stat.flags_agreed,
|
|
|
|
disagreed: user.user_stat.flags_disagreed,
|
|
|
|
ignored: user.user_stat.flags_ignored
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2019-04-11 23:11:35 +08:00
|
|
|
def reason
|
|
|
|
return unless object.reason
|
|
|
|
|
2019-06-06 22:51:54 +08:00
|
|
|
if text = I18n.t("reviewables.reasons.#{object.reason}", base_url: Discourse.base_url, default: nil)
|
2019-04-11 23:11:35 +08:00
|
|
|
# Create a convenient link to any site settings if the user is staff
|
2019-06-01 02:04:34 +08:00
|
|
|
settings_url = "#{Discourse.base_url}/admin/site_settings/category/all_results?filter="
|
2019-04-11 23:11:35 +08:00
|
|
|
|
|
|
|
text.gsub!(/`[a-z_]+`/) do |m|
|
|
|
|
if scope.is_staff?
|
|
|
|
setting = m[1..-2]
|
|
|
|
"<a href=\"#{settings_url}#{setting}\">#{setting.gsub('_', ' ')}</a>"
|
|
|
|
else
|
|
|
|
m.gsub('_', ' ')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
text
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_reason?
|
|
|
|
reason.present?
|
|
|
|
end
|
|
|
|
|
2019-01-04 01:03:01 +08:00
|
|
|
end
|