{"action":"created","comment":{"url":"https://api.github.com/repos/marklogic/roxy/pulls/comments/55413303","id":55413303,"diff_hunk":"@@ -0,0 +1,97 @@\n+(:\n+Copyright 2016 MarkLogic Corporation\n+\n+Licensed under the Apache License, Version 2.0 (the \"License\");\n+you may not use this file except in compliance with the License.\n+You may obtain a copy of the License at\n+\n+   http://www.apache.org/licenses/LICENSE-2.0\n+\n+Unless required by applicable law or agreed to in writing, software\n+distributed under the License is distributed on an \"AS IS\" BASIS,\n+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+See the License for the specific language governing permissions and\n+limitations under the License.\n+:)\n+xquery version \"1.0-ml\";\n+\n+import module namespace trgr=\"http://marklogic.com/xdmp/triggers\" at \"/MarkLogic/triggers.xqy\";\n+\n+declare namespace triggers = \"http://marklogic.com/roxy/triggers\";\n+\n+declare option xdmp:mapping \"false\";\n+\n+(:\n+ : Loads a pipeline from a configuration xml\n+ :\n+ :@param $config - the configuration xml\n+ :\n+:)\n+declare function triggers:load-from-config($config as element(trgr:triggers))\n+{\n+  let $triggers-db := xdmp:database()\n+  for $trgr in $config/trgr:trigger\n+  let $name := $trgr/trgr:name\n+  let $desc as xs:string := $trgr/trgr:description\n+  let $data-event := $trgr/trgr:data-event\n+  let $module :=\n+    <trgr:module>\n+      <trgr:database>{xdmp:database($trgr/trgr:module/trgr:database/fn:string())}</trgr:database>\n+      {\n+        $trgr/trgr:module/* except $trgr/trgr:module/trgr:database\n+      }\n+    </trgr:module>\n+  let $enabled as xs:boolean := $trgr/trgr:enabled\n+  let $permissions as element()* :=\n+    (\n+      triggers:resolve-permissions($trgr/trgr:permissions/sec:permission),\n+      xdmp:default-permissions()\n+    )[1]\n+  let $recursive as xs:boolean := ($trgr/trgr:recursive, fn:true())[1]\n+  let $priority as xs:string? := $trgr/trgr:task-priority\n+  let $_ :=\n+    if (fn:empty($priority) or $priority = (\"normal\", \"higher\")) then ()\n+    else\n+      fn:error(xs:QName(\"PRIORITY-VALUE\"), 'Task priority must be \"normal\" or \"higher\".')\n+  return\n+    if (fn:exists(/trgr:trigger/trgr:trigger-name[. = $name])) then\n+      (: trigger already exists. update it :)\n+      (\n+        trgr:trigger-set-description($name, $desc),\n+        trgr:trigger-set-event($name, $data-event),\n+        trgr:trigger-set-module($name, $module),\n+        if ($enabled) then trgr:trigger-enable($name)\n+        else trgr:trigger-disable($name),\n+        trgr:trigger-set-permissions($name, $permissions),\n+        trgr:trigger-set-recursive($name, $recursive),\n+        trgr:trigger-set-task-priority($name, $priority)\n+      )\n+    else\n+      (: new trigger. create it. :)\n+      trgr:create-trigger(\n+        $name, $desc,\n+        $data-event,\n+        $module,\n+        $enabled,\n+        $permissions,\n+        $recursive,\n+        ($priority, \"normal\")[1]\n+      )\n+};\n+\n+declare function triggers:resolve-permissions($perms as element(sec:permission)*)\n+{\n+  for $perm in $perms\n+  return\n+    <sec:permission>\n+      {$perm/sec:capability}\n+      <sec:role-id>{xdmp:role($perm/sec:role-name)}</sec:role-id>\n+    </sec:permission>","path":"deploy/lib/xquery/triggers.xqy","position":89,"original_position":89,"commit_id":"0b0dd691f002ca7e557abc68af42a6c8d8fe713b","original_commit_id":"0b0dd691f002ca7e557abc68af42a6c8d8fe713b","user":{"login":"grtjn","id":611397,"avatar_url":"https://avatars.githubusercontent.com/u/611397?v=3","gravatar_id":"","url":"https://api.github.com/users/grtjn","html_url":"https://github.com/grtjn","followers_url":"https://api.github.com/users/grtjn/followers","following_url":"https://api.github.com/users/grtjn/following{/other_user}","gists_url":"https://api.github.com/users/grtjn/gists{/gist_id}","starred_url":"https://api.github.com/users/grtjn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/grtjn/subscriptions","organizations_url":"https://api.github.com/users/grtjn/orgs","repos_url":"https://api.github.com/users/grtjn/repos","events_url":"https://api.github.com/users/grtjn/events{/privacy}","received_events_url":"https://api.github.com/users/grtjn/received_events","type":"User","site_admin":false},"body":"How about using http://docs.marklogic.com/xdmp:permission here?","created_at":"2016-03-08T19:28:58Z","updated_at":"2016-03-08T19:28:58Z","html_url":"https://github.com/marklogic/roxy/pull/577#discussion_r55413303","pull_request_url":"https://api.github.com/repos/marklogic/roxy/pulls/577","_links":{"self":{"href":"https://api.github.com/repos/marklogic/roxy/pulls/comments/55413303"},"html":{"href":"https://github.com/marklogic/roxy/pull/577#discussion_r55413303"},"pull_request":{"href":"https://api.github.com/repos/marklogic/roxy/pulls/577"}}},"pull_request":{"url":"https://api.github.com/repos/marklogic/roxy/pulls/577","id":61772141,"html_url":"https://github.com/marklogic/roxy/pull/577","diff_url":"https://github.com/marklogic/roxy/pull/577.diff","patch_url":"https://github.com/marklogic/roxy/pull/577.patch","issue_url":"https://api.github.com/repos/marklogic/roxy/issues/577","number":577,"state":"open","locked":false,"title":"Issue 109","user":{"login":"dmcassel","id":701394,"avatar_url":"https://avatars.githubusercontent.com/u/701394?v=3","gravatar_id":"","url":"https://api.github.com/users/dmcassel","html_url":"https://github.com/dmcassel","followers_url":"https://api.github.com/users/dmcassel/followers","following_url":"https://api.github.com/users/dmcassel/following{/other_user}","gists_url":"https://api.github.com/users/dmcassel/gists{/gist_id}","starred_url":"https://api.github.com/users/dmcassel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dmcassel/subscriptions","organizations_url":"https://api.github.com/users/dmcassel/orgs","repos_url":"https://api.github.com/users/dmcassel/repos","events_url":"https://api.github.com/users/dmcassel/events{/privacy}","received_events_url":"https://api.github.com/users/dmcassel/received_events","type":"User","site_admin":false},"body":"Added commands:\r\n\r\n- ml {env} deploy triggers\r\n- ml {env} clean triggers\r\n\r\nThe code tests to make sure you have a Triggers database configured. The clean wipes out all triggers in the target database, so users are advised to have an application-specific triggers database. ","created_at":"2016-03-04T21:13:24Z","updated_at":"2016-03-08T19:28:58Z","closed_at":null,"merged_at":null,"merge_commit_sha":"3c728f31b79a1df5c3ba3b4238f7abe3e7538144","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/marklogic/roxy/pulls/577/commits","review_comments_url":"https://api.github.com/repos/marklogic/roxy/pulls/577/comments","review_comment_url":"https://api.github.com/repos/marklogic/roxy/pulls/comments{/number}","comments_url":"https://api.github.com/repos/marklogic/roxy/issues/577/comments","statuses_url":"https://api.github.com/repos/marklogic/roxy/statuses/0b0dd691f002ca7e557abc68af42a6c8d8fe713b","head":{"label":"dmcassel:issue-109","ref":"issue-109","sha":"0b0dd691f002ca7e557abc68af42a6c8d8fe713b","user":{"login":"dmcassel","id":701394,"avatar_url":"https://avatars.githubusercontent.com/u/701394?v=3","gravatar_id":"","url":"https://api.github.com/users/dmcassel","html_url":"https://github.com/dmcassel","followers_url":"https://api.github.com/users/dmcassel/followers","following_url":"https://api.github.com/users/dmcassel/following{/other_user}","gists_url":"https://api.github.com/users/dmcassel/gists{/gist_id}","starred_url":"https://api.github.com/users/dmcassel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dmcassel/subscriptions","organizations_url":"https://api.github.com/users/dmcassel/orgs","repos_url":"https://api.github.com/users/dmcassel/repos","events_url":"https://api.github.com/users/dmcassel/events{/privacy}","received_events_url":"https://api.github.com/users/dmcassel/received_events","type":"User","site_admin":false},"repo":{"id":12781748,"name":"roxy","full_name":"dmcassel/roxy","owner":{"login":"dmcassel","id":701394,"avatar_url":"https://avatars.githubusercontent.com/u/701394?v=3","gravatar_id":"","url":"https://api.github.com/users/dmcassel","html_url":"https://github.com/dmcassel","followers_url":"https://api.github.com/users/dmcassel/followers","following_url":"https://api.github.com/users/dmcassel/following{/other_user}","gists_url":"https://api.github.com/users/dmcassel/gists{/gist_id}","starred_url":"https://api.github.com/users/dmcassel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dmcassel/subscriptions","organizations_url":"https://api.github.com/users/dmcassel/orgs","repos_url":"https://api.github.com/users/dmcassel/repos","events_url":"https://api.github.com/users/dmcassel/events{/privacy}","received_events_url":"https://api.github.com/users/dmcassel/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/dmcassel/roxy","description":"","fork":true,"url":"https://api.github.com/repos/dmcassel/roxy","forks_url":"https://api.github.com/repos/dmcassel/roxy/forks","keys_url":"https://api.github.com/repos/dmcassel/roxy/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dmcassel/roxy/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dmcassel/roxy/teams","hooks_url":"https://api.github.com/repos/dmcassel/roxy/hooks","issue_events_url":"https://api.github.com/repos/dmcassel/roxy/issues/events{/number}","events_url":"https://api.github.com/repos/dmcassel/roxy/events","assignees_url":"https://api.github.com/repos/dmcassel/roxy/assignees{/user}","branches_url":"https://api.github.com/repos/dmcassel/roxy/branches{/branch}","tags_url":"https://api.github.com/repos/dmcassel/roxy/tags","blobs_url":"https://api.github.com/repos/dmcassel/roxy/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dmcassel/roxy/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dmcassel/roxy/git/refs{/sha}","trees_url":"https://api.github.com/repos/dmcassel/roxy/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dmcassel/roxy/statuses/{sha}","languages_url":"https://api.github.com/repos/dmcassel/roxy/languages","stargazers_url":"https://api.github.com/repos/dmcassel/roxy/stargazers","contributors_url":"https://api.github.com/repos/dmcassel/roxy/contributors","subscribers_url":"https://api.github.com/repos/dmcassel/roxy/subscribers","subscription_url":"https://api.github.com/repos/dmcassel/roxy/subscription","commits_url":"https://api.github.com/repos/dmcassel/roxy/commits{/sha}","git_commits_url":"https://api.github.com/repos/dmcassel/roxy/git/commits{/sha}","comments_url":"https://api.github.com/repos/dmcassel/roxy/comments{/number}","issue_comment_url":"https://api.github.com/repos/dmcassel/roxy/issues/comments{/number}","contents_url":"https://api.github.com/repos/dmcassel/roxy/contents/{+path}","compare_url":"https://api.github.com/repos/dmcassel/roxy/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dmcassel/roxy/merges","archive_url":"https://api.github.com/repos/dmcassel/roxy/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dmcassel/roxy/downloads","issues_url":"https://api.github.com/repos/dmcassel/roxy/issues{/number}","pulls_url":"https://api.github.com/repos/dmcassel/roxy/pulls{/number}","milestones_url":"https://api.github.com/repos/dmcassel/roxy/milestones{/number}","notifications_url":"https://api.github.com/repos/dmcassel/roxy/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dmcassel/roxy/labels{/name}","releases_url":"https://api.github.com/repos/dmcassel/roxy/releases{/id}","deployments_url":"https://api.github.com/repos/dmcassel/roxy/deployments","created_at":"2013-09-12T11:13:50Z","updated_at":"2014-12-10T14:17:23Z","pushed_at":"2016-03-04T21:11:33Z","git_url":"git://github.com/dmcassel/roxy.git","ssh_url":"git@github.com:dmcassel/roxy.git","clone_url":"https://github.com/dmcassel/roxy.git","svn_url":"https://github.com/dmcassel/roxy","homepage":"","size":8046,"stargazers_count":0,"watchers_count":0,"language":"XQuery","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"marklogic:dev","ref":"dev","sha":"4f0f675759f56fb872c907f8a3a4845fd63c7e80","user":{"login":"marklogic","id":189902,"avatar_url":"https://avatars.githubusercontent.com/u/189902?v=3","gravatar_id":"","url":"https://api.github.com/users/marklogic","html_url":"https://github.com/marklogic","followers_url":"https://api.github.com/users/marklogic/followers","following_url":"https://api.github.com/users/marklogic/following{/other_user}","gists_url":"https://api.github.com/users/marklogic/gists{/gist_id}","starred_url":"https://api.github.com/users/marklogic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/marklogic/subscriptions","organizations_url":"https://api.github.com/users/marklogic/orgs","repos_url":"https://api.github.com/users/marklogic/repos","events_url":"https://api.github.com/users/marklogic/events{/privacy}","received_events_url":"https://api.github.com/users/marklogic/received_events","type":"Organization","site_admin":false},"repo":{"id":3588052,"name":"roxy","full_name":"marklogic/roxy","owner":{"login":"marklogic","id":189902,"avatar_url":"https://avatars.githubusercontent.com/u/189902?v=3","gravatar_id":"","url":"https://api.github.com/users/marklogic","html_url":"https://github.com/marklogic","followers_url":"https://api.github.com/users/marklogic/followers","following_url":"https://api.github.com/users/marklogic/following{/other_user}","gists_url":"https://api.github.com/users/marklogic/gists{/gist_id}","starred_url":"https://api.github.com/users/marklogic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/marklogic/subscriptions","organizations_url":"https://api.github.com/users/marklogic/orgs","repos_url":"https://api.github.com/users/marklogic/repos","events_url":"https://api.github.com/users/marklogic/events{/privacy}","received_events_url":"https://api.github.com/users/marklogic/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/marklogic/roxy","description":"","fork":false,"url":"https://api.github.com/repos/marklogic/roxy","forks_url":"https://api.github.com/repos/marklogic/roxy/forks","keys_url":"https://api.github.com/repos/marklogic/roxy/keys{/key_id}","collaborators_url":"https://api.github.com/repos/marklogic/roxy/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/marklogic/roxy/teams","hooks_url":"https://api.github.com/repos/marklogic/roxy/hooks","issue_events_url":"https://api.github.com/repos/marklogic/roxy/issues/events{/number}","events_url":"https://api.github.com/repos/marklogic/roxy/events","assignees_url":"https://api.github.com/repos/marklogic/roxy/assignees{/user}","branches_url":"https://api.github.com/repos/marklogic/roxy/branches{/branch}","tags_url":"https://api.github.com/repos/marklogic/roxy/tags","blobs_url":"https://api.github.com/repos/marklogic/roxy/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/marklogic/roxy/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/marklogic/roxy/git/refs{/sha}","trees_url":"https://api.github.com/repos/marklogic/roxy/git/trees{/sha}","statuses_url":"https://api.github.com/repos/marklogic/roxy/statuses/{sha}","languages_url":"https://api.github.com/repos/marklogic/roxy/languages","stargazers_url":"https://api.github.com/repos/marklogic/roxy/stargazers","contributors_url":"https://api.github.com/repos/marklogic/roxy/contributors","subscribers_url":"https://api.github.com/repos/marklogic/roxy/subscribers","subscription_url":"https://api.github.com/repos/marklogic/roxy/subscription","commits_url":"https://api.github.com/repos/marklogic/roxy/commits{/sha}","git_commits_url":"https://api.github.com/repos/marklogic/roxy/git/commits{/sha}","comments_url":"https://api.github.com/repos/marklogic/roxy/comments{/number}","issue_comment_url":"https://api.github.com/repos/marklogic/roxy/issues/comments{/number}","contents_url":"https://api.github.com/repos/marklogic/roxy/contents/{+path}","compare_url":"https://api.github.com/repos/marklogic/roxy/compare/{base}...{head}","merges_url":"https://api.github.com/repos/marklogic/roxy/merges","archive_url":"https://api.github.com/repos/marklogic/roxy/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/marklogic/roxy/downloads","issues_url":"https://api.github.com/repos/marklogic/roxy/issues{/number}","pulls_url":"https://api.github.com/repos/marklogic/roxy/pulls{/number}","milestones_url":"https://api.github.com/repos/marklogic/roxy/milestones{/number}","notifications_url":"https://api.github.com/repos/marklogic/roxy/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/marklogic/roxy/labels{/name}","releases_url":"https://api.github.com/repos/marklogic/roxy/releases{/id}","deployments_url":"https://api.github.com/repos/marklogic/roxy/deployments","created_at":"2012-03-01T02:19:52Z","updated_at":"2016-02-29T01:37:27Z","pushed_at":"2016-03-04T21:13:24Z","git_url":"git://github.com/marklogic/roxy.git","ssh_url":"git@github.com:marklogic/roxy.git","clone_url":"https://github.com/marklogic/roxy.git","svn_url":"https://github.com/marklogic/roxy","homepage":"","size":9651,"stargazers_count":57,"watchers_count":57,"language":"XQuery","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":49,"mirror_url":null,"open_issues_count":146,"forks":49,"open_issues":146,"watchers":57,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/marklogic/roxy/pulls/577"},"html":{"href":"https://github.com/marklogic/roxy/pull/577"},"issue":{"href":"https://api.github.com/repos/marklogic/roxy/issues/577"},"comments":{"href":"https://api.github.com/repos/marklogic/roxy/issues/577/comments"},"review_comments":{"href":"https://api.github.com/repos/marklogic/roxy/pulls/577/comments"},"review_comment":{"href":"https://api.github.com/repos/marklogic/roxy/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/marklogic/roxy/pulls/577/commits"},"statuses":{"href":"https://api.github.com/repos/marklogic/roxy/statuses/0b0dd691f002ca7e557abc68af42a6c8d8fe713b"}}}}