From 3726d07ee266d464161303f91f0957e698a4e4f1 Mon Sep 17 00:00:00 2001 From: Rebecca Le <543859+sevenseacat@users.noreply.github.com> Date: Tue, 6 Feb 2024 10:30:08 +0800 Subject: [PATCH] fix: the API is defined on the form, not on the form.source (#131) --- lib/ash_phoenix/form/form.ex | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/ash_phoenix/form/form.ex b/lib/ash_phoenix/form/form.ex index 7bc0ea7..32a0864 100644 --- a/lib/ash_phoenix/form/form.ex +++ b/lib/ash_phoenix/form/form.ex @@ -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. @@ -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() @@ -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. @@ -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