FEATURE: improve error message when double liking (#23698)

If a user somehow is looking at an old version of the page and attempts
to like a post they already like. Display a more reasonable error message.

Previously we would display:

> You are not permitted to view the requested resource.

New error message is:

> Oops! You already performed this action. Can you try refreshing the page?

Triggering this error condition is very tricky, you need to stop the
message bus. A possible reason for it could be bad network connectivity.
This commit is contained in:
Sam
2023-09-28 16:53:48 +10:00
committed by GitHub
parent 76e5a939d4
commit a2da2e02e7
3 changed files with 25 additions and 7 deletions

View File

@@ -80,17 +80,27 @@ class PostActionCreator
@post_action_name,
opts: {
is_warning: @is_warning,
taken_actions: PostAction.counts_for([@post].compact, @created_by)[@post&.id],
taken_actions: taken_actions,
},
)
end
def taken_actions
return @taken_actions if defined?(@taken_actions)
@taken_actions = PostAction.counts_for([@post].compact, @created_by)[@post&.id]
end
def perform
result = CreateResult.new
if !post_can_act? || (@queue_for_review && !guardian.is_staff?)
result.forbidden = true
result.add_error(I18n.t("invalid_access"))
if taken_actions&.keys&.include?(PostActionType.types[@post_action_name])
result.add_error(I18n.t("action_already_performed"))
else
result.add_error(I18n.t("invalid_access"))
end
return result
end