mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
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:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user