diff --git a/openbas-api/src/main/java/io/openbas/rest/inject/InjectApi.java b/openbas-api/src/main/java/io/openbas/rest/inject/InjectApi.java index ed07c9670b..4a3d7c17b9 100644 --- a/openbas-api/src/main/java/io/openbas/rest/inject/InjectApi.java +++ b/openbas-api/src/main/java/io/openbas/rest/inject/InjectApi.java @@ -33,8 +33,12 @@ import java.time.Instant; import java.util.Collection; import java.util.List; +import java.util.Map; import java.util.Optional; +import java.util.function.Function; +import java.util.stream.Collectors; +import static io.openbas.atomic_testing.AtomicTestingMapper.toDto; import static io.openbas.config.SessionHelper.currentUser; import static io.openbas.database.model.User.ROLE_ADMIN; import static io.openbas.database.specification.CommunicationSpecification.fromInject; @@ -240,7 +244,7 @@ public Inject updateInject( @PreAuthorize("isExerciseObserver(#exerciseId)") public Iterable exerciseInjects(@PathVariable String exerciseId) { return injectRepository.findAll(InjectSpecification.fromExercise(exerciseId)).stream() - .sorted(Inject.executionComparator).toList(); + .sorted(Inject.executionComparator).toList(); } @GetMapping("/api/exercises/{exerciseId}/injects/{injectId}") @@ -399,9 +403,9 @@ public Inject createInjectForScenario( @PreAuthorize("isScenarioObserver(#scenarioId)") public Iterable scenarioInjects(@PathVariable @NotBlank final String scenarioId) { return this.injectRepository.findAll(InjectSpecification.fromScenario(scenarioId)) - .stream() - .sorted(Inject.executionComparator) - .toList(); + .stream() + .sorted(Inject.executionComparator) + .toList(); } @GetMapping(SCENARIO_URI + "/{scenarioId}/injects/{injectId}") diff --git a/openbas-api/src/test/java/io/openbas/helper/InjectHelperTest.java b/openbas-api/src/test/java/io/openbas/helper/InjectHelperTest.java index c0c1b76585..8578774a52 100644 --- a/openbas-api/src/test/java/io/openbas/helper/InjectHelperTest.java +++ b/openbas-api/src/test/java/io/openbas/helper/InjectHelperTest.java @@ -41,6 +41,9 @@ public class InjectHelperTest { @Autowired private UserRepository userRepository; + @Autowired + private InjectorContractRepository injectorContractRepository; + @Disabled @DisplayName("Retrieve simple inject to run") @Test @@ -75,7 +78,7 @@ void injectsToRunTest() { Inject inject = new Inject(); inject.setTitle("Test inject"); inject.setType(TYPE); - inject.setContract(EMAIL_DEFAULT); + inject.setInjectorContract(injectorContractRepository.findById(EMAIL_DEFAULT).orElseThrow()); inject.setEnabled(true); inject.setExercise(exerciseSaved); inject.setTeams(List.of(team)); diff --git a/openbas-api/src/test/java/io/openbas/injects/InjectCrudTest.java b/openbas-api/src/test/java/io/openbas/injects/InjectCrudTest.java index ac0e6fbeda..7d89dffc1a 100644 --- a/openbas-api/src/test/java/io/openbas/injects/InjectCrudTest.java +++ b/openbas-api/src/test/java/io/openbas/injects/InjectCrudTest.java @@ -1,9 +1,11 @@ -package io.openbas.injectors; +package io.openbas.injects; import io.openbas.database.model.Exercise; import io.openbas.database.model.Inject; import io.openbas.database.repository.ExerciseRepository; import io.openbas.database.repository.InjectRepository; +import io.openbas.database.repository.InjectorContractRepository; +import io.openbas.injectors.email.EmailContract; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -23,6 +25,8 @@ public class InjectCrudTest { @Autowired private ExerciseRepository exerciseRepository; + @Autowired + private InjectorContractRepository injectorContractRepository; @DisplayName("Test inject creation with non null depends duration") @Test @@ -36,7 +40,7 @@ void createInjectSuccess() { Inject inject = new Inject(); inject.setTitle("test"); inject.setType(TYPE); - inject.setContract(EMAIL_DEFAULT); + inject.setInjectorContract(injectorContractRepository.findById(EmailContract.EMAIL_DEFAULT).orElseThrow()); inject.setExercise(exerciseCreated); inject.setDependsDuration(0L); diff --git a/openbas-api/src/test/java/io/openbas/injects/email/EmailExecutorTest.java b/openbas-api/src/test/java/io/openbas/injects/email/EmailExecutorTest.java index 4ddffaa992..a1f508456d 100644 --- a/openbas-api/src/test/java/io/openbas/injects/email/EmailExecutorTest.java +++ b/openbas-api/src/test/java/io/openbas/injects/email/EmailExecutorTest.java @@ -1,14 +1,17 @@ -package io.openbas.injectors.email; +package io.openbas.injects.email; import com.fasterxml.jackson.databind.ObjectMapper; import io.openbas.database.model.Execution; import io.openbas.database.model.Inject; import io.openbas.database.model.InjectExpectation; import io.openbas.database.model.User; +import io.openbas.database.repository.InjectorContractRepository; import io.openbas.database.repository.UserRepository; import io.openbas.execution.ExecutableInject; import io.openbas.execution.ExecutionContext; import io.openbas.execution.ExecutionContextService; +import io.openbas.injectors.email.EmailContract; +import io.openbas.injectors.email.EmailExecutor; import io.openbas.injectors.email.model.EmailContent; import io.openbas.model.ExecutionProcess; import io.openbas.model.inject.form.Expectation; @@ -31,6 +34,8 @@ public class EmailExecutorTest { @Autowired private UserRepository userRepository; @Autowired + private InjectorContractRepository injectorContractRepository; + @Autowired private ExecutionContextService executionContextService; @Resource protected ObjectMapper mapper; @@ -48,7 +53,7 @@ void process() throws Exception { content.setExpectations(List.of(expectation)); Inject inject = new Inject(); inject.setType(EmailContract.TYPE); - inject.setContract(EmailContract.EMAIL_DEFAULT); + inject.setInjectorContract(injectorContractRepository.findById(EmailContract.EMAIL_DEFAULT).orElseThrow()); inject.setContent(this.mapper.valueToTree(content)); Iterable users = this.userRepository.findAll(); List userInjectContexts = fromIterable(users).stream() diff --git a/openbas-api/src/test/java/io/openbas/injects/manual/ManualExecutorTest.java b/openbas-api/src/test/java/io/openbas/injects/manual/ManualExecutorTest.java index 0af92fad00..a05cc56b81 100644 --- a/openbas-api/src/test/java/io/openbas/injects/manual/ManualExecutorTest.java +++ b/openbas-api/src/test/java/io/openbas/injects/manual/ManualExecutorTest.java @@ -1,4 +1,4 @@ -package io.openbas.injectors.manual; +package io.openbas.injects.manual; import io.openbas.injectors.manual.ManualExecutor; import org.junit.jupiter.api.Assertions; diff --git a/openbas-api/src/test/java/io/openbas/rest/InjectApiTest.java b/openbas-api/src/test/java/io/openbas/rest/InjectApiTest.java index 2339724748..a86b87cfea 100644 --- a/openbas-api/src/test/java/io/openbas/rest/InjectApiTest.java +++ b/openbas-api/src/test/java/io/openbas/rest/InjectApiTest.java @@ -4,6 +4,7 @@ import io.openbas.database.model.Inject; import io.openbas.database.model.Scenario; import io.openbas.database.repository.InjectRepository; +import io.openbas.database.repository.InjectorContractRepository; import io.openbas.database.repository.ScenarioRepository; import io.openbas.rest.inject.form.InjectInput; import io.openbas.service.ScenarioService; @@ -41,6 +42,8 @@ public class InjectApiTest { private ScenarioRepository scenarioRepository; @Autowired private InjectRepository injectRepository; + @Autowired + private InjectorContractRepository injectorContractRepository; static String SCENARIO_ID; static String INJECT_ID; @@ -67,7 +70,7 @@ void addInjectForScenarioTest() throws Exception { InjectInput input = new InjectInput(); input.setTitle("Test inject"); input.setType(TYPE); - input.setContract(EMAIL_DEFAULT); + input.setInjectorContract(EMAIL_DEFAULT); input.setDependsDuration(0L); // -- EXECUTE -- diff --git a/openbas-api/src/test/java/io/openbas/service/ExerciseExpectationServiceTest.java b/openbas-api/src/test/java/io/openbas/service/ExerciseExpectationServiceTest.java index 208c2477cc..ca9d96605c 100644 --- a/openbas-api/src/test/java/io/openbas/service/ExerciseExpectationServiceTest.java +++ b/openbas-api/src/test/java/io/openbas/service/ExerciseExpectationServiceTest.java @@ -43,6 +43,9 @@ public class ExerciseExpectationServiceTest { @Autowired private InjectExpectationRepository injectExpectationRepository; + @Autowired + private InjectorContractRepository injectorContractRepository; + static String EXERCISE_ID; @BeforeAll @@ -61,7 +64,7 @@ void beforeAll() { Inject inject = new Inject(); inject.setTitle("test"); inject.setType(TYPE); - inject.setContract(EMAIL_DEFAULT); + inject.setInjectorContract(injectorContractRepository.findById(EMAIL_DEFAULT).orElseThrow()); inject.setExercise(exerciseCreated); inject.setDependsDuration(0L); Inject injectCreated = this.injectRepository.save(inject); diff --git a/openbas-api/src/test/java/io/openbas/utils/fixtures/InjectFixture.java b/openbas-api/src/test/java/io/openbas/utils/fixtures/InjectFixture.java index 9dcef8e517..1a44942702 100644 --- a/openbas-api/src/test/java/io/openbas/utils/fixtures/InjectFixture.java +++ b/openbas-api/src/test/java/io/openbas/utils/fixtures/InjectFixture.java @@ -13,7 +13,6 @@ public static Inject getInjectForEmailContract() { Inject inject = new Inject(); inject.setTitle(INJECT_EMAIL_NAME); inject.setType(TYPE); - inject.setContract(EMAIL_DEFAULT); inject.setEnabled(true); inject.setDependsDuration(0L); return inject; diff --git a/openbas-front/src/actions/InjectorContracts.js b/openbas-front/src/actions/InjectorContracts.js index 78da75b031..e12c613c2b 100644 --- a/openbas-front/src/actions/InjectorContracts.js +++ b/openbas-front/src/actions/InjectorContracts.js @@ -1,30 +1,5 @@ import * as schema from './Schema'; -import { getReferential, putReferential, postReferential, delReferential, simplePostCall, buildUri } from '../utils/Action'; -import * as Constants from '../constants/ActionTypes'; -import { api } from '../network'; - -export const fetchInjectorContracts = () => async (dispatch) => { - const uri = '/api/injector_contracts'; - try { - const response = await api(schema.arrayOfInjectorContracts) - .get(buildUri(uri)); - response.data.result.forEach((id) => { - const parsedContent = JSON.parse(response.data.entities.injector_contracts[id].injector_contract_content); - response.data.entities.injector_contracts[id] = { - ...response.data.entities.injector_contracts[id], - ...parsedContent, - }; - }); - dispatch({ - type: Constants.DATA_FETCH_SUCCESS, - payload: response.data, - }); - return response.data; - } catch (error) { - dispatch({ type: Constants.DATA_FETCH_ERROR, payload: error }); - throw error; - } -}; +import { getReferential, putReferential, postReferential, delReferential, simplePostCall } from '../utils/Action'; export const fetchInjectorContract = (injectorContractId) => (dispatch) => { const uri = `/api/injector_contracts/${injectorContractId}`; diff --git a/openbas-front/src/actions/Schema.js b/openbas-front/src/actions/Schema.js index 6773ac3742..7015e4ddeb 100644 --- a/openbas-front/src/actions/Schema.js +++ b/openbas-front/src/actions/Schema.js @@ -271,6 +271,25 @@ const entities = (key, state) => Object.values(maps(key, state)); const entity = (id, key, state) => state.referential.entities[key][id]?.asMutable({ deep: true }); const me = (state) => state.referential.entities.users[R.path(['logged', 'user'], state.app)]; +const getInjectWithParsedInjectorContractContent = (i) => { + if (!i) { + return i; + } + return ({ + ...i, + inject_injector_contract: { + ...i.inject_injector_contract, + injector_contract_content_parsed: JSON.parse(i.inject_injector_contract.injector_contract_content), + }, + }); +}; +const getInjectsWithParsedInjectorContractContent = (injects) => { + if (R.isEmpty(injects)) { + return injects; + } + return injects.map(getInjectWithParsedInjectorContractContent); +}; + export const storeHelper = (state) => ({ logged: () => state.app.logged, getMe: () => me(state), @@ -287,7 +306,7 @@ export const storeHelper = (state) => ({ getExerciseTeams: (id) => entities('teams', state).filter((i) => i.team_exercises.includes(id)), getExerciseVariables: (id) => entities('variables', state).filter((i) => i.variable_exercise === id), getExerciseArticles: (id) => entities('articles', state).filter((i) => i.article_exercise === id), - getExerciseInjects: (id) => entities('injects', state).filter((i) => i.inject_exercise === id), + getExerciseInjects: (id) => getInjectsWithParsedInjectorContractContent(entities('injects', state).filter((i) => i.inject_exercise === id)), getExerciseCommunications: (id) => entities('communications', state).filter( (i) => i.communication_exercise === id, ), @@ -354,12 +373,12 @@ export const storeHelper = (state) => ({ getTags: () => entities('tags', state), getTagsMap: () => maps('tags', state), // injects - getInject: (id) => entity(id, 'injects', state), + getInject: (id) => getInjectWithParsedInjectorContractContent(entity(id, 'injects', state)), getAtomicTesting: (id) => entity(id, 'atomics', state), getAtomicTestingDetail: (id) => entity(id, 'atomicdetails', state), getAtomicTestings: () => entities('atomics', state), getTargetResults: (id, injectId) => entities('targetresults', state).filter((r) => (r.target_id === id) && (r.target_inject_id === injectId)), - getInjectsMap: () => maps('injects', state), + getInjectsMap: () => getInjectsWithParsedInjectorContractContent(maps('injects', state)), getNextInjects: () => { const sortFn = (a, b) => new Date(a.inject_date).getTime() - new Date(b.inject_date).getTime(); const injects = entities('injects', state).filter( @@ -417,18 +436,6 @@ export const storeHelper = (state) => ({ getInjectorsMap: () => maps('injectors', state), // injectors contracts getInjectorContract: (id) => entity(id, 'injector_contracts', state), - getInjectorContracts: () => entities('injector_contracts', state), - getInjectorContractsMap: () => maps('injector_contracts', state), - getInjectorContractsMapByType: () => R.indexBy(R.path(['config', 'type']), entities('injector_contracts', state)), - getInjectorContractsWithNoTeams: () => R.uniq( - entities('injector_contracts', state) - .map((t) => ({ - hasTeams: t.fields.filter((f) => f.key === 'teams').length > 0, - ...t, - })) - .filter((t) => !t.hasTeams) - .map((t) => t.config.type), - ), // collectors getCollector: (id) => entity(id, 'collectors', state), getCollectors: () => entities('collectors', state), @@ -476,5 +483,5 @@ export const storeHelper = (state) => ({ getScenarioVariables: (id) => entities('variables', state).filter((i) => i.variable_scenario === id), getScenarioArticles: (id) => entities('articles', state).filter((i) => i.article_scenario === id), getScenarioChallenges: (id) => entities('challenges', state).filter((c) => c.challenge_scenarios.includes(id)), - getScenarioInjects: (id) => entities('injects', state).filter((i) => i.inject_scenario === id), + getScenarioInjects: (id) => getInjectsWithParsedInjectorContractContent(entities('injects', state).filter((i) => i.inject_scenario === id)), }); diff --git a/openbas-front/src/actions/injects/Inject.d.ts b/openbas-front/src/actions/injects/Inject.d.ts index e2ece58158..cbf327d8fa 100644 --- a/openbas-front/src/actions/injects/Inject.d.ts +++ b/openbas-front/src/actions/injects/Inject.d.ts @@ -9,9 +9,14 @@ export type InjectInput = { inject_depends_duration_seconds: number; }; -export type InjectStore = Omit & { +export type InjectStore = Omit & { inject_tags: string[] | undefined; inject_content: { expectationScore: number, challenges: string[] | undefined } + inject_injector_contract: { + // as we don't know the type of the content of a contract we need to put any here + // eslint-disable-next-line @typescript-eslint/no-explicit-any + injector_contract_content_parsed: any + } & Inject['inject_injector_contract'] }; export type InjectExpectationStore = Omit & { diff --git a/openbas-front/src/actions/injects/inject-helper.d.ts b/openbas-front/src/actions/injects/inject-helper.d.ts index 7df8da0eb7..396815245d 100644 --- a/openbas-front/src/actions/injects/inject-helper.d.ts +++ b/openbas-front/src/actions/injects/inject-helper.d.ts @@ -1,4 +1,4 @@ -import type { Exercise, Inject, Scenario } from '../../utils/api-types'; +import type { Exercise, Inject, Scenario, InjectExpectation } from '../../utils/api-types'; export interface InjectHelper { getExerciseInjects: (exerciseId: Exercise['exercise_id']) => Inject[]; diff --git a/openbas-front/src/admin/components/atomic_testings/atomic_testing/AtomicTestingHeader.tsx b/openbas-front/src/admin/components/atomic_testings/atomic_testing/AtomicTestingHeader.tsx index bbbc64713e..4b52f7ccdc 100644 --- a/openbas-front/src/admin/components/atomic_testings/atomic_testing/AtomicTestingHeader.tsx +++ b/openbas-front/src/admin/components/atomic_testings/atomic_testing/AtomicTestingHeader.tsx @@ -8,7 +8,7 @@ import type { AtomicTestingHelper } from '../../../../actions/atomic_testings/at import AtomicTestingPopover from './AtomicTestingPopover'; import { useFormatter } from '../../../../components/i18n'; import Transition from '../../../../components/common/Transition'; -import { AtomicTestingResultContext } from '../../components/Context'; +import { AtomicTestingResultContext } from '../../common/Context'; import StatusChip from './StatusChip'; import type { AtomicTestingOutput } from '../../../../utils/api-types'; import useDataLoader from '../../../../utils/ServerSideEvent'; diff --git a/openbas-front/src/admin/components/atomic_testings/atomic_testing/AtomicTestingPopover.tsx b/openbas-front/src/admin/components/atomic_testings/atomic_testing/AtomicTestingPopover.tsx index 86fe39f627..9d52607f07 100644 --- a/openbas-front/src/admin/components/atomic_testings/atomic_testing/AtomicTestingPopover.tsx +++ b/openbas-front/src/admin/components/atomic_testings/atomic_testing/AtomicTestingPopover.tsx @@ -8,7 +8,7 @@ import ButtonPopover, { ButtonPopoverEntry } from '../../../../components/common import DialogDelete from '../../../../components/common/DialogDelete'; import { deleteAtomicTesting, fetchAtomicTestingForUpdate, updateAtomicTesting } from '../../../../actions/atomic_testings/atomic-testing-actions'; import { useHelper } from '../../../../store'; -import { AtomicTestingResultContext } from '../../components/Context'; +import { AtomicTestingResultContext } from '../../common/Context'; import useDataLoader from '../../../../utils/ServerSideEvent'; import type { AtomicTestingHelper } from '../../../../actions/atomic_testings/atomic-testing-helper'; import UpdateInject from '../../common/injects/UpdateInject'; diff --git a/openbas-front/src/admin/components/atomic_testings/atomic_testing/IndexAtomicTesting.tsx b/openbas-front/src/admin/components/atomic_testings/atomic_testing/IndexAtomicTesting.tsx index 90947ca3f1..9abde02eae 100644 --- a/openbas-front/src/admin/components/atomic_testings/atomic_testing/IndexAtomicTesting.tsx +++ b/openbas-front/src/admin/components/atomic_testings/atomic_testing/IndexAtomicTesting.tsx @@ -13,7 +13,7 @@ import AtomicTestingHeader from './AtomicTestingHeader'; import { fetchAtomicTesting } from '../../../../actions/atomic_testings/atomic-testing-actions'; import type { AtomicTestingOutput } from '../../../../utils/api-types'; import type { AtomicTestingHelper } from '../../../../actions/atomic_testings/atomic-testing-helper'; -import { AtomicTestingResultContext, AtomicTestingResultContextType } from '../../components/Context'; +import { AtomicTestingResultContext, AtomicTestingResultContextType } from '../../common/Context'; const AtomicTesting = lazy(() => import('./AtomicTesting')); const AtomicTestingDetail = lazy(() => import('./AtomicTestingDetail')); diff --git a/openbas-front/src/admin/components/components/Context.ts b/openbas-front/src/admin/components/common/Context.ts similarity index 100% rename from openbas-front/src/admin/components/components/Context.ts rename to openbas-front/src/admin/components/common/Context.ts diff --git a/openbas-front/src/admin/components/common/injects/CreateInject.tsx b/openbas-front/src/admin/components/common/injects/CreateInject.tsx index cca94b71f8..244282c068 100644 --- a/openbas-front/src/admin/components/common/injects/CreateInject.tsx +++ b/openbas-front/src/admin/components/common/injects/CreateInject.tsx @@ -66,11 +66,6 @@ const Createinject: FunctionComponent = ({ title, onCreateInject, isAtomi setActiveStep(0); }; - const submitCreation = async (data: Inject) => { - handleReset(); - await onCreateInject(data); - }; - // Fetching data const { attackPatterns, attackPatternsMap } = useHelper((helper: AttackPatternHelper) => ({ attackPatterns: helper.getAttackPatterns(), @@ -229,7 +224,7 @@ const Createinject: FunctionComponent = ({ title, onCreateInject, isAtomi handleClose={() => setOpen(false)} handleBack={handleBack} handleReset={handleReset} - onCreateInject={submitCreation} + onCreateInject={onCreateInject} isAtomic={isAtomic} {...props} /> diff --git a/openbas-front/src/admin/components/common/injects/CreateinjectDetails.tsx b/openbas-front/src/admin/components/common/injects/CreateinjectDetails.tsx index 2590a275c1..4c9223ca59 100644 --- a/openbas-front/src/admin/components/common/injects/CreateinjectDetails.tsx +++ b/openbas-front/src/admin/components/common/injects/CreateinjectDetails.tsx @@ -1,7 +1,7 @@ import React, { FunctionComponent, useContext } from 'react'; import { Button } from '@mui/material'; import InjectDefinition from './InjectDefinition'; -import { PermissionsContext } from '../../components/Context'; +import { PermissionsContext } from '..'; import type { Inject, Tag } from '../../../../utils/api-types'; import { useHelper } from '../../../../store'; import type { InjectHelper } from '../../../../actions/injects/inject-helper'; diff --git a/openbas-front/src/admin/components/common/injects/InjectAddArticles.tsx b/openbas-front/src/admin/components/common/injects/InjectAddArticles.tsx index daf3e741d3..8baca474d9 100644 --- a/openbas-front/src/admin/components/common/injects/InjectAddArticles.tsx +++ b/openbas-front/src/admin/components/common/injects/InjectAddArticles.tsx @@ -12,7 +12,7 @@ import Transition from '../../../../components/common/Transition'; import ChannelIcon from '../../components/channels/ChannelIcon'; import type { Theme } from '../../../../components/Theme'; import { useAppDispatch } from '../../../../utils/hooks'; -import { PermissionsContext } from '../../components/Context'; +import { PermissionsContext } from '../Context'; import useDataLoader from '../../../../utils/ServerSideEvent'; import { useHelper } from '../../../../store'; import type { ChannelsHelper } from '../../../../actions/channels/channel-helper'; diff --git a/openbas-front/src/admin/components/common/injects/InjectAddChallenges.tsx b/openbas-front/src/admin/components/common/injects/InjectAddChallenges.tsx index 812e8d1543..5a6c968f18 100644 --- a/openbas-front/src/admin/components/common/injects/InjectAddChallenges.tsx +++ b/openbas-front/src/admin/components/common/injects/InjectAddChallenges.tsx @@ -16,7 +16,7 @@ import useDataLoader from '../../../../utils/ServerSideEvent'; import { useAppDispatch } from '../../../../utils/hooks'; import { useHelper } from '../../../../store'; import type { ChallengesHelper } from '../../../../actions/helper'; -import { PermissionsContext } from '../../components/Context'; +import { PermissionsContext } from '../Context'; import type { Challenge } from '../../../../utils/api-types'; const useStyles = makeStyles((theme: Theme) => ({ diff --git a/openbas-front/src/admin/components/common/injects/InjectAddDocuments.tsx b/openbas-front/src/admin/components/common/injects/InjectAddDocuments.tsx index 4e236e59cd..f651d4659d 100644 --- a/openbas-front/src/admin/components/common/injects/InjectAddDocuments.tsx +++ b/openbas-front/src/admin/components/common/injects/InjectAddDocuments.tsx @@ -17,7 +17,7 @@ import { useAppDispatch } from '../../../../utils/hooks'; import type { Theme } from '../../../../components/Theme'; import { useHelper } from '../../../../store'; import type { DocumentsHelper, UsersHelper } from '../../../../actions/helper'; -import { PermissionsContext } from '../../components/Context'; +import { PermissionsContext } from '../Context'; import type { Document } from '../../../../utils/api-types'; const useStyles = makeStyles((theme: Theme) => ({ diff --git a/openbas-front/src/admin/components/common/injects/InjectAddTeams.tsx b/openbas-front/src/admin/components/common/injects/InjectAddTeams.tsx index b5d5371fbf..422de2db4c 100644 --- a/openbas-front/src/admin/components/common/injects/InjectAddTeams.tsx +++ b/openbas-front/src/admin/components/common/injects/InjectAddTeams.tsx @@ -15,7 +15,7 @@ import type { Theme } from '../../../../components/Theme'; import useDataLoader from '../../../../utils/ServerSideEvent'; import { useAppDispatch } from '../../../../utils/hooks'; import type { Option } from '../../../../utils/Option'; -import { PermissionsContext, TeamContext } from '../../components/Context'; +import { PermissionsContext, TeamContext } from '../Context'; import type { TeamStore } from '../../../../actions/teams/Team'; import { useHelper } from '../../../../store'; import type { TeamsHelper } from '../../../../actions/teams/team-helper'; diff --git a/openbas-front/src/admin/components/common/injects/InjectDefinition.js b/openbas-front/src/admin/components/common/injects/InjectDefinition.js index 61570b957d..b3430db177 100644 --- a/openbas-front/src/admin/components/common/injects/InjectDefinition.js +++ b/openbas-front/src/admin/components/common/injects/InjectDefinition.js @@ -650,7 +650,7 @@ class InjectDefinition extends Component { } injectorContract.fields .filter( - (f) => !['teams', 'assets', 'asset_groups', 'articles', 'challenges', 'attachments', 'expectations'].includes( + (f) => !['teams', 'assets', 'assetgroups', 'articles', 'challenges', 'attachments', 'expectations'].includes( f.key, ), ) @@ -738,7 +738,7 @@ class InjectDefinition extends Component { if (injectorContract && Array.isArray(injectorContract.fields)) { injectorContract.fields .filter( - (f) => !['teams', 'assets', 'asset_groups', 'articles', 'challenges', 'attachments', 'expectations'].includes( + (f) => !['teams', 'assets', 'assetgroups', 'articles', 'challenges', 'attachments', 'expectations'].includes( f.key, ), ) @@ -1197,7 +1197,7 @@ class InjectDefinition extends Component { // -- ASSET GROUPS -- const hasAssetGroups = injectorContract.fields .map((f) => f.key) - .includes('asset_groups'); + .includes('assetgroups'); const assetGroups = assetGroupIds .map((a) => assetGroupsMap[a]) .filter((a) => a !== undefined); @@ -1279,7 +1279,7 @@ class InjectDefinition extends Component { const builtInFields = [ 'teams', 'assets', - 'asset_groups', + 'assetgroups', 'articles', 'challenges', 'attachments', diff --git a/openbas-front/src/admin/components/common/injects/InjectPopover.tsx b/openbas-front/src/admin/components/common/injects/InjectPopover.tsx index 78e8325ce6..32801a8e57 100644 --- a/openbas-front/src/admin/components/common/injects/InjectPopover.tsx +++ b/openbas-front/src/admin/components/common/injects/InjectPopover.tsx @@ -4,7 +4,7 @@ import { MoreVert } from '@mui/icons-material'; import { useFormatter } from '../../../../components/i18n'; import Transition from '../../../../components/common/Transition'; import type { InjectStore } from '../../../../actions/injects/Inject'; -import { InjectContext, PermissionsContext } from '../../components/Context'; +import { InjectContext, PermissionsContext } from '../Context'; import type { Inject, InjectStatus, InjectStatusExecution, Tag } from '../../../../utils/api-types'; import { tryInject } from '../../../../actions/Inject'; import { useAppDispatch } from '../../../../utils/hooks'; @@ -12,7 +12,6 @@ import type { Contract } from '../../../../actions/contract/contract'; interface Props { inject: InjectStore; - injectorContractsMap: Record; tagsMap: Record; setSelectedInjectId: (injectId: Inject['inject_id']) => void; isDisabled: boolean; diff --git a/openbas-front/src/admin/components/common/injects/Injects.js b/openbas-front/src/admin/components/common/injects/Injects.js index 6e14604317..4c4a9b1fb0 100644 --- a/openbas-front/src/admin/components/common/injects/Injects.js +++ b/openbas-front/src/admin/components/common/injects/Injects.js @@ -1,6 +1,5 @@ import React, { useContext, useState } from 'react'; import { makeStyles } from '@mui/styles'; -import * as R from 'ramda'; import { Chip, IconButton, List, ListItem, ListItemIcon, ListItemSecondaryAction, ListItemText, Tooltip } from '@mui/material'; import { CSVLink } from 'react-csv'; import { FileDownloadOutlined } from '@mui/icons-material'; @@ -17,12 +16,11 @@ import { useHelper } from '../../../../store'; import ItemBoolean from '../../../../components/ItemBoolean'; import { exportData } from '../../../../utils/Environment'; import Loader from '../../../../components/Loader'; -import { InjectContext, PermissionsContext } from '../../components/Context'; -import CreateInject from './CreateInject'; -import UpdateInject from './UpdateInject'; import useDataLoader from '../../../../utils/ServerSideEvent'; -import { fetchInjectorContracts } from '../../../../actions/InjectorContracts'; import { useAppDispatch } from '../../../../utils/hooks'; +import { InjectContext, PermissionsContext } from '../Context'; +import CreateInject from './CreateInject'; +import UpdateInject from './UpdateInject'; const useStyles = makeStyles(() => ({ container: { @@ -180,21 +178,15 @@ const Injects = ({ dispatch(fetchInjectorContracts()); }); const { - injectorContractsMap, tagsMap, - injectorContractsWithNoTeams, selectedInject, } = useHelper((helper) => { return { - injectorContractsMap: helper.getInjectorContractsMap(), tagsMap: helper.getTagsMap(), - injectorContractsWithNoTeams: helper.getInjectorContractsWithNoTeams(), selectedInject: helper.getInject(selectedInjectId), }; }); - const injectorContracts = Object.values(injectorContractsMap); - const onCreateInject = async (data) => { await injectContext.onAddInject(data); }; @@ -203,12 +195,8 @@ const Injects = ({ }; const sortedInjects = filtering.filterAndSort(injects); - const types = injectorContracts.map((type) => type.config.type); - const disabledTypes = injectorContracts - .filter((type) => type.config.expose === false) - .map((type) => type.config.type); // Rendering - if (injects && !R.isEmpty(injectorContractsMap)) { + if (injects) { return (
<> @@ -322,14 +310,12 @@ const Injects = ({   {sortedInjects.map((inject) => { - const injectContract = injectorContractsMap[inject.inject_injector_contract]; + const injectContract = inject.inject_injector_contract.injector_contract_content_parsed; const injectorContractName = tPick(injectContract?.label); const duration = splitDuration(inject.inject_depends_duration || 0); - const isDisabled = disabledTypes.includes(inject.inject_type) - || !types.includes(inject.inject_type); - const isNoTeam = injectorContractsWithNoTeams.includes( - inject.inject_type, - ); + console.log('injectContract', injectContract); + const isDisabled = !injectContract?.config.expose; + const isNoTeam = !(injectContract?.fields.filter((f) => f.key === 'teams').length > 0); let injectStatus = inject.inject_enabled ? t('Enabled') : t('Disabled'); @@ -420,7 +406,6 @@ const Injects = ({ setSelectedInjectId(null)} onUpdateInject={onUpdateInject} - injectorContract={injectorContractsMap[selectedInject.inject_injector_contract]} + injectorContract={selectedInject.inject_injector_contract.injector_contract_content_parsed} inject={selectedInject} teamsFromExerciseOrScenario={teams} articlesFromExerciseOrScenario={articles} diff --git a/openbas-front/src/admin/components/common/injects/UpdateInject.tsx b/openbas-front/src/admin/components/common/injects/UpdateInject.tsx index 03e68aaffb..fd2cb94256 100644 --- a/openbas-front/src/admin/components/common/injects/UpdateInject.tsx +++ b/openbas-front/src/admin/components/common/injects/UpdateInject.tsx @@ -4,7 +4,7 @@ import Drawer from '../../../../components/common/Drawer'; import InjectDefinition from './InjectDefinition'; import { tagOptions } from '../../../../utils/Option'; import { useFormatter } from '../../../../components/i18n'; -import { PermissionsContext } from '../../components/Context'; +import { PermissionsContext } from '../Context'; import type { Inject, InjectorContract, Tag } from '../../../../utils/api-types'; import type { TeamStore } from '../../../../actions/teams/Team'; import { useHelper } from '../../../../store'; diff --git a/openbas-front/src/admin/components/common/injects/expectations/ExpectationPopover.tsx b/openbas-front/src/admin/components/common/injects/expectations/ExpectationPopover.tsx index 0c4698e503..54340fe562 100644 --- a/openbas-front/src/admin/components/common/injects/expectations/ExpectationPopover.tsx +++ b/openbas-front/src/admin/components/common/injects/expectations/ExpectationPopover.tsx @@ -6,7 +6,7 @@ import { useFormatter } from '../../../../../components/i18n'; import ExpectationFormUpdate from './ExpectationFormUpdate'; import type { ExpectationInput } from './Expectation'; import Dialog from '../../../../../components/common/Dialog'; -import { PermissionsContext } from '../../../components/Context'; +import { PermissionsContext } from '../../Context'; interface ExpectationPopoverProps { index: number; diff --git a/openbas-front/src/admin/components/common/injects/expectations/InjectAddExpectation.tsx b/openbas-front/src/admin/components/common/injects/expectations/InjectAddExpectation.tsx index 74a67f4058..20713644e2 100644 --- a/openbas-front/src/admin/components/common/injects/expectations/InjectAddExpectation.tsx +++ b/openbas-front/src/admin/components/common/injects/expectations/InjectAddExpectation.tsx @@ -7,7 +7,7 @@ import { useFormatter } from '../../../../../components/i18n'; import Dialog from '../../../../../components/common/Dialog'; import ExpectationFormCreate from './ExpectationFormCreate'; import type { ExpectationInput } from './Expectation'; -import { PermissionsContext } from '../../../components/Context'; +import { PermissionsContext } from '../../Context'; const useStyles = makeStyles((theme: Theme) => ({ item: { diff --git a/openbas-front/src/admin/components/components/articles/ArticleAddDocuments.js b/openbas-front/src/admin/components/components/articles/ArticleAddDocuments.js index 74cde86d7c..1e97797752 100644 --- a/openbas-front/src/admin/components/components/articles/ArticleAddDocuments.js +++ b/openbas-front/src/admin/components/components/articles/ArticleAddDocuments.js @@ -14,7 +14,7 @@ import ItemTags from '../../../../components/ItemTags'; import { useHelper } from '../../../../store'; import useDataLoader from '../../../../utils/ServerSideEvent'; import { useAppDispatch } from '../../../../utils/hooks'; -import { PermissionsContext } from '../Context'; +import { PermissionsContext } from '../../common/Context'; const useStyles = makeStyles((theme) => ({ box: { diff --git a/openbas-front/src/admin/components/components/articles/ArticlePopover.js b/openbas-front/src/admin/components/components/articles/ArticlePopover.js index c3288bae84..ca4a961b1d 100644 --- a/openbas-front/src/admin/components/components/articles/ArticlePopover.js +++ b/openbas-front/src/admin/components/components/articles/ArticlePopover.js @@ -4,7 +4,7 @@ import { Button, Dialog, DialogActions, DialogContent, DialogContentText, Dialog import { MoreVert } from '@mui/icons-material'; import { useFormatter } from '../../../../components/i18n'; import ArticleForm from './ArticleForm'; -import { ArticleContext, PermissionsContext } from '../Context'; +import { ArticleContext, PermissionsContext } from '../../common/Context'; const Transition = React.forwardRef((props, ref) => ( diff --git a/openbas-front/src/admin/components/components/articles/Articles.tsx b/openbas-front/src/admin/components/components/articles/Articles.tsx index 16e955ffb0..0492f7162a 100644 --- a/openbas-front/src/admin/components/components/articles/Articles.tsx +++ b/openbas-front/src/admin/components/components/articles/Articles.tsx @@ -22,7 +22,7 @@ import { useFormatter } from '../../../../components/i18n'; import type { DocumentsHelper } from '../../../../actions/helper'; import CreateArticle from './CreateArticle'; import type { ChannelsHelper } from '../../../../actions/channels/channel-helper'; -import { ArticleContext, PermissionsContext } from '../Context'; +import { ArticleContext, PermissionsContext } from '../../common/Context'; const useStyles = makeStyles(() => ({ channel: { diff --git a/openbas-front/src/admin/components/components/articles/CreateArticle.js b/openbas-front/src/admin/components/components/articles/CreateArticle.js index 726168fb07..5b8ad3702f 100644 --- a/openbas-front/src/admin/components/components/articles/CreateArticle.js +++ b/openbas-front/src/admin/components/components/articles/CreateArticle.js @@ -4,7 +4,7 @@ import { Add, ControlPointOutlined } from '@mui/icons-material'; import { makeStyles } from '@mui/styles'; import { useFormatter } from '../../../../components/i18n'; import ArticleForm from './ArticleForm'; -import { ArticleContext } from '../Context'; +import { ArticleContext } from '../../common/Context'; const Transition = React.forwardRef((props, ref) => ( diff --git a/openbas-front/src/admin/components/components/challenges/Challenges.js b/openbas-front/src/admin/components/components/challenges/Challenges.js index 59dadc4ce3..cc7b6131c3 100644 --- a/openbas-front/src/admin/components/components/challenges/Challenges.js +++ b/openbas-front/src/admin/components/components/challenges/Challenges.js @@ -9,7 +9,7 @@ import SearchFilter from '../../../../components/SearchFilter'; import ExpandableMarkdown from '../../../../components/ExpandableMarkdown'; import TagsFilter from '../../../../components/TagsFilter'; import { useFormatter } from '../../../../components/i18n'; -import { ChallengeContext } from '../Context'; +import { ChallengeContext } from '../../common/Context'; const useStyles = makeStyles(() => ({ flag: { diff --git a/openbas-front/src/admin/components/components/documents/CreateDocument.js b/openbas-front/src/admin/components/components/documents/CreateDocument.js index 2db26932eb..5bf929b0ef 100644 --- a/openbas-front/src/admin/components/components/documents/CreateDocument.js +++ b/openbas-front/src/admin/components/components/documents/CreateDocument.js @@ -8,7 +8,7 @@ import { Add, ControlPointOutlined } from '@mui/icons-material'; import DocumentForm from './DocumentForm'; import { addDocument, fetchDocument } from '../../../../actions/Document'; import inject18n from '../../../../components/i18n'; -import { DocumentContext } from '../Context'; +import { DocumentContext } from '../../common/Context'; import Drawer from '../../../../components/common/Drawer'; import Dialog from '../../../../components/common/Dialog'; diff --git a/openbas-front/src/admin/components/components/teams/CreateTeam.tsx b/openbas-front/src/admin/components/components/teams/CreateTeam.tsx index a6831004d4..c3b71b2982 100644 --- a/openbas-front/src/admin/components/components/teams/CreateTeam.tsx +++ b/openbas-front/src/admin/components/components/teams/CreateTeam.tsx @@ -11,7 +11,7 @@ import TeamForm from './TeamForm'; import type { TeamCreateInput } from '../../../../utils/api-types'; import { addTeam } from '../../../../actions/teams/team-actions'; import { useAppDispatch } from '../../../../utils/hooks'; -import { TeamContext } from '../Context'; +import { TeamContext } from '../../common/Context'; const useStyles = makeStyles((theme: Theme) => ({ createButton: { diff --git a/openbas-front/src/admin/components/components/teams/TeamAddPlayers.tsx b/openbas-front/src/admin/components/components/teams/TeamAddPlayers.tsx index f2330edd29..b70a38c02d 100644 --- a/openbas-front/src/admin/components/components/teams/TeamAddPlayers.tsx +++ b/openbas-front/src/admin/components/components/teams/TeamAddPlayers.tsx @@ -18,7 +18,7 @@ import { resolveUserName, truncate } from '../../../../utils/String'; import ItemTags from '../../../../components/ItemTags'; import CreatePlayer from '../../teams/players/CreatePlayer'; import Transition from '../../../../components/common/Transition'; -import { TeamContext } from '../Context'; +import { TeamContext } from '../../common/Context'; const useStyles = makeStyles(() => ({ createButton: { diff --git a/openbas-front/src/admin/components/components/teams/TeamForm.tsx b/openbas-front/src/admin/components/components/teams/TeamForm.tsx index 38660a2a9a..271022d74d 100644 --- a/openbas-front/src/admin/components/components/teams/TeamForm.tsx +++ b/openbas-front/src/admin/components/components/teams/TeamForm.tsx @@ -11,7 +11,7 @@ import type { Theme } from '../../../../components/Theme'; import type { TeamInputForm } from '../../../../actions/teams/Team'; import { schemaValidator } from '../../../../utils/Zod'; import CheckboxField from '../../../../components/CheckboxField'; -import { TeamContext, TeamContextType } from '../Context'; +import { TeamContext, TeamContextType } from '../../common/Context'; const useStyles = makeStyles((theme: Theme) => ({ container: { diff --git a/openbas-front/src/admin/components/components/teams/TeamPlayers.tsx b/openbas-front/src/admin/components/components/teams/TeamPlayers.tsx index 8978483547..4a5ca7d46b 100644 --- a/openbas-front/src/admin/components/components/teams/TeamPlayers.tsx +++ b/openbas-front/src/admin/components/components/teams/TeamPlayers.tsx @@ -21,7 +21,7 @@ import type { OrganizationsHelper, UsersHelper } from '../../../../actions/helpe import type { UserStore } from '../../teams/players/Player'; import type { Option } from '../../../../utils/Option'; import type { TeamsHelper } from '../../../../actions/teams/team-helper'; -import { PermissionsContext, TeamContext } from '../Context'; +import { PermissionsContext, TeamContext } from '../../common/Context'; const useStyles = makeStyles((theme: Theme) => ({ header: { diff --git a/openbas-front/src/admin/components/components/teams/TeamPopover.tsx b/openbas-front/src/admin/components/components/teams/TeamPopover.tsx index d0635cc919..076010033b 100644 --- a/openbas-front/src/admin/components/components/teams/TeamPopover.tsx +++ b/openbas-front/src/admin/components/components/teams/TeamPopover.tsx @@ -13,7 +13,7 @@ import { useHelper } from '../../../../store'; import type { OrganizationsHelper, TagsHelper } from '../../../../actions/helper'; import type { TeamInputForm, TeamStore } from '../../../../actions/teams/Team'; import type { TeamsHelper } from '../../../../actions/teams/team-helper'; -import { TeamContext } from '../Context'; +import { TeamContext } from '../../common/Context'; import type { ExercisesHelper } from '../../../../actions/exercises/exercise-helper'; interface TeamPopoverProps { diff --git a/openbas-front/src/admin/components/components/teams/Teams.tsx b/openbas-front/src/admin/components/components/teams/Teams.tsx index e33283092f..c97856cc1b 100644 --- a/openbas-front/src/admin/components/components/teams/Teams.tsx +++ b/openbas-front/src/admin/components/components/teams/Teams.tsx @@ -20,7 +20,7 @@ import { fetchTeams } from '../../../../actions/teams/team-actions'; import { useAppDispatch } from '../../../../utils/hooks'; import type { TeamsHelper } from '../../../../actions/teams/team-helper'; import TeamPlayers from './TeamPlayers'; -import { PermissionsContext, TeamContext } from '../Context'; +import { PermissionsContext, TeamContext } from '../../common/Context'; import Breadcrumbs from '../../../../components/Breadcrumbs'; const useStyles = makeStyles(() => ({ diff --git a/openbas-front/src/admin/components/components/variables/CreateVariable.tsx b/openbas-front/src/admin/components/components/variables/CreateVariable.tsx index 7c5c32c19d..f370fdc525 100644 --- a/openbas-front/src/admin/components/components/variables/CreateVariable.tsx +++ b/openbas-front/src/admin/components/components/variables/CreateVariable.tsx @@ -6,7 +6,7 @@ import { useFormatter } from '../../../../components/i18n'; import VariableForm from './VariableForm'; import type { VariableInput } from '../../../../utils/api-types'; import Transition from '../../../../components/common/Transition'; -import { VariableContext } from '../Context'; +import { VariableContext } from '../../common/Context'; const useStyles = makeStyles((theme: Theme) => ({ createButton: { diff --git a/openbas-front/src/admin/components/components/variables/Variables.tsx b/openbas-front/src/admin/components/components/variables/Variables.tsx index 6759e4080a..c061127836 100644 --- a/openbas-front/src/admin/components/components/variables/Variables.tsx +++ b/openbas-front/src/admin/components/components/variables/Variables.tsx @@ -7,7 +7,7 @@ import useSearchAnFilter from '../../../../utils/SortingFiltering'; import type { Variable } from '../../../../utils/api-types'; import SearchFilter from '../../../../components/SearchFilter'; import CreateVariable from './CreateVariable'; -import { PermissionsContext, VariableContext } from '../Context'; +import { PermissionsContext, VariableContext } from '../../common/Context'; const useStyles = makeStyles(() => ({ itemHead: { diff --git a/openbas-front/src/admin/components/scenarios/scenario/IndexScenario.tsx b/openbas-front/src/admin/components/scenarios/scenario/IndexScenario.tsx index 24e9afd6a0..8fc608c30a 100644 --- a/openbas-front/src/admin/components/scenarios/scenario/IndexScenario.tsx +++ b/openbas-front/src/admin/components/scenarios/scenario/IndexScenario.tsx @@ -12,7 +12,7 @@ import NotFound from '../../../../components/NotFound'; import ScenarioHeader from './ScenarioHeader'; import type { ScenarioStore } from '../../../../actions/scenarios/Scenario'; import useScenarioPermissions from '../../../../utils/Scenario'; -import { DocumentContext, DocumentContextType, PermissionsContext, PermissionsContextType } from '../../components/Context'; +import { DocumentContext, DocumentContextType, PermissionsContext, PermissionsContextType } from '../../common/Context'; import { useFormatter } from '../../../../components/i18n'; import Breadcrumbs from '../../../../components/Breadcrumbs'; diff --git a/openbas-front/src/admin/components/scenarios/scenario/articles/ScenarioArticles.tsx b/openbas-front/src/admin/components/scenarios/scenario/articles/ScenarioArticles.tsx index 0cd053bcfb..202129e730 100644 --- a/openbas-front/src/admin/components/scenarios/scenario/articles/ScenarioArticles.tsx +++ b/openbas-front/src/admin/components/scenarios/scenario/articles/ScenarioArticles.tsx @@ -10,7 +10,7 @@ import type { ArticlesHelper } from '../../../../../actions/channels/article-hel import type { ScenarioStore } from '../../../../../actions/scenarios/Scenario'; import type { ArticleStore, FullArticleStore } from '../../../../../actions/channels/Article'; import type { ArticleCreateInput, ArticleUpdateInput } from '../../../../../utils/api-types'; -import { ArticleContext } from '../../../components/Context'; +import { ArticleContext } from '../../../common/Context'; export const articleContextForScenario = (scenarioId: ScenarioStore['scenario_id']) => { const dispatch = useAppDispatch(); diff --git a/openbas-front/src/admin/components/scenarios/scenario/challenges/ScenarioChallenges.tsx b/openbas-front/src/admin/components/scenarios/scenario/challenges/ScenarioChallenges.tsx index 0c040560e7..afd85feea5 100644 --- a/openbas-front/src/admin/components/scenarios/scenario/challenges/ScenarioChallenges.tsx +++ b/openbas-front/src/admin/components/scenarios/scenario/challenges/ScenarioChallenges.tsx @@ -8,7 +8,7 @@ import useDataLoader from '../../../../../utils/ServerSideEvent'; import { fetchScenarioChallenges } from '../../../../../actions/Challenge'; import DefinitionMenu from '../../../components/DefinitionMenu'; import Challenges from '../../../components/challenges/Challenges'; -import { ChallengeContext, ChallengeContextType } from '../../../components/Context'; +import { ChallengeContext, ChallengeContextType } from '../../../common/Context'; const ScenarioChallenges = () => { // Standard hooks diff --git a/openbas-front/src/admin/components/scenarios/scenario/injects/ScenarioInjects.tsx b/openbas-front/src/admin/components/scenarios/scenario/injects/ScenarioInjects.tsx index e44db4365d..2d1c702c7f 100644 --- a/openbas-front/src/admin/components/scenarios/scenario/injects/ScenarioInjects.tsx +++ b/openbas-front/src/admin/components/scenarios/scenario/injects/ScenarioInjects.tsx @@ -1,7 +1,7 @@ import React, { FunctionComponent } from 'react'; import { useParams } from 'react-router-dom'; import type { ScenarioStore } from '../../../../../actions/scenarios/Scenario'; -import { ArticleContext, InjectContext, InjectContextType, TeamContext } from '../../../components/Context'; +import { ArticleContext, InjectContext, InjectContextType, TeamContext } from '../../../common/Context'; import { useAppDispatch } from '../../../../../utils/hooks'; import { useHelper } from '../../../../../store'; import type { InjectHelper } from '../../../../../actions/injects/inject-helper'; diff --git a/openbas-front/src/admin/components/scenarios/scenario/teams/ScenarioTeams.tsx b/openbas-front/src/admin/components/scenarios/scenario/teams/ScenarioTeams.tsx index acd59789c2..08ad461644 100644 --- a/openbas-front/src/admin/components/scenarios/scenario/teams/ScenarioTeams.tsx +++ b/openbas-front/src/admin/components/scenarios/scenario/teams/ScenarioTeams.tsx @@ -17,7 +17,7 @@ import type { ScenariosHelper } from '../../../../../actions/scenarios/scenario- import type { ScenarioStore } from '../../../../../actions/scenarios/Scenario'; import type { TeamStore } from '../../../../../actions/teams/Team'; import Teams from '../../../components/teams/Teams'; -import { PermissionsContext, TeamContext } from '../../../components/Context'; +import { PermissionsContext, TeamContext } from '../../../common/Context'; import type { Team, TeamCreateInput } from '../../../../../utils/api-types'; import { addTeam, fetchTeams } from '../../../../../actions/teams/team-actions'; import type { UserStore } from '../../../teams/players/Player'; diff --git a/openbas-front/src/admin/components/scenarios/scenario/variables/ScenarioVariables.tsx b/openbas-front/src/admin/components/scenarios/scenario/variables/ScenarioVariables.tsx index 06c84d9ece..5fd96f38db 100644 --- a/openbas-front/src/admin/components/scenarios/scenario/variables/ScenarioVariables.tsx +++ b/openbas-front/src/admin/components/scenarios/scenario/variables/ScenarioVariables.tsx @@ -8,7 +8,7 @@ import useDataLoader from '../../../../../utils/ServerSideEvent'; import { addVariableForScenario, deleteVariableForScenario, fetchVariablesForScenario, updateVariableForScenario } from '../../../../../actions/variables/variable-actions'; import type { VariablesHelper } from '../../../../../actions/variables/variable-helper'; import type { ScenarioStore } from '../../../../../actions/scenarios/Scenario'; -import { VariableContext, VariableContextType } from '../../../components/Context'; +import { VariableContext, VariableContextType } from '../../../common/Context'; import type { Variable, VariableInput } from '../../../../../utils/api-types'; const ScenarioVariables = () => { diff --git a/openbas-front/src/admin/components/simulations/Index.tsx b/openbas-front/src/admin/components/simulations/Index.tsx index 80ab4e2e84..2290977bb1 100644 --- a/openbas-front/src/admin/components/simulations/Index.tsx +++ b/openbas-front/src/admin/components/simulations/Index.tsx @@ -9,7 +9,7 @@ import useDataLoader from '../../../utils/ServerSideEvent'; import { useAppDispatch } from '../../../utils/hooks'; import ExerciseHeader from './ExerciseHeader'; import type { Exercise as ExerciseType } from '../../../utils/api-types'; -import { DocumentContext, DocumentContextType, PermissionsContext, PermissionsContextType } from '../components/Context'; +import { DocumentContext, DocumentContextType, PermissionsContext, PermissionsContextType } from '../common/Context'; import { usePermissions } from '../../../utils/Exercise'; import type { ExercisesHelper } from '../../../actions/exercises/exercise-helper'; import NotFound from '../../../components/NotFound'; diff --git a/openbas-front/src/admin/components/simulations/articles/ExerciseArticles.tsx b/openbas-front/src/admin/components/simulations/articles/ExerciseArticles.tsx index 78bd309958..c4a87e9904 100644 --- a/openbas-front/src/admin/components/simulations/articles/ExerciseArticles.tsx +++ b/openbas-front/src/admin/components/simulations/articles/ExerciseArticles.tsx @@ -8,7 +8,7 @@ import { useAppDispatch } from '../../../../utils/hooks'; import type { ArticlesHelper } from '../../../../actions/channels/article-helper'; import type { ArticleCreateInput, ArticleUpdateInput, Exercise } from '../../../../utils/api-types'; import DefinitionMenu from '../../components/DefinitionMenu'; -import { ArticleContext } from '../../components/Context'; +import { ArticleContext } from '../../common/Context'; import type { ArticleStore, FullArticleStore } from '../../../../actions/channels/Article'; import type { ExerciseStore } from '../../../../actions/exercises/Exercise'; diff --git a/openbas-front/src/admin/components/simulations/challenges/ExerciseChallenges.tsx b/openbas-front/src/admin/components/simulations/challenges/ExerciseChallenges.tsx index d91c842f67..9eb765e4d6 100644 --- a/openbas-front/src/admin/components/simulations/challenges/ExerciseChallenges.tsx +++ b/openbas-front/src/admin/components/simulations/challenges/ExerciseChallenges.tsx @@ -8,7 +8,7 @@ import useDataLoader from '../../../../utils/ServerSideEvent'; import Challenges from '../../components/challenges/Challenges'; import { fetchExerciseChallenges } from '../../../../actions/Challenge'; import type { ChallengesHelper } from '../../../../actions/helper'; -import { ChallengeContext, ChallengeContextType } from '../../components/Context'; +import { ChallengeContext, ChallengeContextType } from '../../common/Context'; const ExerciseChallenges = () => { // Standard hooks diff --git a/openbas-front/src/admin/components/simulations/controls/Dryrun.js b/openbas-front/src/admin/components/simulations/controls/Dryrun.js index 9c0895de6f..ff5047e302 100644 --- a/openbas-front/src/admin/components/simulations/controls/Dryrun.js +++ b/openbas-front/src/admin/components/simulations/controls/Dryrun.js @@ -177,12 +177,11 @@ const Dryrun = () => { const searchColumns = ['type', 'title', 'date']; const filtering = useSearchAnFilter('dryinject', 'date', searchColumns); // Fetching data - const { dryrun, dryinjects, users, injectorContractsMap } = useHelper((helper) => { + const { dryrun, dryinjects, users } = useHelper((helper) => { return { dryrun: helper.getDryrun(dryrunId), dryinjects: helper.getDryrunInjects(dryrunId), users: helper.getDryrunUsers(dryrunId), - injectorContractsMap: helper.getInjectorContractsMap(), }; }); useDataLoader(() => { @@ -190,7 +189,6 @@ const Dryrun = () => { dispatch(fetchPlayers()); dispatch(fetchDryrun(exerciseId, dryrunId)); dispatch(fetchDryinjects(exerciseId, dryrunId)); - dispatch(fetchInjectorContracts()); }); return (
diff --git a/openbas-front/src/admin/components/simulations/dashboard/Dashboard.js b/openbas-front/src/admin/components/simulations/dashboard/Dashboard.js index 9d30d02108..7a0fe57728 100644 --- a/openbas-front/src/admin/components/simulations/dashboard/Dashboard.js +++ b/openbas-front/src/admin/components/simulations/dashboard/Dashboard.js @@ -18,7 +18,6 @@ import DashboardDefinitionStatistics from './DashboardDefinitionStatistics'; import DashboardDefinitionScoreStatistics from './DashboardDefinitionScoreStatistics'; import DashboardDataStatistics from './DashboardDataStatistics'; import DashboardResultsStatistics from './DashboardResultsStatistics'; -import { fetchInjectorContracts } from '../../../../actions/InjectorContracts'; const useStyles = makeStyles((theme) => ({ container: { @@ -62,7 +61,6 @@ const Dashboard = () => { teams, injects, challengesMap, - injectorContractsMap, teamsMap, injectExpectations, injectsMap, @@ -82,13 +80,11 @@ const Dashboard = () => { organizationsMap: helper.getOrganizationsMap(), injectExpectations: helper.getExerciseInjectExpectations(exerciseId), challengesMap: helper.getChallengesMap(), - injectorContractsMap: helper.getInjectorContractsMapByType(), communications: helper.getExerciseCommunications(exerciseId), }; }); useDataLoader(() => { dispatch(fetchExerciseTeams(exerciseId)); - dispatch(fetchInjectorContracts()); dispatch(fetchInjects(exerciseId)); dispatch(fetchExerciseChallenges(exerciseId)); dispatch(fetchExerciseInjectExpectations(exerciseId)); @@ -150,12 +146,10 @@ const Dashboard = () => { @@ -175,7 +169,6 @@ const Dashboard = () => { usersMap={usersMap} injectsMap={injectsMap} teams={teams} - injectorContractsMap={injectorContractsMap} teamsMap={teamsMap} injectExpectations={injectExpectations} organizations={organizations} diff --git a/openbas-front/src/admin/components/simulations/dashboard/DashboardDefinitionScoreStatistics.js b/openbas-front/src/admin/components/simulations/dashboard/DashboardDefinitionScoreStatistics.js index 5cd6948aca..a91c139089 100644 --- a/openbas-front/src/admin/components/simulations/dashboard/DashboardDefinitionScoreStatistics.js +++ b/openbas-front/src/admin/components/simulations/dashboard/DashboardDefinitionScoreStatistics.js @@ -19,7 +19,6 @@ const useStyles = makeStyles(() => ({ const DashboardDefinitionScoreStatistics = ({ teams, injects, - injectorContractsMap, challengesMap, }) => { const classes = useStyles(); @@ -68,10 +67,9 @@ const DashboardDefinitionScoreStatistics = ({ { name: t('Number of expectations'), data: sortedInjectorContractsWithScoreByNumber.map((a) => ({ - x: tPick(injectorContractsMap && injectorContractsMap[a.inject_type]?.label), + x: tPick(a.inject_injector_contract?.injector_contract_labels), y: a.number, - fillColor: - injectorContractsMap && injectorContractsMap[a.inject_type]?.config?.color, + fillColor: a.inject_injector_contract?.injector_contract_content_parsed?.config?.color, })), }, ]; @@ -83,10 +81,9 @@ const DashboardDefinitionScoreStatistics = ({ { name: t('Total expected score'), data: sortedInjectorContractsWithScoreByScore.map((a) => ({ - x: tPick(injectorContractsMap && injectorContractsMap[a.inject_type]?.label), + x: tPick(a.inject_injector_contract?.injector_contract_labels), y: a.score, - fillColor: - injectorContractsMap && injectorContractsMap[a.inject_type]?.config?.color, + fillColor: a.inject_injector_contract?.injector_contract_content_parsed?.config?.color, })), }, ]; diff --git a/openbas-front/src/admin/components/simulations/dashboard/DashboardDefinitionStatistics.js b/openbas-front/src/admin/components/simulations/dashboard/DashboardDefinitionStatistics.js index 5c537ae814..84bc4e9286 100644 --- a/openbas-front/src/admin/components/simulations/dashboard/DashboardDefinitionStatistics.js +++ b/openbas-front/src/admin/components/simulations/dashboard/DashboardDefinitionStatistics.js @@ -19,7 +19,6 @@ const useStyles = makeStyles(() => ({ const DashboardDefinitionStatistics = ({ teams, injects, - injectorContractsMap, }) => { const classes = useStyles(); const { t, tPick } = useFormatter(); @@ -60,10 +59,9 @@ const DashboardDefinitionStatistics = ({ { name: t('Number of injects'), data: injectsByType.map((a) => ({ - x: tPick(injectorContractsMap && injectorContractsMap[a.inject_type]?.label), + x: tPick(a.inject_injector_contract?.injector_contract_labels), y: a.number, - fillColor: - injectorContractsMap && injectorContractsMap[a.inject_type]?.config?.color, + fillColor: a.inject_injector_contract?.injector_contract_content_parsed?.config?.color, })), }, ]; diff --git a/openbas-front/src/admin/components/simulations/dashboard/DashboardResultsStatistics.js b/openbas-front/src/admin/components/simulations/dashboard/DashboardResultsStatistics.js index d8778dbda5..dc33417ceb 100644 --- a/openbas-front/src/admin/components/simulations/dashboard/DashboardResultsStatistics.js +++ b/openbas-front/src/admin/components/simulations/dashboard/DashboardResultsStatistics.js @@ -23,7 +23,6 @@ const DashboardDefinitionStatistics = ({ teamsMap, injectExpectations, injectsMap, - injectorContractsMap, usersMap, organizationsMap, }) => { @@ -88,10 +87,10 @@ const DashboardDefinitionStatistics = ({ 'inject_expectation_percent_score', Math.round( (cumulation * 100) - / (teamsMap[n[0]] - ? teamsMap[n[0]] - .team_injects_expectations_total_expected_score - : 1), + / (teamsMap[n[0]] + ? teamsMap[n[0]] + .team_injects_expectations_total_expected_score + : 1), ), i, ); @@ -128,10 +127,9 @@ const DashboardDefinitionStatistics = ({ { name: t('Total score'), data: sortedInjectorContractsByTotalScore.map((i) => ({ - x: tPick(injectorContractsMap && injectorContractsMap[i.inject_type]?.label), + x: tPick(i.inject_injector_contract?.injector_contract_labels), y: i.inject_total_score, - fillColor: - injectorContractsMap && injectorContractsMap[i.inject_type]?.config?.color, + fillColor: i.inject_injector_contract?.injector_contract_content_parsed?.config?.color, })), }, ]; @@ -158,8 +156,8 @@ const DashboardDefinitionStatistics = ({ ]; }), R.map((n) => ({ - name: tPick(injectorContractsMap && injectorContractsMap[n[0]]?.label), - color: injectorContractsMap && injectorContractsMap[n[0]]?.config?.color, + name: tPick(n.inject_injector_contract?.injector_contract_labels), + color: n.inject_injector_contract?.injector_contract_content_parsed?.config?.color, data: n[1].map((i) => ({ x: i.inject_expectation_updated_at, y: i.inject_expectation_cumulated_score, @@ -276,7 +274,7 @@ const DashboardDefinitionStatistics = ({ 'team_total_percent_score', Math.round( (n.team_injects_expectations_total_score * 100) - / n.team_injects_expectations_total_expected_score, + / n.team_injects_expectations_total_expected_score, ), n, ), diff --git a/openbas-front/src/admin/components/simulations/injects/ExerciseInjects.tsx b/openbas-front/src/admin/components/simulations/injects/ExerciseInjects.tsx index 4b36b04477..34926fe0d7 100644 --- a/openbas-front/src/admin/components/simulations/injects/ExerciseInjects.tsx +++ b/openbas-front/src/admin/components/simulations/injects/ExerciseInjects.tsx @@ -4,7 +4,7 @@ import { ReorderOutlined, SignalCellularAltOutlined } from '@mui/icons-material' import { Grid, Paper, ToggleButton, ToggleButtonGroup, Tooltip, Typography } from '@mui/material'; import { makeStyles } from '@mui/styles'; import type { Exercise, Inject } from '../../../../utils/api-types'; -import { ArticleContext, InjectContext, InjectContextType, TeamContext } from '../../components/Context'; +import { ArticleContext, InjectContext, InjectContextType, TeamContext } from '../../common/Context'; import { useAppDispatch } from '../../../../utils/hooks'; import { addInjectForExercise, @@ -28,7 +28,6 @@ import type { InjectHelper } from '../../../../actions/injects/inject-helper'; import { fetchExerciseArticles } from '../../../../actions/channels/article-action'; import { articleContextForExercise } from '../articles/ExerciseArticles'; import { teamContextForExercise } from '../teams/ExerciseTeams'; -import { fetchInjectorContracts } from '../../../../actions/InjectorContracts'; import InjectDistributionByType from '../../common/injects/InjectDistributionByType'; import InjectDistributionByTeam from '../../common/injects/InjectDistributionByTeam'; import ExerciseDistributionScoreByTeamInPercentage from '../overview/ExerciseDistributionScoreByTeamInPercentage'; @@ -72,7 +71,6 @@ const ExerciseInjects: FunctionComponent = () => { dispatch(fetchExerciseInjects(exerciseId)); dispatch(fetchExerciseTeams(exerciseId)); dispatch(fetchExerciseArticles(exerciseId)); - dispatch(fetchInjectorContracts()); dispatch(fetchVariablesForExercise(exerciseId)); }); diff --git a/openbas-front/src/admin/components/simulations/injects/asset_groups/InjectAddAssetGroups.tsx b/openbas-front/src/admin/components/simulations/injects/asset_groups/InjectAddAssetGroups.tsx index 5f998f1b36..7fedf983c5 100644 --- a/openbas-front/src/admin/components/simulations/injects/asset_groups/InjectAddAssetGroups.tsx +++ b/openbas-front/src/admin/components/simulations/injects/asset_groups/InjectAddAssetGroups.tsx @@ -5,7 +5,7 @@ import { ControlPointOutlined } from '@mui/icons-material'; import type { Theme } from '../../../../../components/Theme'; import { useFormatter } from '../../../../../components/i18n'; import AssetGroupDialogAdding from '../../../assets/asset_groups/AssetGroupDialogAdding'; -import { PermissionsContext } from '../../../components/Context'; +import { PermissionsContext } from '../../../common/Context'; const useStyles = makeStyles((theme: Theme) => ({ item: { diff --git a/openbas-front/src/admin/components/simulations/injects/endpoints/InjectAddEndpoints.tsx b/openbas-front/src/admin/components/simulations/injects/endpoints/InjectAddEndpoints.tsx index 6b59af5cfc..693586efc1 100644 --- a/openbas-front/src/admin/components/simulations/injects/endpoints/InjectAddEndpoints.tsx +++ b/openbas-front/src/admin/components/simulations/injects/endpoints/InjectAddEndpoints.tsx @@ -6,7 +6,7 @@ import { useFormatter } from '../../../../../components/i18n'; import type { Theme } from '../../../../../components/Theme'; import EndpointsDialogAdding from '../../../assets/endpoints/EndpointsDialogAdding'; import type { EndpointStore } from '../../../assets/endpoints/Endpoint'; -import { PermissionsContext } from '../../../components/Context'; +import { PermissionsContext } from '../../../common/Context'; const useStyles = makeStyles((theme: Theme) => ({ item: { diff --git a/openbas-front/src/admin/components/simulations/mails/Mails.js b/openbas-front/src/admin/components/simulations/mails/Mails.js index 843980b4ca..65975c0ee0 100644 --- a/openbas-front/src/admin/components/simulations/mails/Mails.js +++ b/openbas-front/src/admin/components/simulations/mails/Mails.js @@ -17,7 +17,6 @@ import { useHelper } from '../../../../store'; import { exportData } from '../../../../utils/Environment'; import AnimationMenu from '../AnimationMenu'; import CreateQuickInject from '../injects/CreateQuickInject'; -import { fetchInjectorContracts } from '../../../../actions/InjectorContracts'; import MailDistributionOverTimeChart from './MailDistributionOverTimeChart'; import MailDistributionOverTimeLine from './MailDistributionOverTimeLine'; import MailDistributionByTeam from './MailDistributionByTeam'; @@ -175,16 +174,14 @@ const Mails = () => { const filtering = useSearchAnFilter('inject', 'sent_at', searchColumns); // Fetching data const { exerciseId } = useParams(); - const { exercise, injects, injectorContractsMap, tagsMap } = useHelper((helper) => { + const { exercise, injects, tagsMap } = useHelper((helper) => { return { exercise: helper.getExercise(exerciseId), injects: helper.getExerciseInjects(exerciseId), - injectorContractsMap: helper.getInjectorContractsMap(), tagsMap: helper.getTagsMap(), }; }); useDataLoader(() => { - dispatch(fetchInjectorContracts()); dispatch(fetchExerciseInjects(exerciseId)); }); const sortedInjects = filtering @@ -347,7 +344,7 @@ const Mails = () => {   {sortedInjects.map((inject) => { - const injectContract = injectorContractsMap[inject.inject_injector_contract]; + const injectContract = inject.inject_injector_contract.injector_contract_content_parsed; return ( = ({ const theme: Theme = useTheme(); // Fetching data - const { injectsMap, injectorContractsMap, injectExpectations } = useHelper((helper: InjectHelper & InjectorContractHelper) => ({ + const { injectsMap, injectExpectations } = useHelper((helper: InjectHelper) => ({ injectsMap: helper.getInjectsMap(), - injectorContractsMap: helper.getInjectorContractsMapByType(), injectExpectations: helper.getExerciseInjectExpectations(exerciseId), })); useDataLoader(() => { dispatch(fetchInjects(exerciseId)); - dispatch(fetchInjectorContracts()); dispatch(fetchExerciseInjectExpectations(exerciseId)); }); @@ -62,11 +72,10 @@ const ExerciseDistributionByInjectorContract: FunctionComponent = ({ const totalScoreByInjectorContractData = [ { name: t('Total score'), - data: sortedInjectorContractsByTotalScore.map((i: Inject & { inject_total_score: number }) => ({ - x: tPick(injectorContractsMap && injectorContractsMap[i.inject_type]?.label), + data: sortedInjectorContractsByTotalScore.map((i: InjectStore & { inject_total_score: number, }) => ({ + x: tPick(i.inject_injector_contract?.injector_contract_labels), y: i.inject_total_score, - fillColor: - injectorContractsMap && injectorContractsMap[i.inject_type]?.config?.color, + fillColor: i.inject_injector_contract?.injector_contract_content_parsed?.config?.color, })), }, ]; diff --git a/openbas-front/src/admin/components/simulations/overview/ExerciseDistributionScoreOverTimeByInjectorContract.tsx b/openbas-front/src/admin/components/simulations/overview/ExerciseDistributionScoreOverTimeByInjectorContract.tsx index 052aa1ed91..fb0354d894 100644 --- a/openbas-front/src/admin/components/simulations/overview/ExerciseDistributionScoreOverTimeByInjectorContract.tsx +++ b/openbas-front/src/admin/components/simulations/overview/ExerciseDistributionScoreOverTimeByInjectorContract.tsx @@ -13,9 +13,7 @@ import type { InjectHelper } from '../../../../actions/injects/inject-helper'; import useDataLoader from '../../../../utils/ServerSideEvent'; import { fetchExerciseInjectExpectations } from '../../../../actions/Exercise'; import type { InjectExpectation } from '../../../../utils/api-types'; -import type { InjectExpectationStore } from '../../../../actions/injects/Inject'; -import type { InjectorContractHelper } from '../../../../actions/injector_contracts/injector-contract-helper'; -import { fetchInjectorContracts } from '../../../../actions/InjectorContracts'; +import type { InjectExpectationStore, InjectStore } from '../../../../actions/injects/Inject'; interface Props { exerciseId: ExerciseStore['exercise_id']; @@ -30,14 +28,12 @@ const ExerciseDistributionScoreOverTimeByInjectorContract: FunctionComponent ({ + const { injectsMap, injectExpectations }: { injectsMap: InjectStore[], injectExpectations: InjectExpectationStore[] } = useHelper((helper: InjectHelper) => ({ injectsMap: helper.getInjectsMap(), injectExpectations: helper.getExerciseInjectExpectations(exerciseId), - injectorContractsMap: helper.getInjectorContractsMapByType(), })); useDataLoader(() => { dispatch(fetchExerciseInjectExpectations(exerciseId)); - dispatch(fetchInjectorContracts()); }); let cumulation = 0; @@ -48,7 +44,7 @@ const ExerciseDistributionScoreOverTimeByInjectorContract: FunctionComponent { cumulation = 0; @@ -63,9 +59,9 @@ const ExerciseDistributionScoreOverTimeByInjectorContract: FunctionComponent]) => ({ - name: tPick(injectorContractsMap && injectorContractsMap[n[0]]?.label), - color: injectorContractsMap && injectorContractsMap[n[0]]?.config?.color, + R.map((n: [string, Array]) => ({ + name: tPick(n[1][0].inject_expectation_inject.inject_injector_contract?.injector_contract_labels), + color: n[1][0].inject_injector_contract?.injector_contract_content_parsed?.config?.color, data: n[1].map((i: InjectExpectation & { inject_expectation_cumulated_score: number }) => ({ x: i.inject_expectation_updated_at, y: i.inject_expectation_cumulated_score, diff --git a/openbas-front/src/admin/components/simulations/reports/Report.js b/openbas-front/src/admin/components/simulations/reports/Report.js index 0a394b91ec..ceb64839b8 100644 --- a/openbas-front/src/admin/components/simulations/reports/Report.js +++ b/openbas-front/src/admin/components/simulations/reports/Report.js @@ -26,7 +26,6 @@ import { fetchObjectives } from '../../../../actions/Objective'; import LessonsObjectives from '../lessons/LessonsObjectives'; import LessonsCategories from '../lessons/LessonsCategories'; import ExportButtons from '../../../../components/ExportButtons'; -import { fetchInjectorContracts } from '../../../../actions/InjectorContracts'; const useStyles = makeStyles((theme) => ({ container: { @@ -82,7 +81,6 @@ const Dashboard = () => { teams, injects, challengesMap, - injectorContractsMap, teamsMap, injectExpectations, injectsMap, @@ -107,7 +105,6 @@ const Dashboard = () => { organizationsMap: helper.getOrganizationsMap(), injectExpectations: helper.getExerciseInjectExpectations(exerciseId), challengesMap: helper.getChallengesMap(), - injectorContractsMap: helper.getInjectorContractsMapByType(), communications: helper.getExerciseCommunications(exerciseId), objectives: helper.getExerciseObjectives(exerciseId), lessonsCategories: helper.getExerciseLessonsCategories(exerciseId), @@ -118,7 +115,6 @@ const Dashboard = () => { useDataLoader(() => { dispatch(fetchReports(exerciseId)); dispatch(fetchExerciseTeams(exerciseId)); - dispatch(fetchInjectorContracts()); dispatch(fetchInjects(exerciseId)); dispatch(fetchExerciseChallenges(exerciseId)); dispatch(fetchExerciseInjectExpectations(exerciseId)); @@ -214,14 +210,12 @@ const Dashboard = () => { )} {report.report_stats_definition_score && ( )} @@ -249,7 +243,6 @@ const Dashboard = () => { usersMap={usersMap} injectsMap={injectsMap} teams={teams} - injectorContractsMap={injectorContractsMap} teamsMap={teamsMap} injectExpectations={injectExpectations} organizations={organizations} diff --git a/openbas-front/src/admin/components/simulations/teams/ExerciseTeams.tsx b/openbas-front/src/admin/components/simulations/teams/ExerciseTeams.tsx index 737ed2c1ed..5ac484dbbf 100644 --- a/openbas-front/src/admin/components/simulations/teams/ExerciseTeams.tsx +++ b/openbas-front/src/admin/components/simulations/teams/ExerciseTeams.tsx @@ -5,7 +5,7 @@ import useDataLoader from '../../../../utils/ServerSideEvent'; import { useAppDispatch } from '../../../../utils/hooks'; import DefinitionMenu from '../../components/DefinitionMenu'; import Teams from '../../components/teams/Teams'; -import { PermissionsContext, TeamContext } from '../../components/Context'; +import { PermissionsContext, TeamContext } from '../../common/Context'; import type { UserStore } from '../../teams/players/Player'; import AddTeams from '../../components/teams/AddTeams'; import type { Team, TeamCreateInput } from '../../../../utils/api-types'; diff --git a/openbas-front/src/admin/components/simulations/timeline/Timeline.js b/openbas-front/src/admin/components/simulations/timeline/Timeline.js index ef2cbf5622..48ebfadac8 100644 --- a/openbas-front/src/admin/components/simulations/timeline/Timeline.js +++ b/openbas-front/src/admin/components/simulations/timeline/Timeline.js @@ -27,7 +27,6 @@ import { fetchExerciseArticles } from '../../../../actions/channels/article-acti import { fetchVariablesForExercise } from '../../../../actions/variables/variable-actions'; import InjectOverTimeArea from './InjectOverTimeArea'; import InjectOverTimeLine from './InjectOverTimeLine'; -import { fetchInjectorContracts } from '../../../../actions/InjectorContracts'; import UpdateInject from '../../common/injects/UpdateInject'; const useStyles = makeStyles(() => ({ @@ -144,8 +143,6 @@ const Timeline = () => { exercise, teams, injects, - injectorContractsMap, - injectorContractsWithNoTeams, tagsMap, teamsInjectsMap, technicalInjectsMap, @@ -168,18 +165,18 @@ const Timeline = () => { teamsInjectsMap: injectsPerTeam, technicalInjectsMap: helper.getExerciseTechnicalInjectsPerType(exerciseId), - injectorContractsMap: helper.getInjectorContractsMap(), - injectorContractsWithNoTeams: helper.getInjectorContractsWithNoTeams(), articles: helper.getExerciseArticles(exerciseId), variables: helper.getExerciseVariables(exerciseId), selectedInject: helper.getInject(selectedInjectId), }; }); - const technicalTeams = injectorContractsWithNoTeams - .filter( - (injectorContract) => injects.filter((i) => i.inject_type === injectorContract).length > 0, - ) - .map((type) => ({ team_id: type, team_name: type })); + const technicalTeams = R.pipe( + R.groupBy(R.prop('inject_type')), + R.toPairs, + R.filter((n) => !(n[1][0].inject_injector_contract?.injector_contract_content_parsed?.fields?.filter((f) => f.key === 'teams').length > 0)), + R.map((n) => ({ team_id: n[0], team_name: n[0] })), + )(injects); + const sortedNativeTeams = R.sortWith( [R.ascend(R.prop('team_name'))], teams, @@ -187,7 +184,6 @@ const Timeline = () => { const sortedTeams = [...technicalTeams, ...sortedNativeTeams]; const injectsMap = { ...teamsInjectsMap, ...technicalInjectsMap }; useDataLoader(() => { - dispatch(fetchInjectorContracts()); dispatch(fetchExerciseTeams(exerciseId)); dispatch(fetchInjects(exerciseId)); dispatch(fetchExerciseArticles(exerciseId)); @@ -226,11 +222,6 @@ const Timeline = () => { [R.descend(R.prop('inject_depends_duration'))], injects.filter((i) => i.inject_status !== null), ); - const injectorContracts = R.values(injectorContractsMap); - const disabledTypes = injectorContracts - .filter((type) => type.config.expose === false) - .map((type) => type.config.type); - const types = injectorContracts.map((type) => type.config.type); const grid0 = theme.palette.mode === 'light' ? 'rgba(0,0,0,0)' : 'rgba(255,255,255,0)'; const grid5 = theme.palette.mode === 'light' ? 'rgba(0,0,0,0.05)' @@ -412,8 +403,7 @@ const Timeline = () => { {pendingInjects.length > 0 ? ( {pendingInjects.map((inject) => { - const isDisabled = disabledTypes.includes(inject.inject_type) - || !types.includes(inject.inject_type); + const isDisabled = !inject.inject_injector_contract.injector_contract_content_parsed?.config.expose; return ( { exerciseId={exerciseId} exercise={exercise} tagsMap={tagsMap} - injectorContractsMap={injectorContractsMap} setSelectedInjectId={setSelectedInjectId} isDisabled={isDisabled} /> @@ -576,7 +565,7 @@ const Timeline = () => { open={selectedInjectId !== null} handleClose={() => setSelectedInjectId(null)} onUpdateInject={onUpdateInject} - injectorContract={injectorContractsMap[selectedInject.inject_injector_contract]} + injectorContract={selectedInject.inject_injector_contract.injector_contract_content_parsed} inject={selectedInject} teamsFromExerciseOrScenario={teams} articlesFromExerciseOrScenario={articles} diff --git a/openbas-front/src/admin/components/simulations/validation/Validations.js b/openbas-front/src/admin/components/simulations/validation/Validations.js index 3ca945848b..cfa05fd2f7 100644 --- a/openbas-front/src/admin/components/simulations/validation/Validations.js +++ b/openbas-front/src/admin/components/simulations/validation/Validations.js @@ -16,7 +16,6 @@ import TagsFilter from '../../../../components/TagsFilter'; import InjectIcon from '../../common/injects/InjectIcon'; import ItemTags from '../../../../components/ItemTags'; import TeamOrAssetLine from './common/TeamOrAssetLine'; -import { fetchInjectorContracts } from '../../../../actions/InjectorContracts'; const Transition = React.forwardRef((props, ref) => ( @@ -51,7 +50,6 @@ const Validations = () => { // Fetching data const { exercise, - injectorContractsMap, injectExpectations, injectsMap, } = useHelper((helper) => { @@ -59,11 +57,9 @@ const Validations = () => { exercise: helper.getExercise(exerciseId), injectsMap: helper.getInjectsMap(), injectExpectations: helper.getExerciseInjectExpectations(exerciseId), - injectorContractsMap: helper.getInjectorContractsMap(), }; }); useDataLoader(() => { - dispatch(fetchInjectorContracts()); dispatch(fetchExerciseInjectExpectations(exerciseId)); dispatch(fetchExerciseInjects(exerciseId)); }); @@ -132,7 +128,7 @@ const Validations = () => { }; // Rendering - if (exercise && injectExpectations && !R.isEmpty(injectorContractsMap)) { + if (exercise && injectExpectations) { return (
@@ -154,7 +150,7 @@ const Validations = () => { {Object.entries(groupedByInject).map(([injectId, expectationsByInject]) => { const inject = injectsMap[injectId] || {}; - const injectContract = injectorContractsMap[inject.inject_injector_contract] || {}; + const injectContract = inject.inject_injector_contract.injector_contract_content_parsed || {}; return (
diff --git a/openbas-front/src/admin/components/simulations/variables/ExerciseVariables.tsx b/openbas-front/src/admin/components/simulations/variables/ExerciseVariables.tsx index d60d5e1b70..80d850ebcb 100644 --- a/openbas-front/src/admin/components/simulations/variables/ExerciseVariables.tsx +++ b/openbas-front/src/admin/components/simulations/variables/ExerciseVariables.tsx @@ -8,7 +8,7 @@ import Variables from '../../components/variables/Variables'; import type { VariablesHelper } from '../../../../actions/variables/variable-helper'; import { addVariableForExercise, deleteVariableForExercise, fetchVariablesForExercise, updateVariableForExercise } from '../../../../actions/variables/variable-actions'; import DefinitionMenu from '../../components/DefinitionMenu'; -import { VariableContext, VariableContextType } from '../../components/Context'; +import { VariableContext, VariableContextType } from '../../common/Context'; const ExerciseVariables = () => { // Standard hooks diff --git a/openbas-front/src/admin/components/teams/Teams.tsx b/openbas-front/src/admin/components/teams/Teams.tsx index 0d3f39748f..b9f5d5fae6 100644 --- a/openbas-front/src/admin/components/teams/Teams.tsx +++ b/openbas-front/src/admin/components/teams/Teams.tsx @@ -1,6 +1,6 @@ import React from 'react'; import TeamsComponent from '../components/teams/Teams'; -import { PermissionsContext, PermissionsContextType, TeamContext, type TeamContextType } from '../components/Context'; +import { PermissionsContext, PermissionsContextType, TeamContext, type TeamContextType } from '../common/Context'; import { useHelper } from '../../../store'; import type { UsersHelper } from '../../../actions/helper'; import CreateTeam from '../components/teams/CreateTeam'; diff --git a/openbas-front/src/admin/components/teams/players/PlayerPopover.tsx b/openbas-front/src/admin/components/teams/players/PlayerPopover.tsx index 1e57893eef..7d36354cd8 100644 --- a/openbas-front/src/admin/components/teams/players/PlayerPopover.tsx +++ b/openbas-front/src/admin/components/teams/players/PlayerPopover.tsx @@ -12,7 +12,7 @@ import { countryOption, Option, organizationOption, tagOptions } from '../../../ import { useHelper } from '../../../../store'; import type { OrganizationsHelper, TagsHelper, UsersHelper } from '../../../../actions/helper'; import type { PlayerInputForm, UserStore } from './Player'; -import { TeamContext } from '../../components/Context'; +import { TeamContext } from '../../common/Context'; interface PlayerPopoverProps { user: UserStore; diff --git a/openbas-front/src/utils/api-types.d.ts b/openbas-front/src/utils/api-types.d.ts index c59d39c41d..8d9b2d1e8d 100644 --- a/openbas-front/src/utils/api-types.d.ts +++ b/openbas-front/src/utils/api-types.d.ts @@ -9,28 +9,6 @@ * --------------------------------------------------------------- */ -export interface AiGenericTextInput { - ai_content: string; - ai_format?: string; - ai_tone?: string; -} - -export interface AiMessageInput { - ai_context?: string; - ai_format: string; - ai_input: string; - /** @format int32 */ - ai_paragraphs?: number; - ai_recipient?: string; - ai_sender?: string; - ai_tone?: string; -} - -export interface AiResult { - chunk_content?: string; - chunk_id?: string; -} - export interface Article { article_author?: string; article_channel?: Channel; @@ -480,9 +458,9 @@ export interface CreateUserInput { export interface DirectInjectInput { inject_content?: object; + inject_contract?: string; inject_description?: string; inject_documents?: InjectDocumentInput[]; - inject_injector_contract?: string; inject_title?: string; inject_type?: string; inject_users?: string[]; @@ -591,7 +569,7 @@ export interface Endpoint { endpoint_hostname?: string; endpoint_ips: string[]; endpoint_mac_addresses?: string[]; - endpoint_platform: "Linux" | "Windows" | "MacOS" | "Service" | "Generic" | "Internal"; + endpoint_platform: "Linux" | "Windows" | "Darwin"; updateAttributes?: object; } @@ -608,7 +586,7 @@ export interface EndpointInput { */ endpoint_ips: string[]; endpoint_mac_addresses?: string[]; - endpoint_platform: "Linux" | "Windows" | "MacOS" | "Service" | "Generic" | "Internal"; + endpoint_platform: "Linux" | "Windows" | "Darwin"; } export interface Evaluation { @@ -855,6 +833,7 @@ export interface Inject { /** @format int64 */ inject_communications_number?: number; inject_content?: object; + inject_contract?: string; inject_country?: string; /** @format date-time */ inject_created_at?: string; @@ -953,13 +932,13 @@ export interface InjectInput { inject_assets?: string[]; inject_city?: string; inject_content?: object; + inject_contract?: string; inject_country?: string; /** @format int64 */ inject_depends_duration?: number; inject_depends_from_another?: string; inject_description?: string; inject_documents?: InjectDocumentInput[]; - inject_injector_contract?: string; inject_tags?: string[]; inject_teams?: string[]; inject_title?: string; @@ -1033,16 +1012,12 @@ export interface InjectUpdateTriggerInput { } export interface Injector { - injector_category?: string; /** @format date-time */ injector_created_at?: string; injector_custom_contracts?: boolean; injector_external?: boolean; injector_id: string; injector_name: string; - injector_simulation_agent?: boolean; - injector_simulation_agent_doc?: string; - injector_simulation_agent_platforms?: string[]; injector_type: string; /** @format date-time */ injector_updated_at?: string; @@ -1070,7 +1045,6 @@ export interface InjectorContract { injector_contract_injector?: Injector; injector_contract_labels?: Record; injector_contract_manual?: boolean; - injector_contract_platforms?: string[]; /** @format date-time */ injector_contract_updated_at?: string; updateAttributes?: object; @@ -1084,7 +1058,6 @@ export interface InjectorContractAddInput { contract_id: string; contract_labels?: Record; contract_manual?: boolean; - contract_platforms?: string[]; injector_id: string; is_atomic_testing?: boolean; } @@ -1096,7 +1069,6 @@ export interface InjectorContractInput { contract_id: string; contract_labels?: Record; contract_manual?: boolean; - contract_platforms?: string[]; is_atomic_testing?: boolean; } @@ -1106,7 +1078,6 @@ export interface InjectorContractUpdateInput { contract_content: string; contract_labels?: Record; contract_manual?: boolean; - contract_platforms?: string[]; is_atomic_testing?: boolean; } @@ -1115,14 +1086,10 @@ export interface InjectorContractUpdateMappingInput { } export interface InjectorCreateInput { - injector_category?: string; injector_contracts?: InjectorContractInput[]; injector_custom_contracts?: boolean; injector_id: string; injector_name: string; - injector_simulation_agent?: boolean; - injector_simulation_agent_doc?: string; - injector_simulation_agent_platforms?: string[]; injector_type: string; } @@ -1132,13 +1099,9 @@ export interface InjectorRegistration { } export interface InjectorUpdateInput { - injector_category?: string; injector_contracts?: InjectorContractInput[]; injector_custom_contracts?: boolean; injector_name: string; - injector_simulation_agent?: boolean; - injector_simulation_agent_doc?: string; - injector_simulation_agent_platforms?: string[]; } export type JsonNode = object; @@ -1379,43 +1342,6 @@ export interface LoginUserInput { password: string; } -export interface Mitigation { - mitigation_attack_patterns?: AttackPattern[]; - /** @format date-time */ - mitigation_created_at?: string; - mitigation_description?: string; - mitigation_external_id: string; - mitigation_id: string; - mitigation_log_sources?: string[]; - mitigation_name: string; - mitigation_stix_id: string; - mitigation_threat_hunting_techniques?: string; - /** @format date-time */ - mitigation_updated_at?: string; - updateAttributes?: object; -} - -export interface MitigationCreateInput { - mitigation_attack_patterns?: string[]; - mitigation_description?: string; - mitigation_external_id: string; - mitigation_log_sources?: string[]; - mitigation_name: string; - mitigation_stix_id?: string; - mitigation_threat_hunting_techniques?: string; -} - -export interface MitigationUpdateInput { - mitigation_attack_patterns?: string[]; - mitigation_description?: string; - mitigation_external_id: string; - mitigation_name: string; -} - -export interface MitigationUpsertInput { - mitigations?: MitigationCreateInput[]; -} - export interface OAuthProvider { provider_login?: string; provider_name?: string; @@ -1630,25 +1556,6 @@ export interface PageKillChainPhase { totalPages?: number; } -export interface PageMitigation { - content?: Mitigation[]; - empty?: boolean; - first?: boolean; - last?: boolean; - /** @format int32 */ - number?: number; - /** @format int32 */ - numberOfElements?: number; - pageable?: PageableObject; - /** @format int32 */ - size?: number; - sort?: SortObject[]; - /** @format int64 */ - totalElements?: number; - /** @format int32 */ - totalPages?: number; -} - export interface PagePayload { content?: Payload[]; empty?: boolean; @@ -1668,25 +1575,6 @@ export interface PagePayload { totalPages?: number; } -export interface PageScenario { - content?: Scenario[]; - empty?: boolean; - first?: boolean; - last?: boolean; - /** @format int32 */ - number?: number; - /** @format int32 */ - numberOfElements?: number; - pageable?: PageableObject; - /** @format int32 */ - size?: number; - sort?: SortObject[]; - /** @format int64 */ - totalElements?: number; - /** @format int32 */ - totalPages?: number; -} - export interface PageTag { content?: Tag[]; empty?: boolean; @@ -1780,16 +1668,10 @@ export interface PlatformSettings { platform_saml2_providers?: OAuthProvider[]; auth_local_enable?: boolean; auth_openid_enable?: boolean; - caldera_url?: string; java_version?: string; map_tile_server_dark?: string; map_tile_server_light?: string; - platform_ai_enabled?: boolean; - platform_ai_has_token?: boolean; - platform_ai_model?: string; - platform_ai_type?: string; platform_dark_theme?: ThemeInput; - platform_enterprise_edition?: string; platform_lang?: string; platform_light_theme?: ThemeInput; platform_name?: string; @@ -1907,7 +1789,6 @@ export interface Scenario { /** @format int64 */ scenario_all_users_number?: number; scenario_articles?: Article[]; - scenario_category?: string; /** @format int64 */ scenario_communications_number?: number; /** @format date-time */ @@ -1921,7 +1802,6 @@ export interface Scenario { scenario_lessons_categories?: LessonsCategory[]; scenario_mail_from: string; scenario_mails_reply_to?: string[]; - scenario_main_focus?: string; scenario_message_footer?: string; scenario_message_header?: string; scenario_name: string; @@ -1932,7 +1812,6 @@ export interface Scenario { scenario_recurrence_end?: string; /** @format date-time */ scenario_recurrence_start?: string; - scenario_severity?: string; scenario_subtitle?: string; scenario_tags?: Tag[]; scenario_teams?: Team[]; @@ -1953,11 +1832,8 @@ export interface ScenarioInformationInput { } export interface ScenarioInput { - scenario_category?: string; scenario_description?: string; - scenario_main_focus?: string; scenario_name: string; - scenario_severity?: string; scenario_subtitle?: string; scenario_tags?: string[]; } @@ -2019,10 +1895,6 @@ export interface SearchTerm { searchTerm?: string; } -export interface SettingsEnterpriseEditionUpdateInput { - platform_enterprise_edition: string; -} - export interface SettingsUpdateInput { platform_lang: string; platform_name: string; diff --git a/openbas-model/src/main/java/io/openbas/database/model/Inject.java b/openbas-model/src/main/java/io/openbas/database/model/Inject.java index 4b123fbf9c..91f370f6f7 100644 --- a/openbas-model/src/main/java/io/openbas/database/model/Inject.java +++ b/openbas-model/src/main/java/io/openbas/database/model/Inject.java @@ -64,6 +64,11 @@ public class Inject implements Base, Injection { @JsonProperty("inject_description") private String description; + @Getter + @Transient + @JsonProperty("inject_injector_contract") + private InjectorContract injectorContract; + @Getter @Column(name = "inject_country") @JsonProperty("inject_country") @@ -134,13 +139,6 @@ public class Inject implements Base, Injection { @Min(value = 0L, message = "The value must be positive") private Long dependsDuration; - @Getter - @ManyToOne(fetch = FetchType.EAGER) - @JoinColumn(name = "inject_injector_contract") - @JsonSerialize(using = MonoIdDeserializer.class) - @JsonProperty("inject_injector_contract") - private InjectorContract injectorContract; - @Getter @ManyToOne(fetch = FetchType.LAZY) @JsonSerialize(using = MonoIdDeserializer.class) @@ -192,8 +190,8 @@ public class Inject implements Base, Injection { @Getter @ManyToMany(fetch = FetchType.LAZY) @JoinTable(name = "injects_payloads", - joinColumns = @JoinColumn(name = "inject_id"), - inverseJoinColumns = @JoinColumn(name = "payload_id")) + joinColumns = @JoinColumn(name = "inject_id"), + inverseJoinColumns = @JoinColumn(name = "payload_id")) @JsonSerialize(using = MultiIdDeserializer.class) @JsonProperty("inject_payloads") private List payloads = new ArrayList<>();