Created
April 21, 2017 20:25
-
-
Save jmakeig/7399d5af538f7974ae20d4d108c5ef02 to your computer and use it in GitHub Desktop.
Invoke a MarkLogic JavaScript function as a particular user
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| '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