core icon indicating copy to clipboard operation
core copied to clipboard

Content type is allowed to be saved with blank "variable" thru REST

Open shaydotcms opened this issue 9 years ago • 5 comments

When you update a content type thru REST and leave the "variable" field blank, the system returns 200 OK status and doesn't validate that this field is required.

This is the result in the UI: image

Expected Behavior

System should validate that "variable" field is required

Current Behavior

Variable field can be left empty

Steps to Reproduce (for bugs)

  1. Startup a dotcms instance
  2. Create a new Content Type thru UI or REST. Fill up all required fields.
  3. Now update the same Content Type you just created thru rest and leave "variable" field in blank

Rest endpoint:

PUT /v1/contenttype/id/{typeId}

Curl command:

curl -v -u [email protected]:admin -XPUT http://localhost:8080/api/v1/contenttype/id/39fecdb0-46cc-40a9-a056-f2e1a80ea78c -H "Content-Type: application/json" --data @bodyUpdate.json

bodyCreate.json file: (notice that required field variable is blank for testing purposes) { "clazz": "com.dotcms.contenttype.model.type.ImmutableSimpleContentType", "defaultType": false, "id": "39fecdb0-46cc-40a9-a056-f2e1a80ea78c",

"name": "The Content Type 2",
"description": "THE DESCRIPTION 2",

"host": "48190c8c-42c4-46af-8d1a-0cd5db894797",
"owner": "dotcms.org.1",

"variable": "",

"fixed": false,
"system": false,
"folder": "SYSTEM\_FOLDER"

}

Your Environment

dotCMS version used: Dotcms 4.1.0 distribution generated from Release-4.1 Database and version: MSSQL Server 2012 Operating System and version: Windows 7 Pro Browser Name and version: Firefox v45.0.1 Application Server and version: Tomcat 8 Java Brand and version: Java 8

shaydotcms avatar Jun 01 '17 21:06 shaydotcms

Does it automatically assign a variable? It should, based on the name. Check and see if it does.

wezell avatar Jun 02 '17 00:06 wezell

Hi @wezell,

I just looked at your previous comment/question. I started looking at this ticket this afternoon and unfortunately left the office before your comment.

To answer your question: I just checked and I am afraid that neither Content-Type Resource or Content-Type API does not automatically assign variable field if not provided.

After looking around and thinking more about it, I believe this responsibility should be centralized in Content-Type Factory-Impl in the same way as it is done for Fields:

  • Using approach similar to https://github.com/dotCMS/core/blob/master/dotCMS/src/main/java/com/dotcms/contenttype/business/FieldFactoryImpl.java#L224-L226
  • Relying on same code than https://github.com/dotCMS/core/blob/master/dotCMS/src/main/java/com/dotmarketing/portlets/structure/action/EditStructureAction.java#L356-L357

What do you think? May I proceed to solve this issue as outlined above?

Thanks, Anibal

agomez-dotcms avatar Jun 02 '17 04:06 agomez-dotcms

PR Master: https://github.com/dotCMS/core/pull/11814

agomez-dotcms avatar Jun 05 '17 16:06 agomez-dotcms

This issue was finally fixed by automatically generating value for content-type variable when null or empty.

Please notice that value for content-type variable:

  • is used on content-type creation if specified. Uniqueness is ensured by the system
  • can not be change on content-type update. System always preserves existing value

Thanks, Anibal

agomez-dotcms avatar Jun 05 '17 16:06 agomez-dotcms

Passed QA. Followed steps to reproduce.

@DeanGonzalez please include additional info in the docs letting the end user know that the "variable" field always preserves existing value assigned at the moment of creating the content-type. The system does not update this "variable" field through REST and this behavior is expected.

Tested locally using the following environments: Upgrade from dotcms_3.3 with client dataset (db and assets) to master branch / commit 7187688c9a1f58906abdc6d76ddc57dd9c90d705 Ubuntu 14.04.1 / Postgres 9.3.5 / Chrome v54.0.2840.98 / Tomcat 8 / Java 8

shaydotcms avatar Jun 06 '17 16:06 shaydotcms