Skip to content

Commit

Permalink
fix: the API is defined on the form, not on the form.source (#131)
Browse files Browse the repository at this point in the history
  • Loading branch information
sevenseacat authored Feb 6, 2024
1 parent 8ccbed8 commit 3726d07
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/ash_phoenix/form/form.ex
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ defmodule AshPhoenix.Form do
end

def can_submit?(form) do
unless form.source.api do
unless form.api do
raise """
No Api configured, but one is required to check authorization to submit a form.
Expand All @@ -647,7 +647,7 @@ defmodule AshPhoenix.Form do
"""
end

form.source.api.can?(form.source, form.source.context[:private][:actor])
form.api.can?(form.source, form.source.context[:private][:actor])
end

@spec ensure_can_submit!(t()) :: t()
Expand All @@ -657,7 +657,7 @@ defmodule AshPhoenix.Form do
end

def ensure_can_submit!(form) do
unless form.source.api do
unless form.api do
raise """
No Api configured, but one is required to check authorization to submit a form.
Expand All @@ -667,7 +667,9 @@ defmodule AshPhoenix.Form do
"""
end

case form.source.api.can(form.source, form.source.context[:private][:actor]) do
case form.api.can(form.source, form.source.context[:private][:actor],
return_forbidden_error?: true
) do
{:ok, false, %{stacktrace: %{stacktrace: stacktrace}} = exception} ->
reraise exception, stacktrace

Expand Down

0 comments on commit 3726d07

Please sign in to comment.