Skip to content

Commit

Permalink
Merge branch 'master' into issue-27603-sdk-experiment-fetch-store-data-2
Browse files Browse the repository at this point in the history
  • Loading branch information
oidacra authored Feb 29, 2024
2 parents 50e2198 + ad285d0 commit ccf8ee4
Show file tree
Hide file tree
Showing 15 changed files with 93 additions and 32 deletions.
18 changes: 17 additions & 1 deletion dotCMS/src/curl-test/FolderResource.postman_collection.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,22 @@
"});",
"",
"pm.collectionVariables.set(\"siteId\", jsonData.entity.identifier);",
"",
"pm.test(\"ModUser should contain a valid user identifier\", function () {",
" const responseData = pm.response.json();",
" ",
" pm.expect(responseData).to.be.an('object');",
" pm.expect(responseData.entity.modUser).to.be.a('string').and.not.eql(\"\");",
"});",
"",
"",
"",
"pm.test(\"Permissions array should be empty for public endpoints\", function () {",
" const responseData = pm.response.json();",
" ",
" pm.expect(responseData.permissions).to.be.an('array').that.is.empty;",
"});",
"",
""
],
"type": "text/javascript"
Expand Down Expand Up @@ -1259,4 +1275,4 @@
"value": "25e35d3f515876f8c76524065ca00a9f"
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,23 @@
" pm.expect(jsonData.entity).to.not.eq(undefined);",
" pm.expect(jsonData.entity.jwt).to.not.eq(undefined);",
" pm.collectionVariables.set(\"token\", jsonData.entity.jwt);",
"});"
"});",
"",
"pm.test('Response has a valid JWT', function () {",
" pm.expect(pm.response.json().entity.jwt).to.match(/^[A-Za-z0-9-_]+\\.[A-Za-z0-9-_]+\\.[A-Za-z0-9-_.+/=]*$/);",
"})",
"",
"pm.test(\"Token ID should be unique\", function () {",
" var jsonData = pm.response.json();",
" const tokenID = jsonData.entity.token.id;",
" pm.collectionVariables.get(\"tokenIDs\") || pm.collectionVariables.set(\"tokenIDs\", []);",
" const tokenIDs = pm.collectionVariables.get(\"tokenIDs\");",
" pm.expect(tokenIDs).to.not.include(tokenID);",
" tokenIDs.push(tokenID);",
" pm.collectionVariables.set(\"tokenIDs\", tokenIDs);",
"});",
""

],
"type": "text/javascript"
}
Expand Down Expand Up @@ -1055,4 +1071,4 @@
"value": "48db03da-d303-47cc-af29-9be490e99648"
}
]
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.dotcms.business;

import com.dotcms.config.DotInitializer;
import com.dotmarketing.business.APILocator;
import com.dotmarketing.util.Config;

/**
Expand All @@ -13,6 +14,8 @@ public class SystemTableInitializer implements DotInitializer {
@Override
public void init() {
Config.initSystemTableConfigSource();
// Load the all system table into the system cache
APILocator.getSystemAPI().getSystemTable().all();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* Encapsulates the context of the Javascript execution.
* @author jsanca
*/
public class JsContext extends HashMap implements Serializable {
public class JsContext extends HashMap<String, Object> implements Serializable {

private final JsRequest request;
private final JsResponse response;
Expand Down
13 changes: 7 additions & 6 deletions dotCMS/src/main/java/com/dotcms/rendering/js/JsEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public class JsEngine implements ScriptEngine {
public static final String WEB_INF = "WEB-INF";
private final JsFileSystem jsFileSystem = new JsFileSystem();
private final JsDotLogger jsDotLogger = new JsDotLogger();
private final Map<String, Class> jsRequestViewToolMap = new ConcurrentHashMap<>();
private final Map<String, Class<? extends JsViewTool>> jsRequestViewToolMap = new ConcurrentHashMap<>();
private final Map<String, JsViewTool> jsAplicationViewToolMap = new ConcurrentHashMap<>();

private final Lazy<Boolean> allowAllHostAccess = Lazy.of(()-> Config.getBooleanProperty("ALLOW_ALL_HOST_ACCESS", false));
Expand Down Expand Up @@ -124,7 +124,7 @@ private void initApplicationView(final JsViewTool jsViewToolInstance) {
* Remove a JsViewTool from the engine
* @param jsViewTool
*/
public void removeJsViewTool(final Class jsViewTool) {
public <T extends JsViewTool> void removeJsViewTool(final Class<T> jsViewTool) {

this.jsRequestViewToolMap.remove(jsViewTool.getName());
}
Expand All @@ -140,7 +140,8 @@ private Context buildContext () {
.err(new ConsumerOutputStream(msg->Logger.debug(JsEngine.class, msg)))
.fileSystem(jsFileSystem);

if (allowAllHostAccess.get()) {
final boolean allowAllHostAccess = this.allowAllHostAccess.get();
if (allowAllHostAccess) {
builder.allowHostAccess(HostAccess.ALL);
}
//allows access to all Java classes
Expand All @@ -162,7 +163,7 @@ public Object eval(final HttpServletRequest request,
final List<Source> dotSources = getDotSources();
final Value bindings = context.getBindings(ENGINE_JS);
contextParams.entrySet().forEach(entry -> bindings.putMember(entry.getKey(), entry.getValue()));
this.addTools(request, response, bindings, contextParams);
this.addTools(request, response, bindings);

final JsRequest jsRequest = new JsRequest(request, contextParams);
final JsResponse jsResponse = new JsResponse(response);
Expand Down Expand Up @@ -207,6 +208,7 @@ private Object asValue (final Value eval, final DotJSON dotJSON) {
}

final Value finalValue = eval;
// note: we can not parametrized this Map, b/c literally we do not know what it is, could be anything coming from the JS
final Map resultMap = Try.of(()-> finalValue.as(Map.class)).getOrNull();
if (Objects.nonNull(resultMap)) {
return CollectionsUtils.toSerializableMap(resultMap); // we need to do that b.c the context will be close after the return and the resultMap won;t be usable.
Expand Down Expand Up @@ -419,8 +421,7 @@ private Object[] buildArgs(final JsRequest request,

private void addTools(final HttpServletRequest request,
final HttpServletResponse response,
final Value bindings,
final Map<String, Object> contextParams) {
final Value bindings) {

this.jsRequestViewToolMap.entrySet().forEach(entry -> {

Expand Down
25 changes: 25 additions & 0 deletions dotCMS/src/main/java/com/dotcms/rendering/js/JsException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.dotcms.rendering.js;

/**
* Just a generic exception for the JS rendering
*/
public class JsException extends Exception {
public JsException() {
}

public JsException(String message) {
super(message);
}

public JsException(String message, Throwable cause) {
super(message, cause);
}

public JsException(Throwable cause) {
super(cause);
}

public JsException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}
}
9 changes: 5 additions & 4 deletions dotCMS/src/main/java/com/dotcms/rendering/js/JsResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
import java.io.File;
Expand Down Expand Up @@ -528,10 +529,10 @@ private Response processRequest(final RequestParams requestParams,
.build();

final JavascriptReader javascriptReader = JavascriptReaderFactory.getJavascriptReader(UtilMethods.isSet(folderName));
final Map queryParams = uriInfo.getQueryParameters();
final MultivaluedMap<String, String> queryParams = uriInfo.getQueryParameters();
final Map<String, Object> contextParams = CollectionsUtils.map(
"pathParam", pathParam,
"queryParams", ProxyHashMap.from(queryParams),
"queryParams", ProxyHashMap.from((Map)queryParams),
"bodyMap", ProxyHashMap.from(toObjectObjectMap(bodyMap)),
"binaries", ProxyArray.fromList(Arrays.asList(binaries)));

Expand Down Expand Up @@ -563,7 +564,7 @@ private Map<Object, Object> toObjectObjectMap (final Map<String, Object> map) {
private Response evalJavascript(final HttpServletRequest request, final HttpServletResponse response,
final Reader javascriptReader, final Map<String, Object> contextParams,
final User user, final DotJSONCache cache)
throws Exception {
throws JsException {

final ScriptEngine scriptEngine = ScriptEngineFactory.getInstance().getEngine(ScriptEngineFactory.JAVASCRIPT_ENGINE);

Expand All @@ -585,7 +586,7 @@ private Response evalJavascript(final HttpServletRequest request, final HttpServ
if (e.getCause() instanceof DotToolException) {

Logger.error(this,"Error evaluating javascript: " + (e.getCause()).getCause().getMessage());
throw (Exception) (e.getCause()).getCause();
throw new JsException(e.getCause().getCause());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ private String resultToString(final Object result) {

if (result instanceof Map) {

final Map map = Map.class.cast(result);
final Map<?,?> map = Map.class.cast(result); // note: we do not know what could it be, so we have to handle as a generic Map.
if (map.containsKey("output")) {
return map.get("output").toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public class JsScriptActionlet extends WorkFlowActionlet {
private static final List<WorkflowActionletParameter> PARAMETER_LIST = createParamList();
private boolean stop = false;



private static List<WorkflowActionletParameter> createParamList () {

final ImmutableList.Builder<WorkflowActionletParameter> paramList = new ImmutableList.Builder<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public JsHeaders getHeaders() {
@HostAccess.Export
public ProxyHashMap getJson() {

final Map json = new JSONObject(this.getBody());
final JSONObject json = new JSONObject(this.getBody());
return ProxyHashMap.from(json);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public int hashCode() {
@HostAccess.Export
public ProxyHashMap toMap() {

final Map roleMap = new HashMap<>();
final Map<String, Object> roleMap = new HashMap<>();
roleMap.put("DBFQN", this.getDBFQN());
roleMap.put("description", this.getDescription());
roleMap.put("editLayouts", this.isEditLayouts());
Expand All @@ -151,7 +151,7 @@ public ProxyHashMap toMap() {
roleMap.put("parent", this.getParent());
roleMap.put("roleKey", this.getRoleKey());
roleMap.put("system", this.isSystem());
return ProxyHashMap.from(roleMap);
return ProxyHashMap.from((Map)roleMap);
}

@HostAccess.Export
Expand Down
6 changes: 6 additions & 0 deletions dotCMS/src/main/resources/dotmarketing-config.properties
Original file line number Diff line number Diff line change
Expand Up @@ -854,4 +854,10 @@ FEATURE_FLAG_NEW_BINARY_FIELD=true
## Telemetry
FEATURE_FLAG_TELEMETRY=false

## New Edit Page
FEATURE_FLAG_NEW_EDIT_PAGE=false

## Content Editor V2
CONTENT_EDITOR2_ENABLED=false

STARTER_BUILD_VERSION=${starter.deploy.version}
Original file line number Diff line number Diff line change
Expand Up @@ -878,8 +878,4 @@ analytics.app.config.url=http://localhost:8088/c/customer1/cluster1/keys
DELETE_CONTENT_TYPE_ASYNC=true
DELETE_CONTENT_TYPE_ASYNC_WITH_JOB=false

secrets.scripting.enabled=true

#Feature Flags for the new Edit Page and Content Editor
FEATURE_FLAG_NEW_EDIT_PAGE=false
CONTENT_EDITOR2_ENABLED=false
secrets.scripting.enabled=true
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,13 @@ quarkus.log.handler.console."DOTCMS_CONSOLE".enable=true
quarkus.log.handler.console."DOTCMS_CONSOLE".level=FATAL
%test.quarkus.log.handler.console."DOTCMS_CONSOLE".level=DEBUG
quarkus.log.category."com.dotcms".handlers=DOTCMS_CONSOLE

# disable the banner
quarkus.banner.enabled=false
quarkus.http.port=9000

#deactivate the http server that is started by default in quarkus
quarkus.http.host-enabled=false
# quarkus.http.port=9000
# Your configuration properties
dotcms.client.servers.default=http://localhost:8080/api
dotcms.client.servers.demo=https://demo.dotcms.com/api

%test.com.dotcms.service.config=test-service.yml

com.dotcms.starter.site=default
# change me accordingly to your starter site
%test.com.dotcms.starter.site=default
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
quarkus.banner.enabled=false
quarkus.http.port=9000
# Your configuration properties
quarkus.picocli.top-command=com.dotcms.cli.command.EntryCommand

Expand Down

0 comments on commit ccf8ee4

Please sign in to comment.