mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FEATURE: allow admins to enable announced experimental features (#29244)
Toggle the button to enable the experimental site setting from "What's new" announcement. The toggle button is displayed when: - site setting exists and is boolean; - potentially required plugin is enabled.
This commit is contained in:
committed by
GitHub
parent
644e6c7f46
commit
433fadbd52
34
app/services/experiments/toggle.rb
Normal file
34
app/services/experiments/toggle.rb
Normal file
@@ -0,0 +1,34 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class Experiments::Toggle
|
||||
include Service::Base
|
||||
|
||||
policy :current_user_is_admin
|
||||
|
||||
contract do
|
||||
attribute :setting_name, :string
|
||||
validates :setting_name, presence: true
|
||||
end
|
||||
|
||||
policy :setting_is_available
|
||||
|
||||
transaction { step :toggle }
|
||||
|
||||
private
|
||||
|
||||
def current_user_is_admin(guardian:)
|
||||
guardian.is_admin?
|
||||
end
|
||||
|
||||
def setting_is_available(contract:)
|
||||
SiteSetting.respond_to?(contract.setting_name)
|
||||
end
|
||||
|
||||
def toggle(contract:, guardian:)
|
||||
SiteSetting.set_and_log(
|
||||
contract.setting_name,
|
||||
!SiteSetting.send(contract.setting_name),
|
||||
guardian.user,
|
||||
)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user