Skip to content

fix: reject contradictory create/update config#144

Open
tfwright wants to merge 1 commit into
mainfrom
fix/disallow-disabled-with-custom-component
Open

fix: reject contradictory create/update config#144
tfwright wants to merge 1 commit into
mainfrom
fix/disallow-disabled-with-custom-component

Conversation

@tfwright
Copy link
Copy Markdown
Owner

Summary

Validates at compile time, in admin_resource/2, that a resource isn't configured with create_with: false alongside a custom :create component (or update_with: false alongside a custom :edit component). 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/3 stashes scope opts in @__live_admin_scope_opts__ on the router module.
  • admin_resource/2 calls LiveAdmin.Router.__validate_config__!/3 at compile time with the resource module, scope opts, and the app-level config read via Application.compile_env.
  • App-level :create_with, :update_with, and :components are now read via compile_env rather than get_env. They can no longer be changed at runtime without recompiling.

Closes #139

Test plan

  • docker compose run app mix test — 39 tests pass
  • docker compose run app mix credo on changed files — clean
  • New test/live_admin/router_test.exs covers: resource-level conflict, scope-level conflict, app-level conflict, and a no-conflict baseline

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Custom create component should override create_with: false

1 participant