Reputation: 2495
I am trying to trigger a process on the backend when data gets changed.
Here is a working trigger that I am currently using.
xquery version "1.0-ml";
import module namespace trgr="http://marklogic.com/xdmp/triggers"
at "/MarkLogic/triggers.xqy";
if (xdmp:database() eq xdmp:database("nbcu-test-ml-triggers"))
then ()
else fn:error((), 'NOTTRIGGERSDB', xdmp:database()) ,
trgr:create-trigger(
"typeahead_modify",
"Update Typeahead Document",
trgr:trigger-data-event(trgr:directory-scope("/triplestore/", "1"), trgr:document-content("modify"), trgr:post-commit()),
trgr:trigger-module(
xdmp:database("nbcu-test-ml-modules"),
"/ext/",
"sample-trigger.xqy"),
fn:true(),
xdmp:default-permissions(),
fn:true() )
However at the end of the module it is triggering, I would like to call an xdmp:spawn-function in order to do some asynchronous processing.
I am pretty new to Permission management, but I tried adding to the set of permissions a xdmp:privilege
, but that didn't work.
Can someone please help to advise how to add xdmp:Spawn execute
privilege to this trigger?
Thanks
Edit: I use mlgradle to deploy the /ext/sample-trigger.xqy
Upvotes: 0
Views: 100
Reputation: 7770
The scope of the user running the trigger is the user that caused the insert/update/delete/property-change on the document. The only exception to this rule is the database online event in which you actually define a user.
Therefore, the xdmp:spawn privilege must be attached to a role that is attached (directly or indirectly) to the user described above.
To troubleshoot, you could add xdm:log(xdmp:get-current-user()) to the trigger module to make sure you understand the user being used to invoke the code. Then add the xdmp:spawn privilege to one of the roles of that user.
Upvotes: 2