Jason
Jason
AEAsh Elixir
Created by Jason on 9/17/2023 in #support
Filter check is returning an error tuple, rather than filtering rows.
Will do. Thanks!
23 replies
AEAsh Elixir
Created by Jason on 9/17/2023 in #support
Filter check is returning an error tuple, rather than filtering rows.
Let me know if there is an easier, more recommended Ash way to do this.
23 replies
AEAsh Elixir
Created by Jason on 9/17/2023 in #support
Filter check is returning an error tuple, rather than filtering rows.
router
ash_authentication_live_session :authenticated_tasks_view,
# live_user_optional
on_mount: {TaskApp.LiveUserAuth, :task_visible_to_live_user} do
ash_authentication_live_session :authenticated_tasks_view,
# live_user_optional
on_mount: {TaskApp.LiveUserAuth, :task_visible_to_live_user} do
<live_user_auth.ex>
def on_mount(
:task_visible_to_live_user,
params,
_session,
socket
) do
task =
TaskApp.Tasks.Task.get!(task_id,
load: [
editable_by: %{user_id: current_user.id},
visible_to: %{user_id: current_user.id}
]
)
cond do
not task.visible_to ->
{:half, redirect(socket, to: ~p"/unauthorized/")}

def on_mount(
:task_visible_to_live_user,
params,
_session,
socket
) do
task =
TaskApp.Tasks.Task.get!(task_id,
load: [
editable_by: %{user_id: current_user.id},
visible_to: %{user_id: current_user.id}
]
)
cond do
not task.visible_to ->
{:half, redirect(socket, to: ~p"/unauthorized/")}

23 replies
AEAsh Elixir
Created by Jason on 9/17/2023 in #support
Filter check is returning an error tuple, rather than filtering rows.
Then that is also used for routing as well. For instance, if an unauthorized user tries to access a url that requires authorization, the condition defined as calculations is used to determine it is an unauthorized access and route them to the appropriate page.
23 replies
AEAsh Elixir
Created by Jason on 9/17/2023 in #support
Filter check is returning an error tuple, rather than filtering rows.
Invisible was a simplified example. The real one is more complex like visible if admin, or author, or autorized by author, etc. It becomes pretty complex pretty quickly.
23 replies
AEAsh Elixir
Created by Jason on 9/17/2023 in #support
Filter check is returning an error tuple, rather than filtering rows.
Yeah, I read it from the doc.
23 replies
AEAsh Elixir
Created by Jason on 9/17/2023 in #support
Filter check is returning an error tuple, rather than filtering rows.
Ahhh.... makes perfect sense 🙂 Thank you. I have been doing these filtering through making calculations (such as calculate :invisible, calculate: :is_author, etc) and then mixing and matching them in read actions. It appears that using policies can replace them in many cases, but it feels that having calculations will provide more flexibility because it can be used elsewhere (e.g., to show visibility of a task, rather than filtering invisible ones out altogether). Is there a useful rule of thumb in terms of where to define filters, for instance, policies vs. calculation+action?
23 replies
AEAsh Elixir
Created by Jason on 9/17/2023 in #support
Filter check is returning an error tuple, rather than filtering rows.
defmodule TaskApp.Checks.Invisible do

use Ash.Policy.FilterCheck

require Ash.Query
import Ash.Filter.TemplateHelpers, only: [actor: 1]

def filter(_options) do

Ash.Query.expr(visibility != 1)
end
end
defmodule TaskApp.Checks.Invisible do

use Ash.Policy.FilterCheck

require Ash.Query
import Ash.Filter.TemplateHelpers, only: [actor: 1]

def filter(_options) do

Ash.Query.expr(visibility != 1)
end
end
23 replies
AEAsh Elixir
Created by Jason on 9/13/2023 in #support
Resource MyApp.Accounts.FriendLink is not present in any known Ash.Api module.
Oddly enough, I'm not getting that warning anymore. I didn't even change anything 🙂
12 replies
AEAsh Elixir
Created by Jason on 9/13/2023 in #support
Resource MyApp.Accounts.FriendLink is not present in any known Ash.Api module.
on compile
12 replies
AEAsh Elixir
Created by Jason on 9/13/2023 in #support
Resource MyApp.Accounts.FriendLink is not present in any known Ash.Api module.
Trying resource FriendLink now.
12 replies
AEAsh Elixir
Created by Jason on 9/13/2023 in #support
Resource MyApp.Accounts.FriendLink is not present in any known Ash.Api module.
Yes, registry Registry is there.
12 replies
AEAsh Elixir
Created by Jason on 9/10/2023 in #support
(Postgrex.Error) ERROR 42P18 (indeterminate_datatype) could not determine data type of parameter $1
This works!! So the concatenation was the key. Thanks!
|> Ash.Query.filter(fragment("? ~* ('^'||?::text||'\\d+')", task_id, ^prefix))
|> Ash.Query.filter(fragment("? ~* ('^'||?::text||'\\d+')", task_id, ^prefix))
17 replies
AEAsh Elixir
Created by Jason on 9/10/2023 in #support
(Postgrex.Error) ERROR 42P18 (indeterminate_datatype) could not determine data type of parameter $1
Then I get " (Postgrex.Error) ERROR 42601 (syntax_error) syntax error at or near ""
WHERE ((t0."task_id"::text ~* $1::text||+)) ORDER BY t0."task_id" DESC LIMIT $2 ["T", 1]
WHERE ((t0."task_id"::text ~* $1::text||+)) ORDER BY t0."task_id" DESC LIMIT $2 ["T", 1]
|> Ash.Query.filter(fragment("(? ~* ?::text||\d+)", task_id, ^prefix))
17 replies
AEAsh Elixir
Created by Jason on 9/10/2023 in #support
(Postgrex.Error) ERROR 42P18 (indeterminate_datatype) could not determine data type of parameter $1
If I run where task_id::text ~* '^T::text\d+' in pgadmin, it returns nothing because ::text is treated as part of the regex pattern. That makes me think type(^prefix, :string)` is not going to work, even if the error message goes away.
17 replies
AEAsh Elixir
Created by Jason on 9/10/2023 in #support
(Postgrex.Error) ERROR 42P18 (indeterminate_datatype) could not determine data type of parameter $1
Same error with the query repeating ::text 3 times.
WHERE (t0."task_id"::text ~* '$1::text::text::text\d+') ORDER BY t0."task_id" DESC LIMIT $2 ["T", 1]
WHERE (t0."task_id"::text ~* '$1::text::text::text\d+') ORDER BY t0."task_id" DESC LIMIT $2 ["T", 1]
17 replies
AEAsh Elixir
Created by Jason on 9/10/2023 in #support
(Postgrex.Error) ERROR 42P18 (indeterminate_datatype) could not determine data type of parameter $1
It translates to this SQL statement, and I still get "could not determine data type of parameter $1"
WHERE (t0."task_id"::text ~* '$1::text::text\d+') ORDER BY t0."task_id" DESC LIMIT $2["T", 1]

dbg #=>
filter: #Ash.Filter<fragment(
{:raw, ""},
{:expr, task_id},
{:raw, " ~* '"},
{:expr, type("T", :string, [])},
{:raw, "\\d+'"}
)>
WHERE (t0."task_id"::text ~* '$1::text::text\d+') ORDER BY t0."task_id" DESC LIMIT $2["T", 1]

dbg #=>
filter: #Ash.Filter<fragment(
{:raw, ""},
{:expr, task_id},
{:raw, " ~* '"},
{:expr, type("T", :string, [])},
{:raw, "\\d+'"}
)>
17 replies
AEAsh Elixir
Created by Jason on 6/25/2023 in #support
no route found for POST /admin
after getting ash_admin, authentication, and authentication_phoenix from github.
73 replies
AEAsh Elixir
Created by Jason on 6/25/2023 in #support
no route found for POST /admin
It's working!!
73 replies
AEAsh Elixir
Created by Jason on 6/25/2023 in #support
no route found for POST /admin
* ash 2.13.2 ([email protected]:ash-project/ash.git) (mix)
locked at b9abe2a
ok
* ash_admin 0.8.1 (Hex package) (mix)
locked at 0.8.1 (ash_admin) 1f4f7eca
ok
* ash_authentication 3.11.6 (Hex package) (mix)
locked at 3.11.6 (ash_authentication) 506b72ac
ok
* ash_authentication_phoenix 1.7.2 (Hex package) (mix)
locked at 1.7.2 (ash_authentication_phoenix) 76edd8c4
ok
* ash_phoenix 1.2.14 (Hex package) (mix)
locked at 1.2.14 (ash_phoenix) 1a801b31
ok
* ash_postgres 1.3.30 (Hex package) (mix)
* ash 2.13.2 ([email protected]:ash-project/ash.git) (mix)
locked at b9abe2a
ok
* ash_admin 0.8.1 (Hex package) (mix)
locked at 0.8.1 (ash_admin) 1f4f7eca
ok
* ash_authentication 3.11.6 (Hex package) (mix)
locked at 3.11.6 (ash_authentication) 506b72ac
ok
* ash_authentication_phoenix 1.7.2 (Hex package) (mix)
locked at 1.7.2 (ash_authentication_phoenix) 76edd8c4
ok
* ash_phoenix 1.2.14 (Hex package) (mix)
locked at 1.2.14 (ash_phoenix) 1a801b31
ok
* ash_postgres 1.3.30 (Hex package) (mix)
73 replies