fix: add catch-all can?/3 clause for custom item actions#13
Merged
enoonan merged 1 commit intoenoonan:mainfrom Dec 22, 2025
Merged
fix: add catch-all can?/3 clause for custom item actions#13enoonan merged 1 commit intoenoonan:mainfrom
enoonan merged 1 commit intoenoonan:mainfrom
Conversation
When using custom item_actions in an AshBackpex.LiveResource, the page would crash with FunctionClauseError because the transformer only generated can?/3 clauses for standard actions (:new, :index, :show, :edit, :delete). The fix adds a fallback can?/3 clause that: - Returns true for actions that don't exist on the Ash resource - Checks Ash authorization for actions that do exist on the resource This mirrors the base Backpex.LiveResource behavior while integrating with Ash's authorization system.
Owner
|
Awesome work. Thank you for this! |
Contributor
Author
|
🙇 Thanks for merging! |
Owner
|
Just pushed the new version to Hex and created a release |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
item_actionsin AshBackpex.LiveResourcecan?/3clause that handles custom actionsProblem
When using custom
item_actionsin an AshBackpex.LiveResource, the page crashes with:This happens because the transformer generates specific
can?/3function clauses for standard actions (:new,:index,:show,:edit,:delete) but does NOT generate a catch-all fallback clause.Solution
Added a catch-all
can?/3clause after the destroy_action block that:truefor actions that don't exist on the Ash resource (custom UI actions)Ash.can?for actions that do exist on the resourceThis mirrors the base Backpex.LiveResource behavior (which returns
trueby default) while integrating with Ash's authorization system when applicable.Test plan
TestPromoteItemAction- a custom item action with icon for testingTestCustomItemActionLive- a LiveResource with the custom item action:promote) returntrue:read) check Ash authorization