Skip to content

Commit a519ddc

Browse files
[backend] Check available playbooks for an entity according to filters (#13856)
Co-authored-by: Samuel Hassine <[email protected]>
1 parent fbe7174 commit a519ddc

File tree

3 files changed

+10
-12
lines changed

3 files changed

+10
-12
lines changed

opencti-platform/opencti-front/src/private/components/common/stix_core_objects/StixCoreObjectEnrollPlaybookLines.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ const styles = (theme) => ({
3434
noResult: {
3535
color: theme.palette.text.primary,
3636
fontSize: 15,
37+
textAlign: 'center',
38+
marginTop: 20,
3739
},
3840
itemIcon: {
3941
color: theme.palette.primary.main,

opencti-platform/opencti-graphql/src/manager/playbookManager/playbookManager.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import { AUTOMATION_MANAGER_USER, executionContext, RETENTION_MANAGER_USER, SYST
2626
import type { SseEvent, StreamDataEvent } from '../../types/event';
2727
import type { StixBundle, StixObject } from '../../types/stix-2-1-common';
2828
import { streamEventId, utcDate } from '../../utils/format';
29-
import { findById } from '../../modules/playbook/playbook-domain';
29+
import { findById, findPlaybooksForEntity } from '../../modules/playbook/playbook-domain';
3030
import { type CronConfiguration, PLAYBOOK_INTERNAL_DATA_CRON, type StreamConfiguration } from '../../modules/playbook/playbook-components';
3131
import { PLAYBOOK_COMPONENTS } from '../../modules/playbook/playbook-components';
3232
import type { BasicStoreEntityPlaybook, ComponentDefinition } from '../../modules/playbook/playbook-types';
@@ -132,15 +132,17 @@ const playbookStreamHandler = async (streamEvents: Array<SseEvent<StreamDataEven
132132
};
133133

134134
export const executePlaybookOnEntity = async (context: AuthContext, id: string, entityId: string) => {
135-
const playbooks = await getEntitiesListFromCache<BasicStoreEntityPlaybook>(context, SYSTEM_USER, ENTITY_TYPE_PLAYBOOK);
135+
// fetch playbooks allowed for this entity
136+
const playbooks = await findPlaybooksForEntity(context, RETENTION_MANAGER_USER, entityId);
136137
let playbook = null;
138+
// keep the playbook corresponding to the id
137139
const filteredPlaybooks = playbooks.filter((n) => n.id === id);
138140
if (filteredPlaybooks.length > 0) {
139141
playbook = filteredPlaybooks.at(0);
140142
} else {
141-
throw FunctionalError('Playbook does not exist', { id });
143+
throw FunctionalError('Playbook does not exist for this entity', { id });
142144
}
143-
// Execute only of definition is available
145+
// Execute only if definition is available
144146
if (playbook && playbook.playbook_definition) {
145147
const def = JSON.parse(playbook.playbook_definition) as ComponentDefinition;
146148
const instance = def.nodes.find((n) => n.id === playbook.playbook_start);

opencti-platform/opencti-graphql/src/modules/playbook/playbook-domain.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { notify } from '../../database/redis';
2222
import type { DomainFindById } from '../../domain/domainTypes';
2323
import { ABSTRACT_INTERNAL_OBJECT } from '../../schema/general';
2424
import type { AuthContext, AuthUser } from '../../types/user';
25-
import { type EditInput, FilterMode, type PlaybookAddInput, type PlaybookAddLinkInput, type PlaybookAddNodeInput, type PositionInput } from '../../generated/graphql';
25+
import { type EditInput, type PlaybookAddInput, type PlaybookAddLinkInput, type PlaybookAddNodeInput, type PositionInput } from '../../generated/graphql';
2626
import type { BasicStoreEntityPlaybook, ComponentDefinition } from './playbook-types';
2727
import { ENTITY_TYPE_PLAYBOOK } from './playbook-types';
2828
import { PLAYBOOK_COMPONENTS, type SharingConfiguration, type StreamConfiguration } from './playbook-components';
@@ -32,7 +32,6 @@ import { isStixMatchFilterGroup } from '../../utils/filtering/filtering-stix/sti
3232
import { registerConnectorQueues, unregisterConnector } from '../../database/rabbitmq';
3333
import { getEntitiesListFromCache } from '../../database/cache';
3434
import { SYSTEM_USER } from '../../utils/access';
35-
import { findFiltersFromKey } from '../../utils/filtering/filtering-utils';
3635
import { checkEnterpriseEdition, isEnterpriseEdition } from '../../enterprise-edition/ee';
3736
import pjson from '../../../package.json';
3837
import { extractContentFrom } from '../../utils/fileToContent';
@@ -72,12 +71,7 @@ export const findPlaybooksForEntity = async (context: AuthContext, user: AuthUse
7271
if (instance && (instance.component_id === 'PLAYBOOK_INTERNAL_DATA_STREAM' || instance.component_id === 'PLAYBOOK_INTERNAL_MANUAL_TRIGGER')) {
7372
const { filters } = JSON.parse(instance.configuration ?? '{}') as StreamConfiguration;
7473
const jsonFilters = filters ? JSON.parse(filters) : null;
75-
const newFilters = {
76-
mode: FilterMode.And,
77-
filters: findFiltersFromKey(jsonFilters?.filters ?? [], 'entity_type'),
78-
filterGroups: [],
79-
};
80-
const isMatch = await isStixMatchFilterGroup(context, SYSTEM_USER, stixEntity, newFilters);
74+
const isMatch = await isStixMatchFilterGroup(context, SYSTEM_USER, stixEntity, jsonFilters);
8175
if (isMatch) {
8276
filteredPlaybooks.push(playbook);
8377
}

0 commit comments

Comments
 (0)