From c11c783119370f08ab827b4c2124f15f4378d262 Mon Sep 17 00:00:00 2001 From: Jens Hardings Date: Mon, 8 Jul 2024 20:44:06 -0400 Subject: [PATCH] allow tracking of artifact hits for rest paths (defaults to false) --- .../groovy/org/moqui/impl/service/RestApi.groovy | 7 +++++-- framework/xsd/moqui-conf-3.xsd | 1 + framework/xsd/rest-api-3.xsd | 12 ++++++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/framework/src/main/groovy/org/moqui/impl/service/RestApi.groovy b/framework/src/main/groovy/org/moqui/impl/service/RestApi.groovy index bf6ee2449..f15e15f6c 100644 --- a/framework/src/main/groovy/org/moqui/impl/service/RestApi.groovy +++ b/framework/src/main/groovy/org/moqui/impl/service/RestApi.groovy @@ -570,6 +570,7 @@ class RestApi { PathNode parent List fullPathList = [] Set pathParameters = new LinkedHashSet() + String trackArtifactHit int childPaths = 0 int childMethods = 0 @@ -589,6 +590,7 @@ class RestApi { fullPathList.add(isId ? "{${name}}".toString() : name) if (isId) pathParameters.add(name) requireAuthentication = node.attribute("require-authentication") ?: parent?.requireAuthentication ?: "true" + trackArtifactHit = node.attribute("track-artifact-hit") ?: parent?.trackArtifactHit ?: "false" for (MNode childNode in node.children) { if (childNode.name == "method") { @@ -645,8 +647,6 @@ class RestApi { // push onto artifact stack, check authz String curPath = getFullPathName([]) ArtifactExecutionInfoImpl aei = new ArtifactExecutionInfoImpl(curPath, ArtifactExecutionInfo.AT_REST_PATH, getActionFromMethod(ec), null) - // for now don't track/count artifact hits for REST path - aei.setTrackArtifactHit(false) // NOTE: consider setting parameters on aei, but don't like setting entire context, currently used for entity/service calls ec.artifactExecutionFacade.pushInternal(aei, !moreInPath ? (requireAuthentication == null || requireAuthentication.length() == 0 || "true".equals(requireAuthentication)) : false, true) @@ -660,6 +660,9 @@ class RestApi { loggedInAnonymous = ec.userFacade.loginAnonymousIfNoUser() } + aei.setTrackArtifactHit("true".equals(trackArtifactHit)) + aei.setAuthzReqdAndIsAccess(!loggedInAnonymous, true) + try { if (moreInPath) { String nextPath = pathList[nextPathIndex] diff --git a/framework/xsd/moqui-conf-3.xsd b/framework/xsd/moqui-conf-3.xsd index d060a6176..ca97d9c68 100644 --- a/framework/xsd/moqui-conf-3.xsd +++ b/framework/xsd/moqui-conf-3.xsd @@ -158,6 +158,7 @@ along with this software (see the LICENSE.md file). If not, see + diff --git a/framework/xsd/rest-api-3.xsd b/framework/xsd/rest-api-3.xsd index 6fac469ae..8e5cdb73b 100644 --- a/framework/xsd/rest-api-3.xsd +++ b/framework/xsd/rest-api-3.xsd @@ -29,6 +29,10 @@ along with this software (see the LICENSE.md file). If not, see + + If set to true, ArtifactHit and ArtifactHitBin data will be kept for + this rest path unless overridden by child node(s) + @@ -40,6 +44,10 @@ along with this software (see the LICENSE.md file). If not, see + + If set to true, ArtifactHit and ArtifactHitBin data will be kept for + this rest path unless overridden by child node(s) + If set to true arbitrary path elements following this screen's path are allowed. Default is false and an exception will be thrown if there is an extra path element that does not match a @@ -67,6 +75,10 @@ along with this software (see the LICENSE.md file). If not, see + + If set to true, ArtifactHit and ArtifactHitBin data will be kept for + this rest path unless overridden by child node(s) +