fix default partition setting on resource (#5617)

* fix default partition setting on resource

* changelog

* Handle DEFAULT partition in rule checker.

* Fix spotless

---------

Co-authored-by: Michael Buckley <michaelabuckley@gmail.com>
Co-authored-by: James Agnew <jamesagnew@gmail.com>
This commit is contained in:
Ken Stevens 2024-01-22 17:29:40 -05:00 committed by GitHub
parent 4aa3b97228
commit c207b4949b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 16 additions and 2 deletions

View File

@ -0,0 +1,5 @@
---
type: fix
issue: 5617
title: "Resource UserData RESOURCE_PARTITION_ID was incorrectly being set to null for the default partition.
This has been corrected to use RequestPartitionId.defaultPartition()"

View File

@ -23,6 +23,7 @@ import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.context.FhirVersionEnum;
import ca.uhn.fhir.context.RuntimeResourceDefinition;
import ca.uhn.fhir.i18n.Msg;
import ca.uhn.fhir.interceptor.model.RequestPartitionId;
import ca.uhn.fhir.jpa.api.config.JpaStorageSettings;
import ca.uhn.fhir.jpa.api.dao.IDao;
import ca.uhn.fhir.jpa.dao.data.IResourceHistoryTableDao;
@ -248,7 +249,7 @@ public class JpaStorageResourceParser implements IJpaStorageResourceParser {
myPartitionLookupSvc.getPartitionById(partitionId.getPartitionId());
retVal.setUserData(Constants.RESOURCE_PARTITION_ID, persistedPartition.toRequestPartitionId());
} else {
retVal.setUserData(Constants.RESOURCE_PARTITION_ID, null);
retVal.setUserData(Constants.RESOURCE_PARTITION_ID, RequestPartitionId.defaultPartition());
}
}
}

View File

@ -263,7 +263,7 @@ public class JpaConstants {
/**
* The name of the default partition
*/
public static final String DEFAULT_PARTITION_NAME = "DEFAULT";
public static final String DEFAULT_PARTITION_NAME = ProviderConstants.DEFAULT_PARTITION_NAME;
/**
* The name of the collection of all partitions

View File

@ -25,6 +25,7 @@ import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.rest.api.Constants;
import ca.uhn.fhir.rest.api.RestOperationTypeEnum;
import ca.uhn.fhir.rest.api.server.RequestDetails;
import ca.uhn.fhir.rest.server.provider.ProviderConstants;
import com.google.common.collect.Lists;
import jakarta.annotation.Nonnull;
import org.apache.commons.lang3.Validate;
@ -234,6 +235,11 @@ public class RuleBuilder implements IAuthRuleBuilder {
RequestPartitionId partitionId =
(RequestPartitionId) theResource.getUserData(Constants.RESOURCE_PARTITION_ID);
if (partitionId != null) {
if (partitionId.hasDefaultPartitionId()
&& myTenantIds.contains(ProviderConstants.DEFAULT_PARTITION_NAME)) {
return myOutcome;
}
String partitionNameOrNull = partitionId.getFirstPartitionNameOrNull();
if (partitionNameOrNull == null || !myTenantIds.contains(partitionNameOrNull)) {
return !myOutcome;

View File

@ -52,6 +52,8 @@ public class ProviderConstants {
public static final String PARTITION_MANAGEMENT_PARTITION_NAME = "name";
public static final String PARTITION_MANAGEMENT_PARTITION_DESC = "description";
public static final String DEFAULT_PARTITION_NAME = "DEFAULT";
/**
* Operation name: diff
*/