Alan Heywood
Alan Heywood
AEAsh Elixir
Created by Alan Heywood on 9/12/2023 in #support
Implementing token inactivity timeout with automatic expiry extend
For posterity, the token record is now provided by the plug helper (https://github.com/team-alembic/ash_authentication/pull/426/commits/2d6e563c1bc4b02a160bc2b374e61d500739b5d6), and I was able to implement session inactivity timeout in my application outside of ash_auth. Now that's done, I could possibly extract it (time allowing) and implement it in ash_auth as a new feature. Perhaps as an option on the tokens do block
26 replies
AEAsh Elixir
Created by Alan Heywood on 9/12/2023 in #support
Implementing token inactivity timeout with automatic expiry extend
I like the sound of that! Using extensions I have had to dig into the source, and this would help a lot.
26 replies
AEAsh Elixir
Created by Alan Heywood on 9/12/2023 in #support
Implementing token inactivity timeout with automatic expiry extend
Interesting thought, so extensions would never add actions, and users would need to add them in. However the extension could provide preparations / helpers to make this easy.
26 replies
AEAsh Elixir
Created by Alan Heywood on 9/12/2023 in #support
Implementing token inactivity timeout with automatic expiry extend
Yes that seems reasonable to me, thanks 🙂
26 replies
AEAsh Elixir
Created by Alan Heywood on 9/12/2023 in #support
Implementing token inactivity timeout with automatic expiry extend
That's a good point, as a work-around I could potentially set a very long token_lifetime and manage expiry myself outside ash_auth.
26 replies
AEAsh Elixir
Created by djacobs7 on 8/18/2023 in #support
How can I do a 'like' query or similarity search?
(this assumes you're using ash_postgres as your datalayer)
9 replies
AEAsh Elixir
Created by djacobs7 on 8/18/2023 in #support
How can I do a 'like' query or similarity search?
You could use an expression for this:
App.EmailHandler.User
|> Ash.Query.filter(
expr(
ilike(email, "%" <> ^search_slug <> "%") ||
ilike(name, "%" <> ^search_slug <> "%")
)
)
App.EmailHandler.User
|> Ash.Query.filter(
expr(
ilike(email, "%" <> ^search_slug <> "%") ||
ilike(name, "%" <> ^search_slug <> "%")
)
)
9 replies
AEAsh Elixir
Created by Alan Heywood on 8/16/2023 in #support
Nested aggregates and calculations
Ok good to know, and that there's a workaround 😀
13 replies
AEAsh Elixir
Created by Alan Heywood on 8/16/2023 in #support
Nested aggregates and calculations
OK this is brilliant, thank you! It gives me confidence that I can continue to build up calculations and aggregates and they will be composable.
13 replies
AEAsh Elixir
Created by Alan Heywood on 8/16/2023 in #support
Nested aggregates and calculations
Thanks, good to know it should work. I have submitted a PR that reproduces the issue here: https://github.com/ash-project/ash_postgres/pull/164
13 replies
AEAsh Elixir
Created by richaard0 on 7/3/2023 in #support
Expected at most one result but got ...
@richaard0 you can also do the following, which will define the filter on the read action for you, and return a single record instead of a list:
code_interface do
...
define :get, action: :read, get_by: [:id]
end
code_interface do
...
define :get, action: :read, get_by: [:id]
end
5 replies
AEAsh Elixir
Created by Alan Heywood on 6/8/2023 in #support
Metaprogramming with expressions
Found it 😀 – I had to use ref like this: Ash.Query.filter(ref(:id) == ^id)
3 replies
AEAsh Elixir
Created by Blibs on 6/6/2023 in #support
Run an create/update action without persisting the data
There are also generic actions available that don't persist. https://www.ash-hq.org/docs/guides/ash/latest/topics/actions#generic-actions
8 replies
AEAsh Elixir
Created by moxley on 6/6/2023 in #support
Can't get policies to work with AshGraphql
You're welcome!
27 replies
AEAsh Elixir
Created by moxley on 6/6/2023 in #support
Can't get policies to work with AshGraphql
You can create a new read action that gets the current actor from session. Here is what I have on my actor resource:
read :current_actor do
get? true
manual Ht.Actor.Actions.CurrentActorRead
end
read :current_actor do
get? true
manual Ht.Actor.Actions.CurrentActorRead
end
defmodule Ht.Actor.Actions.CurrentActorRead do
use Ash.Resource.ManualRead

@impl true
def read(_, _, _, %{actor: actor}) when not is_nil(actor) do
{:ok, [actor]}
end

def read(_, _, _, _), do: {:ok, []}
end
defmodule Ht.Actor.Actions.CurrentActorRead do
use Ash.Resource.ManualRead

@impl true
def read(_, _, _, %{actor: actor}) when not is_nil(actor) do
{:ok, [actor]}
end

def read(_, _, _, _), do: {:ok, []}
end
Then in your graphql definition:
mutations do
update :update do
identity false
read_action :current_actor
end

...
mutations do
update :update do
identity false
read_action :current_actor
end

...
27 replies
AEAsh Elixir
Created by moxley on 6/6/2023 in #support
Can't get policies to work with AshGraphql
Does your actor have a relationship to the customer already?
27 replies
AEAsh Elixir
Created by moxley on 6/6/2023 in #support
Can't get policies to work with AshGraphql
Great! Glad you got it working. Also I just ran one of my unit tests that uses GQL, and when I turn on the policy logging it does log all the policy logs with breakdown, so i'm not sure why that doesn't work for you.
27 replies
AEAsh Elixir
Created by moxley on 6/6/2023 in #support
Can't get policies to work with AshGraphql
From memory, ash_graphql does need to have permission to also :read the thing it's updating, could that be it?
27 replies