-
Notifications
You must be signed in to change notification settings - Fork 569
PUT/DELETE spec defined search params not allowed #5266
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…efined search params. Avoid updating spec dedined search params.
| public async Task GivenADeleteResourceRequest_WhenDeletingASpecDefinedSearchParameterResource_ThenDeleteSearchParameterShouldNotBeCalled() | ||
| { | ||
| var searchParameter = new SearchParameter() { Id = "code", Url = "http://hl7.org/fhir/SearchParameter/code" }; | ||
| var resource = searchParameter.ToTypedElement().ToResourceElement(); |
Check warning
Code scanning / CodeQL
Useless assignment to local variable
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 3 days ago
To fix the problem, remove the assignment to the resource variable on line 168, as its value is never read and the assignment serves no purpose. This can be done by simply deleting (or commenting out) the line to avoid maintaining unnecessary code. This change is limited to the method GivenADeleteResourceRequest_WhenDeletingASpecDefinedSearchParameterResource_ThenDeleteSearchParameterShouldNotBeCalled in the file src/Microsoft.Health.Fhir.Shared.Core.UnitTests/Features/Search/SearchParameters/SearchParameterBehaviorTests.cs, as shown in the provided code snippet. No further changes or imports are needed, since this assignment does not affect any other logic.
| @@ -165,7 +165,6 @@ | ||
| public async Task GivenADeleteResourceRequest_WhenDeletingASpecDefinedSearchParameterResource_ThenDeleteSearchParameterShouldNotBeCalled() | ||
| { | ||
| var searchParameter = new SearchParameter() { Id = "code", Url = "http://hl7.org/fhir/SearchParameter/code" }; | ||
| var resource = searchParameter.ToTypedElement().ToResourceElement(); | ||
|
|
||
| var key = new ResourceKey("SearchParameter", "code"); | ||
| var request = new DeleteResourceRequest(key, DeleteOperation.SoftDelete); |
| var request = new DeleteResourceRequest(key, DeleteOperation.SoftDelete); | ||
|
|
||
| // Spec-defined parameters do not exist in the Resource table, so GetAsync returns null | ||
| _fhirDataStore.GetAsync(key, Arg.Any<CancellationToken>()).Returns((ResourceWrapper)null); |
Check warning
Code scanning / CodeQL
Useless upcast
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 3 days ago
To fix this issue, remove the explicit upcast to ResourceWrapper from the expression (ResourceWrapper)null and simply use null. This makes the code cleaner and more idiomatic. The change should be made at line 174, inside the GivenADeleteResourceRequest_WhenDeletingASpecDefinedSearchParameterResource_ThenDeleteSearchParameterShouldNotBeCalled test. No additional imports, methods, or definitions are needed for this change.
-
Copy modified line R174
| @@ -171,7 +171,7 @@ | ||
| var request = new DeleteResourceRequest(key, DeleteOperation.SoftDelete); | ||
|
|
||
| // Spec-defined parameters do not exist in the Resource table, so GetAsync returns null | ||
| _fhirDataStore.GetAsync(key, Arg.Any<CancellationToken>()).Returns((ResourceWrapper)null); | ||
| _fhirDataStore.GetAsync(key, Arg.Any<CancellationToken>()).Returns(null); | ||
|
|
||
| var response = new DeleteResourceResponse(key); | ||
|
|
|
|
||
| // Setup: No stored resource (returns null) | ||
| var resourceKey = new ResourceKey(KnownResourceTypes.SearchParameter, searchParam.Id); | ||
| _fhirDataStore.GetAsync(resourceKey, Arg.Any<CancellationToken>()).Returns((ResourceWrapper)null); |
Check warning
Code scanning / CodeQL
Useless upcast
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 3 days ago
The best fix is to remove the explicit cast to ResourceWrapper and simply write null in the .Returns() call. This avoids clutter and makes the code clearer, with no change in behaviour. Only one line (line 310) in the shown code needs to be changed. No imports, definitions, or method changes are required.
-
Copy modified line R310
| @@ -307,7 +307,7 @@ | ||
|
|
||
| // Setup: No stored resource (returns null) | ||
| var resourceKey = new ResourceKey(KnownResourceTypes.SearchParameter, searchParam.Id); | ||
| _fhirDataStore.GetAsync(resourceKey, Arg.Any<CancellationToken>()).Returns((ResourceWrapper)null); | ||
| _fhirDataStore.GetAsync(resourceKey, Arg.Any<CancellationToken>()).Returns(null); | ||
|
|
||
| var validator = new SearchParameterValidator( | ||
| () => _fhirOperationDataStore.CreateMockScope(), |
| } | ||
|
|
||
| if (searchParamResource != null && searchParamResource.IsDeleted == false) | ||
| if (customSearchParamResource != null && customSearchParamResource.IsDeleted == false) |
Check notice
Code scanning / CodeQL
Unnecessarily complex Boolean expression
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 3 days ago
To fix the unnecessarily complex boolean expression, replace the comparison customSearchParamResource.IsDeleted == false with its simpler, equivalent form !customSearchParamResource.IsDeleted. This change should be made at line 76 of the file src/Microsoft.Health.Fhir.Core/Features/Search/Parameters/DeleteSearchParameterBehavior.cs. No additional methods, imports, or supporting changes are required, as the replacement uses intrinsic language operators. The fix is both locally correct and consistent with codebase conventions.
-
Copy modified line R76
| @@ -73,7 +73,7 @@ | ||
| } | ||
| } | ||
|
|
||
| if (customSearchParamResource != null && customSearchParamResource.IsDeleted == false) | ||
| if (customSearchParamResource != null && !customSearchParamResource.IsDeleted) | ||
| { | ||
| // This is a custom search parameter | ||
| await _searchParameterOperations.DeleteSearchParameterAsync(customSearchParamResource.RawResource, cancellationToken); |
src/Microsoft.Health.Fhir.Shared.Core/Features/Search/Parameters/SearchParameterValidator.cs
Show resolved
Hide resolved
src/Microsoft.Health.Fhir.Core/Features/Search/Parameters/DeleteSearchParameterBehavior.cs
Show resolved
Hide resolved
| if (deleteRequest.ResourceKey.ResourceType.Equals(KnownResourceTypes.SearchParameter, StringComparison.Ordinal)) | ||
| { | ||
| searchParamResource = await _fhirDataStore.GetAsync(deleteRequest.ResourceKey, cancellationToken); | ||
| customSearchParamResource = await _fhirDataStore.GetAsync(deleteRequest.ResourceKey, cancellationToken); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed, I am concerned with this approach as users could in theory create a param as "http://hl7.org/fhir/SearchParameter/" then perform a hard delete which removes from the table, but leaves it in PendingDelete and therefore it would have remained in def manager and not in resource table.
To be more accurate, it might be better to use our JSON file that provides or Spec Defined parameters and if found in that file, we throw method not allowed.
Updated responses when deleting nonexistent search params and spec defined search params. Avoid updating spec defined search params.
Description
Describe the changes in this PR.
Related issues
Addresses issue https://microsofthealth.visualstudio.com/Health/_workitems/edit/177538
Testing
Describe how this change was tested. Using unit tests and REST API Calls.
FHIR Team Checklist
Semver Change (docs)
Patch|Skip|Feature|Breaking (reason)