Skip to content

Commit

Permalink
#11668 prevent read-only or fixed fields from being deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
wezell committed May 22, 2017
1 parent 44b6d86 commit 12a54bc
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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);
}


Expand Down

0 comments on commit 12a54bc

Please sign in to comment.