Rails 6.0
Users belong to department and departments belong to organization.
We set up a user tag to filter by organization ($currentUser.tags.organization). This works well to scope collections but I also need to use it in forms.
When creating a new user via a smart action, I need to filter the department collection in the select list to show only those departments belonging to the current user’s organization, not all departments in the db.
Ideally if I had access to the current user or $currentUser.tags.organization in forest_liana/collections/user.rb, then I could use the on load hook to filter the collection.
I guess my question is what is the best way to do this? The select list in the regular forms also need to filter by departments belonging only to the current user’s organization.
Edit:
In forest/users_controller.rb I have access to @jwt_decoded_token, so I was able to get the organization name like so @jwt_decoded_token[“tags”][0][“value”].
Unfortunately I haven’t been able to figure out if there is a similar JWT token accessible in forest_liana/collections/user.rb when a smart action is triggered?
Does context[:user] have access to the current user’s tags? I have set my user’s tags, so I assumed that it would have access to the tags when I am trying to add a user via a smart action.
In the standard form, say for adding users, it would be great if there was a way to filter the collections from a relationship. For example, only listing departments that belong to the current user’s organization.