Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import static org.opensearch.sample.resource.TestUtils.RESOURCE_SHARING_INDEX;
import static org.opensearch.sample.resource.TestUtils.SAMPLE_FULL_ACCESS_RESOURCE_AG;
import static org.opensearch.sample.resource.TestUtils.SAMPLE_READ_ONLY_RESOURCE_AG;
import static org.opensearch.sample.resource.TestUtils.SAMPLE_RESOURCE_GET_ENDPOINT;
import static org.opensearch.sample.resource.TestUtils.SECURITY_SHARE_ENDPOINT;
import static org.opensearch.sample.resource.TestUtils.newCluster;
import static org.opensearch.sample.resource.TestUtils.putSharingInfoPayload;
Expand Down Expand Up @@ -251,13 +252,17 @@ public void testPatchSharingInfo() {
response.assertStatusCode(HttpStatus.SC_OK);
}

// limited access user will now be able to call patch endpoint, but full-access won't
// limited access user will now be able to call get and patch endpoint, but full-access won't
try (TestRestClient client = cluster.getRestClient(LIMITED_ACCESS_USER)) {
TestRestClient.HttpResponse response = client.patch(SECURITY_SHARE_ENDPOINT, patchSharingInfoPayloadBuilder.build());
TestRestClient.HttpResponse response = client.get(SAMPLE_RESOURCE_GET_ENDPOINT + "/" + adminResId);
response.assertStatusCode(HttpStatus.SC_OK);
response = client.patch(SECURITY_SHARE_ENDPOINT, patchSharingInfoPayloadBuilder.build());
response.assertStatusCode(HttpStatus.SC_OK);
}
try (TestRestClient client = cluster.getRestClient(FULL_ACCESS_USER)) {
TestRestClient.HttpResponse response = client.patch(SECURITY_SHARE_ENDPOINT, patchSharingInfoPayloadBuilder.build());
TestRestClient.HttpResponse response = client.get(SAMPLE_RESOURCE_GET_ENDPOINT + "/" + adminResId);
Comment thread
cwperks marked this conversation as resolved.
response.assertStatusCode(HttpStatus.SC_FORBIDDEN);
response = client.patch(SECURITY_SHARE_ENDPOINT, patchSharingInfoPayloadBuilder.build());
response.assertStatusCode(HttpStatus.SC_FORBIDDEN);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -786,8 +786,8 @@ public void patchSharingInfo(
fetchSharingInfo(resourceIndex, resourceId, sharingInfoListener);

// Apply patch and update the document
sharingInfoListener.whenComplete(resourceSharing -> {
ShareWith updatedShareWith = resourceSharing.getShareWith();
sharingInfoListener.whenComplete(sharingInfo -> {
ShareWith updatedShareWith = sharingInfo.getShareWith();
if (updatedShareWith == null) {
updatedShareWith = new ShareWith(new HashMap<>());
}
Expand All @@ -806,7 +806,7 @@ public void patchSharingInfo(
}
}

ResourceSharing updatedSharingInfo = new ResourceSharing(resourceId, resourceSharing.getCreatedBy(), cleaned);
ResourceSharing updatedSharingInfo = new ResourceSharing(resourceId, sharingInfo.getCreatedBy(), cleaned);

try (ThreadContext.StoredContext ctx = this.threadPool.getThreadContext().stashContext()) {
// update the record
Expand All @@ -826,7 +826,19 @@ public void patchSharingInfo(
resourceIndex
);

listener.onResponse(updatedSharingInfo);
updateResourceVisibility(
resourceId,
resourceIndex,
updatedSharingInfo.getAllPrincipals(),
ActionListener.wrap((updateResponse) -> {
LOGGER.debug("Successfully updated visibility for resource {} within index {}", resourceId, resourceIndex);
listener.onResponse(updatedSharingInfo);
}, (e) -> {
LOGGER.error("Failed to update principals field in [{}] for resource [{}]", resourceIndex, resourceId, e);
listener.onResponse(updatedSharingInfo);
})
);

}, (e) -> {
LOGGER.error(e.getMessage());
listener.onFailure(e);
Expand Down
Loading