Fix card view "M" hotkey using stale user from fragment cache

The hidden "Assign to me" button on the card detail view baked
Current.user.id into the form action at render time. When served from
fragment cache, a stale user ID could be embedded, assigning cards to
the wrong person.

Switch to card_self_assignment_path which resolves the current user at
request time via SelfAssignmentsController, matching the fix already
applied to the board view in 2527f073.

ref: https://app.fizzy.do/5986089/cards/3722
This commit is contained in:
Mike Dalessio
2026-03-17 14:43:05 -04:00
parent 22f46e73c9
commit 7f65f4aabd
2 changed files with 11 additions and 2 deletions
@@ -12,8 +12,8 @@
</span>
</button>
<% if Current.user && !local_assigns[:preview] %>
<%= button_to "Assign to me", card_assignments_path(card, params: { assignee_id: Current.user.id }), method: :post, data: {controller: "hotkey", action: "keydown.m@document->hotkey#click" }, hidden: true %>
<% unless local_assigns[:preview] %>
<%= button_to "Assign to me", card_self_assignment_path(card), method: :post, data: {controller: "hotkey", action: "keydown.m@document->hotkey#click" }, hidden: true %>
<% end %>
<dialog class="popup panel flex-column align-start gap-half fill-white shadow" data-dialog-target="dialog" data-action="turbo:before-morph-attribute->dialog#preventCloseOnMorphing turbo:submit-end->dialog#close">
@@ -42,6 +42,15 @@ class CardsControllerTest < ActionDispatch::IntegrationTest
assert_redirected_to card_draft_path(card)
end
test "show renders assign-to-me hotkey using self assignment path" do
card = cards(:logo)
get card_path(card)
assert_response :success
assert_select "form[action=?] button[hidden]", card_self_assignment_path(card), text: "Assign to me"
end
test "show renders inline code in title" do
card = cards(:logo)
card.update_column :title, "Fix the `bug` in production"