Fórumok
User Listener not updating Group relationships
Dave Weitzel, módosítva 11 év-val korábban
User Listener not updating Group relationships
Regular Member Bejegyzések: 208 Csatlakozás dátuma: 2009.11.18. Legújabb bejegyzések
I am writing my first listener extending BaseModelListener<User> .
I am in the onAfterUpdate() method monitoring a n expando field that records the "type" of user.
If that value changes I need to ensure the user is put int a specific UserGroup for that type so that the user gets the right access controls for web content and other services.
I am using exactly the same code that is used by Administrators using managing UserGroups (EditUerGroupAssignmentsAction.java):
Whichever method I call none of them will actually update the assignments and the user is not added to the group.
Can anyone advise why processing something in a Listener would be failing? To me this is a pretty standard requirement (there are three field I will be monitoring like this). It isnt as if we are updating the user from within the User Listener and creating a loop. I see no exceptions being thrown.
As a side question is there any way of monitoring to see if that field was affected in the update (like doing a beforeUpdate and then afterUpdate) so I can tell if it was changed easily?
I am in the onAfterUpdate() method monitoring a n expando field that records the "type" of user.
If that value changes I need to ensure the user is put int a specific UserGroup for that type so that the user gets the right access controls for web content and other services.
I am using exactly the same code that is used by Administrators using managing UserGroups (EditUerGroupAssignmentsAction.java):
UserGroup typeGroup = UserGroupLocalServiceUtil.getUserGroup(user.getCompanyId(), gName);
long typeGroupId = typeGroup.getPrimaryKey();
if(UserGroupUtil.containsUser(typeGroupId,userId)){
_log.info("user " + userId + " already in group " + typeGroupId);
}else{
String userIdS = String.valueOf(userId);
long[] userIds = StringUtil.split(userIdS, 0L);
try {
UserServiceUtil.addUserGroupUsers(typeGroupId, userIds);
// UserGroupUtil.addUser(typeGroupId,user);
// UserLocalServiceUtil.addUserGroupUsers(typeGroupId, userIds);
}catch (Exception e) {
_log.error(e);
}
_log.info("user " + userId + " added to group " + typeGroupId);
_log.info("testing if that is true " + UserGroupUtil.containsUser(typeGroupId,userId));
}
Whichever method I call none of them will actually update the assignments and the user is not added to the group.
Can anyone advise why processing something in a Listener would be failing? To me this is a pretty standard requirement (there are three field I will be monitoring like this). It isnt as if we are updating the user from within the User Listener and creating a loop. I see no exceptions being thrown.
As a side question is there any way of monitoring to see if that field was affected in the update (like doing a beforeUpdate and then afterUpdate) so I can tell if it was changed easily?