Skip to content

Commit

Permalink
[Backend|Frontend]Merge tabs in scenario form
Browse files Browse the repository at this point in the history
  • Loading branch information
johanah29 committed Nov 7, 2024
1 parent 8eabb12 commit a7d431b
Show file tree
Hide file tree
Showing 11 changed files with 300 additions and 128 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import io.openbas.database.model.Scenario.SEVERITY;
import jakarta.annotation.Nullable;
import jakarta.persistence.Column;
import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.NotBlank;

import java.util.ArrayList;
import java.util.List;

import lombok.Data;

@Data
Expand Down Expand Up @@ -45,4 +49,19 @@ public class ScenarioInput {

@JsonProperty("scenario_tags")
private List<String> tagIds = new ArrayList<>();

@JsonProperty("scenario_mail_from")
@Email
@NotBlank
private String from;

@Column(name = "scenario_reply_to", nullable = false)
@JsonProperty("scenario_mails_reply_to")
private List<String> replyTos = new ArrayList<>();

@JsonProperty("scenario_message_header")
private String header;

@JsonProperty("scenario_message_footer")
private String footer;
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
import io.openbas.rest.settings.form.PolicyInput;
import io.openbas.rest.settings.form.ThemeInput;
import jakarta.validation.constraints.NotNull;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
Expand Down Expand Up @@ -158,4 +160,11 @@ public Map<String, List<String>> getPlatformBannerByLevel() {
@NotNull
@JsonProperty("expectation_manual_default_score_value")
private int expectationDefaultScoreValue;

// EMAIL CONFIG
@JsonProperty("default_mailer")
private String defaultMailer;

@JsonProperty("default_reply_to")
private String defaultReplyTo;
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@
import io.openbas.rest.stream.ai.AiConfig;
import jakarta.annotation.Resource;
import jakarta.validation.constraints.NotBlank;

import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;

import lombok.extern.java.Log;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.security.oauth2.client.OAuth2ClientProperties;
Expand All @@ -48,9 +50,12 @@ public class PlatformSettingsService {
private AiConfig aiConfig;
private CalderaExecutorConfig calderaExecutorConfig;

@Resource private OpenBASConfig openBASConfig;
@Resource private ExpectationPropertiesConfig expectationPropertiesConfig;
@Resource private RabbitmqConfig rabbitmqConfig;
@Resource
private OpenBASConfig openBASConfig;
@Resource
private ExpectationPropertiesConfig expectationPropertiesConfig;
@Resource
private RabbitmqConfig rabbitmqConfig;

@Autowired
public void setOpenCTIConfig(OpenCTIConfig openCTIConfig) {
Expand Down Expand Up @@ -180,6 +185,8 @@ public PlatformSettings findSettings() {
ofNullable(dbSettings.get(DEFAULT_LANG.key()))
.map(Setting::getValue)
.orElse(DEFAULT_LANG.defaultValue()));
platformSettings.setDefaultMailer(openBASConfig.getDefaultMailer());
platformSettings.setDefaultReplyTo(openBASConfig.getDefaultReplyTo());

// Build authenticated user settings
OpenBASPrincipal user = currentUser();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ const Injects: FunctionComponent<Props> = ({
checked={
(selectAll && !(inject.inject_id
in (deSelectedElements || {})))
|| inject.inject_id in (selectedElements || {})
|| inject.inject_id in (selectedElements || {})
}
disableRipple
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import { FunctionComponent, useState } from 'react';
import { useNavigate } from 'react-router-dom';

import { fetchPlatformParameters } from '../../../actions/Application';
import { LoggedHelper } from '../../../actions/helper';
import type { ScenarioStore } from '../../../actions/scenarios/Scenario';
import { addScenario } from '../../../actions/scenarios/scenario-actions';
import ButtonCreate from '../../../components/common/ButtonCreate';
import Drawer from '../../../components/common/Drawer';
import { useFormatter } from '../../../components/i18n';
import type { ScenarioInput } from '../../../utils/api-types';
import { useHelper } from '../../../store';
import type { PlatformSettings, ScenarioInput } from '../../../utils/api-types';
import { useAppDispatch } from '../../../utils/hooks';
import useDataLoader from '../../../utils/hooks/useDataLoader';
import ScenarioForm from './ScenarioForm';

interface Props {
Expand All @@ -23,6 +27,7 @@ const ScenarioCreation: FunctionComponent<Props> = ({
const navigate = useNavigate();

const dispatch = useAppDispatch();

const onSubmit = (data: ScenarioInput) => {
dispatch(addScenario(data)).then(
(result: { result: string; entities: { scenarios: Record<string, ScenarioStore> } }) => {
Expand All @@ -38,6 +43,29 @@ const ScenarioCreation: FunctionComponent<Props> = ({
);
};

const { settings }: { settings: PlatformSettings } = useHelper((helper: LoggedHelper) => ({
settings: helper.getPlatformSettings(),
}));
useDataLoader(() => {
dispatch(fetchPlatformParameters());
});

const initialValues: ScenarioInput = {
scenario_name: '',
scenario_category: 'attack-scenario',
scenario_main_focus: 'incident-response',
scenario_severity: 'high',
scenario_subtitle: '',
scenario_description: '',
scenario_external_reference: '',
scenario_external_url: '',
scenario_tags: [],
scenario_message_header: 'SIMULATION HEADER',
scenario_message_footer: 'SIMULATION FOOTER',
scenario_mail_from: settings.default_mailer ? settings.default_mailer : '',
scenario_mails_reply_to: [settings.default_reply_to ? settings.default_reply_to : ''],
};

return (
<>
<ButtonCreate onClick={() => setOpen(true)} />
Expand All @@ -48,6 +76,7 @@ const ScenarioCreation: FunctionComponent<Props> = ({
>
<ScenarioForm
onSubmit={onSubmit}
initialValues={initialValues}
handleClose={() => setOpen(false)}
/>
</Drawer>
Expand Down
Loading

0 comments on commit a7d431b

Please sign in to comment.