michaelst
michaelst
AEAsh Elixir
Created by michaelst on 8/3/2023 in #support
warning: Changeset has already been validated for action :create.
I am getting this warning when trying to set an attribute before submitting a form, since this isn't user provided and I don't want to make the http call if this isn't going to be submitted, is there maybe another way to accomplish this as the warning says this will be an error in the future.
case AshPhoenix.Form.submit(socket.assigns.form,
params: params,
before_submit: fn changeset ->
{:ok, %{body: %{"id" => stripe_customer_id}}} = QueryDesk.Stripe.create_customer()

changeset
|> Ash.Changeset.change_attribute(:stripe_customer_id, stripe_customer_id)
|> Ash.Changeset.manage_relationship(
:users,
[socket.assigns.current_user],
type: :append_and_remove
)
end
) do
case AshPhoenix.Form.submit(socket.assigns.form,
params: params,
before_submit: fn changeset ->
{:ok, %{body: %{"id" => stripe_customer_id}}} = QueryDesk.Stripe.create_customer()

changeset
|> Ash.Changeset.change_attribute(:stripe_customer_id, stripe_customer_id)
|> Ash.Changeset.manage_relationship(
:users,
[socket.assigns.current_user],
type: :append_and_remove
)
end
) do
16 replies
AEAsh Elixir
Created by michaelst on 7/5/2023 in #support
Policy authorizer not applying to read action
I have this policy
policies do
policy always() do
authorize_if action(:create)
authorize_if expr(user_id == ^actor(:id))
end
end
policies do
policy always() do
authorize_if action(:create)
authorize_if expr(user_id == ^actor(:id))
end
end
When I use Api.read on my read action (list) it is not filtering out records from other users. Is there something else I am supposed to configure for it to filter?
7 replies
AEAsh Elixir
Created by michaelst on 7/5/2023 in #support
How to pass args to Api.read
I'm trying to accomplish something like this
Spendable.Api.read!(BudgetAllocationTemplate, action: :list, search: socket.assigns[:search])
Spendable.Api.read!(BudgetAllocationTemplate, action: :list, search: socket.assigns[:search])
for an action that looks like this
read :list do
argument :search, :string

prepare before_action(fn query ->
IO.inspect {query, arg(:search)}
end)

prepare build(sort: [:name])
end
read :list do
argument :search, :string

prepare before_action(fn query ->
IO.inspect {query, arg(:search)}
end)

prepare build(sort: [:name])
end
8 replies
AEAsh Elixir
Created by michaelst on 7/4/2023 in #support
Invalid association, not an ecto schema
I'm getting a strange compile error that I can't replicate locally, only in GitHub Actions, I'm on the latest version of everything, ash deps, elixir and erlang.
==> spendable
Compiling 5 files (.ex)
warning: invalid association `budget` in schema Spendable.BudgetAllocation: associated module Spendable.Budget is not an Ecto schema
Warning: lib/spendable/resources/budget_allocation.ex:1
==> spendable
Compiling 5 files (.ex)
warning: invalid association `budget` in schema Spendable.BudgetAllocation: associated module Spendable.Budget is not an Ecto schema
Warning: lib/spendable/resources/budget_allocation.ex:1
I'm not sure what would be different in GitHub Actions to cause this, any ideas where to look?
22 replies
AEAsh Elixir
Created by michaelst on 7/4/2023 in #support
Can't add form with auto forms
I'm getting this error when setting up with auto forms. Attempted to add a form at path: [:budget_allocations], but no create_action was configured. here is my action
update :user_update do
argument :budget_allocations, {:array, :map}
change manage_relationship(:budget_allocations, type: :append_and_remove)
end
update :user_update do
argument :budget_allocations, {:array, :map}
change manage_relationship(:budget_allocations, type: :append_and_remove)
end
and the form
form =
transaction
|> AshPhoenix.Form.for_update(:user_update,
api: QueryDesk.Api,
forms: [auto?: true]
)
|> to_form()
|> AshPhoenix.Form.add_form([:budget_allocations])
form =
transaction
|> AshPhoenix.Form.for_update(:user_update,
api: QueryDesk.Api,
forms: [auto?: true]
)
|> to_form()
|> AshPhoenix.Form.add_form([:budget_allocations])
108 replies
AEAsh Elixir
Created by michaelst on 6/30/2023 in #support
Action argument shows up as JsonString in graphql schema
I have this argument referencing another resource
argument :credentials, {:array, Credential}
change manage_relationship(:credentials, type: :direct_control)
argument :credentials, {:array, Credential}
change manage_relationship(:credentials, type: :direct_control)
however this argument is not showing the inputs that are available, is there a specific way to configure this so the input shows up correct in the schema?
4 replies
AEAsh Elixir
Created by michaelst on 6/24/2023 in #support
How to remove id as input option on create actions
My create actions for graphql are showing id as an option for input, is there a way to disable that? It breaks with the codegen library as it is sending id as an empty string
4 replies
AEAsh Elixir
Created by michaelst on 6/23/2023 in #support
Allow writing values but not reading them back in graphql
I have sensitive fields that I want to allow setting in create/update but don't want them to be read back. I was able to make them return null with this
read :non_sensitive_info do
prepare build(deselect: [:cacertfile])
end
read :non_sensitive_info do
prepare build(deselect: [:cacertfile])
end
however I would like the schema to reflect those can't be selected, is there a way to do this? hide_fields also removes them from create/update
8 replies
AEAsh Elixir
Created by michaelst on 6/21/2023 in #support
How to manage belongs_to with phoenix form
Is there an example for how to manage belongs_to resource with phoenix form
61 replies
AEAsh Elixir
Created by michaelst on 6/21/2023 in #support
Don't show existing value of form field
I have a sensitive value that I don't want displayed again, but I want an input to be able to update the value. Is there an option that exists for that?
64 replies
AEAsh Elixir
Created by michaelst on 6/17/2023 in #support
How to write complex query with fragments
I'm trying to write this query with Ash
select DATE(inserted_at), round(avg(percentage), 2)
from coverage
where "owner" = 'coverbot-io' and "repo" = 'coverbot' and is_for_default_branch
group by 1
order by 1;
select DATE(inserted_at), round(avg(percentage), 2)
from coverage
where "owner" = 'coverbot-io' and "repo" = 'coverbot' and is_for_default_branch
group by 1
order by 1;
I've gotten this far but I'm getting an error about fragment/1 being undefined and also not sure how to implement the group by.
Coverage
|> Ash.Query.filter(owner == ^owner and repo == ^repo and is_for_default_branch)
|> Ash.Query.select([fragment("DATE(inserted_at)"), fragment("ROUND(AVG(percentage), 2)")])
|> Ash.Query.sort([1])
|> Coverbot.Api.read!()
Coverage
|> Ash.Query.filter(owner == ^owner and repo == ^repo and is_for_default_branch)
|> Ash.Query.select([fragment("DATE(inserted_at)"), fragment("ROUND(AVG(percentage), 2)")])
|> Ash.Query.sort([1])
|> Coverbot.Api.read!()
24 replies