-
Notifications
You must be signed in to change notification settings - Fork 116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Assert allow field during node field updates #975
Comments
HI, @Jotschi can you please add some more details to this, like steps to reproduce and test this. |
HI, @Jotschi could you please respond to my query above. |
I quickly sketched a test that should help you. The test should assert for the You can use the call function to expect a specific error. Example: call(() -> client().createNode(PROJECT_NAME, request), BAD_REQUEST, "node_no_languagecode_specified"); I assume a new I18n entry also needs to be added with a meaningful message in case of failing allow checks. Besides the test there are two places which need to be updated:
package com.gentics.mesh.core.schema;
import static com.gentics.mesh.test.TestDataProvider.PROJECT_NAME;
import static com.gentics.mesh.test.TestSize.FULL;
import static com.gentics.mesh.test.context.ElasticsearchTestMode.TRACKING;
import java.util.Collections;
import org.junit.Before;
import org.junit.Test;
import com.gentics.mesh.core.rest.node.FieldMapImpl;
import com.gentics.mesh.core.rest.node.NodeCreateRequest;
import com.gentics.mesh.core.rest.node.field.Field;
import com.gentics.mesh.core.rest.node.field.impl.NodeFieldImpl;
import com.gentics.mesh.core.rest.node.field.list.impl.NodeFieldListImpl;
import com.gentics.mesh.core.rest.node.field.list.impl.NodeFieldListItemImpl;
import com.gentics.mesh.core.rest.schema.FieldSchema;
import com.gentics.mesh.core.rest.schema.impl.ListFieldSchemaImpl;
import com.gentics.mesh.core.rest.schema.impl.NodeFieldSchemaImpl;
import com.gentics.mesh.core.rest.schema.impl.SchemaCreateRequest;
import com.gentics.mesh.core.rest.schema.impl.SchemaResponse;
import com.gentics.mesh.test.context.AbstractMeshTest;
import com.gentics.mesh.test.context.MeshTestSetting;
@MeshTestSetting(elasticsearch = TRACKING, testSize = FULL, startServer = true)
public class SchemaAllowNodeFieldTest extends AbstractMeshTest {
private String nodeUuid;
@Before
public void setUp() throws Exception {
nodeUuid = tx(() -> folder("2015").getUuid());
}
private void createSchema(FieldSchema field) {
field.setName("testField");
SchemaCreateRequest req = new SchemaCreateRequest();
req.setName("test");
req.setFields(Collections.singletonList(field));
SchemaResponse response = client().createSchema(req).blockingGet();
client().assignSchemaToProject(PROJECT_NAME, response.getUuid()).blockingAwait();
}
private void createNode(Field field) {
NodeCreateRequest req = new NodeCreateRequest();
req.setLanguage("en");
req.setSchemaName("test");
req.setParentNodeUuid(nodeUuid);
FieldMapImpl fieldMap = new FieldMapImpl();
fieldMap.put("testField", field);
req.setFields(fieldMap);
client().createNode(PROJECT_NAME, req).blockingAwait();
}
private void runTest(FieldSchema schemaField, Field nodeField) {
createSchema(schemaField);
createNode(nodeField);
}
@Test
public void node() {
runTest(
new NodeFieldSchemaImpl().setAllowedSchemas("test"),
new NodeFieldImpl().setUuid(nodeUuid));
}
@Test
public void nodeNotAllowed() {
runTest(
new NodeFieldSchemaImpl().setAllowedSchemas("test2"),
new NodeFieldImpl().setUuid(nodeUuid));
}
@Test
public void nodeList() {
runTest(
new ListFieldSchemaImpl().setListType("node").setAllowedSchemas("test"),
new NodeFieldListImpl().setItems(Collections.singletonList(new NodeFieldListItemImpl().setUuid(nodeUuid))));
}
@Test
public void nodeListNotAllowed() {
runTest(
new ListFieldSchemaImpl().setListType("node").setAllowedSchemas("test2"),
new NodeFieldListImpl().setItems(Collections.singletonList(new NodeFieldListItemImpl().setUuid(nodeUuid))));
}
} |
@Jotschi We are not able to get the SchemaReference from the Nodefield. |
@karowin Yes. That looks correct from a quick glance. Regarding your question: I think you use the wrong object here. The Node node = ac.getProject().getNodeRoot().findByUuid(nodeField.getUuid()); You can get the schema name via: node.getSchemaContainer().getName(); Avoiding loading the node would be nice but is not possible at the moment. I hope this helps. You can revert the changes to NodeFieldImp. If possible also avoid white space changes. Those sometimes happen when the IDE uses a different format compared to that which was previously used. I can handle those also when merging the PR. No big issues. |
I noticed that the allow field will currently not be validated strictly in the API.
We should add the same checks that have also been added via #431
The text was updated successfully, but these errors were encountered: