Skip to content

Commit

Permalink
allow tracking of artifact hits for rest paths (defaults to false)
Browse files Browse the repository at this point in the history
  • Loading branch information
jenshp committed Jul 15, 2024
1 parent 1c69844 commit c11c783
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,7 @@ class RestApi {
PathNode parent
List<String> fullPathList = []
Set<String> pathParameters = new LinkedHashSet<String>()
String trackArtifactHit

int childPaths = 0
int childMethods = 0
Expand All @@ -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") {
Expand Down Expand Up @@ -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)
Expand All @@ -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]
Expand Down
1 change: 1 addition & 0 deletions framework/xsd/moqui-conf-3.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ along with this software (see the LICENSE.md file). If not, see
<xs:enumeration value="AT_XML_SCREEN_TRANS"/>
<xs:enumeration value="AT_SERVICE"/>
<xs:enumeration value="AT_ENTITY"/>
<xs:enumeration value="AT_REST_PATH"/>
</xs:restriction></xs:simpleType></xs:attribute>
<!-- Removed, note that entity-auto and entity-implicit service calls never have hits persisted and that is
mainly what this was used for: <xs:attribute name="sub-type" type="xs:string"/> -->
Expand Down
12 changes: 12 additions & 0 deletions framework/xsd/rest-api-3.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ along with this software (see the LICENSE.md file). If not, see
<xs:attribute name="description" type="xs:string"/>
<xs:attribute name="version" type="xs:string"/>
<xs:attribute name="require-authentication" type="authc-options" default="true"/>
<xs:attribute name="track-artifact-hit" type="xs:string" default="false">
<xs:annotation><xs:documentation>If set to true, ArtifactHit and ArtifactHitBin data will be kept for
this rest path unless overridden by child node(s)</xs:documentation></xs:annotation>
</xs:attribute>
</xs:complexType>
</xs:element>
<xs:element name="id">
Expand All @@ -40,6 +44,10 @@ along with this software (see the LICENSE.md file). If not, see
</xs:sequence>
<xs:attribute name="name" type="xs:string" use="required"/>
<xs:attribute name="require-authentication" type="authc-options" default="true"/>
<xs:attribute name="track-artifact-hit" type="xs:string" default="false">
<xs:annotation><xs:documentation>If set to true, ArtifactHit and ArtifactHitBin data will be kept for
this rest path unless overridden by child node(s)</xs:documentation></xs:annotation>
</xs:attribute>
<xs:attribute name="allow-extra-path" type="boolean" default="false">
<xs:annotation><xs:documentation>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
Expand Down Expand Up @@ -67,6 +75,10 @@ along with this software (see the LICENSE.md file). If not, see
</xs:simpleType>
</xs:attribute>
<xs:attribute name="require-authentication" type="authc-options" default="true"/>
<xs:attribute name="track-artifact-hit" type="xs:string" default="false">
<xs:annotation><xs:documentation>If set to true, ArtifactHit and ArtifactHitBin data will be kept for
this rest path unless overridden by child node(s)</xs:documentation></xs:annotation>
</xs:attribute>
</xs:complexType>
</xs:element>
<xs:element name="service">
Expand Down

0 comments on commit c11c783

Please sign in to comment.