Ash Framework

AF

Ash Framework

The Elixir backend framework for unparalleled productivity. Declarative tools that let you stop wasting time. Use with Phoenix LiveView or build APIs in minutes for your front-end of choice.

Join

support

showcase

today-i-learned

redirect from oauth callback

I am currently using google oauth sign on but I want to enable return to functionality. case conn.params["returnto"] do "/" <> = return_to -> redirect(conn, to: returnto) -> redirect(conn, to: ~p"/")...

Google/OAuth Passing State

I'm implementing an invite type system, where the user can join a team with an invite code. This all works with the normal password flow (I added the invite code as an argument to the action) with a custom change to read the argument, but I'm not quite sure how to get that invite code through the various redirects for google/oauth flows, so it gets added to the google registration action as an argument. Previously in other tools and languages I've passed state back and forth through as query params on the redirect_url or state. Is there any mechanism for that with the existing strategies? I want to support both invite code and no invite codes based on the registration url. So far, I've been able to work around this by utilizing the secrets module for building up the authorization_params. If I add a state keyword, then it gets forwarded to Assent (though that is deprecated) and passed through the flow. So far, that works for passing the state back and forth between redirects! I can pass the invite code back and forth in the state (though I think I'll also want to include a nonce, and Assent will verify it)....

Ash.Policy.FilterCheck

Are we using this wrong? We have the following policy module: ```elixir def describe(_opts), do: "Organization is one of the users orgs that they are an admin of" ...

Get user's role in given organization

Users belong to multiple organizations. In some orgs they are regular users and in others they are admins. I need to add something to the User resource that takes an organization ID and returns the user's role in that organization. What would that thing be? A read action? A calculation? There's an existing calculation called organization_hierarchy that let's me get a list of organizations the user is a member of, e.g....

Controlling tenancy when joining resources in queries

I have been working on a user-facing query builder in my application. I have a resource Atlas.Tracking.Entity that I configured the multitenancy like so: ```elixir multitenancy do strategy :context...
Solution:
ok so it looks like I goofed. it's mostly working as described. I might have changed multiple things:
Atlas.Tracking.Entity |> Ash.Query.for_read(:read, %{}, tenant: client) |> Atlas.QueryParser.add_to_query(query) |> Ash.read!()
Atlas.Tracking.Entity |> Ash.Query.for_read(:read, %{}, tenant: client) |> Atlas.QueryParser.add_to_query(query) |> Ash.read!()
...

Multitenancy plug

Hi. I am trying to create a multitenant system eith AshAuthentication and AshGraphql. However, I could not get actor put in context, so the tenant too. In my case single actor can have access to multiple tenants. Let's assume there is a function get_selected_tenant(conn) and the User resource has_many Tenants (resource) with a role. I want to call PlugHelpers.put_tenant if the actor has any role in their selected tenant. Currently I could not even get the actor from conn (using :load_from_bearer plug, before my plug which will set the tenant)...

ash json api filters

``` question-filter-q_explanation{ contains [...] eq [...] greater_than [...]...

AshTrans update issue

This is for @Robert Timis. I created a new project on ash HQ and added an attribute to user: ``` attribute :about_me, :string do allow_nil? true...
Solution:
what the hell... now it works. 👺 sorry for bothering you. I don't understand what happened. 🙇 okay, maybe because I didn't create the user with embedded structs the update didn't work 🤔 might just be that. again, sorry, my bad....

ash json api

I added ash json api via mix igniter.install ash_json_api and updated resource via ...

Complex Input Flattening - Action or Code Interface?

I have a create action that takes an argument (:member, a :map) which I call change manage_relationship on a relationship, which then calls another instance of manage_relationship within that create action. This is all working beautifully, but it makes the API kind of gnarly, since I need to pass in a struct, which contains a struct, and then another struct within that, which really only have like 4 fields in total. I was hoping to "flatten" the API a bit. I know there is a way to use custom_input to transform that when creating a code interface, but the examples in the docs are fairly simple (like going from artist to artist.id). I was able to get it to work this way, so functionality wise it works. It feels weird to have this flattening logic defined with the code interface, is that the right way? I feel like this should process of going from a few args to a more complex arg should be in the action. I guess I can have a custom change action which calls Ash.Changeset.manage_relationship and builds the argument from there?...

Bad join query when using attribute tenancy

Hi! I'm noticing a major performance bug when using attribute-based multi-tenancy in our app: We have an a resource Visit that has: belongs_to :patient, Practices.Patient, public?: true ...

Using struct data in filter expressions

I think I've tried to do this a few times and have never gotten it to work properly. I have a calculation that takes a struct as an argument, and I want to use data from that struct in the expression, eg. ```elixir...
Solution:
instead of ^get_path(arg(:npc), :faction_id) it should be get_path(^arg(:npc), :faction_id)

Confirmation Token Generated on Every Google Login

I'm using Ash Authentication + Google OAuth2 and I've noticed that every time I sign in with Google - even if I've already confirmed my account - a new confirm_new_user token/email is generated. Here is my setup: ```elixir authentication do add_ons do log_out_everywhere do...
Solution:
which you can do by configuring it in the auto_confirm_actions of the confirmation strategy list

Specify graphql interface

Is there a way to specify that the generated graphql object type for a resource implements a graphql interface?

Calling policy modules "directly"

Is there a way to invoke a policy module on an "ad-hoc" manner, similar to doing Resource.my_calculation? I have this: ``` defmodule MyApp.Ash.Accounts.User.Authorizers.UserIsMemberOfOrganization do...

select fields from nested associations

I have two tables: users and user_profiles, with a one-to-one relationship. I know it might sound a bit silly, but I don't always need the information from the profile. Back to the point: I created a read action for searching that looks like this: ```elixir...

ash sqlite "get your installer" failed

sh <(curl 'https://ash-hq.org/install/mediacontrol?install=phoenix&with_args=--database%20sqlite3') \ && cd mediacontrol && mix igniter.install ash ash_phoenix ash_sqlite ash_authentication \ ash_authentication_phoenix ash_admin live_debugger tidewave --auth-strategy password --yes \ && mix ash.setup ...
Solution:
okay try again

Relationship-Based Policies

I’m building an app with a many-to-many between Users and Teams via a TeamMember join resource and need guidance writing two related authorization policies: 1. TeamMember Resource Policy In team_member.ex I’ve defined: ```elixir read :list_team_members do...
Solution:
You can use relates_to_actor_via

Full text search on a given field in ash expression?

I have a table, which emits the map like %{question_text: "filter keyword that should exist"} I am composing queries like ``` filter_expr = Ash.Expr.expr(contains(^key , ^value))...

How to Compute Permissions

What is the recommended way to design a permissions data structure—based on policies—that can serve as the source of truth for conditional UI rendering? (I am using React via Inertia)
Solution:
in Elixir-land we have Ash.can? and code interfaces have can_<name>? generated