Skip to content

Commit

Permalink
[frontend/backend] Add PAP at init + fix leftbar (#6154)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kedae committed Mar 2, 2024
1 parent b8fdd2c commit 8a6f69b
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 83 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState, useRef, useLayoutEffect } from 'react';
import React, { useRef, useState } from 'react';
import { Link, useHistory, useLocation } from 'react-router-dom';
import { createStyles, makeStyles, styled, useTheme } from '@mui/styles';
import Toolbar from '@mui/material/Toolbar';
Expand All @@ -10,41 +10,41 @@ import Divider from '@mui/material/Divider';
import Drawer from '@mui/material/Drawer';
import Tooltip, { tooltipClasses } from '@mui/material/Tooltip';
import {
AccountBalanceOutlined,
AssignmentOutlined,
BiotechOutlined,
BugReportOutlined,
CasesOutlined,
ChevronLeft,
ChevronRight,
ConstructionOutlined,
DashboardOutlined,
DescriptionOutlined,
DiamondOutlined,
DomainOutlined,
EventOutlined,
ExpandLessOutlined,
ExpandMoreOutlined,
ExploreOutlined,
FlagOutlined,
InsertChartOutlinedOutlined,
LayersOutlined,
DescriptionOutlined,
WorkspacesOutlined,
BiotechOutlined,
SubjectOutlined,
LocalOfferOutlined,
TaskAltOutlined,
VisibilityOutlined,
WifiTetheringOutlined,
ExpandLessOutlined,
ExpandMoreOutlined,
DiamondOutlined,
BugReportOutlined,
WebAssetOutlined,
SurroundSoundOutlined,
StreamOutlined,
SourceOutlined,
SpeakerNotesOutlined,
MapOutlined,
PersonOutlined,
StorageOutlined,
AccountBalanceOutlined,
EventOutlined,
DomainOutlined,
PlaceOutlined,
MapOutlined,
FlagOutlined,
PublicOutlined,
SourceOutlined,
SpeakerNotesOutlined,
StorageOutlined,
StreamOutlined,
SubjectOutlined,
SurroundSoundOutlined,
TaskAltOutlined,
VisibilityOutlined,
WebAssetOutlined,
WifiTetheringOutlined,
WorkspacesOutlined,
} from '@mui/icons-material';
import {
AccountMultipleOutline,
Expand Down Expand Up @@ -304,10 +304,6 @@ const LeftBar = () => {
} = useAuth();
const settingsMessagesBannerHeight = useSettingsMessagesBannerHeight();
const { dimension } = useDimensions();
const [height, setHeight] = useState(0);
useLayoutEffect(() => {
setHeight(ref.current.offsetHeight);
}, [selectedMenu]);
const isMobile = dimension.width < 768;
const generateSubMenu = (menu, entries) => {
return navOpen ? (
Expand Down Expand Up @@ -860,12 +856,11 @@ const LeftBar = () => {
</MenuList>
</Security>
</div>
<div style={height + (navOpen && selectedMenu ? 300 : 130) < dimension.height ? { position: 'fixed', bottom: 10, left: 0 } : {}}>
<div style={{ marginTop: 'auto' }}>
<MenuList component="nav">
{(!platform_whitemark || !isEnterpriseEdition) && (
<MenuItem
dense={true}
style={{ marginBottom: bannerHeightNumber }}
classes={{
root: navOpen ? classes.menuLogoOpen : classes.menuLogo,
}}
Expand Down Expand Up @@ -893,7 +888,7 @@ const LeftBar = () => {
)}
<MenuItem
dense={true}
style={{ marginBottom: bannerHeightNumber }}
style={{ marginBottom: bannerHeightNumber ? 6 : undefined }}
classes={{
root: navOpen ? classes.menuCollapseOpen : classes.menuCollapse,
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export const CAPABILITIES = [
// endregion

const createMarkingDefinitions = async (context) => {
// Create marking defs
// Create marking defs for TLP
await addMarkingDefinition(context, SYSTEM_USER, {
definition_type: 'TLP',
definition: 'TLP:CLEAR',
Expand Down Expand Up @@ -136,6 +136,32 @@ const createMarkingDefinitions = async (context) => {
x_opencti_color: '#c62828',
x_opencti_order: 4,
});

// Creation markings for PAP
await addMarkingDefinition(context, SYSTEM_USER, {
definition_type: 'PAP',
definition: 'PAP:CLEAR',
x_opencti_color: '#ffffff',
x_opencti_order: 1,
});
await addMarkingDefinition(context, SYSTEM_USER, {
definition_type: 'PAP',
definition: 'PAP:GREEN',
x_opencti_color: '#2e7d32',
x_opencti_order: 2,
});
await addMarkingDefinition(context, SYSTEM_USER, {
definition_type: 'PAP',
definition: 'PAP:AMBER',
x_opencti_color: '#d84315',
x_opencti_order: 3,
});
await addMarkingDefinition(context, SYSTEM_USER, {
definition_type: 'PAP',
definition: 'PAP:RED',
x_opencti_color: '#c62828',
x_opencti_order: 4,
});
};

const createVocabularies = async (context) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ describe('Elasticsearch pagination', () => {
it('should entity paginate everything', async () => {
const data = await elPaginate(testContext, ADMIN_USER, READ_ENTITIES_INDICES, { first: ES_MAX_PAGINATION });
expect(data).not.toBeNull();
expect(data.edges.length).toEqual(502);
expect(data.edges.length).toEqual(506);
const filterBaseTypes = R.uniq(R.map((e) => e.node.base_type, data.edges));
expect(filterBaseTypes.length).toEqual(1);
expect(R.head(filterBaseTypes)).toEqual('ENTITY');
Expand Down Expand Up @@ -501,7 +501,7 @@ describe('Elasticsearch pagination', () => {
filterGroups: [],
};
const data = await elPaginate(testContext, ADMIN_USER, READ_ENTITIES_INDICES, { filters });
expect(data.edges.length).toEqual(7);
expect(data.edges.length).toEqual(11);
});
it('should entity paginate with equality filter', async () => {
// eq operation will use the field.keyword to do an exact field equality
Expand All @@ -511,7 +511,7 @@ describe('Elasticsearch pagination', () => {
filterGroups: [],
};
let data = await elPaginate(testContext, ADMIN_USER, READ_ENTITIES_INDICES, { filters });
expect(data.edges.length).toEqual(1);
expect(data.edges.length).toEqual(2);
// Special case when operator = eq + the field key is a dateFields => use a match
filters = {
mode: 'and',
Expand All @@ -528,7 +528,7 @@ describe('Elasticsearch pagination', () => {
filterGroups: [],
};
let data = await elPaginate(testContext, ADMIN_USER, READ_ENTITIES_INDICES, { filters });
expect(data.edges.length).toEqual(7); // The 4 Default TLP + MITRE Corporation
expect(data.edges.length).toEqual(11); // The 4 Default TLP + MITRE Corporation
// Verify that nothing is found in this case if using the eq operator
filters = {
mode: 'and',
Expand All @@ -555,7 +555,7 @@ describe('Elasticsearch pagination', () => {
filterGroups: [],
};
data = await elPaginate(testContext, ADMIN_USER, READ_ENTITIES_INDICES, { filters, first: ES_MAX_PAGINATION });
expect(data.edges.length).toEqual(356);
expect(data.edges.length).toEqual(360);
filters = {
mode: 'and',
filters: [
Expand All @@ -573,7 +573,7 @@ describe('Elasticsearch pagination', () => {
orderMode: 'asc',
first: ES_MAX_PAGINATION
});
expect(data.edges.length).toEqual(502);
expect(data.edges.length).toEqual(506);
const createdDates = R.map((e) => e.node.created, data.edges);
let previousCreatedDate = null;
for (let index = 0; index < createdDates.length; index += 1) {
Expand All @@ -600,20 +600,24 @@ describe('Elasticsearch pagination', () => {
orderBy: 'definition',
orderMode: 'desc',
});
expect(data.edges.length).toEqual(7);
expect(data.edges.length).toEqual(11);
const markings = R.map((e) => e.node.definition, data.edges);
expect(markings[0]).toEqual('TLP:TEST');
expect(markings[1]).toEqual('TLP:RED');
expect(markings[2]).toEqual('TLP:GREEN');
expect(markings[3]).toEqual('TLP:CLEAR');
expect(markings[4]).toEqual('TLP:AMBER+STRICT');
expect(markings[5]).toEqual('TLP:AMBER');
expect(markings[6]).toEqual('PAP:RED');
expect(markings[7]).toEqual('PAP:GREEN');
expect(markings[8]).toEqual('PAP:CLEAR');
expect(markings[9]).toEqual('PAP:AMBER');
});
it('should relation paginate everything', async () => {
let data = await elPaginate(testContext, ADMIN_USER, READ_RELATIONSHIPS_INDICES, { includeAuthorities: true });
expect(data).not.toBeNull();
const groupByIndices = R.groupBy((e) => e.node._index, data.edges);
expect(groupByIndices[`${ES_INDEX_PREFIX}_internal_relationships-000001`].length).toEqual(43);
expect(groupByIndices[`${ES_INDEX_PREFIX}_internal_relationships-000001`].length).toEqual(47);
expect(groupByIndices[`${ES_INDEX_PREFIX}_stix_core_relationships-000001`].length).toEqual(24);
expect(groupByIndices[`${ES_INDEX_PREFIX}_stix_meta_relationships-000001`].length).toEqual(124);
expect(groupByIndices[`${ES_INDEX_PREFIX}_stix_sighting_relationships-000001`].length).toEqual(2);
Expand All @@ -625,14 +629,14 @@ describe('Elasticsearch pagination', () => {
expect(metaByEntityType['external-reference'].length).toEqual(7);
expect(metaByEntityType['object-marking'].length).toEqual(26);
expect(metaByEntityType['kill-chain-phase'].length).toEqual(3);
expect(data.edges.length).toEqual(193);
expect(data.edges.length).toEqual(197);
let filterBaseTypes = R.uniq(R.map((e) => e.node.base_type, data.edges));
expect(filterBaseTypes.length).toEqual(1);
expect(R.head(filterBaseTypes)).toEqual('RELATION');
// Same query with no pagination
data = await elPaginate(testContext, ADMIN_USER, READ_RELATIONSHIPS_INDICES, { connectionFormat: false });
expect(data).not.toBeNull();
expect(data.length).toEqual(193);
expect(data.length).toEqual(197);
filterBaseTypes = R.uniq(R.map((e) => e.base_type, data));
expect(filterBaseTypes.length).toEqual(1);
expect(R.head(filterBaseTypes)).toEqual('RELATION');
Expand Down
Loading

0 comments on commit 8a6f69b

Please sign in to comment.