MjmlServices.xml
9.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<?xml version="1.0" encoding="UTF-8"?>
<!--
This software is in the public domain under CC0 1.0 Universal plus a
Grant of Patent License.
To the extent possible under law, the author(s) have dedicated all
copyright and related and neighboring rights to this software to the
public domain worldwide. This software is distributed without any
warranty.
You should have received a copy of the CC0 Public Domain Dedication
along with this software (see the LICENSE.md file). If not, see
<http://creativecommons.org/publicdomain/zero/1.0/>.
-->
<services xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://moqui.org/xsd/service-definition-3.xsd">
<service verb="load" noun="GrapeJs">
<description>Load GrapesJs resource. Can be adapted to entity other than EmailTemplate, but must have data for the grapesLocation and htmlLocation to ensure safety of read and write of resources.</description>
<in-parameters>
<parameter name="grapesLocation"/>
<parameter name="htmlLocation"/>
<parameter name="emailTemplateId" required="true"/>
</in-parameters>
<out-parameters>
<parameter name="grapesLocation"/>
<parameter name="htmlLocation"/>
<parameter name="data"/>
</out-parameters>
<actions>
<if condition="grapesLocation == 'null'"><set field="grapesLocation" from="null"/></if>
<if condition="htmlLocation == 'null'"><set field="htmlLocation" from="null"/></if>
<!-- <log level="warn" message="resourceId is ${resourceId} resourceId.getClass().getName() ${resourceId.getClass().getName()} resourceId == 'null' ${resourceId == 'null'} resourceId == null ${resourceId == null}"/>-->
<!-- <log level="warn" message="load context.toString() ${context.toString()}"/>-->
<entity-find-one entity-name="moqui.basic.email.EmailTemplate" value-field="emailTemplate" auto-field-map="[emailTemplateId:emailTemplateId]"/>
<if condition="!emailTemplate"><return error="true" message="Resource not found"/></if>
<set field="grapesLocation" from="emailTemplate?.grapesLocation"/>
<set field="htmlLocation" from="emailTemplate?.htmlLocation"/>
<set field="grapesJsResource" from="ec.resource.getLocationReference('dbresource://grapesjs/project')"/>
<if condition="!grapesLocation && !htmlLocation">
<then>
<set field="htmlFile" from="grapesJsResource.makeFile(java.util.UUID.randomUUID().toString()+'.html')"/>
<set field="grapesFile" from="grapesJsResource.makeFile(java.util.UUID.randomUUID().toString()+'.json')"/>
<set field="data" from="ec.resource.getLocationReference('dbresource://grapesjs/template/default.json').getText()"/>
<set field="htmlLocation" from="grapesJsResource.location + '/' + htmlFile?.dbResourceId + '.html'"/>
<set field="grapesLocation" from="grapesJsResource.location + '/' + grapesFile?.dbResourceId + '.json'"/>
<script><![CDATA[
htmlFile.move(htmlLocation)
grapesFile.putText(data)
grapesFile.move(grapesLocation)
]]></script>
<service-call name="update#moqui.basic.email.EmailTemplate" in-map="[emailTemplateId:emailTemplateId,grapesLocation:grapesLocation,htmlLocation:htmlLocation]"/>
</then>
<else-if condition="grapesLocation && htmlLocation">
<set field="putDbResource" from="ec.resource.getLocationReference(grapesLocation)"/>
<!-- TODO: Is this a strong enough check to prevent unauthorized access? -->
<if condition="!putDbResource || putDbResource.parent?.location != grapesJsResource.location">
<return error="true" message="Resource not found"/>
</if>
<set field="data" from="putDbResource.getText()"/>
</else-if>
<else>
<return error="true" message="Resource not found"/>
</else>
</if>
</actions>
</service>
<service verb="store" noun="GrapeJs" authenticate="anonymous-all">
<description>Store GrapesJs resource. Can be adapted to entity other than EmailTemplate, but must have data for the grapesLocation and htmlLocation to ensure safety of read and write of resources.</description>
<in-parameters>
<parameter name="htmlLocation"/>
<parameter name="grapesLocation"/>
<parameter name="emailTemplateId"/>
<parameter name="data"/>
<parameter name="html" allow-html="any"/>
</in-parameters>
<out-parameters>
<parameter name="htmlLocation"/>
<parameter name="grapesLocation"/>
</out-parameters>
<actions>
<if condition="htmlLocation == 'null'"><set field="htmlLocation" from="null"/></if>
<if condition="grapesLocation == 'null'"><set field="grapesLocation" from="null"/></if>
<entity-find-one entity-name="moqui.basic.email.EmailTemplate" value-field="emailTemplate" auto-field-map="[emailTemplateId:emailTemplateId]"/>
<if condition="!emailTemplate"><return error="true" message="Resource not found"/></if>
<set field="grapesLocation" from="emailTemplate?.grapesLocation"/>
<set field="htmlLocation" from="emailTemplate?.htmlLocation"/>
<set field="data" from="groovy.json.JsonOutput.toJson(new groovy.json.JsonSlurper().parseText(ec.web.secureRequestParameters._requestBodyText).data)"/>
<set field="grapesJsResource" from="ec.resource.getLocationReference('dbresource://grapesjs/project')"/>
<if condition="!htmlLocation && !grapesLocation">
<then>
<!-- TODO: This should work, but isn't used anywhere and is untested.
<set field="htmlFile" from="grapesJsResource.makeFile(java.util.UUID.randomUUID().toString()+'.html')"/>
<set field="grapesFile" from="grapesJsResource.makeFile(java.util.UUID.randomUUID().toString()+'.json')"/>
<set field="htmlLocation" from="grapesJsResource.location + '/' + htmlFile?.dbResourceId + '.html'"/>
<set field="grapesLocation" from="grapesJsResource.location + '/' + grapesFile?.dbResourceId + '.json'"/>
<if condition="ec.resource.getLocationReference(htmlLocation).parent?.location != grapesJsResource.location">
<return error="true" message="Resource not found"/>
</if>
<if condition="ec.resource.getLocationReference(grapesLocation).parent?.location != grapesJsResource.location">
<return error="true" message="Resource not found"/>
</if>
<script><![CDATA[
htmlFile.putText(html)
htmlFile.move(htmlLocation)
grapesFile.putText(data)
grapesFile.move(grapesLocation)
]]></script>-->
<return error="true" message="Resource not found"/>
</then>
<else-if condition="grapesLocation">
<set field="grapesFile" from="ec.resource.getLocationReference(grapesLocation)"/>
<if condition="!grapesFile || grapesFile.parent?.location != grapesJsResource.location">
<return error="true" message="Resource not found"/>
</if>
<script>grapesFile.putText(data)</script>
<set field="htmlFile" from="null"/>
<if condition="htmlLocation"><then>
<set field="htmlFile" from="ec.resource.getLocationReference(htmlLocation)"/>
</then><else>
<entity-find entity-name="moqui.basic.email.EmailTemplate" list="emailTemplateList">
<econdition field-name="grapesLocation"/>
<order-by field-name="-lastUpdatedStamp"/></entity-find>
<set field="emailTemplate" from="emailTemplateList.getFirst()"/>
<if condition="emailTemplateList.size() == 1 && emailTemplate.htmlLocation"><then>
<set field="htmlFile" from="ec.resource.getLocationReference(emailTemplate.htmlLocation)"/>
</then><else>
<set field="htmlFile" from="grapesJsResource.makeFile(java.util.UUID.randomUUID().toString()+'.html')"/>
<set field="htmlLocation" from="grapesJsResource.location + '/' + htmlFile?.dbResourceId + '.html'"/>
<script><![CDATA[htmlFile.move(htmlLocation)]]></script>
<service-call name="update#moqui.basic.email.EmailTemplate" in-map="[emailTemplateId:emailTemplateId,htmlLocation:htmlLocation]"/>
</else></if>
</else></if>
<if condition="!htmlFile || htmlFile.parent?.location != grapesJsResource.location">
<return error="true" message="Resource not found"/>
</if>
<script><![CDATA[htmlFile.putText(html)]]></script>
</else-if>
<else>
<return error="true" message="Resource not found"/>
</else>
</if>
</actions>
</service>
</services>