From c9137075990ef2f7b312ab117cedcabf7da7ab14 Mon Sep 17 00:00:00 2001 From: Jimmy Deng Date: Wed, 22 Sep 2021 10:15:22 -0400 Subject: [PATCH] added header check --- .../java/ca/uhn/fhir/jpa/dao/BaseHapiFhirResourceDao.java | 2 +- .../ca/uhn/fhir/jpa/dao/expunge/DeleteExpungeDaoTest.java | 3 ++- .../main/java/ca/uhn/fhir/jpa/model/util/JpaConstants.java | 6 ++++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirResourceDao.java b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirResourceDao.java index 54264fc136c..c1605a90183 100644 --- a/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirResourceDao.java +++ b/hapi-fhir-jpaserver-base/src/main/java/ca/uhn/fhir/jpa/dao/BaseHapiFhirResourceDao.java @@ -586,7 +586,7 @@ public abstract class BaseHapiFhirResourceDao extends B throw new MethodNotAllowedException("_expunge is not enabled on this server: " + getConfig().cannotDeleteExpungeReason()); } - if (theUrl.contains("_cascade")) { + if (theUrl.contains(JpaConstants.PARAM_DELETE_CASACADE) || theRequest.getHeader("X-Cascade").equals("delete")) { throw new NotImplementedOperationException("_expunge cannot be used with _cascade"); } diff --git a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/expunge/DeleteExpungeDaoTest.java b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/expunge/DeleteExpungeDaoTest.java index 306f1f14e50..fd1fa912677 100644 --- a/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/expunge/DeleteExpungeDaoTest.java +++ b/hapi-fhir-jpaserver-base/src/test/java/ca/uhn/fhir/jpa/dao/expunge/DeleteExpungeDaoTest.java @@ -67,10 +67,11 @@ class DeleteExpungeDaoTest extends BaseJpaR4Test { // Try to delete _cascade and _expunge on the organization BaseServerResponseException e = assertThrows(BaseServerResponseException.class, () -> {myOrganizationDao - .deleteByUrl("Organization?" + "_cascade=true&" + JpaConstants.PARAM_DELETE_EXPUNGE + "=true", mySrd);}); + .deleteByUrl("Organization?" + "_cascade=delete&" + JpaConstants.PARAM_DELETE_EXPUNGE + "=true", mySrd);}); // Get not implemented HTTP 501 error assertEquals(Constants.STATUS_HTTP_501_NOT_IMPLEMENTED, e.getStatusCode()); + assertEquals("_expunge cannot be used with _cascade", e.getMessage()); } @Test diff --git a/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/util/JpaConstants.java b/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/util/JpaConstants.java index 823c3a42cd3..c3a1f35722e 100644 --- a/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/util/JpaConstants.java +++ b/hapi-fhir-jpaserver-model/src/main/java/ca/uhn/fhir/jpa/model/util/JpaConstants.java @@ -200,6 +200,12 @@ public class JpaConstants { public static final String PARAM_DELETE_EXPUNGE = "_expunge"; + /** + * Parameter for delete to indicate the resource should be cascading delete + */ + + public static final String PARAM_DELETE_CASACADE = "_cascade"; + /** * URL for extension on a SearchParameter indicating that text values should not be indexed */