Access user groups and users

I assumed that an user group is connected only to one project. Therefore jRQL let you access user groups from an instance of class Project only. Later I learned, that RedDot CMS treats user groups even outside of project scope.

Let’s focus to get a user group from a project. As usual jRQL offers the access by GUID or name:

String logonGuid="6EB1C39F6A584ABBB9DBB6D36E27FAD7";
String sessionKey="36E1E61495654EB8A4505AC604925FCA";
String projectGuid="73671509FA5C43ED8FC4171AD0298AD2";

CmsClient client = new CmsClient(logonGuid);
Project project = client.getProject(sessionKey, projectGuid);

UserGroup userGroup1 = project.getUserGroupByGuid(“userGroupGuid”);
UserGroup userGroup2 = project.getUserGroupByName(“userGroupName”);

In addition you get a list of user groups as follows:

List<UserGroup> userGroups1 = project.getUserGroups();
List<UserGroup> userGroups2 = project.getUserGroupsNameStartsWith("area-");

The last method getUserGroupsNameStartsWith() is quite handy to get only some groups. I use prefixes to divide  user groups by target group: groups for administrator rights and groups for author rights.

The following basic methods are available on a user group:

boolean contains2 = userGroup1.contains(“user name”);
User user = client.getUserByName(“userName”);
boolean contains2 = userGroup1.contains(user);
userGroup2.addUser(user);

jRQL offers 2 contains() methods to check, if a user is within a user group, one be user name and one by the user itself. In addition you can change the user group and assign a given user to it (last line).

From a user group you can easily get all assigned users and list basic user information.

List<User> users = userGroup1.getUsers();
for (User user : users) {
System.out.println(user.getName());
System.out.println(user.getFullname());
System.out.println(user.getDescription());
System.out.println(user.getEmailAddress());
}

In addition you can use the following methods to get detailed information about a user.

user.isAdministratorInCurrentProject();
user.isAuthorInCurrentProject();
user.isSiteBuilderInCurrentProject();
user.isVisitorInCurrentProject();

user.isActive();
user.logout();
user.isDirectEditCtlAndMouse();
user.isDirectEditMouseOnly();
user.getPublishableProjectVariants();

The top group check the licence the user has in the current project. The method isActive() returns true, if the user is currently connected to RedDot CMS, you can logout() it.

Next 2 methods check for a user property regarding direct edit mode. And the last getPublishableProjectVariants() returns only the project variants the user has the right to publish; means he will see in his Publish page dialog.

For further details (e.g. how to edit a user) please check the javadoc for user group and user.

Advertisements
Post a comment or leave a trackback: Trackback URL.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: