Return users from a role?

Last post 07-18-2008, 7:03 AM by DavidL. 4 replies.
Sort Posts: Previous Next
  •  07-16-2008, 2:00 AM 24890

    Return users from a role?

    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!!
     

  •  07-16-2008, 3:20 AM 24893 in reply to 24890

    Re: Return users from a role?

    Ultimate what I am trying to achieve is check if a given name exits in that role.
  •  07-16-2008, 4:13 AM 24894 in reply to 24893

    Re: Return users from a role?

    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));
                            }


                        }

                    }
                }

     

  •  07-18-2008, 6:15 AM 24961 in reply to 24894

    Re: Return users from a role?

    Thanks!! That helped a lot!!!!
  •  07-18-2008, 7:03 AM 24963 in reply to 24961

    Re: Return users from a role?

    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.
    The statements and opinions made in my postings are my own, and do not reflect the opinions of SourceCode Technology Holdings, Inc. or its subsidiaries. All information is provided as is with no warranties, express or implied, and grants no rights or licenses.
View as RSS news feed in XML