2024-07-03 06:45:37 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class Flags::DestroyFlag
|
|
|
|
include Service::Base
|
|
|
|
|
|
|
|
model :flag
|
|
|
|
policy :not_system
|
|
|
|
policy :not_used
|
|
|
|
policy :invalid_access
|
|
|
|
transaction do
|
|
|
|
step :destroy
|
|
|
|
step :log
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def fetch_flag(id:)
|
2024-10-17 23:15:35 +08:00
|
|
|
Flag.find_by(id: id)
|
2024-07-03 06:45:37 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def not_system(flag:)
|
|
|
|
!flag.system?
|
|
|
|
end
|
|
|
|
|
|
|
|
def not_used(flag:)
|
|
|
|
!flag.used?
|
|
|
|
end
|
|
|
|
|
|
|
|
def invalid_access(guardian:, flag:)
|
|
|
|
guardian.can_edit_flag?(flag)
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy(flag:)
|
|
|
|
flag.destroy!
|
|
|
|
end
|
|
|
|
|
|
|
|
def log(guardian:, flag:)
|
|
|
|
StaffActionLogger.new(guardian.user).log_custom(
|
|
|
|
"delete_flag",
|
2024-10-17 23:15:35 +08:00
|
|
|
flag.slice(:name, :description, :applies_to, :enabled),
|
2024-07-03 06:45:37 +08:00
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|