Skip to content

Instantly share code, notes, and snippets.

@jmakeig
Last active November 19, 2018 20:40
Show Gist options
  • Save jmakeig/c334411d00718314092f34b820713ea5 to your computer and use it in GitHub Desktop.
Save jmakeig/c334411d00718314092f34b820713ea5 to your computer and use it in GitHub Desktop.
Get the permissions of a MarkLogic document by URI, including role names, instead of IDs
'use strict';
const sec = require('/MarkLogic/security');
function role(id) {
return fn
.head(
xdmp.invokeFunction(() => sec.getRoleNames(id), {
database: xdmp.database('Security')
})
)
.xpath('text()')
.valueOf();
}
const uri = '/helloWorld/helloWorld.sjs';
xdmp.documentGetPermissions(uri).map(perm => {
return { capability: perm.capability, role: role(perm.roleId) };
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment