Script-changes to userprofile are not visible in profile history

Any issue about Cyclos 4 scripting and Webservices

Moderators: hugo, alexandre, rmvanarkel

Post Reply
sandrab
Posts: 13
Joined: Tue Sep 11, 2018 8:26 am

Script-changes to userprofile are not visible in profile history

Post by sandrab » Tue Sep 11, 2018 9:27 am

Hi,

When a groovy script changes the contents of a userprofile field of a Cyclos user, this is not visible in the profile history of the user. Is it possible to configure this somehow?

Thanks,
Sandra

Using Cyclos 4.9.1

luis
Posts: 179
Joined: Fri Feb 17, 2006 11:01 am

Re: Script-changes to userprofile are not visible in profile history

Post by luis » Wed Sep 12, 2018 8:24 am

For this you have to use the regular save of the UserService, through DTOs, not directly manipulating the entity.
Example:

Code: Select all

def dto = userService.load(userId)
def fields = scriptHelper.wrap(dto)
fields.fieldName = value
userService.save(dto)
Luis Fernando Planella Gonzalez
Cyclos development team

sandrab
Posts: 13
Joined: Tue Sep 11, 2018 8:26 am

Re: Script-changes to userprofile are not visible in profile history

Post by sandrab » Thu Sep 13, 2018 7:17 am

Works indeed, this is nice to know. Thanks Luis!

sandrab
Posts: 13
Joined: Tue Sep 11, 2018 8:26 am

Re: Script-changes to userprofile are not visible in profile history

Post by sandrab » Tue Sep 18, 2018 8:32 am

While this works great when the code is in an extension script on validating or creating a user, or when using the 'Run as' script functionality, we would like to use this in a custom web service script as well. We need this script to run as Guest. Does that mean we can not use userService.load() in this case?

When I try, the userService.load() results in an exception:

org.cyclos.impl.access.ScriptSessionData cannot be cast to org.cyclos.impl.access.GuestSessionData

The code used:

Code: Select all

String userName = 'user_x'	// Adjust this to an existing username.
try{
	def user = conversionHandler.convert(User, userName)
	def usrDTO = userService.load(user.id)
	def usr = scriptHelper.wrap(usrDTO)
	usr.email = "tester@mysite.com"
	userService.save(usrDTO)
	return "Saved in user ${userName}."
} catch(Exception e){
	return "\nException: ${e.getMessage()}"
}

rmvanarkel
Posts: 240
Joined: Tue Oct 05, 2010 1:14 pm

Re: Script-changes to userprofile are not visible in profile history

Post by rmvanarkel » Tue Sep 18, 2018 10:34 am

Dear Sandra,

Sorry for the inconvenience, at this moment it is not possible to run this script as guest, we will make sure this works in Cyclos 4.11.

Thanks for your patience!

sandrab
Posts: 13
Joined: Tue Sep 11, 2018 8:26 am

Re: Script-changes to userprofile are not visible in profile history

Post by sandrab » Thu Nov 22, 2018 11:17 am

I can confirm it works, now we are using Cyclos 4.11.1.

Thanks!
Sandra

Post Reply