Trying to retrieve a list of roles for a given user. Doing something wrong obviously as this call returns back every role in my system.
var roles = Apis.Get<IRoles>().List(new RolesListOptions { UserId = user.Id });
Trying to retrieve a list of roles for a given user. Doing something wrong obviously as this call returns back every role in my system.
var roles = Apis.Get<IRoles>().List(new RolesListOptions { UserId = user.Id });
Try:
var roles = Apis.Get<IRoles>().List(new RolesListOptions { UserId = user.Id, Include = "user" });
Thanks Mathew D'Amico - that worked.
Mathew D'Amico (mdamico) - Looks like I asked this on v9 - on V12 this code seems off...I'm getting b ack a redundant list of what appears to be roles within a group as well, mixed-in with my system roles. Here's an example string list of roles that comes back with this call for a user... any idea how I can just get back system roles?
You can see I get back "Members" and "owners" multiple times, but I really only want "Administrators" and "Staff" as those are defined roles in the admin and not group membership roles...
Administrators Members Members Members Owners Staff Members Owners Owners Members Owners Owners Owners Owners Owners Owners Owners Owners Owners Owners
Ben Tiedt any ideas here?
You are getting back the correct list of all site roles and group roles a member belongs too. We don't have an option to only get Site roles in that API. You should be able to filter the list and only select the roles that do not have a group Id set (or maybe set to 0).
Ok...can I do that with the API or would I need to loop through the results
You will need to filter the result from the API call. It allows and defaults to a page size of 9999. So a single call should get everything, unless you have an extreme use case with users being in 10,000 plus roles.
var roles = Apis.Get<IRoles>().List(new RolesListOptions { UserId = user.Id, Include = "user" }).Select(r => r.GroupId == 0);
You will need to filter the result from the API call. It allows and defaults to a page size of 9999. So a single call should get everything, unless you have an extreme use case with users being in 10,000 plus roles.
var roles = Apis.Get<IRoles>().List(new RolesListOptions { UserId = user.Id, Include = "user" }).Select(r => r.GroupId == 0);