-
Type: Improvement
-
Status: Resolved
-
Priority: Minor
-
Resolution: Won't Fix
-
Affects Version/s: None
-
Fix Version/s: None
-
Component/s: Automation, User Profile / User Manager
-
Tags:
There seems to be no easy/direct way to get the current user when running an automation script triggered by the loginSuccess event.
i.e. CurrentUser.getActingUser() is null
This script provides a workaround, but is definitely less than obvious:
function run(input, params) { Console.info("script log_user_js:"); Console.info(" ctx : '" + ctx + "' (" + typeof(ctx) + ")"); if (ctx && ctx.Event) { Console.info(" event : '" + ctx.Event + "' (" + typeof(ctx.Event) + ")"); Console.info(" name : '" + ctx.Event.name + "' (" + typeof(ctx.Event.name) + ")"); } var actingUser; var eventCtx; var principal; var UserManager; UserManager = Fn.getUserManager(); Console.info(" UserManager: '" + UserManager + "'"); eventCtx = ctx.Event.getContext(); Console.info(" eventCtx : '" + eventCtx + "'"); // org.nuxeo.ecm.core.api.impl.UserPrincipal principal = eventCtx.getPrincipal(); Console.info(" principal : '" + principal + "'"); actingUser = principal.getActingUser(); Console.info(" actingUser : '" + actingUser + "'"); // org.nuxeo.ecm.platform.usermanager.NuxeoPrincipalImpl principal = UserManager.getPrincipal(actingUser); Console.info(" principal : '" + principal + "'"); Console.info(" firstName : '" + principal.getFirstName() + "'"); Console.info(" lastName : '" + principal.getLastName() + "'"); Console.info(" email : '" + principal.getEmail() + "'"); return input; }