From 12a54bcaf5e553ae9ed4c9fb23845975f0a16700 Mon Sep 17 00:00:00 2001 From: Will Ezell Date: Mon, 22 May 2017 16:07:32 -0400 Subject: [PATCH] #11668 prevent read-only or fixed fields from being deleted --- .../business/ContentTypeFactoryImpl.java | 2 +- .../dotcms/contenttype/business/FieldAPIImpl.java | 9 +++++++-- .../contenttype/business/FieldFactoryImpl.java | 13 ++++--------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/dotCMS/src/main/java/com/dotcms/contenttype/business/ContentTypeFactoryImpl.java b/dotCMS/src/main/java/com/dotcms/contenttype/business/ContentTypeFactoryImpl.java index 4c0082d4338a..a12ea2c40cc9 100644 --- a/dotCMS/src/main/java/com/dotcms/contenttype/business/ContentTypeFactoryImpl.java +++ b/dotCMS/src/main/java/com/dotcms/contenttype/business/ContentTypeFactoryImpl.java @@ -381,7 +381,7 @@ private ContentType dbSaveUpdate(final ContentType saveType) throws DotDataExcep } } - FieldAPI fapi = new FieldAPIImpl().instance(); + FieldAPI fapi = APILocator.getContentTypeFieldAPI(); for (Field f : fields) { f = FieldBuilder.builder(f).contentTypeId(retType.id()).build(); try { diff --git a/dotCMS/src/main/java/com/dotcms/contenttype/business/FieldAPIImpl.java b/dotCMS/src/main/java/com/dotcms/contenttype/business/FieldAPIImpl.java index 37a5c55b90e3..80ca60eae582 100644 --- a/dotCMS/src/main/java/com/dotcms/contenttype/business/FieldAPIImpl.java +++ b/dotCMS/src/main/java/com/dotcms/contenttype/business/FieldAPIImpl.java @@ -159,6 +159,10 @@ public void delete(Field field, User user) throws DotDataException, DotSecurityE perAPI.checkPermission(type, PermissionLevel.PUBLISH, user); + Field oldField = fac.byId(field.id()); + if(oldField.fixed() || oldField.readOnly()){ + throw new DotDataException("You cannot delete a fixed or read only fiedl"); + } Structure structure = new StructureTransformer(type).asStructure(); com.dotmarketing.portlets.structure.model.Field legacyField = new LegacyFieldTransformer(field).asOldField(); @@ -193,8 +197,9 @@ public void delete(Field field, User user) throws DotDataException, DotSecurityE } // rebuild contentlets indexes - conAPI.reindex(structure); - + if(field.indexed()){ + conAPI.reindex(structure); + } // remove the file from the cache ContentletServices.removeContentletFile(structure); ContentletMapServices.removeContentletMapFile(structure); diff --git a/dotCMS/src/main/java/com/dotcms/contenttype/business/FieldFactoryImpl.java b/dotCMS/src/main/java/com/dotcms/contenttype/business/FieldFactoryImpl.java index e730854ef482..a0e438e13b8b 100644 --- a/dotCMS/src/main/java/com/dotcms/contenttype/business/FieldFactoryImpl.java +++ b/dotCMS/src/main/java/com/dotcms/contenttype/business/FieldFactoryImpl.java @@ -185,14 +185,11 @@ private Field dbSaveUpdate(final Field throwAwayField) throws DotDataException { Field oldField = null; try { oldField = selectInDb(throwAwayField.id()); + builder.fixed(oldField.fixed()); + builder.readOnly(oldField.readOnly()); + builder.dataType(oldField.dataType()); } catch (NotFoundInDbException e) { - - } - - - - if (oldField == null) { - + // assign an inode and db column if needed if (throwAwayField.id() == null) { builder.id(UUID.randomUUID().toString()); @@ -211,8 +208,6 @@ private Field dbSaveUpdate(final Field throwAwayField) throws DotDataException { ? suggestVelocityVar(throwAwayField.name(), fieldsAlreadyAdded) : throwAwayField.variable(); builder.variable(tryVar); - builder.fixed(false); - builder.readOnly(false); }