Class: ReviewableScoreSerializer

Inherits:
ApplicationSerializer show all
Defined in:
app/serializers/reviewable_score_serializer.rb

Constant Summary collapse

REASONS_AND_SETTINGS =
{
  post_count: "approve_post_count",
  trust_level: "approve_unless_trust_level",
  new_topics_unless_trust_level: "approve_new_topics_unless_trust_level",
  fast_typer: "min_first_post_typing_time",
  auto_silence_regex: "auto_silence_first_post_regex",
  staged: "approve_unless_staged",
  must_approve_users: "must_approve_users",
  invite_only: "invite_only",
  email_spam: "email_in_spam_header",
  suspect_user: "approve_suspect_users",
  contains_media: "review_media_unless_trust_level",
}

Instance Method Summary collapse

Methods inherited from ApplicationSerializer

expire_cache_fragment!, fragment_cache

Methods inherited from ActiveModel::Serializer

#include!

Instance Method Details

#agree_statsObject



27
28
29
30
31
32
33
# File 'app/serializers/reviewable_score_serializer.rb', line 27

def agree_stats
  {
    agreed: user.user_stat.flags_agreed,
    disagreed: user.user_stat.flags_disagreed,
    ignored: user.user_stat.flags_ignored,
  }
end

#include_reason?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'app/serializers/reviewable_score_serializer.rb', line 51

def include_reason?
  reason.present?
end

#reasonObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'app/serializers/reviewable_score_serializer.rb', line 35

def reason
  return unless object.reason

  link_text = setting_name_for_reason(object.reason)
  link_text = I18n.t("reviewables.reasons.links.#{object.reason}", default: nil) if link_text.nil?

  if link_text
    link = build_link_for(object.reason, link_text)
    text = I18n.t("reviewables.reasons.#{object.reason}", link: link, default: nil)
  else
    text = I18n.t("reviewables.reasons.#{object.reason}", default: nil)
  end

  text
end

#setting_name_for_reason(reason) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
# File 'app/serializers/reviewable_score_serializer.rb', line 55

def setting_name_for_reason(reason)
  setting_name = REASONS_AND_SETTINGS[reason.to_sym]

  if setting_name.nil?
    plugin_options = DiscoursePluginRegistry.reviewable_score_links
    option = plugin_options.detect { |o| o[:reason] == reason.to_sym }

    setting_name = option[:setting] if option
  end

  setting_name
end