discourse/app/services/admin_notices/dismiss.rb
Loïc Guitaut e95edd079b DEV: Refactor some core services
Extracted from https://github.com/discourse/discourse/pull/29129.

This patch makes the code more compliant with the upcoming service docs
best practices.
2024-10-18 16:06:58 +02:00

35 lines
620 B
Ruby

# frozen_string_literal: true
class AdminNotices::Dismiss
include Service::Base
policy :invalid_access
model :admin_notice, optional: true
transaction do
step :destroy
step :reset_problem_check
end
private
def invalid_access(guardian:)
guardian.is_admin?
end
def fetch_admin_notice(id:)
AdminNotice.find_by(id: id)
end
def destroy(admin_notice:)
return if admin_notice.blank?
admin_notice.destroy!
end
def reset_problem_check(admin_notice:)
return if admin_notice.blank?
ProblemCheckTracker.find_by(identifier: admin_notice.identifier)&.reset
end
end