I want to create an administration view where I list all user accounts with one or more of a set of custom roles. Is there an easy way of combining/querying Users or Roles in a combination so that I can get that to happen? The User API does not seem to allow for more than one role to be queried at once. Same seems to be the situation using Codeless Server Code.
My goal is to end up with a list showing users, some key info fields and their roles.
According to the following API you can find users by one role in one request
https://backendless.com/docs/js/users_user_roles.html
If there are not many roles you can load for all of them and then merge these lists into a single one.
How can I merge these lists in a reliable manner, when the users can have multiple roles? I want to display them in a list setup like:
Somebody - Admin, User, Editor
Anotherbody - User, Editor
Thirdbody - User
Lastbody - Admin
Is it better to gra a list of all users, and then iterate over each user grabbing their roles and only show the ones with one or more custom roles?
1 Like
Hello @Egil_Helland
If I understand Vova correctly it looks like
But it work only for custom roles. And block “Get user by role” can load no more then 100 users. To load all users you should create a function like this:
How to set pageSIze > 100 in the "Load Table Objects" block
Also, if you can load roles by user id, there will be a bad performance - for every user one request. I think it is ok if you are going to display users with paging.
I going to discuss with team if we can add ability to load users with roles.
Regards
1 Like
Thanks @viktor.liablin for this. It certainly is doable the way you describe/envision.
This means though that I have to give all users a custom role, as the Get users by role does not support a blank/empty role name to get users without any custom roles…
Just to follow up on this, in case someone else bumps into this problem, I have now found a solution as follows:
- I loop through and fetches users in batches per role, so that I have a list of all users. I use the “load rules=true” setting in the Get users by role function to also get roles output. This means I can get duplicate user accounts listed, which I don’t want.
- To get a list of unique accounts, I filter the result with a custom function to get back only the ones that are unique. This is how the function looks:
A bit cumbersome, but it seems to be the only good way as long as you have to fetch users roles this way.