From b303435aa09bf18395ea2ac7ee1264b3ce21b499 Mon Sep 17 00:00:00 2001 From: Stevan Buzejic Date: Wed, 19 Apr 2023 09:13:44 +0200 Subject: [PATCH] Updated conditions for unstashing the context when indexing and deleting the workflow Signed-off-by: Stevan Buzejic --- .../alerting/transport/TransportDeleteWorkflowAction.kt | 6 +++--- .../alerting/transport/TransportIndexWorkflowAction.kt | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/alerting/src/main/kotlin/org/opensearch/alerting/transport/TransportDeleteWorkflowAction.kt b/alerting/src/main/kotlin/org/opensearch/alerting/transport/TransportDeleteWorkflowAction.kt index fb7ec9664..0bc223cfa 100644 --- a/alerting/src/main/kotlin/org/opensearch/alerting/transport/TransportDeleteWorkflowAction.kt +++ b/alerting/src/main/kotlin/org/opensearch/alerting/transport/TransportDeleteWorkflowAction.kt @@ -152,9 +152,7 @@ class TransportDeleteWorkflowAction @Inject constructor( val deleteResponse = deleteWorkflow(workflow) if (deleteDelegateMonitors == true) { - if (user == null) { - deleteMonitors(delegateMonitorIds, RefreshPolicy.IMMEDIATE) - } else { + if (user != null && filterByEnabled) { // Un-stash the context withClosableContext( InjectorContextElement( @@ -167,6 +165,8 @@ class TransportDeleteWorkflowAction @Inject constructor( ) { deleteMonitors(delegateMonitorIds, RefreshPolicy.IMMEDIATE) } + } else { + deleteMonitors(delegateMonitorIds, RefreshPolicy.IMMEDIATE) } } actionListener.onResponse(DeleteWorkflowResponse(deleteResponse.id, deleteResponse.version)) diff --git a/alerting/src/main/kotlin/org/opensearch/alerting/transport/TransportIndexWorkflowAction.kt b/alerting/src/main/kotlin/org/opensearch/alerting/transport/TransportIndexWorkflowAction.kt index 5fdd4490a..a68a32ab8 100644 --- a/alerting/src/main/kotlin/org/opensearch/alerting/transport/TransportIndexWorkflowAction.kt +++ b/alerting/src/main/kotlin/org/opensearch/alerting/transport/TransportIndexWorkflowAction.kt @@ -604,7 +604,7 @@ class TransportIndexWorkflowAction @Inject constructor( val searchSource = SearchSourceBuilder().query(query) val searchRequest = SearchRequest(SCHEDULED_JOBS_INDEX).source(searchSource) - if (user != null && !isAdmin(user) && filterByEnabled) { + if (user != null && filterByEnabled) { addFilter(user, searchRequest.source(), "monitor.user.backend_roles.keyword") } @@ -647,9 +647,7 @@ class TransportIndexWorkflowAction @Inject constructor( val indicesSearchRequest = SearchRequest().indices(*indices.toTypedArray()) .source(SearchSourceBuilder.searchSource().size(1).query(QueryBuilders.matchAllQuery())) - if (user == null) { - checkIndicesAccess(client, indicesSearchRequest, indices, actionListener) - } else { + if (user != null && filterByEnabled) { // Unstash the context and check if user with specified roles has indices access withClosableContext( InjectorContextElement( @@ -662,6 +660,8 @@ class TransportIndexWorkflowAction @Inject constructor( ) { checkIndicesAccess(client, indicesSearchRequest, indices, actionListener) } + } else { + checkIndicesAccess(client, indicesSearchRequest, indices, actionListener) } }