Checkbox Forums

Help
+ Reply to Thread
Results 1 to 5 of 5
  1. #1
    noneerror is offline Junior Member
    Join Date
    Jun 2009
    Posts
    4

    Default Accessing User Groups

    Hi,

    Going through the API, it is easy to see how to create a new user and assign roles to that user. I want to programmatically create a new group and assign users to that group. What API calls do I use to perform these actions. The API says that the Checkbox.User namespace is the "Base namespace for all functionality related to user or user group management", but I can see no further reference to group management at all in the UserManager (the only class in the namespace) methods. All directions would be greatly appreciated.

    Cheers,

    Jeremy.

  2. #2
    pwiesner is offline Administrator
    Join Date
    Mar 2007
    Posts
    385

    Default

    You will want to use the CreateUserGroup method which is part of the user management web services.
    /// Create a user group
    /// contextToken - Guid context identifying the requesting user.
    /// userGroupName - Name of the new group.
    /// userGroupDescription - Description of the new group.
    /// returns - ID of the newly created group. If the value is negative, a group was not successfully created.
    public int CreateUserGroup(Guid contextToken, string userGroupName, string userGroupDescription)
    This method is can be found in the UserManagmentServiceProxy class. Additional information about this class can be found in \DevKit_AddOn\Checkbox\Documentation\Checkbox_WebS ervicesAPI.chm
    Last edited by pwiesner; 06-24-2009 at 05:42 PM. Reason: Fixed formatting issues

  3. #3
    noneerror is offline Junior Member
    Join Date
    Jun 2009
    Posts
    4

    Default Which API?

    Overall, which API is recommended for use with web applications wanting to integrate with Checkbox? The web.service API or the API exposed through the assemblies? I had started off going directly through to the assemblies, but will change if I am not doing things the recommended way.

    Thanx for your quick reply.

    Cheers,

    Jeremy.

  4. #4
    pwiesner is offline Administrator
    Join Date
    Mar 2007
    Posts
    385

    Default

    I apologize. I missed that you were using the direct API. You can use either the direct API or the web services it is your choice. That being said I think you will find that the web services are easier to work with but may not be as powerful. Originally the web services only supported the management of users and groups. Today you can also manage invitations, reports and surveys using the web services.

    In the case of the direct API you will want to use the Checkbox.Users.Group.cs class. Below is simple example of a method designed to create a user group.

    public static int CreateUserGroup(Guid guid, string userGroupName, string userGroupDescription)
    {
    ExtendedPrincipal callingPrincipal = Security.AuthorizeUserContext(guid, "Group.Create");

    if (Utilities.IsNullOrEmpty(userGroupName))
    {
    throw new Exception("No group name specified.");
    }

    //Trim the name
    userGroupName = userGroupName.Trim();

    if (Group.GetGroup(userGroupName) != null)
    {
    throw new UserGroupAlreadyExistsException(userGroupName);
    }

    Group g = Group.CreateGroup(userGroupName, userGroupDescription);

    if (g != null)
    {
    Group.Commit(g, callingPrincipal);
    return g.ID.Value;
    }

    return -1;
    }

    The first example I provided was incomplete. I have included the method that the web services delegates to.
    Last edited by pwiesner; 06-24-2009 at 06:04 PM. Reason: Corrected an error in the example

  5. #5
    noneerror is offline Junior Member
    Join Date
    Jun 2009
    Posts
    4

    Default Thank You

    Thanx for your help. I see the Group object and the methods/properties that it exposes. Looks like everything I need is there.

    Cheers,

    Jeremy.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

SEO by vBSEO 3.5.0