Skip to content
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

Added "Create Relationship" Button to Objects #7034

Open
wants to merge 6 commits into
base: release/6.4.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions opencti-platform/opencti-front/lang/front/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,7 @@
"Create observables from this indicator": "Erstellen von Observablen aus diesem Indikator",
"Create relations in bulk": "Beziehungen in Massen erstellen",
"Create relations in bulk for": "Erstellen von Relationen im Bulk für",
"Create Relationship": "Beziehung erstellen",
"created": "Erstellt",
"Created entities": "Erstellte Entitäten",
"Created the": "Erstellt die",
Expand Down Expand Up @@ -1822,6 +1823,7 @@
"No restrictions": "Keine Einschränkungen",
"No task": "Keine Aufgabe",
"No tasks has been found.": "Es wurden keine Aufgaben gefunden.",
"No valid target entities": "Keine gültigen Zieleinheiten",
"No template found for this name": "Keine Vorlage für diesen Namen gefunden",
"No value": "Kein Wert",
"No widget in this workspace": "Kein Widget in diesem Arbeitsbereich",
Expand Down
2 changes: 2 additions & 0 deletions opencti-platform/opencti-front/lang/front/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,7 @@
"Create observables from this indicator": "Create observables from this indicator",
"Create relations in bulk": "Create relations in bulk",
"Create relations in bulk for": "Create relations in bulk for",
"Create Relationship": "Create Relationship",
"created": "Created",
"Created entities": "Created entities",
"Created the": "Created the",
Expand Down Expand Up @@ -1822,6 +1823,7 @@
"No restrictions": "No restrictions",
"No task": "No task",
"No tasks has been found.": "No tasks has been found.",
"No valid target entities": "No valid target entities",
"No template found for this name": "No template found for this name",
"No value": "No value",
"No widget in this workspace": "No widget in this workspace",
Expand Down
2 changes: 2 additions & 0 deletions opencti-platform/opencti-front/lang/front/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,7 @@
"Create observables from this indicator": "Crear observables a partir de este indicador",
"Create relations in bulk": "Crear relaciones en bloque",
"Create relations in bulk for": "Crear relaciones en bloque para",
"Create Relationship": "Nueva relación",
"created": "Creado",
"Created entities": "Entidades creadas",
"Created the": "Creado el",
Expand Down Expand Up @@ -1822,6 +1823,7 @@
"No restrictions": "Sin restricciones",
"No task": "Ninguna tarea",
"No tasks has been found.": "No se han encontrado tareas.",
"No valid target entities": "No hay entidades de destino válidas",
"No template found for this name": "No se ha encontrado ninguna plantilla para este nombre",
"No value": "Sin valor",
"No widget in this workspace": "Sin elementos gráficos en este espacio de trabajo",
Expand Down
2 changes: 2 additions & 0 deletions opencti-platform/opencti-front/lang/front/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,7 @@
"Create observables from this indicator": "Créer des observables à partir de cet indicateur",
"Create relations in bulk": "Créer des relations en masse",
"Create relations in bulk for": "Créer des relations en masse pour",
"Create Relationship": "Créer une relation",
"created": "Créé",
"Created entities": "Entités créées",
"Created the": "Créé le",
Expand Down Expand Up @@ -1822,6 +1823,7 @@
"No restrictions": "Aucune restriction",
"No task": "Aucune tâche",
"No tasks has been found.": "Aucune tâche n'a été trouvée.",
"No valid target entities": "Aucune entité cible valide",
"No template found for this name": "Aucun modèle n'a été trouvé pour ce nom",
"No value": "Aucune valeur",
"No widget in this workspace": "Aucun widget dans cet espace de travail",
Expand Down
2 changes: 2 additions & 0 deletions opencti-platform/opencti-front/lang/front/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,7 @@
"Create observables from this indicator": "このインジケータから観測値を作成する",
"Create relations in bulk": "リレーションの一括作成",
"Create relations in bulk for": "リレーションシップの一括作成",
"Create Relationship": "リレーションシップを作成",
"created": "作成日時",
"Created entities": "作成されたエンティティ",
"Created the": "作成日時",
Expand Down Expand Up @@ -1822,6 +1823,7 @@
"No restrictions": "制限なし",
"No task": "タスクなし",
"No tasks has been found.": "タスクが見つかりませんでした。",
"No valid target entities": "有効なターゲットエンティティがありません",
"No template found for this name": "この名前に対応するテンプレートは見つかりませんでした",
"No value": "値なし",
"No widget in this workspace": "このワークスペースにウィジェットはありません",
Expand Down
2 changes: 2 additions & 0 deletions opencti-platform/opencti-front/lang/front/ko.json
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,7 @@
"Create observables from this indicator": "이 지표에서 관찰 가능 항목 생성",
"Create relations in bulk": "대량으로 관계 만들기",
"Create relations in bulk for": "다음에 대한 대량 관계 만들기",
"Create Relationship": "관계 만들기",
"created": "생성됨",
"Created entities": "생성된 엔터티",
"Created the": "생성됨",
Expand Down Expand Up @@ -1822,6 +1823,7 @@
"No restrictions": "제한 없음",
"No task": "작업 없음",
"No tasks has been found.": "작업이 발견되지 않았습니다.",
"No valid target entities": "유효한 대상 엔터티 없음",
"No template found for this name": "이 이름에 대한 템플릿을 찾을 수 없습니다",
"No value": "값 없음",
"No widget in this workspace": "이 작업 공간에 위젯 없음",
Expand Down
2 changes: 2 additions & 0 deletions opencti-platform/opencti-front/lang/front/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,7 @@
"Create observables from this indicator": "从该指标创建观测值",
"Create relations in bulk": "批量创建关系",
"Create relations in bulk for": "批量创建关系",
"Create Relationship": "创建关系",
"created": "创建",
"Created entities": "创建的实体",
"Created the": "已创建",
Expand Down Expand Up @@ -1822,6 +1823,7 @@
"No restrictions": "无限制",
"No task": "没有任务",
"No tasks has been found.": "没有找到任务。",
"No valid target entities": "没有有效的目标实体",
"No template found for this name": "此名称未找到模板",
"No value": "没有价值",
"No widget in this workspace": "此工作区没有控件",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import { getMainRepresentative } from '../../../../utils/defaultRepresentatives'
import { getCurrentTab, getPaddingRight } from '../../../../utils/utils';
import MalwareAnalysisEdition from './MalwareAnalysisEdition';
import useHelper from '../../../../utils/hooks/useHelper';
import CreateRelationshipContextProvider from '../../common/menus/CreateRelationshipContextProvider';
import CreateRelationshipButtonComponent from '../../common/menus/CreateRelationshipButtonComponent';

const subscription = graphql`
subscription RootMalwareAnalysisSubscription($id: ID!) {
Expand Down Expand Up @@ -86,7 +88,7 @@ const RootMalwareAnalysis = () => {
useSubscription(subConfig);
const link = `/dashboard/analyses/malware_analyses/${malwareAnalysisId}/knowledge`;
return (
<>
<CreateRelationshipContextProvider>
<QueryRenderer
query={malwareAnalysisQuery}
variables={{ id: malwareAnalysisId }}
Expand Down Expand Up @@ -114,6 +116,7 @@ const RootMalwareAnalysis = () => {
<MalwareAnalysisEdition malwareAnalysisId={malwareAnalysis.id} />
</Security>
)}
RelateComponent={CreateRelationshipButtonComponent}
noAliases={true}
/>
<Box
Expand Down Expand Up @@ -228,7 +231,7 @@ const RootMalwareAnalysis = () => {
return <Loader />;
}}
/>
</>
</CreateRelationshipContextProvider>
);
};
export default RootMalwareAnalysis;
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import useHelper from '../../../../utils/hooks/useHelper';
import Security from '../../../../utils/Security';
import { KNOWLEDGE_KNUPDATE } from '../../../../utils/hooks/useGranted';
import ChannelEdition from './ChannelEdition';
import CreateRelationshipContextProvider from '../../common/menus/CreateRelationshipContextProvider';
import CreateRelationshipButtonComponent from '../../common/menus/CreateRelationshipButtonComponent';

const subscription = graphql`
subscription RootChannelSubscription($id: ID!) {
Expand Down Expand Up @@ -101,7 +103,7 @@ const RootChannel = ({ queryRef, channelId }: RootChannelProps) => {
const paddingRight = getPaddingRight(location.pathname, channelId, '/dashboard/arsenal/channels');
const link = `/dashboard/arsenal/channels/${channelId}/knowledge`;
return (
<>
<CreateRelationshipContextProvider>
{channel ? (
<>
<Routes>
Expand Down Expand Up @@ -145,6 +147,7 @@ const RootChannel = ({ queryRef, channelId }: RootChannelProps) => {
<ChannelEdition channelId={channel.id} />
</Security>
)}
RelateComponent={CreateRelationshipButtonComponent}
enableQuickSubscription={true}
/>
<Box
Expand Down Expand Up @@ -260,7 +263,7 @@ const RootChannel = ({ queryRef, channelId }: RootChannelProps) => {
) : (
<ErrorNotFound />
)}
</>
</CreateRelationshipContextProvider>
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import Security from '../../../../utils/Security';
import { KNOWLEDGE_KNUPDATE } from '../../../../utils/hooks/useGranted';
import MalwareEdition from './MalwareEdition';
import EditEntityControlledDial from '../../../../components/EditEntityControlledDial';
import CreateRelationshipContextProvider from '../../common/menus/CreateRelationshipContextProvider';
import CreateRelationshipButtonComponent from '../../common/menus/CreateRelationshipButtonComponent';

const subscription = graphql`
subscription RootMalwareSubscription($id: ID!) {
Expand Down Expand Up @@ -106,7 +108,7 @@ const RootMalware = ({ queryRef, malwareId }: RootMalwareProps) => {
const paddingRight = getPaddingRight(location.pathname, malwareId, '/dashboard/arsenal/malwares');
const link = `/dashboard/arsenal/malwares/${malwareId}/knowledge`;
return (
<>
<CreateRelationshipContextProvider>
{malware ? (
<>
<Routes>
Expand Down Expand Up @@ -155,6 +157,7 @@ const RootMalware = ({ queryRef, malwareId }: RootMalwareProps) => {
/>
</Security>
)}
RelateComponent={CreateRelationshipButtonComponent}
enableQuickSubscription={true}
/>
<Box
Expand Down Expand Up @@ -276,7 +279,7 @@ const RootMalware = ({ queryRef, malwareId }: RootMalwareProps) => {
) : (
<ErrorNotFound />
)}
</>
</CreateRelationshipContextProvider>
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import useHelper from '../../../../utils/hooks/useHelper';
import Security from '../../../../utils/Security';
import { KNOWLEDGE_KNUPDATE } from '../../../../utils/hooks/useGranted';
import ToolEdition from './ToolEdition';
import CreateRelationshipContextProvider from '../../common/menus/CreateRelationshipContextProvider';
import CreateRelationshipButtonComponent from '../../common/menus/CreateRelationshipButtonComponent';

const subscription = graphql`
subscription RootToolSubscription($id: ID!) {
Expand Down Expand Up @@ -103,7 +105,7 @@ const RootTool = ({ queryRef, toolId }: RootToolProps) => {
const paddingRight = getPaddingRight(location.pathname, toolId, '/dashboard/arsenal/tools');
const link = `/dashboard/arsenal/tools/${toolId}/knowledge`;
return (
<>
<CreateRelationshipContextProvider>
{tool ? (
<>
<Routes>
Expand Down Expand Up @@ -146,6 +148,7 @@ const RootTool = ({ queryRef, toolId }: RootToolProps) => {
<ToolEdition toolId={tool.id} />
</Security>
)}
RelateComponent={CreateRelationshipButtonComponent}
enableQuickSubscription={true}
/>
<Box
Expand Down Expand Up @@ -261,7 +264,7 @@ const RootTool = ({ queryRef, toolId }: RootToolProps) => {
) : (
<ErrorNotFound />
)}
</>
</CreateRelationshipContextProvider>
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import useHelper from '../../../../utils/hooks/useHelper';
import Security from '../../../../utils/Security';
import { KNOWLEDGE_KNUPDATE } from '../../../../utils/hooks/useGranted';
import VulnerabilityEdition from './VulnerabilityEdition';
import CreateRelationshipContextProvider from '../../common/menus/CreateRelationshipContextProvider';
import CreateRelationshipButtonComponent from '../../common/menus/CreateRelationshipButtonComponent';

const subscription = graphql`
subscription RootVulnerabilitySubscription($id: ID!) {
Expand Down Expand Up @@ -101,7 +103,7 @@ const RootVulnerability = ({ queryRef, vulnerabilityId }: RootVulnerabilityProps
const paddingRight = getPaddingRight(location.pathname, vulnerabilityId, '/dashboard/arsenal/vulnerabilities');
const link = `/dashboard/arsenal/vulnerabilities/${vulnerabilityId}/knowledge`;
return (
<>
<CreateRelationshipContextProvider>
{vulnerability ? (
<>
<Routes>
Expand Down Expand Up @@ -145,6 +147,7 @@ const RootVulnerability = ({ queryRef, vulnerabilityId }: RootVulnerabilityProps
<VulnerabilityEdition vulnerabilityId={vulnerabilityId} />
</Security>
)}
RelateComponent={CreateRelationshipButtonComponent}
enableQuickSubscription={true}
isOpenctiAlias={true}
/>
Expand Down Expand Up @@ -263,7 +266,7 @@ const RootVulnerability = ({ queryRef, vulnerabilityId }: RootVulnerabilityProps
) : (
<ErrorNotFound />
)}
</>
</CreateRelationshipContextProvider>
);
};

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import React, { FunctionComponent } from 'react';
import Security from 'src/utils/Security';
import { KNOWLEDGE_KNUPDATE } from 'src/utils/hooks/useGranted';
import StixCoreRelationshipCreationFromControlledDial from '../stix_core_relationships/StixCoreRelationshipCreationFromControlledDial';

interface CreateRelationshipButtonComponentProps {
id: string,
defaultStartTime?: string | number | Date,
defaultStopTime?: string | number | Date,
}

const CreateRelationshipButtonComponent: FunctionComponent<CreateRelationshipButtonComponentProps> = ({
id,
defaultStartTime,
defaultStopTime,
}) => {
const startTime = new Date(defaultStartTime ?? new Date()).toISOString();
const stopTime = new Date(defaultStopTime ?? new Date()).toISOString();
return (
<Security needs={[KNOWLEDGE_KNUPDATE]}>
<StixCoreRelationshipCreationFromControlledDial
entityId={id}
defaultStartTime={startTime}
defaultStopTime={stopTime}
/>
</Security>
);
};

export default CreateRelationshipButtonComponent;
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import React, { ReactNode, createContext, useMemo, useState } from 'react';

interface CreateRelationshipContextStateType {
relationshipTypes?: string[];
stixCoreObjectTypes?: string[];
connectionKey?: string;
reversed?: boolean;
paginationOptions?: unknown;
onCreate?: () => void;
}

export interface CreateRelationshipContextType {
state: CreateRelationshipContextStateType;
setState: (state: CreateRelationshipContextStateType) => void;
}

const defaultContext: CreateRelationshipContextType = {
state: {
relationshipTypes: [],
stixCoreObjectTypes: [],
connectionKey: 'Pagination_stixCoreObjects',
reversed: false,
},
setState: () => {},
};

export const CreateRelationshipContext = createContext<CreateRelationshipContextType>(defaultContext);

const CreateRelationshipContextProvider = ({ children }: { children: ReactNode }) => {
const [relationshipTypes, setRelationshipTypes] = useState<string[]>([]);
const [stixCoreObjectTypes, setStixCoreObjectTypes] = useState<string[]>([]);
const [connectionKey, setConnectionKey] = useState<string>('Pagination_stixCoreObjects');
const [reversed, setReversed] = useState<boolean>(false);
const [paginationOptions, setPaginationOptions] = useState<unknown>();
const [onCreate, setOnCreate] = useState<() => void>();
const state = {
relationshipTypes,
stixCoreObjectTypes,
connectionKey,
reversed,
paginationOptions,
onCreate,
};
const setState = ({
relationshipTypes: updatedRelationshipTypes,
stixCoreObjectTypes: updatedStixCoreObjectTypes,
connectionKey: updatedConnectionKey,
reversed: updatedReversed,
paginationOptions: updatedPaginationOptions,
onCreate: updatedOnCreate,
}: CreateRelationshipContextStateType) => {
if (updatedRelationshipTypes) setRelationshipTypes(updatedRelationshipTypes);
if (updatedStixCoreObjectTypes) setStixCoreObjectTypes(updatedStixCoreObjectTypes);
if (updatedConnectionKey) setConnectionKey(updatedConnectionKey);
if (updatedReversed) setReversed(updatedReversed);
if (updatedPaginationOptions) setPaginationOptions(updatedPaginationOptions);
if (updatedOnCreate) setOnCreate(() => updatedOnCreate); // Dispatching inner function to let context consumer call the onCreate function
};
const values = useMemo<CreateRelationshipContextType>(() => ({
state,
setState,
}), [...Object.values(state)]);
return <CreateRelationshipContext.Provider value={values}>
{children}
</CreateRelationshipContext.Provider>;
};

export default CreateRelationshipContextProvider;
Loading