mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
Refactor flag types for more customization
This commit is contained in:
@@ -15,7 +15,7 @@ class FlaggedTopicSummarySerializer < ActiveModel::Serializer
|
||||
|
||||
def flag_counts
|
||||
object.flag_counts.map do |k, v|
|
||||
{ flag_type_id: k, count: v }
|
||||
{ post_action_type_id: k, count: v, name_key: PostActionType.types[k] }
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -2,13 +2,25 @@ require_dependency 'configurable_urls'
|
||||
|
||||
class PostActionTypeSerializer < ApplicationSerializer
|
||||
|
||||
attributes :name_key, :name, :description, :short_description, :long_form, :is_flag, :icon, :id, :is_custom_flag
|
||||
attributes(
|
||||
:id,
|
||||
:name_key,
|
||||
:name,
|
||||
:description,
|
||||
:short_description,
|
||||
:long_form,
|
||||
:is_flag,
|
||||
:is_custom_flag
|
||||
)
|
||||
|
||||
include ConfigurableUrls
|
||||
|
||||
def is_custom_flag
|
||||
object.id == PostActionType.types[:notify_user] ||
|
||||
object.id == PostActionType.types[:notify_moderators]
|
||||
!!PostActionType.custom_types[object.id]
|
||||
end
|
||||
|
||||
def is_flag
|
||||
!!PostActionType.flag_types[object.id]
|
||||
end
|
||||
|
||||
def name
|
||||
@@ -27,10 +39,14 @@ class PostActionTypeSerializer < ApplicationSerializer
|
||||
i18n('short_description', tos_url: tos_path)
|
||||
end
|
||||
|
||||
def name_key
|
||||
PostActionType.types[object.id]
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def i18n(field, vars = nil)
|
||||
key = "post_action_types.#{object.name_key}.#{field}"
|
||||
key = "post_action_types.#{name_key}.#{field}"
|
||||
vars ? I18n.t(key, vars) : I18n.t(key)
|
||||
end
|
||||
|
||||
|
||||
@@ -246,7 +246,7 @@ class PostSerializer < BasicPostSerializer
|
||||
# The following only applies if you're logged in
|
||||
if summary[:can_act] && scope.current_user.present?
|
||||
summary[:can_defer_flags] = true if scope.is_staff? &&
|
||||
PostActionType.flag_types.values.include?(id) &&
|
||||
PostActionType.flag_types_without_custom.values.include?(id) &&
|
||||
active_flags.present? && active_flags.has_key?(id) &&
|
||||
active_flags[id].count > 0
|
||||
end
|
||||
|
||||
@@ -52,13 +52,14 @@ class SiteSerializer < ApplicationSerializer
|
||||
|
||||
def post_action_types
|
||||
cache_fragment("post_action_types_#{I18n.locale}") do
|
||||
ActiveModel::ArraySerializer.new(PostActionType.ordered).as_json
|
||||
types = PostActionType.types.values.map { |id| PostActionType.new(id: id) }
|
||||
ActiveModel::ArraySerializer.new(types).as_json
|
||||
end
|
||||
end
|
||||
|
||||
def topic_flag_types
|
||||
cache_fragment("post_action_flag_types_#{I18n.locale}") do
|
||||
flags = PostActionType.ordered.where(name_key: ['inappropriate', 'spam', 'notify_moderators'])
|
||||
flags = PostActionType.ordered.where(id: PostActionType.topic_flag_types.values)
|
||||
ActiveModel::ArraySerializer.new(flags, each_serializer: TopicFlagTypeSerializer).as_json
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user