+ Reply to Thread
Results 1 to 5 of 5
Thread: Accessing User Groups
-
06-24-2009 05:19 PM #1
Junior Member
- Join Date
- Jun 2009
- Posts
- 4
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.
-
06-24-2009 05:37 PM #2
Administrator
- Join Date
- Mar 2007
- Posts
- 385
You will want to use the CreateUserGroup method which is part of the user management web services.
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/// 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)Last edited by pwiesner; 06-24-2009 at 05:42 PM. Reason: Fixed formatting issues
-
06-24-2009 05:46 PM #3
Junior Member
- Join Date
- Jun 2009
- Posts
- 4
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.
-
06-24-2009 05:57 PM #4
Administrator
- Join Date
- Mar 2007
- Posts
- 385
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
-
06-25-2009 09:20 AM #5
Junior Member
- Join Date
- Jun 2009
- Posts
- 4
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.


LinkBack URL
About LinkBacks
Reply With Quote

