mirror of
https://github.com/discourse/discourse.git
synced 2024-12-24 06:23:45 +08:00
7ecb258b83
If you have the admin dashboard open, and one of the admin notices listed has already been dismissed (e.g. in another tab, or by another admin) we would show an ugly "FAILED" modal. This change makes the admin dismiss endpoint idempotent. If the admin notice is already destroyed, then respond with 200. This will also correctly remove it from the list in the front-end.
37 lines
622 B
Ruby
37 lines
622 B
Ruby
# frozen_string_literal: true
|
|
|
|
class AdminNotices::Dismiss
|
|
include Service::Base
|
|
|
|
model :admin_notice, optional: true
|
|
|
|
policy :invalid_access
|
|
|
|
transaction do
|
|
step :destroy
|
|
step :reset_problem_check
|
|
end
|
|
|
|
private
|
|
|
|
def fetch_admin_notice(id:)
|
|
AdminNotice.find_by(id: id)
|
|
end
|
|
|
|
def invalid_access(guardian:)
|
|
guardian.is_admin?
|
|
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
|