FEATURE: admin can disable flags (#27171)

UI for admins to disable system flags.
This commit is contained in:
Krzysztof Kotlarek
2024-05-29 14:39:58 +10:00
committed by GitHub
parent e9c8e182d3
commit 963b9fd157
31 changed files with 350 additions and 7 deletions

View File

@@ -1,7 +1,16 @@
# frozen_string_literal: true
class PostActionTypeSerializer < ApplicationSerializer
attributes(:id, :name_key, :name, :description, :short_description, :is_flag, :is_custom_flag)
attributes(
:id,
:name_key,
:name,
:description,
:short_description,
:is_flag,
:is_custom_flag,
:enabled,
)
include ConfigurableUrls
@@ -29,6 +38,10 @@ class PostActionTypeSerializer < ApplicationSerializer
PostActionType.types[object.id].to_s
end
def enabled
!!PostActionType.enabled_flag_types[object.id]
end
protected
def i18n(field, default: nil, vars: nil)

View File

@@ -0,0 +1,40 @@
# frozen_string_literal: true
class ToggleFlag
include Service::Base
contract
model :flag
policy :invalid_access
transaction do
step :toggle
step :log
end
class Contract
attribute :flag_id, :integer
validates :flag_id, presence: true
end
private
def fetch_flag(flag_id:)
Flag.find(flag_id)
end
def invalid_access(guardian:)
guardian.can_toggle_flag?
end
def toggle(flag:)
flag.update!(enabled: !flag.enabled)
end
def log(guardian:, flag:)
StaffActionLogger.new(guardian.user).log_custom(
"toggle_flag",
{ flag: flag.name, enabled: flag.enabled },
)
end
end