Skip to content

Commit

Permalink
[backend/frontend] Rework model for Max shareable markings (#7348)
Browse files Browse the repository at this point in the history
Co-authored-by: Adrien Servel <adrien.servel@filigran.io>
Co-authored-by: Landry Trebon <landry.trebon@filigran.io>
  • Loading branch information
3 people authored Jun 12, 2024
1 parent 505978c commit ef515b0
Show file tree
Hide file tree
Showing 33 changed files with 266 additions and 148 deletions.
2 changes: 2 additions & 0 deletions opencti-platform/opencti-front/lang/back/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -378,9 +378,11 @@
"Marking color": "Farbe der Markierung",
"Marking definition": "Definition der Markierung",
"Marking of related entity": "Markierung der verwandten Entität",
"Marking Type": "Markierung Typ",
"Markings": "Markierungen",
"Max Confidence": "Maximale Konfidenz",
"Max policy length": "Max policy length",
"Max shareable markings": "Maximal teilbare Markierungen",
"Maximum marking": "Maximale Markierung",
"Maximum retention": "Maximale Aufbewahrung",
"MD5": "MD5",
Expand Down
2 changes: 2 additions & 0 deletions opencti-platform/opencti-front/lang/back/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -378,9 +378,11 @@
"Marking color": "Marking color",
"Marking definition": "Marking definition",
"Marking of related entity": "Marking of related entity",
"Marking Type": "Marking Type",
"Markings": "Markings",
"Max Confidence": "Max Confidence",
"Max policy length": "Max policy length",
"Max shareable markings": "Max shareable markings",
"Maximum marking": "Maximum marking",
"Maximum retention": "Maximum retention",
"MD5": "MD5",
Expand Down
2 changes: 2 additions & 0 deletions opencti-platform/opencti-front/lang/back/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -378,9 +378,11 @@
"Marking color": "Color de marcado",
"Marking definition": "Definición de marcado",
"Marking of related entity": "Marca de la entidad relacionada",
"Marking Type": "Tipo de marcado",
"Markings": "Marcas",
"Max Confidence": "Confianza máxima",
"Max policy length": "Longitud máxima de la política",
"Max shareable markings": "Marcas máximas compartibles",
"Maximum marking": "Marcado máximo",
"Maximum retention": "Retención máxima",
"MD5": "MD5",
Expand Down
2 changes: 2 additions & 0 deletions opencti-platform/opencti-front/lang/back/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -378,9 +378,11 @@
"Marking color": "Couleur de marquage",
"Marking definition": "Définition du marquage",
"Marking of related entity": "Marquage de l'entité apparentée",
"Marking Type": "Type de marquage",
"Markings": "Marques",
"Max Confidence": "Confiance maximale",
"Max policy length": "Longueur maximale de la politique",
"Max shareable markings": "Marques maximales partageables",
"Maximum marking": "Marquage maximum",
"Maximum retention": "Rétention maximale",
"MD5": "MD5",
Expand Down
2 changes: 2 additions & 0 deletions opencti-platform/opencti-front/lang/back/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -378,9 +378,11 @@
"Marking color": "マーキングの色",
"Marking definition": "マーキング定義",
"Marking of related entity": "関連エンティティのマーク",
"Marking Type": "マーキング・タイプ",
"Markings": "マーキング",
"Max Confidence": "最大信頼度",
"Max policy length": "最大ポリシー長",
"Max shareable markings": "共有可能な最大マーキング",
"Maximum marking": "最大マーキング",
"Maximum retention": "最大保有期間",
"MD5": "MD5",
Expand Down
2 changes: 2 additions & 0 deletions opencti-platform/opencti-front/lang/back/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -378,9 +378,11 @@
"Marking color": "标记颜色",
"Marking definition": "标记定义",
"Marking of related entity": "相关实体的标记",
"Marking Type": "标记类型",
"Markings": "标记",
"Max Confidence": "最大置信度",
"Max policy length": "最多长度要求",
"Max shareable markings": "最大可共享标记",
"Maximum marking": "最大标记",
"Maximum retention": "最大保留时间",
"MD5": "MD5",
Expand Down
1 change: 1 addition & 0 deletions opencti-platform/opencti-front/lang/front/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -1611,6 +1611,7 @@
"No public dashboard created yet": "Noch kein öffentliches Dashboard erstellt",
"No relations history about this entity.": "Keine Beziehungshistorie zu dieser Entität.",
"No reports about this entity.": "Keine Berichte über diese Entität.",
"No restrictions": "Keine Einschränkungen",
"No task": "Keine Aufgabe",
"No tasks has been found.": "Es wurden keine Aufgaben gefunden.",
"No value": "Kein Wert",
Expand Down
1 change: 1 addition & 0 deletions opencti-platform/opencti-front/lang/front/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1611,6 +1611,7 @@
"No public dashboard created yet": "No public dashboard created yet",
"No relations history about this entity.": "No relations history about this entity.",
"No reports about this entity.": "No reports about this entity.",
"No restrictions": "No restrictions",
"No task": "No task",
"No tasks has been found.": "No tasks has been found.",
"No value": "No value",
Expand Down
1 change: 1 addition & 0 deletions opencti-platform/opencti-front/lang/front/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -1611,6 +1611,7 @@
"No public dashboard created yet": "Aún no se ha creado ningún panel público",
"No relations history about this entity.": "No hay historial de relaciones sobre esta entidad",
"No reports about this entity.": "Ningún informe sobre esta entidad.",
"No restrictions": "Sin restricciones",
"No task": "Ninguna tarea",
"No tasks has been found.": "No se han encontrado tareas.",
"No value": "Sin valor",
Expand Down
1 change: 1 addition & 0 deletions opencti-platform/opencti-front/lang/front/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -1611,6 +1611,7 @@
"No public dashboard created yet": "Aucun tableau de bord public n'a encore été créé",
"No relations history about this entity.": "Aucun historique de relations à propos cette entité.",
"No reports about this entity.": "Aucun rapport à propos de cette entité.",
"No restrictions": "Aucune restriction",
"No task": "Aucune tâche",
"No tasks has been found.": "Aucune tâche n'a été trouvée.",
"No value": "Aucune valeur",
Expand Down
1 change: 1 addition & 0 deletions opencti-platform/opencti-front/lang/front/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -1611,6 +1611,7 @@
"No public dashboard created yet": "まだ作成されていない公開ダッシュボード",
"No relations history about this entity.": "このエンティティにはリレーションの履歴がありません。",
"No reports about this entity.": "このエンティティに関するレポートはありません。",
"No restrictions": "制限なし",
"No task": "タスクなし",
"No tasks has been found.": "タスクが見つかりませんでした。",
"No value": "値なし",
Expand Down
1 change: 1 addition & 0 deletions opencti-platform/opencti-front/lang/front/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -1611,6 +1611,7 @@
"No public dashboard created yet": "尚未创建公共仪表盘",
"No relations history about this entity.": "尚无关于此实体的关系历史",
"No reports about this entity.": "没有关于此实体的报告。",
"No restrictions": "无限制",
"No task": "没有任务",
"No tasks has been found.": "没有找到任务。",
"No value": "没有价值",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,19 @@ export type EntityMarkingDefinition = {
x_opencti_order: number
};

type MarkingsSelectFieldValue = string[];
type MarkingsSelectFieldValue = EntityMarkingDefinition[];

interface MarkingsSelectFieldInternalValue {
[key: string]: string
}

interface MarkingsSelectFieldProps extends FieldProps<MarkingsSelectFieldValue> {
markingDefinitions: EntityMarkingDefinition[]
onChange?: (val: MarkingsSelectFieldValue) => void
onChange?: (type: string, val: string) => void
}

const NOT_SHAREABLE_ID = 'not_shareable';
const ALL_ID = 'all';
const NOT_SHAREABLE_ID = 'none';

const MarkingsSelectField = ({
form,
Expand All @@ -37,25 +38,24 @@ const MarkingsSelectField = ({
const markingTypes = Array.from(new Set(
markingDefinitions.map((m) => m.definition_type),
));

const initialValues = markingTypes.reduce((acc, type) => ({
...acc,
[type]: value.find((defId) => {
const marking = markingDefinitions.find((def) => def.id === defId);
return marking?.definition_type === type;
}) ?? NOT_SHAREABLE_ID,
}), {});
const initialValues: Record<string, string> = {};
markingTypes.forEach((type) => {
if (!value.find((v) => v.definition_type === type)) {
initialValues[type] = ALL_ID;
} else if (value.find((v) => v.definition_type === type && v.id === 'none')) {
initialValues[type] = NOT_SHAREABLE_ID;
} else {
const val = value.find((v) => v.definition_type === type);
if (val) {
initialValues[type] = val.id;
}
}
});

const changeMarking = (type: string, markingId: string) => {
const newValue = value.filter((defId) => {
const marking = markingDefinitions.find((def) => def.id === defId);
return marking?.definition_type !== type;
});
if (markingId !== NOT_SHAREABLE_ID) {
newValue.push(markingId);
}
const newValue = [...Object.entries(initialValues).filter(([definition_type]) => definition_type !== type).map(([_, v]) => v), { id: markingId, definition_type: type }];
setFieldValue(name, newValue);
onChange?.(newValue);
onChange?.(type, markingId);
};

return (
Expand All @@ -76,6 +76,9 @@ const MarkingsSelectField = ({
onChange={changeMarking}
displ
>
<MenuItem value={ALL_ID} key={ALL_ID}>
{t_i18n('No restrictions')}
</MenuItem>
<MenuItem value={NOT_SHAREABLE_ID} key={NOT_SHAREABLE_ID}>
{t_i18n('Not shareable')}
</MenuItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import GroupPopover from './GroupPopover';
import ItemIcon from '../../../../components/ItemIcon';
import GroupHiddenTypesChipList from './GroupHiddenTypesChipList';
import ExpandableMarkdown from '../../../../components/ExpandableMarkdown';
import { checkIsMarkingAllowed } from '../../../../utils/markings/markingsFiltering';

// Deprecated - https://mui.com/system/styles/basics/
// Do not use it for new code.
Expand Down Expand Up @@ -108,6 +109,7 @@ const groupFragment = graphql`
x_opencti_color
x_opencti_order
}
not_shareable_marking_types
max_shareable_marking {
id
definition
Expand Down Expand Up @@ -368,7 +370,7 @@ const Group = ({ groupData }: { groupData: Group_group$key }) => {
{markingTypes.map((type) => {
const marking = maxShareableMarkingsByType.get(type);
if (marking) {
const isMarkingAllowed = allowedMarkings.some((m) => m.definition_type === marking.definition_type && m.x_opencti_order >= marking.x_opencti_order);
const isMarkingAllowed = checkIsMarkingAllowed(marking, allowedMarkings);
return (
<ListItem
key={marking.id}
Expand All @@ -379,26 +381,49 @@ const Group = ({ groupData }: { groupData: Group_group$key }) => {
<Typography variant="h3" gutterBottom={true} width={100}>
{truncate(type, 40)}
</Typography>
<ListItemIcon>
<ItemIcon
type="Marking-Definition"
color={marking.x_opencti_color ?? undefined}
/>
</ListItemIcon>
<ListItemText
primary={truncate(marking.definition, 40)}
/>
{isMarkingAllowed
? <>
<ListItemIcon>
<ItemIcon
type="Marking-Definition"
color={marking.x_opencti_color ?? undefined}
/>
</ListItemIcon>
<ListItemText
primary={truncate(marking.definition, 40)}
/>
</>
: <ListItemText
primary={t_i18n('No restrictions')}
/>
}
{!isMarkingAllowed
&& <Tooltip
title={t_i18n(
'This marking is not allowed for this group: users of this group can only share their allowed markings that are less restricted than this one.',
'The maximum shareable marking set for this definition type is not allowed for this group, so users can only share their allowed markings independently from the maximum shareable marking set.',
)}
>
<WarningOutlined color="warning"/>
</Tooltip>
}
</ListItem>
);
} if (group.not_shareable_marking_types.includes(type)) {
return (
<ListItem
key={type}
dense={true}
divider={true}
button={false}
>
<Typography variant="h3" gutterBottom={true} width={100}>
{truncate(type, 40)}
</Typography>
<ListItemText
primary={t_i18n('Not shareable')}
/>
</ListItem>
);
}
return (
<ListItem
Expand All @@ -411,7 +436,7 @@ const Group = ({ groupData }: { groupData: Group_group$key }) => {
{truncate(type, 40)}
</Typography>
<ListItemText
primary={t_i18n('not shareable')}
primary={t_i18n('No restrictions')}
/>
</ListItem>
);
Expand Down
Loading

0 comments on commit ef515b0

Please sign in to comment.