Skip to content

Commit

Permalink
filter namespace out of SOs when the spaceId is default
Browse files Browse the repository at this point in the history
  • Loading branch information
gmmorris committed Apr 14, 2020
1 parent 43becd4 commit 4822c7c
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 10 deletions.
9 changes: 4 additions & 5 deletions x-pack/plugins/actions/server/lib/action_executor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ export class ActionExecutor {
} = this.actionExecutorContext!;

const services = getServices(request);
const namespace = spaces && spaces.getSpaceId(request);
const spaceId = spaces && spaces.getSpaceId(request);
const namespace = spaceId && spaceId !== 'default' ? { namespace: spaceId } : {};

// Ensure user can read the action before processing
const {
Expand All @@ -91,9 +92,7 @@ export class ActionExecutor {
} = await encryptedSavedObjectsPlugin.getDecryptedAsInternalUser<RawAction>(
'action',
actionId,
{
namespace: namespace === 'default' ? undefined : namespace,
}
namespace
);
const actionType = actionTypeRegistry.get(actionTypeId);

Expand All @@ -112,7 +111,7 @@ export class ActionExecutor {
const actionLabel = `${actionTypeId}:${actionId}: ${name}`;
const event: IEvent = {
event: { action: EVENT_LOG_ACTIONS.execute },
kibana: { saved_objects: [{ type: 'action', id: actionId, namespace }] },
kibana: { saved_objects: [{ type: 'action', id: actionId, ...namespace }] },
};

eventLogger.startTiming(event);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,10 @@ test('calls actionsPlugin.execute per selected action', async () => {
"saved_objects": Array [
Object {
"id": "1",
"namespace": "default",
"type": "alert",
},
Object {
"id": "1",
"namespace": "default",
"type": "action",
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,17 @@ export function createExecutionHandler({
apiKey,
});

const namespace = spaceId === 'default' ? {} : { namespace: spaceId };

const event: IEvent = {
event: { action: EVENT_LOG_ACTIONS.executeAction },
kibana: {
alerting: {
instance_id: alertInstanceId,
},
saved_objects: [
{ type: 'alert', id: alertId, namespace: spaceId },
{ type: 'action', id: action.id, namespace: spaceId },
{ type: 'alert', id: alertId, ...namespace },
{ type: 'action', id: action.id, ...namespace },
],
},
};
Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/event_log/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ Here's the event written to the event log index:
"kibana": {
"saved_objects": [
{
"namespace": "default",
"type": "action",
"id": "79b4c37e-ef42-4421-a0b0-b536840f930d"
}
Expand Down

0 comments on commit 4822c7c

Please sign in to comment.