Skip to content

Instantly share code, notes, and snippets.

@jmakeig
Created April 21, 2017 20:25
Show Gist options
  • Select an option

  • Save jmakeig/7399d5af538f7974ae20d4d108c5ef02 to your computer and use it in GitHub Desktop.

Select an option

Save jmakeig/7399d5af538f7974ae20d4d108c5ef02 to your computer and use it in GitHub Desktop.
Invoke a MarkLogic JavaScript function as a particular user
'use strict';
/** Invokes any function as a specific user */
const asUser = (fn, user) =>
xdmp.invokeFunction(fn, { userId: xdmp.user(user) });
/** The actual function that does the work. */
function _doStuff(param) {
return `${param}: ${xdmp.getCurrentUser()}`;
}
/** A new synthetic function that combines the actual function and the user swithcing */
const doStuff = param =>
asUser((/* zero params*/) => _doStuff(param), 'nobody');
/** Call `doStuff` just as you would `_doStuff` */
doStuff('User');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment