Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[backend/frontend] Merge tabs in scenario form (#1822) #1828

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.fasterxml.jackson.annotation.JsonProperty;
import io.openbas.database.model.Scenario.SEVERITY;
import jakarta.annotation.Nullable;
import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.NotBlank;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -45,4 +46,18 @@ public class ScenarioInput {

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

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

@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 @@ -158,4 +158,11 @@
@NotNull
@JsonProperty("expectation_manual_default_score_value")
private int expectationDefaultScoreValue;

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

Check warning on line 164 in openbas-api/src/main/java/io/openbas/rest/settings/response/PlatformSettings.java

View check run for this annotation

Codecov / codecov/patch

openbas-api/src/main/java/io/openbas/rest/settings/response/PlatformSettings.java#L164

Added line #L164 was not covered by tests

@JsonProperty("default_reply_to")
private String defaultReplyTo;

Check warning on line 167 in openbas-api/src/main/java/io/openbas/rest/settings/response/PlatformSettings.java

View check run for this annotation

Codecov / codecov/patch

openbas-api/src/main/java/io/openbas/rest/settings/response/PlatformSettings.java#L167

Added line #L167 was not covered by tests
}
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@
ofNullable(dbSettings.get(DEFAULT_LANG.key()))
.map(Setting::getValue)
.orElse(DEFAULT_LANG.defaultValue()));
platformSettings.setDefaultMailer(openBASConfig.getDefaultMailer());
platformSettings.setDefaultReplyTo(openBASConfig.getDefaultReplyTo());

Check warning on line 184 in openbas-api/src/main/java/io/openbas/service/PlatformSettingsService.java

View check run for this annotation

Codecov / codecov/patch

openbas-api/src/main/java/io/openbas/service/PlatformSettingsService.java#L183-L184

Added lines #L183 - L184 were not covered by tests

// Build authenticated user settings
OpenBASPrincipal user = currentUser();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ void createScenarioTest() throws Exception {
// -- PREPARE --
String name = "My scenario";
scenarioInput.setName(name);
String from = "[email protected]";
scenarioInput.setFrom(from);

// -- EXECUTE --
String response =
Expand Down Expand Up @@ -132,6 +134,7 @@ void updateScenarioTest() throws Exception {
ScenarioInput scenarioInput = new ScenarioInput();
String subtitle = "A subtitle";
scenarioInput.setName(JsonPath.read(response, "$.scenario_name"));
scenarioInput.setFrom(JsonPath.read(response, "$.scenario_mail_from"));
scenarioInput.setSubtitle(subtitle);

// -- EXECUTE --
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -578,8 +578,7 @@ const Injects: FunctionComponent<Props> = ({
edge="start"
checked={
(selectAll && !(inject.inject_id
in (deSelectedElements || {})))
|| inject.inject_id in (selectedElements || {})
in (deSelectedElements || {}))) || inject.inject_id in (selectedElements || {})
}
disableRipple
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { FunctionComponent, useState } from 'react';
import { useNavigate } from 'react-router-dom';

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 ScenarioForm from './ScenarioForm';

Expand All @@ -23,6 +25,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 +41,26 @@ const ScenarioCreation: FunctionComponent<Props> = ({
);
};

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

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: t('SIMULATION HEADER'),
scenario_message_footer: t('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 +71,7 @@ const ScenarioCreation: FunctionComponent<Props> = ({
>
<ScenarioForm
onSubmit={onSubmit}
initialValues={initialValues}
handleClose={() => setOpen(false)}
/>
</Drawer>
Expand Down
Loading