If you click on the “getGroups” function in the editor - you’ll notice that it returns a JSDataSet, NOT a string.
If you then expand the “Security” node - you’ll notice a “JSDataSet” node that has all the functions you can do on a JSDataSet.
You would have to loop through the JSDataSet (because you can have more than one group returned) - and see if ‘doc_control’ is one of them.
Hope this helps.
I tried this code (from another post in the forum) but still get a different error. Alto the debugger does pick up userID = my group name (‘admin’) that i was logged into.
var userId = security.getUserName() // user id
var userGroupId = security.getUserGroups(userId) // dataset containg the groups authorized for the selected user
for (var i = 1; i <= userGroupId.getMaxRowIndex() ; i++)
{
var ug_id = userGroupId.getValue(i,1) // group id for the user
var ug_name = userGroupId.getValue(i,2) // group name
}
I get error message "JDBC SQL server 200 driver error. Syntax error converting the nvarcar value ‘admin’ to a column of data type int.
var userID = security.getUserId(security.getUserName())
var groupID = security.getGroupId(userID) //optional not used in this method
var userGroupId = security.getUserGroups(userID)
for (var i = 1; i <= userGroupId.getMaxRowIndex() ; i++)
{
var ug_id = userGroupId.getValue(i,1) // group id for the user
var ug_name = userGroupId.getValue(i,2) // group name
}
var userID = security.getUserId(security.getUserName())
var groupID = security.getGroupId(userID) //optional not used in this method
var userGroupId = security.getUserGroups(userID)
for (var i = 1; i <= userGroupId.getMaxRowIndex() ; i++)
{
var ug_id = userGroupId.getValue(i,1) // group id for the user
var ug_name = userGroupId.getValue(i,2) // group name
}
DOH! still doens’t look liek it works, it went back to the first error message of null values.On the debugger, the group_ID = null, group_name = null as well.
var userID = security.getUserId(security.getUserName())
var userGroups = security.getUserGroups(userID);
where userID is the current UUID for the currently logged on user, it returns the list with ALL AVAILABLE groups. If on the other hand I call getUserGroups with a different userID, it returns the correct list of groups to which the respective user is member.
I create the users from code with:
var uid = security.createUser(username, pass);
I add a user to a group with:
security.addUserToGroup(user_uuid,groupName);
which shows correctly on the “User/Group Editor”.
So, as a conclusion, getUserGroups(userID) acts as getGroups for the current user, and behaves as expected for the other users, other than the logged on one.
You are great! That was actually the problem. This is the code I used:
groups = security.getGroups().getColumnAsArray(2);
if (security.checkPassword(user_uuid,txtPassword)){
var ok = security.login(txtUsername, user_uuid, groups);
if (!ok) {
plugins.dialogs.showErrorDialog('i18n:login_error', 'i18n:login_error_msg', 'OK')
}
} else {
plugins.dialogs.showErrorDialog('i18n:login_error', 'i18n:login_error_msg', 'OK')
}
Now I have changed the login line to:
groups = security.getUserGroups(user_uuid).getColumnAsArray(2);
I thought that the groups that are passed as parameter, should be all available groups, so that the servoy login function can check access against those. Thanks for pointing me into the right direction.