How to set the actor within an action

Hey everyone! Currently, we have an action that takes a user as an argument:
create :upsert_meeting_prep_action do
...

argument :user, :struct do
allow_nil? false
end

...
end
create :upsert_meeting_prep_action do
...

argument :user, :struct do
allow_nil? false
end

...
end
I know that I can use change relate_actor(:user) to set the actor but that would require me to update the function signature everywhere. Is it possible to set the actor within an action using one of the available arguments? Thanks!
4 Replies
ZachDaniel
ZachDaniel•3mo ago
It is possible, but could you tell me more about what you're trying to accomplish?
Jimbo Slice
Jimbo SliceOP•3mo ago
Hey Zach! We recently created an Ash.Resource.Change module to have additional scoping for some of our resources. In order for that to work correctly, it requires an actor via
def change(changeset, _opts, context) do
user_id = context.actor.id
...
def change(changeset, _opts, context) do
user_id = context.actor.id
...
which is why I want to set the actor.
ZachDaniel
ZachDaniel•3mo ago
Gotcha. So, that may not work the way you want to even if you do set the actor into the changeset's private context 🤔 Which is something you can do, but I don't think it would get set into the context of subsequent changes My suggestion is to "figure something else out", since setting the actor isn't really true, i.e it wasn't that user who initiated the change. i.e use arguments or changeset context instead
Jimbo Slice
Jimbo SliceOP•3mo ago
sounds good. thanks!

Did you find this page helpful?