mirror of
https://github.com/discourse/discourse.git
synced 2025-06-14 19:29:21 +08:00
DEV: Improve support for extending flags. (#8619)
- Ensure that the 'notify_moderators' flag is always the last flag when using custom flags. - Support passign a custom FlagSettings object when replacing flags to reuse existing ones.
This commit is contained in:
@ -18,7 +18,7 @@
|
|||||||
<h3>{{i18n 'flagging.notify_staff'}}</h3>
|
<h3>{{i18n 'flagging.notify_staff'}}</h3>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
{{else}}
|
{{else}}
|
||||||
<div class='controls'>
|
<div class="controls {{flag.name_key}}">
|
||||||
<label class='radio'>
|
<label class='radio'>
|
||||||
<input type='radio' id="radio_{{unbound flag.name_key}}" {{action "changePostActionType" flag}} name='post_action_type_index'>
|
<input type='radio' id="radio_{{unbound flag.name_key}}" {{action "changePostActionType" flag}} name='post_action_type_index'>
|
||||||
<div class='flag-action-type-details'>
|
<div class='flag-action-type-details'>
|
||||||
|
@ -54,17 +54,16 @@ class SiteSerializer < ApplicationSerializer
|
|||||||
|
|
||||||
def post_action_types
|
def post_action_types
|
||||||
cache_fragment("post_action_types_#{I18n.locale}") do
|
cache_fragment("post_action_types_#{I18n.locale}") do
|
||||||
types = PostActionType.types.values.map { |id| PostActionType.new(id: id) }
|
types = ordered_flags(PostActionType.types.values)
|
||||||
ActiveModel::ArraySerializer.new(types).as_json
|
ActiveModel::ArraySerializer.new(types).as_json
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def topic_flag_types
|
def topic_flag_types
|
||||||
cache_fragment("post_action_flag_types_#{I18n.locale}") do
|
cache_fragment("post_action_flag_types_#{I18n.locale}") do
|
||||||
types = PostActionType.topic_flag_types.values.map { |id| PostActionType.new(id: id) }
|
types = ordered_flags(PostActionType.topic_flag_types.values)
|
||||||
ActiveModel::ArraySerializer.new(types, each_serializer: TopicFlagTypeSerializer).as_json
|
ActiveModel::ArraySerializer.new(types, each_serializer: TopicFlagTypeSerializer).as_json
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def default_archetype
|
def default_archetype
|
||||||
@ -163,4 +162,16 @@ class SiteSerializer < ApplicationSerializer
|
|||||||
scope.can_create_shared_draft?
|
scope.can_create_shared_draft?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def ordered_flags(flags)
|
||||||
|
notify_moderators_type = PostActionType.flag_types[:notify_moderators]
|
||||||
|
types = flags
|
||||||
|
|
||||||
|
if notify_moderators_flag = types.index(notify_moderators_type)
|
||||||
|
types.insert(types.length, types.delete_at(notify_moderators_flag))
|
||||||
|
end
|
||||||
|
|
||||||
|
types.map { |id| PostActionType.new(id: id) }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -127,8 +127,7 @@ class Plugin::Instance
|
|||||||
end
|
end
|
||||||
|
|
||||||
# Applies to all sites in a multisite environment. Ignores plugin.enabled?
|
# Applies to all sites in a multisite environment. Ignores plugin.enabled?
|
||||||
def replace_flags
|
def replace_flags(settings: ::FlagSettings.new)
|
||||||
settings = ::FlagSettings.new
|
|
||||||
yield settings
|
yield settings
|
||||||
|
|
||||||
reloadable_patch do |plugin|
|
reloadable_patch do |plugin|
|
||||||
|
Reference in New Issue
Block a user