mirror of
https://github.com/discourse/discourse.git
synced 2024-12-14 10:23:40 +08:00
2f334964f2
We decided to keep only one way to access values from a contract. This patch thus removes the hash-like access from contracts.
39 lines
651 B
Ruby
39 lines
651 B
Ruby
# frozen_string_literal: true
|
|
|
|
class Flags::ToggleFlag
|
|
include Service::Base
|
|
|
|
policy :invalid_access
|
|
params do
|
|
attribute :flag_id, :integer
|
|
|
|
validates :flag_id, presence: true
|
|
end
|
|
model :flag
|
|
transaction do
|
|
step :toggle
|
|
step :log
|
|
end
|
|
|
|
private
|
|
|
|
def invalid_access(guardian:)
|
|
guardian.can_toggle_flag?
|
|
end
|
|
|
|
def fetch_flag(params:)
|
|
Flag.find_by(id: params.flag_id)
|
|
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
|