How to specify actor in AshAdmin?

I'd like to use it to (temporarily during development) trigger some actions, but the actions have policies limiting to the relevant user. I don't mind that, I don't need access to EVERYTHING in the admin. But what is the intended way for me to set my actor correctly?
Solution:
You can designate some resources as actor resources ```elixir admin do actor? true end...
Jump to solution
17 Replies
ZachDaniel
ZachDaniel5d ago
by default it doesn't run authorization AFAIK so policies shouldn't prevent you from doing things in AshAdmin
Solution
ZachDaniel
ZachDaniel5d ago
You can designate some resources as actor resources
admin do
actor? true
end
admin do
actor? true
end
and you can then go log in as those users
ZachDaniel
ZachDaniel5d ago
by navigating to them and clicking the key icon
Shawn McCool
Shawn McCoolOP5d ago
I see, that makes sense. I assumed that was the problem, but what's actually happening is I fill in my form for adding a new resource, a create action. And when it comes to the text field for user_id, i copy / paste the uuid from the database into the field. Then the user_id is rejected on submit.
ZachDaniel
ZachDaniel5d ago
Not really following sorry
Shawn McCool
Shawn McCoolOP5d ago
It's ok, I'm just not understanding why it isn't letting me paste in a UUID for the user_id field in an admin form. It's the form refreshes, shows an error saying "user_id is required", but all other data validates correctly.
ZachDaniel
ZachDaniel5d ago
Sorry, I just don't think I really understand what you're saying yet. Are you saying copy/pasting isn't working? There is no field for it?
Shawn McCool
Shawn McCoolOP5d ago
Here's the form before.
No description
Shawn McCool
Shawn McCoolOP5d ago
Here's when I submit it.
No description
ZachDaniel
ZachDaniel5d ago
what happens if you like backspace the last letter and then type it back in? Just trying to see if it something weird with the form state or what Also does the action itself do anything to manipulate user_id in some way? does it, for instance, use relate_actor to connect the current user to the thing being created?
Shawn McCool
Shawn McCoolOP5d ago
user_id is required to user_id is invalid
create :add do
accept [
:user_id,
:google_user_id,
:google_account_email,
:scopes,
:access_token,
:refresh_token,
:added_at,
:expires_at
]

change set_attribute(:user_id, actor(:id))
change DataHoard.Accounts.GoogleAccount.Changes.SetExpiresAt
change DataHoard.Accounts.GoogleAccount.Changes.CleanScopes

validate present([:google_user_id, :access_token, :expires_at])
end
create :add do
accept [
:user_id,
:google_user_id,
:google_account_email,
:scopes,
:access_token,
:refresh_token,
:added_at,
:expires_at
]

change set_attribute(:user_id, actor(:id))
change DataHoard.Accounts.GoogleAccount.Changes.SetExpiresAt
change DataHoard.Accounts.GoogleAccount.Changes.CleanScopes

validate present([:google_user_id, :access_token, :expires_at])
end
ZachDaniel
ZachDaniel5d ago
change set_attribute(:user_id, actor(:id))
change set_attribute(:user_id, actor(:id))
that is setting user_id to nil because there is no actor
Shawn McCool
Shawn McCoolOP5d ago
ah hah change set_attribute(:user_id, ^arg(:user_id)) probably something more like this then again, i can just remove that
ZachDaniel
ZachDaniel5d ago
is this meant to only be done in admin? or what is this action actually used for in real life?
Shawn McCool
Shawn McCoolOP5d ago
no, it's done through user-led oauth
ZachDaniel
ZachDaniel5d ago
So the alternative would be for you to do the actor configuration I mentioned above click into that actor and authenticate as them and then call that action
Shawn McCool
Shawn McCoolOP5d ago
Oh I see, I understand that comment now Great it works, thanks.

Did you find this page helpful?