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

#11725 Validate wrong varNamea and return proper response. #11726

Merged
merged 2 commits into from
May 25, 2017
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -226,13 +226,13 @@ public Field find(String id) throws DotDataException {
public Field byContentTypeAndVar(ContentType type, String fieldVar) throws DotDataException {
return fac.byContentTypeFieldVar(type, fieldVar);
}

@Override
public Field byContentTypeIdAndVar(String id, String fieldVar) throws DotDataException {
try {
return APILocator.getContentTypeAPI(APILocator.systemUser()).find(id).fieldMap().get(fieldVar);
} catch (Exception e) {
throw new DotDataException(e);
return byContentTypeAndVar(APILocator.getContentTypeAPI(APILocator.systemUser()).find(id), fieldVar);
} catch (DotSecurityException e) {
throw new DotDataException(e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,13 @@ public Field byId(String id) throws DotDataException {

@Override
public Field byContentTypeFieldVar(ContentType type, String var) throws DotDataException {

return type.fieldMap().get(var);
Field field = type.fieldMap().get(var);

if(field==null) {
throw new NotFoundInDbException("Field variable with var:" + var + " not found");
}

return field;

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ public Response updateContentTypeFieldByVar(@PathParam("typeId") final String ty
} else {

field = fapi.save(field, user);

response = Response.ok(new ResponseEntityView(new JsonFieldTransformer(field).mapObject())).build();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.dotcms.contenttype.exception.NotFoundInDbException;
import com.dotcms.contenttype.model.type.ContentType;
import com.dotcms.repackage.com.google.common.io.Files;
import com.dotcms.repackage.org.apache.commons.collections.LRUMap;
Expand Down Expand Up @@ -313,9 +314,11 @@ public void doGet(HttpServletRequest req, HttpServletResponse resp) throws Servl
//Find the contentlet content type
ContentType type = APILocator.getContentTypeAPI(APILocator.systemUser()).find((content.getContentTypeId()));
//And the file asset field
com.dotcms.contenttype.model.field.Field field = APILocator.getContentTypeFieldAPI().byContentTypeAndVar(type, fieldVarName);
com.dotcms.contenttype.model.field.Field field;

if(field == null){
try {
field = APILocator.getContentTypeFieldAPI().byContentTypeAndVar(type, fieldVarName);
} catch (NotFoundInDbException e) {
Logger.debug(this,"Field " + fieldVarName + " does not exists within structure " + content.getStructure().getVelocityVarName());
resp.sendError(404);
return;
Expand Down