mirror of
https://github.com/discourse/discourse.git
synced 2024-11-29 23:16:18 +08:00
aa88b07640
Continued work on moderate flags UI. In this PR admins are allowed to change the order of flags. The notify user flag is always on top but all other flags can be moved.
41 lines
648 B
Ruby
41 lines
648 B
Ruby
# 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
|