fix: reject contradictory create/update config#144
Open
tfwright wants to merge 1 commit into
Open
Conversation
Configuring a resource with `create_with: false` alongside a custom `:create` component (or `update_with: false` alongside a custom `:edit` component) is contradictory: the disabling option says the action is off, while the component override says it's customized. Catching the misconfiguration at compile time forces users to pick one approach instead of silently behaving in unexpected ways. Closes #139
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
Validates at compile time, in
admin_resource/2, that a resource isn't configured withcreate_with: falsealongside a custom:createcomponent (orupdate_with: falsealongside a custom:editcomponent). These combinations are contradictory: the disabling option says the action is off, while the component override says it's customized.Catching this at compile time forces users to pick one approach rather than the silent / unexpected runtime behavior reported in #139.
Implementation notes:
live_admin/3stashes scope opts in@__live_admin_scope_opts__on the router module.admin_resource/2callsLiveAdmin.Router.__validate_config__!/3at compile time with the resource module, scope opts, and the app-level config read viaApplication.compile_env.:create_with,:update_with, and:componentsare now read viacompile_envrather thanget_env. They can no longer be changed at runtime without recompiling.Closes #139
Test plan
docker compose run app mix test— 39 tests passdocker compose run app mix credoon changed files — cleantest/live_admin/router_test.exscovers: resource-level conflict, scope-level conflict, app-level conflict, and a no-conflict baseline