mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FEATURE: admin can disable flags (#27171)
UI for admins to disable system flags.
This commit is contained in:
committed by
GitHub
parent
e9c8e182d3
commit
963b9fd157
@@ -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)
|
||||
|
||||
40
app/serializers/toggle_flag.rb
Normal file
40
app/serializers/toggle_flag.rb
Normal 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
|
||||
Reference in New Issue
Block a user