Skip to content

Commit

Permalink
#24266 include in 23.01.9
Browse files Browse the repository at this point in the history
  • Loading branch information
erickgonzalez committed Nov 16, 2023
1 parent ca00104 commit 85c8fed
Show file tree
Hide file tree
Showing 4 changed files with 227 additions and 0 deletions.
155 changes: 155 additions & 0 deletions dotCMS/src/curl-test/ContentTypeResourceTests.json
Original file line number Diff line number Diff line change
Expand Up @@ -2049,6 +2049,161 @@
}
],
"description": "This Test Collection will verify that the Content Type Filtering Endpoint works as expected. This endpoint can take a list of specific Content Types and perform filtering and pagination operations on them."
},
{
"name": "Test delete publish/expire field",
"item": [
{
"name": "Create ContentType with publish/expire fields",
"event": [
{
"listen": "test",
"script": {
"exec": [
"var jsonData = pm.response.json();",
"",
"pm.collectionVariables.set(\"contentTypeID\", jsonData.entity[0].id);",
"pm.collectionVariables.set(\"contentTypeVAR\", jsonData.entity[0].variable);",
"pm.collectionVariables.set(\"contentTypeFieldID\", jsonData.entity[0].fields[0].id);",
"",
"pm.test(\"Status code should be ok 200\", function () {",
" pm.response.to.have.status(200);",
"});",
"",
"pm.test(\"icon check\", function () {",
" pm.expect(jsonData.entity[0].icon).to.eql('testIcon');",
"});",
"",
"pm.test(\"Fields check\", function () {",
" pm.expect(jsonData.entity[0].fields.length).to.eql(2);",
"});"
],
"type": "text/javascript"
}
}
],
"request": {
"auth": {
"type": "basic",
"basic": [
{
"key": "password",
"value": "admin",
"type": "string"
},
{
"key": "username",
"value": "[email protected]",
"type": "string"
},
{
"key": "saveHelperData",
"type": "any"
},
{
"key": "showPassword",
"value": false,
"type": "boolean"
}
]
},
"method": "POST",
"header": [
{
"key": "Content-Type",
"name": "Content-Type",
"type": "text",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n\t\"clazz\": \"com.dotcms.contenttype.model.type.SimpleContentType\",\n\t\"description\": \"My Structure\",\n\t\"defaultType\": false,\n\t\"system\": false,\n\t\"folder\": \"SYSTEM_FOLDER\",\n\t\"name\": \"Test dates content {{$randomBankAccount}}\",\n\t\"variable\": \"testDatesContent{{$randomBankAccount}}\",\n\t\"host\": \"SYSTEM_HOST\",\n\t\"fixed\": false,\n \"icon\": \"testIcon\",\n \"sortOrder\": 3,\n \"publishDateVar\": \"publishDate\",\n \"expireDateVar\": \"expireDate\",\n\t\"fields\": [\n {\n \"clazz\": \"com.dotcms.contenttype.model.field.ImmutableDateTimeField\",\n \"dataType\": \"DATE\",\n \"fieldType\": \"Date-and-Time\",\n \"fieldTypeLabel\": \"Date and Time\",\n \"fieldVariables\": [],\n \"fixed\": false,\n \"forceIncludeInApi\": false,\n \"indexed\": true,\n \"listed\": true,\n \"name\": \"Publish Date\",\n \"readOnly\": false,\n \"required\": false,\n \"searchable\": false,\n \"sortOrder\": 3,\n \"unique\": false,\n \"variable\": \"publishDate\"\n },\n {\n \"clazz\": \"com.dotcms.contenttype.model.field.ImmutableDateTimeField\",\n \"dataType\": \"DATE\",\n \"fieldType\": \"Date-and-Time\",\n \"fieldTypeLabel\": \"Date and Time\",\n \"fieldVariables\": [],\n \"fixed\": false,\n \"forceIncludeInApi\": false,\n \"iDate\": 1685054935000,\n \"indexed\": true,\n \"listed\": true,\n \"modDate\": 1685054935000,\n \"name\": \"Expire Date\",\n \"readOnly\": false,\n \"required\": false,\n \"searchable\": false,\n \"sortOrder\": 3,\n \"unique\": false,\n \"variable\": \"expireDate\"\n }\n\n\t],\n \"workflow\":[\"d61a59e1-a49c-46f2-a929-db2b4bfa88b2\"]\n}"
},
"url": {
"raw": "{{serverURL}}/api/v1/contenttype",
"host": [
"{{serverURL}}"
],
"path": [
"api",
"v1",
"contenttype"
]
},
"description": "Given a content type payload containing field variables.\nWhen sending a POST.\nExpect that code is 200.\nExpect content type is created with the provided fields.\nExpect that new properties of content types are set (icon and sortOrder)."
},
"response": []
},
{
"name": "Delete dateTime field",
"event": [
{
"listen": "test",
"script": {
"exec": [
"pm.test(\"Status code should be 400\", function () {",
" pm.response.to.have.status(400);",
"});"
],
"type": "text/javascript"
}
}
],
"request": {
"auth": {
"type": "basic",
"basic": [
{
"key": "password",
"value": "admin",
"type": "string"
},
{
"key": "username",
"value": "[email protected]",
"type": "string"
},
{
"key": "saveHelperData",
"type": "any"
},
{
"key": "showPassword",
"value": false,
"type": "boolean"
}
]
},
"method": "DELETE",
"header": [],
"body": {
"mode": "raw",
"raw": "{\"fieldsID\": [\"{{contentTypeFieldID}}\"]}",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "{{serverURL}}/api/v3/contenttype/{{contentTypeID}}/fields",
"host": [
"{{serverURL}}"
],
"path": [
"api",
"v3",
"contenttype",
"{{contentTypeID}}",
"fields"
]
},
"description": "Given a content type ID.\nExpect that code is 200.\nExpect content type is deleted successfully."
},
"response": []
}
]
}
],
"variable": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
import com.dotcms.datagen.SiteDataGen;
import com.dotcms.datagen.TestDataUtils;
import com.dotcms.datagen.TestUserUtils;
import com.dotcms.enterprise.publishing.PublishDateUpdater;
import com.dotmarketing.beans.Host;
import com.dotmarketing.beans.Permission;
import com.dotmarketing.beans.PermissionableProxy;
Expand Down Expand Up @@ -2412,6 +2413,63 @@ public void Fields_Should_Not_Get_Removed_When_Host_Is_Empty_Null(final SiteTest
}
}

/**
* Method to test: {@link com.dotcms.enterprise.publishing.PublishDateUpdater#getContentTypeVariableWithPublishField()} } }}
* Given Scenario: Add empty validation on publish and Expire date of the content type
* ExpectedResult: return only content types with publish date != of null o empty
*
* @throws DotDataException
* @throws DotSecurityException
*
*/

@Test
public void test_getContentTypeVariableWithPublishField_ShouldReturnNonNullOrEmpty() throws Exception {
long time = System.currentTimeMillis();
int base = BaseContentType.CONTENT.ordinal();
//create a new content type with publish date
ContentType contentType = ContentTypeBuilder.builder(BaseContentType.getContentTypeClass(base))
.description("ContentTypeWithPublishField " + time).folder(FolderAPI.SYSTEM_FOLDER)
.host(Host.SYSTEM_HOST).name("ContentTypeWithPublishField " + time)
.owner(APILocator.systemUser().toString()).variable("testContentVar"+time).publishDateVar("publishDate").build();

contentType = contentTypeApi.save(contentType);

//validate if the content exist
assertThat("Content was not created correctly", contentTypeApi.find(contentType.inode()) != null);

//create the publishing date field
List<Field> newFieldsList = new ArrayList<>();
Field fieldToSave = FieldBuilder.builder(DateTimeField.class).name("Publish Date").variable("publishDate")
.contentTypeId(contentType.id()).dataType(DataTypes.DATE).indexed(true).build();

newFieldsList.add(fieldToSave);

contentType = contentTypeApi.save(contentType, newFieldsList);

//get all the objects in the structure != null or empty
List<String> structureList = PublishDateUpdater.getContentTypeVariableWithPublishField();

//validate if the content type name appears in the retrieved data
assertTrue("The publish date of the content is empty or null", structureList.contains(contentType.variable()));

//remove the published dates
contentType = ContentTypeBuilder.builder(BaseContentType.getContentTypeClass(base))
.description("ContentTypeWithPublishExpireFields " + time).folder(FolderAPI.SYSTEM_FOLDER)
.host(Host.SYSTEM_HOST).name("ContentTypeWithPublishExpireFields " + time)
.id(contentType.inode())
.owner(APILocator.systemUser().toString()).variable(contentType.variable()).publishDateVar("")
.expireDateVar("").build();

contentType = contentTypeApi.save(contentType);

structureList = PublishDateUpdater.getContentTypeVariableWithPublishField();

//validate that the content type name didn't appear in the retrieved data
assertFalse("Publish date wasn't deleted", structureList.contains(contentType.variable()));

}

@DataProvider
public static Object[] getSites() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.stream.Collectors;

import static com.dotcms.util.CollectionsUtils.map;

/**
Expand Down Expand Up @@ -206,6 +208,17 @@ public Response deleteFields(

final List<String> fieldsID = deleteFieldsForm.getFieldsID();
final ContentType contentType = APILocator.getContentTypeAPI(user).find(typeIdOrVarName);
final String publishDateVar = contentType.publishDateVar();
final String expireDateVar = contentType.expireDateVar();

final List<Field> filteredFields = contentType.fields().stream().filter(field -> fieldsID.contains(field.id())).collect(Collectors.toList());

for (final Field field : filteredFields) {
if ((publishDateVar != null && publishDateVar.equals(field.variable())) ||
(expireDateVar != null && expireDateVar.equals(field.variable()))){
throw new DotDataException("Field is being used as Publish or Expire Field at Content Type Level. Please unlink the field before deleting it.");
}
};

final ContentTypeFieldLayoutAPI.DeleteFieldResult deleteFieldResult =
this.contentTypeFieldLayoutAPI.deleteField(contentType, fieldsID, user);
Expand Down
1 change: 1 addition & 0 deletions hotfix_tracking.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,4 @@ This maintenance release includes the following code fixes:
131. https://github.com/dotCMS/core/issues/22534 : Caching empty containers in the Velocity2 cache when accessing in a language where the content doesn't exist #22534
132. https://github.com/dotCMS/core/issues/24167 : Relationship fields couldn't update with workflow apis #24167
133. https://github.com/dotCMS/core/issues/24227 : [SASS] : Minify CSS output by default #24227
134. https://github.com/dotCMS/core/issues/24266 : Content Type publish and expire date are set to empty #24266

0 comments on commit 85c8fed

Please sign in to comment.