FEATURE: created edit and delete flags (#27484)

Allow admins to create edit and delete flags.
This commit is contained in:
Krzysztof Kotlarek
2024-07-03 08:45:37 +10:00
committed by GitHub
parent a86590ffd6
commit c3fadc7330
43 changed files with 1112 additions and 42 deletions

View File

@@ -10,6 +10,8 @@ class PostActionTypeSerializer < ApplicationSerializer
:is_flag,
:is_custom_flag,
:enabled,
:applies_to,
:is_used,
)
include ConfigurableUrls
@@ -27,7 +29,14 @@ class PostActionTypeSerializer < ApplicationSerializer
end
def description
i18n("description", vars: { tos_url:, base_path: Discourse.base_path })
i18n(
"description",
vars: {
tos_url:,
base_path: Discourse.base_path,
},
default: object.class.descriptions[object.id],
)
end
def short_description
@@ -42,6 +51,15 @@ class PostActionTypeSerializer < ApplicationSerializer
!!PostActionType.enabled_flag_types[object.id]
end
def applies_to
Array.wrap(PostActionType.applies_to[object.id])
end
def is_used
PostAction.exists?(post_action_type_id: object.id) ||
ReviewableScore.exists?(reviewable_score_type: object.id)
end
protected
def i18n(field, default: nil, vars: nil)

View File

@@ -10,8 +10,7 @@ class ReviewableScoreTypeSerializer < ApplicationSerializer
# Allow us to share post action type translations for backwards compatibility
def title
I18n.t("post_action_types.#{type}.title", default: nil) ||
I18n.t("reviewable_score_types.#{type}.title", default: nil) ||
PostActionType.flag_settings.names[id]
I18n.t("reviewable_score_types.#{type}.title", default: nil) || PostActionType.names[id]
end
def reviewable_priority

View File

@@ -48,6 +48,7 @@ class SiteSerializer < ApplicationSerializer
:privacy_policy_url,
:system_user_avatar_template,
:lazy_load_categories,
:valid_flag_applies_to_types,
)
has_many :archetypes, embed: :objects, serializer: ArchetypeSerializer
@@ -350,6 +351,14 @@ class SiteSerializer < ApplicationSerializer
scope.can_lazy_load_categories?
end
def valid_flag_applies_to_types
Flag.valid_applies_to_types
end
def include_valid_flag_applies_to_types?
scope.is_admin?
end
private
def ordered_flags(flags)