mirror of
https://github.com/discourse/discourse.git
synced 2025-01-19 08:12:46 +08:00
FIX: Support idempotent admin notice dismissal (#29099)
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.
This commit is contained in:
parent
4ba8d3b76b
commit
7ecb258b83
|
@ -3,7 +3,7 @@
|
|||
class AdminNotices::Dismiss
|
||||
include Service::Base
|
||||
|
||||
model :admin_notice
|
||||
model :admin_notice, optional: true
|
||||
|
||||
policy :invalid_access
|
||||
|
||||
|
@ -23,10 +23,14 @@ class AdminNotices::Dismiss
|
|||
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
|
||||
|
|
|
@ -12,6 +12,14 @@ RSpec.describe(AdminNotices::Dismiss) do
|
|||
it { is_expected.to fail_a_policy(:invalid_access) }
|
||||
end
|
||||
|
||||
context "when the admin notice has already been dismissed" do
|
||||
fab!(:current_user) { Fabricate(:admin) }
|
||||
|
||||
before { admin_notice.destroy! }
|
||||
|
||||
it { is_expected.to run_successfully }
|
||||
end
|
||||
|
||||
context "when user is allowed to perform the action" do
|
||||
fab!(:current_user) { Fabricate(:admin) }
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user