Skip to content
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

Hotfix 1.10.x sup 15603 #1571

Open
wants to merge 3 commits into
base: hotfix-1.10.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions LTS-CHANGELOG.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ All fixes and changes in LTS releases will be released the next minor release. C
[[v1.10.24]]
== 1.10.24 (TBD)

icon:check[] REST: New endpoints have been added for retrieving referenced projects for schema/microschema.

icon:check[] REST: The documentation of the generic parameter `fields` has been fixed. Now `fields` works over the Language entities as well, the values are `uuid`,`name`,`languageTag`,`nativeName`.

icon:check[] GraphQL. Some of (micro)schema fields related queries rely on the target (micro)schema having at least one field, crashing in HTTP 500 otherwise. This has now been fixed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import static com.gentics.mesh.core.rest.error.Errors.error;
import static com.gentics.mesh.rest.Messages.message;
import static io.netty.handler.codec.http.HttpResponseStatus.FORBIDDEN;
import static io.netty.handler.codec.http.HttpResponseStatus.NOT_FOUND;
import static io.netty.handler.codec.http.HttpResponseStatus.NO_CONTENT;
import static io.netty.handler.codec.http.HttpResponseStatus.OK;

Expand All @@ -21,6 +22,9 @@
import com.gentics.mesh.core.data.dao.BranchDao;
import com.gentics.mesh.core.data.dao.MicroschemaDao;
import com.gentics.mesh.core.data.dao.UserDao;
import com.gentics.mesh.core.data.page.Page;
import com.gentics.mesh.core.data.page.PageTransformer;
import com.gentics.mesh.core.data.page.impl.DynamicStreamPageImpl;
import com.gentics.mesh.core.data.project.HibProject;
import com.gentics.mesh.core.data.schema.HibMicroschema;
import com.gentics.mesh.core.data.schema.HibMicroschemaVersion;
Expand All @@ -29,15 +33,19 @@
import com.gentics.mesh.core.db.Database;
import com.gentics.mesh.core.endpoint.handler.AbstractCrudHandler;
import com.gentics.mesh.core.rest.MeshEvent;
import com.gentics.mesh.core.rest.error.NotModifiedException;
import com.gentics.mesh.core.rest.microschema.impl.MicroschemaModelImpl;
import com.gentics.mesh.core.rest.microschema.impl.MicroschemaResponse;
import com.gentics.mesh.core.rest.schema.MicroschemaModel;
import com.gentics.mesh.core.rest.schema.change.impl.SchemaChangesListModel;
import com.gentics.mesh.core.result.Result;
import com.gentics.mesh.core.verticle.handler.HandlerUtilities;
import com.gentics.mesh.core.verticle.handler.WriteLock;
import com.gentics.mesh.json.JsonUtil;
import com.gentics.mesh.parameter.PagingParameters;
import com.gentics.mesh.parameter.SchemaUpdateParameters;
import com.gentics.mesh.util.UUIDUtil;
import com.gentics.mesh.util.ValidationUtil;

import dagger.Lazy;

Expand All @@ -52,13 +60,16 @@ public class MicroschemaCrudHandler extends AbstractCrudHandler<HibMicroschema,

private final ProjectMicroschemaLoadAllActionImpl projectMicroschemaLoadAllAction;

private final PageTransformer pageTransformer;

@Inject
public MicroschemaCrudHandler(Database db, MicroschemaComparatorImpl comparator, Lazy<BootstrapInitializer> boot, HandlerUtilities utils,
WriteLock writeLock, ProjectMicroschemaLoadAllActionImpl projectMicroschemaLoadAllAction, MicroschemaDAOActions microschemaActions) {
WriteLock writeLock, ProjectMicroschemaLoadAllActionImpl projectMicroschemaLoadAllAction, MicroschemaDAOActions microschemaActions, PageTransformer pageTransformer) {
super(db, utils, writeLock, microschemaActions);
this.comparator = comparator;
this.boot = boot;
this.projectMicroschemaLoadAllAction = projectMicroschemaLoadAllAction;
this.pageTransformer = pageTransformer;
}

@Override
Expand Down Expand Up @@ -251,4 +262,36 @@ public void handleRemoveMicroschemaFromProject(InternalActionContext ac, String
}
}, () -> ac.send(NO_CONTENT));
}

/**
* Handle the request for the project, linked to the schema with the given UUID.
*
* @param ac
* @param microschemaUuid
*/
public void handleGetLinkedProjects(InternalActionContext ac, String microschemaUuid) {
validateParameter(microschemaUuid, "microschemaUuid");

PagingParameters pagingInfo = ac.getPagingParameters();
ValidationUtil.validate(pagingInfo);

utils.syncTx(ac, tx -> {
MicroschemaDao microschemaDao = tx.microschemaDao();
UserDao userDao = tx.userDao();
HibMicroschema microschema = microschemaDao.loadObjectByUuid(ac, microschemaUuid, READ_PERM);

Result<HibProject> result = microschemaDao.findLinkedProjects(microschema);
plyhun marked this conversation as resolved.
Show resolved Hide resolved
Page<? extends HibProject> page = new DynamicStreamPageImpl<>(result.stream().filter(p -> userDao.hasPermission(ac.getUser(), p, READ_PERM)), pagingInfo);

// Handle etag
if (ac.getGenericParameters().getETag()) {
String etag = pageTransformer.getETag(page, ac);
ac.setEtag(etag, true);
if (ac.matches(etag, true)) {
throw new NotModifiedException();
}
}
return pageTransformer.transformToRestSync(page, ac, 0);
}, m -> ac.send(m, OK));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@
import com.gentics.mesh.auth.MeshAuthChainImpl;
import com.gentics.mesh.context.InternalActionContext;
import com.gentics.mesh.core.db.Database;
import com.gentics.mesh.core.endpoint.RolePermissionHandlingEndpoint;
import com.gentics.mesh.core.endpoint.admin.LocalConfigApi;
import com.gentics.mesh.etc.config.MeshOptions;
import com.gentics.mesh.core.endpoint.RolePermissionHandlingEndpoint;
import com.gentics.mesh.parameter.impl.GenericParametersImpl;
import com.gentics.mesh.parameter.impl.PagingParametersImpl;
import com.gentics.mesh.parameter.impl.VersioningParametersImpl;
import com.gentics.mesh.rest.InternalEndpointRoute;
Expand Down Expand Up @@ -62,6 +63,7 @@ public void registerEndPoints() {
addReadHandlers();
addUpdateHandler();
addDeleteHandler();
addMiscHandlers();
addRolePermissionHandler("microschemaUuid", MICROSCHEMA_UUID, "microschema", crudHandler, false);
}

Expand Down Expand Up @@ -193,4 +195,25 @@ private void addCreateHandler() {
crudHandler.handleCreate(wrap(rc));
}, isOrderedBlockingHandlers());
}

private void addMiscHandlers() {
InternalEndpointRoute readOne = createRoute();
readOne.path("/:microschemaUuid/projects");
readOne.addUriParameter("microschemaUuid", "Uuid of the microschema.", MICROSCHEMA_UUID);
readOne.method(GET);
readOne.description("Load the projects, attached to the microschema with the given uuid.");
readOne.exampleResponse(OK, projectExamples.getProjectListResponse(), "Loaded projects.");
readOne.addQueryParameters(GenericParametersImpl.class);
plyhun marked this conversation as resolved.
Show resolved Hide resolved
readOne.addQueryParameters(PagingParametersImpl.class);
readOne.produces(APPLICATION_JSON);
readOne.blockingHandler(rc -> {
String uuid = rc.request().params().get("microschemaUuid");
if (StringUtils.isEmpty(uuid)) {
rc.next();
} else {
InternalActionContext ac = wrap(rc);
crudHandler.handleGetLinkedProjects(ac, uuid);
}
}, false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
import com.gentics.mesh.core.data.dao.PersistingSchemaDao;
import com.gentics.mesh.core.data.dao.SchemaDao;
import com.gentics.mesh.core.data.dao.UserDao;
import com.gentics.mesh.core.data.page.Page;
import com.gentics.mesh.core.data.page.PageTransformer;
import com.gentics.mesh.core.data.page.impl.DynamicStreamPageImpl;
import com.gentics.mesh.core.data.perm.InternalPermission;
import com.gentics.mesh.core.data.project.HibProject;
import com.gentics.mesh.core.data.schema.HibMicroschema;
Expand All @@ -34,18 +37,22 @@
import com.gentics.mesh.core.db.Database;
import com.gentics.mesh.core.endpoint.handler.AbstractCrudHandler;
import com.gentics.mesh.core.rest.MeshEvent;
import com.gentics.mesh.core.rest.error.NotModifiedException;
import com.gentics.mesh.core.rest.schema.FieldSchema;
import com.gentics.mesh.core.rest.schema.MicronodeFieldSchema;
import com.gentics.mesh.core.rest.schema.SchemaModel;
import com.gentics.mesh.core.rest.schema.change.impl.SchemaChangesListModel;
import com.gentics.mesh.core.rest.schema.impl.SchemaResponse;
import com.gentics.mesh.core.rest.schema.impl.SchemaUpdateRequest;
import com.gentics.mesh.core.result.Result;
import com.gentics.mesh.core.verticle.handler.HandlerUtilities;
import com.gentics.mesh.core.verticle.handler.WriteLock;
import com.gentics.mesh.json.JsonUtil;
import com.gentics.mesh.parameter.PagingParameters;
import com.gentics.mesh.parameter.SchemaUpdateParameters;
import com.gentics.mesh.search.index.node.NodeIndexHandlerImpl;
import com.gentics.mesh.util.UUIDUtil;
import com.gentics.mesh.util.ValidationUtil;

import dagger.Lazy;

Expand All @@ -62,15 +69,18 @@ public class SchemaCrudHandler extends AbstractCrudHandler<HibSchema, SchemaResp

private final ProjectSchemaLoadAllActionImpl projectSchemaDAOActions;

private final PageTransformer pageTransformer;

@Inject
public SchemaCrudHandler(Database db, SchemaComparatorImpl comparator, Lazy<BootstrapInitializer> boot,
HandlerUtilities utils, NodeIndexHandlerImpl nodeIndexHandler, WriteLock writeLock, ProjectSchemaLoadAllActionImpl projectSchemaDAOActions,
SchemaDAOActions schemaActions) {
SchemaDAOActions schemaActions, PageTransformer pageTransformer) {
super(db, utils, writeLock, schemaActions);
this.comparator = comparator;
this.boot = boot;
this.nodeIndexHandler = nodeIndexHandler;
this.projectSchemaDAOActions = projectSchemaDAOActions;
this.pageTransformer = pageTransformer;
}

/**
Expand Down Expand Up @@ -329,4 +339,35 @@ public void handleApplySchemaChanges(InternalActionContext ac, String schemaUuid

}

/**
* Handle the request for the project, linked to the schema with the given UUID.
*
* @param ac
* @param schemaUuid
*/
public void handleGetLinkedProjects(InternalActionContext ac, String schemaUuid) {
validateParameter(schemaUuid, "schemaUuid");

PagingParameters pagingInfo = ac.getPagingParameters();
ValidationUtil.validate(pagingInfo);

utils.syncTx(ac, tx -> {
SchemaDao schemaDao = tx.schemaDao();
UserDao userDao = tx.userDao();
HibSchema schema = schemaDao.loadObjectByUuid(ac, schemaUuid, READ_PERM);

Result<HibProject> result = schemaDao.findLinkedProjects(schema);
plyhun marked this conversation as resolved.
Show resolved Hide resolved
Page<? extends HibProject> page = new DynamicStreamPageImpl<>(result.stream().filter(p -> userDao.hasPermission(ac.getUser(), p, READ_PERM)), pagingInfo);

// Handle etag
if (ac.getGenericParameters().getETag()) {
String etag = pageTransformer.getETag(page, ac);
ac.setEtag(etag, true);
if (ac.matches(etag, true)) {
throw new NotModifiedException();
}
}
return pageTransformer.transformToRestSync(page, ac, 0);
}, m -> ac.send(m, OK));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public void registerEndPoints() {
addCreateHandler();
addUpdateHandler();
addDeleteHandler();
addMiscHandlers();

addRolePermissionHandler("schemaUuid", SCHEMA_VEHICLE_UUID, "schema", crudHandler, false);
}
Expand Down Expand Up @@ -202,6 +203,26 @@ private void addReadHandlers() {
InternalActionContext ac = wrap(rc);
crudHandler.handleReadList(ac);
}, false);
}

private void addMiscHandlers() {
InternalEndpointRoute readOne = createRoute();
readOne.path("/:schemaUuid/projects");
readOne.addUriParameter("schemaUuid", "Uuid of the schema.", SCHEMA_VEHICLE_UUID);
readOne.method(GET);
readOne.description("Load the projects, attached to the schema with the given uuid.");
readOne.exampleResponse(OK, projectExamples.getProjectListResponse(), "Loaded projects.");
readOne.addQueryParameters(GenericParametersImpl.class);
plyhun marked this conversation as resolved.
Show resolved Hide resolved
readOne.addQueryParameters(PagingParametersImpl.class);
readOne.produces(APPLICATION_JSON);
readOne.blockingHandler(rc -> {
String uuid = rc.request().params().get("schemaUuid");
if (StringUtils.isEmpty(uuid)) {
rc.next();
} else {
InternalActionContext ac = wrap(rc);
crudHandler.handleGetLinkedProjects(ac, uuid);
}
}, false);
}
}
16 changes: 16 additions & 0 deletions core/src/main/java/com/gentics/mesh/rest/MeshLocalClientImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,22 @@ public MeshRequest<SchemaListResponse> findSchemas(String projectName, Parameter
return new MeshLocalRequestImpl<>(ac.getFuture());
}

@Override
public MeshRequest<ProjectListResponse> findSchemaProjects(String uuid, ParameterProvider... parameters) {
LocalActionContextImpl<ProjectListResponse> ac = createContext(ProjectListResponse.class, parameters);
ac.setParameter("schemaUuid", uuid);
schemaCrudHandler.handleGetLinkedProjects(ac, uuid);
return new MeshLocalRequestImpl<>(ac.getFuture());
}

@Override
public MeshRequest<ProjectListResponse> findMicroschemaProjects(String uuid, ParameterProvider... parameters) {
LocalActionContextImpl<ProjectListResponse> ac = createContext(ProjectListResponse.class, parameters);
ac.setParameter("microschemaUuid", uuid);
microschemaCrudHandler.handleGetLinkedProjects(ac, uuid);
return new MeshLocalRequestImpl<>(ac.getFuture());
}

@Override
public MeshRequest<MicroschemaResponse> assignMicroschemaToProject(String projectName, String microschemaUuid) {
LocalActionContextImpl<MicroschemaResponse> ac = createContext(MicroschemaResponse.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,4 +191,12 @@ public interface ContainerDao<
* @param batch
*/
void unassign(SC schema, HibProject project, EventQueueBatch batch);

/**
* Find all projects which reference the schema.
*
* @param schema
* @return
*/
Result<HibProject> findLinkedProjects(SC schema);
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,6 @@ default HibSchema create(SchemaVersionModel schema, HibUser creator) throws Mesh
*/
Result<? extends HibNode> getNodes(HibSchema schema);

/**
* Find all projects which reference the schema.
*
* @param schema
* @return
*/
Result<HibProject> findLinkedProjects(HibSchema schema);

/**
* Load all nodes, accessible in the given branch with Read Published permission.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,7 @@ default HibMicroschemaVersion fromReference(HibProject project, MicroschemaRefer
return fromReference(project, reference, null);
}

/**
* Find all projects which reference the schema.
*
* @param schema
* @return
*/
@Override
default Result<HibProject> findLinkedProjects(HibMicroschema schema) {
return new TraversalResult<>(Tx.get().projectDao()
.findAll().stream().filter(project -> isLinkedToProject(schema, project)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,12 +223,7 @@ default HibSchema create(SchemaVersionModel schema, HibUser creator, String uuid
return mergeIntoPersisted(container);
}

/**
* Find all projects which reference the schema.
*
* @param schema
* @return
*/
@Override
default Result<HibProject> findLinkedProjects(HibSchema schema) {
return new TraversalResult<>(Tx.get().projectDao()
.findAll().stream().filter(project -> isLinkedToProject(schema, project)));
Expand Down
Loading