Skip to content

Commit

Permalink
[frontend/backend] Max shareable markings at the group level for expo…
Browse files Browse the repository at this point in the history
…rts and public dashboard (#7006)
  • Loading branch information
Archidoit authored Jun 10, 2024
1 parent d6b4445 commit e166e0c
Show file tree
Hide file tree
Showing 49 changed files with 556 additions and 458 deletions.
3 changes: 3 additions & 0 deletions opencti-platform/opencti-front/lang/front/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -1495,6 +1495,8 @@
"Maximum": "Maximum",
"Maximum marking definition allowed to be shared for public dashboard": "Maximale Markierungsdefinition, die für das öffentliche Dashboard freigegeben werden kann",
"Maximum retention days": "Maximale Aufbewahrungstage",
"Maximum shareable marking definitions": "Maximal teilbare Markierungsdefinitionen",
"Maximum shareable markings": "Maximal gemeinsam nutzbare Markierungen",
"Med": "Mittel",
"MEDIUM": "MITTEL",
"Member": "Mitglied",
Expand Down Expand Up @@ -1627,6 +1629,7 @@
"Not equals": "Nicht gleich",
"Not implemented yet": "Noch nicht implementiert",
"Not shareable": "Nicht gemeinsam nutzbar",
"not shareable": "nicht teilbar",
"Not Specified": "Nicht spezifiziert",
"Not starts with": "Nicht beginnt mit",
"not_contains": "enthält nicht",
Expand Down
3 changes: 3 additions & 0 deletions opencti-platform/opencti-front/lang/front/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1495,6 +1495,8 @@
"Maximum": "Maximum",
"Maximum marking definition allowed to be shared for public dashboard": "Maximum marking definition allowed to be shared for public dashboard",
"Maximum retention days": "Maximum retention days",
"Maximum shareable marking definitions": "Maximum shareable marking definitions",
"Maximum shareable markings": "Maximum shareable markings",
"Med": "Med",
"MEDIUM": "MEDIUM",
"Member": "Member",
Expand Down Expand Up @@ -1627,6 +1629,7 @@
"Not equals": "Not equals",
"Not implemented yet": "Not implemented yet",
"Not shareable": "Not shareable",
"not shareable": "not shareable",
"Not Specified": "Not Specified",
"Not starts with": "Not starts with",
"not_contains": "not contains",
Expand Down
3 changes: 3 additions & 0 deletions opencti-platform/opencti-front/lang/front/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -1495,6 +1495,8 @@
"Maximum": "Máximo",
"Maximum marking definition allowed to be shared for public dashboard": "Máxima definición de marcado que se permite compartir para el cuadro de mandos público",
"Maximum retention days": "Días de retención máxima",
"Maximum shareable marking definitions": "Definiciones de marcado máximo compartible",
"Maximum shareable markings": "Marcas máximas compartibles",
"Med": "Mediano",
"MEDIUM": "MEDIO",
"Member": "Miembro",
Expand Down Expand Up @@ -1627,6 +1629,7 @@
"Not equals": "No igual",
"Not implemented yet": "Aún no implementado",
"Not shareable": "No compartible",
"not shareable": "no compartibles",
"Not Specified": "No especificado",
"Not starts with": "No comienza con",
"not_contains": "no contiene",
Expand Down
3 changes: 3 additions & 0 deletions opencti-platform/opencti-front/lang/front/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -1495,6 +1495,8 @@
"Maximum": "Maximum",
"Maximum marking definition allowed to be shared for public dashboard": "Définition maximale du marquage autorisée à être partagée pour le tableau de bord public",
"Maximum retention days": "Jours de rétention maximum",
"Maximum shareable marking definitions": "Définitions du marquage maximum partageable",
"Maximum shareable markings": "Niveau de markings partageables maximum",
"Med": "Moyen",
"MEDIUM": "MOYEN",
"Member": "Membre",
Expand Down Expand Up @@ -1627,6 +1629,7 @@
"Not equals": "Pas égal",
"Not implemented yet": "Pas encore mis en œuvre",
"Not shareable": "Non partageable",
"not shareable": "non partageable",
"Not Specified": "Non spécifié",
"Not starts with": "Ne commence pas par",
"not_contains": "ne contient pas",
Expand Down
3 changes: 3 additions & 0 deletions opencti-platform/opencti-front/lang/front/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -1495,6 +1495,8 @@
"Maximum": "最大値",
"Maximum marking definition allowed to be shared for public dashboard": "公開ダッシュボードで共有できるマーキング定義の最大値",
"Maximum retention days": "最大保持日数",
"Maximum shareable marking definitions": "最大共有マーキング定義",
"Maximum shareable markings": "最大共有可能マーキング",
"Med": "中くらい",
"MEDIUM": "",
"Member": "メンバー",
Expand Down Expand Up @@ -1627,6 +1629,7 @@
"Not equals": "等しくない",
"Not implemented yet": "未実装",
"Not shareable": "共有不可",
"not shareable": "共有不可",
"Not Specified": "指定されていない",
"Not starts with": "で始まらない",
"not_contains": "を含まない",
Expand Down
3 changes: 3 additions & 0 deletions opencti-platform/opencti-front/lang/front/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -1495,6 +1495,8 @@
"Maximum": "最大值",
"Maximum marking definition allowed to be shared for public dashboard": "公共仪表板允许共享的最大标记定义",
"Maximum retention days": "最长保留天数",
"Maximum shareable marking definitions": "最大可共享标记定义",
"Maximum shareable markings": "最大可共享标记",
"Med": "中等",
"MEDIUM": "",
"Member": "成员",
Expand Down Expand Up @@ -1627,6 +1629,7 @@
"Not equals": "不等于",
"Not implemented yet": "尚未实施",
"Not shareable": "不可共享",
"not shareable": "不可共享",
"Not Specified": "未指定",
"Not starts with": "不以...开始",
"not_contains": "不包含",
Expand Down
11 changes: 5 additions & 6 deletions opencti-platform/opencti-front/src/private/Root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,6 @@ const rootSettingsFragment = graphql`
platform_whitemark
platform_session_idle_timeout
platform_session_timeout
platform_data_sharing_max_markings {
id
definition
definition_type
x_opencti_order
}
platform_feature_flags {
id
enable
Expand Down Expand Up @@ -131,6 +125,11 @@ const rootPrivateQuery = graphql`
x_opencti_color
x_opencti_order
}
max_shareable_marking {
id
definition_type
x_opencti_order
}
personal_notifiers {
id
name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ const FileManager = ({
onChange={(_, values) => handleSelectedContentMaxMarkingsChange(values)}
style={fieldSpacingContainerStyle}
setFieldValue={setFieldValue}
limitToMaxSharing
/>
<ObjectMarkingField
name="fileMarkings"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import MenuItem from '@mui/material/MenuItem';
import { useFormatter } from '../../../../components/i18n';
import SelectField from '../../../../components/fields/SelectField';

interface MarkingDefinition {
export type EntityMarkingDefinition = {
id: string
definition: string
definition_type: string
x_opencti_order: number
}
};

type MarkingsSelectFieldValue = string[];

Expand All @@ -18,7 +18,7 @@ interface MarkingsSelectFieldInternalValue {
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { useFormatter } from '../../../../components/i18n';
import { convertMarking } from '../../../../utils/edition';
import { Option } from './ReferenceField';
import { filterMarkingsOutFor } from '../../../../utils/markings/markingsFiltering';
import { isEmptyField } from '../../../../utils/utils';

// Deprecated - https://mui.com/system/styles/basics/
// Do not use it for new code.
Expand Down Expand Up @@ -86,13 +87,12 @@ const ObjectMarkingField: FunctionComponent<ObjectMarkingFieldProps> = ({
>(undefined);
const [operation, setOperation] = useState<string | undefined>(undefined);

const { me, settings } = useAuth();
const { me } = useAuth();
let allowedMarkingDefinitions = me.allowed_marking?.map(convertMarking) ?? [];
if (limitToMaxSharing) {
const { platform_data_sharing_max_markings } = settings;
allowedMarkingDefinitions = allowedMarkingDefinitions.filter((def) => {
const maxMarking = platform_data_sharing_max_markings?.find((marking) => marking.definition_type === def.definition_type);
return !!maxMarking && maxMarking.x_opencti_order >= def.x_opencti_order;
const maxMarkingsOfType = me.max_shareable_marking?.filter((marking) => marking.definition_type === def.definition_type);
return !isEmptyField(maxMarkingsOfType) && maxMarkingsOfType.some((maxMarking) => maxMarking.x_opencti_order >= def.x_opencti_order);
});
}
const filteredAllowedMarkingDefinitionsOut = filterTargetIds
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ const StixCoreObjectFileExportComponent = ({
onChange={(_, values) => handleSelectedContentMaxMarkingsChange(values)}
style={fieldSpacingContainerStyle}
setFieldValue={setFieldValue}
limitToMaxSharing
/>
<ObjectMarkingField
name="fileMarkings"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,7 @@ const StixCoreObjectFilesAndHistory = ({
onChange={(_, values) => handleSelectedContentMaxMarkingsChange(values)}
style={fieldSpacingContainerStyle}
setFieldValue={setFieldValue}
limitToMaxSharing
/>
<ObjectMarkingField
name="fileMarkings"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ const StixCoreObjectsExportCreationComponent = ({
onChange={(_, values) => handleSelectedContentMaxMarkingsChange(values)}
style={fieldSpacingContainerStyle}
setFieldValue={setFieldValue}
limitToMaxSharing
/>
<ObjectMarkingField
name="fileMarkings"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ class StixCoreRelationshipsExportCreationComponent extends Component {
onChange={(_, values) => this.handleSelectedContentMaxMarkingsChange(values)}
style={fieldSpacingContainerStyle}
setFieldValue={setFieldValue}
limitToMaxSharing
/>
<ObjectMarkingField
name="fileMarkings"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ class StixDomainObjectsExportCreationComponent extends Component {
onChange={(_, values) => this.handleSelectedContentMaxMarkingsChange(values)}
style={fieldSpacingContainerStyle}
setFieldValue={setFieldValue}
limitToMaxSharing
/>
<ObjectMarkingField
name="fileMarkings"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ class StixCyberObservablesExportCreationComponent extends Component {
label={t('Content max marking definition levels')}
onChange={(_, values) => this.handleSelectedContentMaxMarkingsChange(values)}
style={fieldSpacingContainerStyle}
limitToMaxSharing
/>
<ObjectMarkingField
name="fileMarkings"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ import { VpnKeyOutlined } from '@mui/icons-material';
import ListItemText from '@mui/material/ListItemText';
import EEChip from '@components/common/entreprise_edition/EEChip';
import EETooltip from '@components/common/entreprise_edition/EETooltip';
import { PoliciesMarkingDefinitions$key } from '@components/settings/__generated__/PoliciesMarkingDefinitions.graphql';
import MarkingsSelectField from '@components/common/form/MarkingsSelectField';
import AccessesMenu from './AccessesMenu';
import ObjectOrganizationField from '../common/form/ObjectOrganizationField';
import { useFormatter } from '../../../components/i18n';
Expand Down Expand Up @@ -65,11 +63,6 @@ const PoliciesFragment = graphql`
password_policy_min_words
password_policy_min_lowercase
password_policy_min_uppercase
platform_data_sharing_max_markings {
id
definition
definition_type
}
platform_providers {
name
strategy
Expand All @@ -82,27 +75,11 @@ const PoliciesFragment = graphql`
}
`;

const PoliciesMarkingDefinitionsFragment = graphql`
fragment PoliciesMarkingDefinitions on MarkingDefinitionConnection {
edges {
node {
id
definition
definition_type
x_opencti_order
}
}
}
`;

const policiesQuery = graphql`
query PoliciesQuery {
settings {
...Policies
}
markingDefinitions {
...PoliciesMarkingDefinitions
}
}
`;

Expand Down Expand Up @@ -131,7 +108,6 @@ const policiesValidation = () => Yup.object().shape({
platform_consent_confirm_text: Yup.string().nullable(),
platform_banner_level: Yup.string().nullable(),
platform_banner_text: Yup.string().nullable(),
platform_data_sharing_max_markings: Yup.array().of(Yup.string()).nullable(),
});

interface PoliciesComponentProps {
Expand All @@ -146,10 +122,6 @@ const PoliciesComponent: FunctionComponent<PoliciesComponentProps> = ({

const data = usePreloadedQuery(policiesQuery, queryRef);
const settings = useFragment<Policies$key>(PoliciesFragment, data.settings);
const markings = useFragment<PoliciesMarkingDefinitions$key>(
PoliciesMarkingDefinitionsFragment,
data.markingDefinitions,
);

const [commitField] = useApiMutation(policiesFieldPatch);
const classes = useStyles();
Expand Down Expand Up @@ -190,7 +162,6 @@ const PoliciesComponent: FunctionComponent<PoliciesComponentProps> = ({
platform_banner_level: settings.platform_banner_level,
platform_banner_text: settings.platform_banner_text,
otp_mandatory: settings.otp_mandatory,
platform_data_sharing_max_markings: settings.platform_data_sharing_max_markings?.map((m) => m.id) ?? [],
};
const authProviders = settings.platform_providers;
return (
Expand Down Expand Up @@ -465,20 +436,6 @@ const PoliciesComponent: FunctionComponent<PoliciesComponentProps> = ({
/>
</Paper>
</Grid>

<Grid item={true} xs={6} style={{ marginTop: 30 }}>
<Typography variant="h4" gutterBottom={true}>
{t_i18n('Maximum marking definition allowed to be shared for public dashboard')}
</Typography>
<Paper classes={{ root: classes.paper }} variant="outlined">
<Field
component={MarkingsSelectField}
markingDefinitions={(markings?.edges ?? []).map((e) => e.node)}
name="platform_data_sharing_max_markings"
onChange={(val: string[]) => handleSubmitField('platform_data_sharing_max_markings', val)}
/>
</Paper>
</Grid>
</Grid>
</Form>
)}
Expand Down
Loading

0 comments on commit e166e0c

Please sign in to comment.