Return users from a role?


Badge +2

Hi all!

Ok, I have created a new role called Supervisor in the workspace and have added 3 users to that role. What I want to be able to do now, is return the names of those users that belong to the Supervisor role?

 

Any help on how to go about this will be greatly appreciated!!

 

Thanks!!
 


4 replies

Badge +2
Ultimate what I am trying to achieve is check if a given name exits in that role.
Badge +1

Hi,


This is how we getting it...hope it helps.


 The code basically populates a dropdown box with users for a specific role...


 public void GetUserRoleDropDownList(string k2Connectionstring, string role, ref DropDownList ddlReasignUser)
        {
            if (k2Connectionstring != "" && role != "")
            {


               XmlDocument doc;
               XmlElement root;

                SourceCode.Security.UserRoleManager.Management.UserRoleManager sm = new SourceCode.Security.UserRoleManager.Management.UserRoleManager();


                sm.CreateConnection();
                sm.Connection.Open(k2Connectionstring);
                SourceCode.Security.UserRoleManager.Management.Role[] RoleList = sm.GetRoles(role);


                foreach (SourceCode.Security.UserRoleManager.Management.Role Role in RoleList)
                {


                    doc = new XmlDocument();
                    doc.LoadXml(Role.GetData());
                    XmlElement root = doc.DocumentElement;
                    XmlNodeList nodes = root.SelectNodes("/role/include/users"); // You can filter elements


                    foreach (XmlNode node in nodes)
                    {


                        XmlNodeList innerNodes = node.SelectNodes("user");
                        foreach (XmlNode innerNode in innerNodes)
                        {
                            string userName = innerNode.Attributes[0].Value;


                            //Remove(0,3) needed for K2: security label trimming.
                            ddlReasignUser.Items.Add(userName.Remove(0, 3));
                        }



                    }


                }
            }


 

Badge +2
Thanks!! That helped a lot!!!!
Badge +11
You can also do this without code by connecting a SmartObject to the User Role Manager Service.  In the User ServiceObject, invoke the Get Role Users method and pass in the name of a role to get back a list of the members.

Reply