Skip to content

feat: add pre_flight_authorization() builtin validation for conditional checks during Ash.can?#2587

Merged
zachdaniel merged 1 commit intoash-project:mainfrom
emadshaaban92:pre-flight-validation
Feb 25, 2026
Merged

feat: add pre_flight_authorization() builtin validation for conditional checks during Ash.can?#2587
zachdaniel merged 1 commit intoash-project:mainfrom
emadshaaban92:pre-flight-validation

Conversation

@emadshaaban92
Copy link
Contributor

@emadshaaban92 emadshaaban92 commented Feb 25, 2026

  • Set pre_flight_authorization? in context earlier so it's available during validation, rather than setting it after subject construction.
  • Use that private context to implement pre_flight_authorization()

Btw is there a reason context is ignored here?

%Ash.Changeset{} = changeset ->
    changeset
    |> Ash.Changeset.set_tenant(opts[:tenant] || changeset.tenant)
    |> Ash.Changeset.set_context(%{private: %{actor: actor}})

Also for %Ash.ActionInput{} and %Ash.Query{}

I know the caller can add whatever context they want in the subject itself when they call Ash.can like this:

Ash.can?(changeset |> Ash.Changeset.set_context(...), actor)

But the context is ignored if sent like this, which isn't what I expected since context almost always get merged in other places.

Ash.can?(changeset, actor, context: ...)

Contributor checklist

Leave anything that you believe does not apply unchecked.

  • I accept the AI Policy, or AI was not used in the creation of this PR.
  • Bug fixes include regression tests
  • Chores
  • Documentation changes
  • Features include unit/acceptance tests
  • Refactoring
  • Update dependencies

@emadshaaban92 emadshaaban92 changed the title feat: add pre_flight() builtin validation for conditional checks during Ash.can? feat: add pre_flight_authorization() builtin validation for conditional checks during Ash.can? Feb 25, 2026
@zachdaniel zachdaniel merged commit ef3f8bb into ash-project:main Feb 25, 2026
45 checks passed
@zachdaniel
Copy link
Contributor

🚀 Thank you for your contribution! 🚀

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.

2 participants