diff --git a/openbas-api/src/main/java/io/openbas/migration/V3_43__Payloads_default_values.java b/openbas-api/src/main/java/io/openbas/migration/V3_43__Payloads_default_values.java new file mode 100644 index 0000000000..844087db24 --- /dev/null +++ b/openbas-api/src/main/java/io/openbas/migration/V3_43__Payloads_default_values.java @@ -0,0 +1,24 @@ +package io.openbas.migration; + +import org.flywaydb.core.api.migration.BaseJavaMigration; +import org.flywaydb.core.api.migration.Context; +import org.springframework.stereotype.Component; + +import java.sql.Connection; +import java.sql.Statement; + +@Component +public class V3_43__Payloads_default_values extends BaseJavaMigration { + + @Override + public void migrate(Context context) throws Exception { + Connection connection = context.getConnection(); + Statement select = connection.createStatement(); + + select.executeUpdate("UPDATE payloads SET payload_source = 'MANUAL' WHERE payload_source IS NULL;"); + select.executeUpdate("UPDATE payloads SET payload_status = 'UNVERIFIED' WHERE payload_status IS NULL;"); + + select.execute("ALTER TABLE payloads ALTER COLUMN payload_source SET DEFAULT 'MANUAL';"); + select.execute("ALTER TABLE payloads ALTER COLUMN payload_status SET DEFAULT 'UNVERIFIED';"); + } +} diff --git a/openbas-api/src/main/java/io/openbas/rest/payload/form/PayloadCreateInput.java b/openbas-api/src/main/java/io/openbas/rest/payload/form/PayloadCreateInput.java index 7083cad651..3da4acc944 100644 --- a/openbas-api/src/main/java/io/openbas/rest/payload/form/PayloadCreateInput.java +++ b/openbas-api/src/main/java/io/openbas/rest/payload/form/PayloadCreateInput.java @@ -2,10 +2,13 @@ import com.fasterxml.jackson.annotation.JsonProperty; import io.openbas.database.model.Endpoint.PLATFORM_TYPE; +import io.openbas.database.model.Payload.PAYLOAD_SOURCE; +import io.openbas.database.model.Payload.PAYLOAD_STATUS; import io.openbas.database.model.PayloadArgument; import io.openbas.database.model.PayloadPrerequisite; import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotEmpty; +import jakarta.validation.constraints.NotNull; import lombok.Getter; import lombok.Setter; @@ -26,13 +29,13 @@ public class PayloadCreateInput { @JsonProperty("payload_name") private String name; - @NotBlank(message = MANDATORY_MESSAGE) + @NotNull(message = MANDATORY_MESSAGE) @JsonProperty("payload_source") - private String source; + private PAYLOAD_SOURCE source; - @NotBlank(message = MANDATORY_MESSAGE) + @NotNull(message = MANDATORY_MESSAGE) @JsonProperty("payload_status") - private String status; + private PAYLOAD_STATUS status; @NotEmpty(message = MANDATORY_MESSAGE) @JsonProperty("payload_platforms") diff --git a/openbas-framework/src/main/java/io/openbas/integrations/PayloadService.java b/openbas-framework/src/main/java/io/openbas/integrations/PayloadService.java index 9d9a15ca5e..073395325d 100644 --- a/openbas-framework/src/main/java/io/openbas/integrations/PayloadService.java +++ b/openbas-framework/src/main/java/io/openbas/integrations/PayloadService.java @@ -183,16 +183,13 @@ public Payload duplicate(@NotBlank final String payloadId) { return duplicate; } - private void duplicateCommonProperties(@org.jetbrains.annotations.NotNull final T origin, - @org.jetbrains.annotations.NotNull T duplicate) { - BeanUtils.copyProperties(origin, duplicate); - duplicate.setId(null); - duplicate.setName(StringUtils.duplicateString(origin.getName())); - duplicate.setAttackPatterns(new ArrayList<>(origin.getAttackPatterns())); - duplicate.setTags(new HashSet<>(origin.getTags())); - duplicate.setExternalId(null); - duplicate.setSource(MANUAL); - duplicate.setStatus(VERIFIED); - duplicate.setCollector(null); - } + private void duplicateCommonProperties(@org.jetbrains.annotations.NotNull final T origin, @org.jetbrains.annotations.NotNull T duplicate) { + BeanUtils.copyProperties(origin, duplicate); + duplicate.setId(null); + duplicate.setName(StringUtils.duplicateString(origin.getName())); + duplicate.setAttackPatterns(new ArrayList<>(origin.getAttackPatterns())); + duplicate.setTags(new HashSet<>(origin.getTags())); + duplicate.setExternalId(null); + duplicate.setCollector(null); + } } diff --git a/openbas-framework/src/main/java/io/openbas/utils/OperationUtilsJpa.java b/openbas-framework/src/main/java/io/openbas/utils/OperationUtilsJpa.java index 3fff320e7f..7bd3995a31 100644 --- a/openbas-framework/src/main/java/io/openbas/utils/OperationUtilsJpa.java +++ b/openbas-framework/src/main/java/io/openbas/utils/OperationUtilsJpa.java @@ -190,7 +190,7 @@ public static Predicate empty(Expression paths, CriteriaBuilder cb, Clas } else { finalPaths = paths; } - if (type.equals(Instant.class)) { + if (type.equals(Instant.class) || type.isEnum()) { return cb.isNull(finalPaths); } return cb.or( diff --git a/openbas-front/src/admin/components/scenarios/scenario/ScenarioDistributionByExercise.tsx b/openbas-front/src/admin/components/scenarios/scenario/ScenarioDistributionByExercise.tsx index 3a9e1e9369..355ad870c2 100644 --- a/openbas-front/src/admin/components/scenarios/scenario/ScenarioDistributionByExercise.tsx +++ b/openbas-front/src/admin/components/scenarios/scenario/ScenarioDistributionByExercise.tsx @@ -27,9 +27,9 @@ const ScenarioDistributionByExercise: FunctionComponent = ({ exercise_name: 'fake', exercise_start_date: now.toISOString(), exercise_global_score: [ - { type: 'PREVENTION', distribution: [{ value: 0.69, label: t('Unknown') }], avgResult: 'PARTIAL' }, - { type: 'DETECTION', distribution: [{ value: 0.84, label: t('Unknown') }], avgResult: 'PARTIAL' }, - { type: 'HUMAN_RESPONSE', distribution: [{ value: 0.46, label: t('Unknown') }], avgResult: 'PARTIAL' }, + { type: 'PREVENTION', distribution: [{ id: 'PARTIAL_ID', value: 0.69, label: t('Unknown') }], avgResult: 'PARTIAL' }, + { type: 'DETECTION', distribution: [{ id: 'PARTIAL_ID', value: 0.84, label: t('Unknown') }], avgResult: 'PARTIAL' }, + { type: 'HUMAN_RESPONSE', distribution: [{ id: 'PARTIAL_ID', value: 0.46, label: t('Unknown') }], avgResult: 'PARTIAL' }, ], exercise_targets: [], exercise_tags: undefined, diff --git a/openbas-front/src/components/common/queryable/filter/FilterUtils.tsx b/openbas-front/src/components/common/queryable/filter/FilterUtils.tsx index d8464adf3e..2ca27a87b6 100644 --- a/openbas-front/src/components/common/queryable/filter/FilterUtils.tsx +++ b/openbas-front/src/components/common/queryable/filter/FilterUtils.tsx @@ -91,18 +91,18 @@ export const availableOperators = (propertySchema: PropertySchemaDTO) => { if (propertySchema.schema_property_type.includes('instant')) { return ['gt', 'gte', 'lt', 'lte', 'empty', 'not_empty']; } - // Array - if (propertySchema.schema_property_type_array || propertySchema.schema_property_values) { - return ['contains', 'not_contains', 'empty', 'not_empty']; - } // Enum & not array if (propertySchema.schema_property_values && !propertySchema.schema_property_type_array) { - return ['eq']; + return ['eq', 'not_eq', 'empty', 'not_empty']; } // Dynamic value & not array if (propertySchema.schema_property_has_dynamic_value && !propertySchema.schema_property_type_array) { return ['contains', 'not_contains', 'empty', 'not_empty']; } + // Array + if (propertySchema.schema_property_type_array) { + return ['contains', 'not_contains', 'empty', 'not_empty']; + } return [ 'eq', 'not_eq', diff --git a/openbas-front/src/utils/api-types.d.ts b/openbas-front/src/utils/api-types.d.ts index 532bd29cf2..c60e7b05aa 100644 --- a/openbas-front/src/utils/api-types.d.ts +++ b/openbas-front/src/utils/api-types.d.ts @@ -2344,8 +2344,8 @@ export interface Payload { payload_name: string; payload_platforms?: ("Linux" | "Windows" | "MacOS" | "Container" | "Service" | "Generic" | "Internal" | "Unknown")[]; payload_prerequisites?: PayloadPrerequisite[]; - payload_source?: "COMMUNITY" | "FILIGRAN" | "MANUAL"; - payload_status?: "UNVERIFIED" | "VERIFIED"; + payload_source: "COMMUNITY" | "FILIGRAN" | "MANUAL"; + payload_status: "UNVERIFIED" | "VERIFIED"; /** @uniqueItems true */ payload_tags?: Tag[]; payload_type?: string; @@ -2374,8 +2374,8 @@ export interface PayloadCreateInput { payload_name: string; payload_platforms: ("Linux" | "Windows" | "MacOS" | "Container" | "Service" | "Generic" | "Internal" | "Unknown")[]; payload_prerequisites?: PayloadPrerequisite[]; - payload_source: string; - payload_status: string; + payload_source: "COMMUNITY" | "FILIGRAN" | "MANUAL"; + payload_status: "UNVERIFIED" | "VERIFIED"; payload_tags?: string[]; payload_type: string; } @@ -2691,13 +2691,13 @@ export interface ReportInjectComment { export interface ReportInjectCommentInput { inject_id: string; - report_inject_comment: string; + report_inject_comment?: string; } export interface ReportInput { + report_global_observation?: string; report_informations?: ReportInformationInput[]; report_name: string; - report_global_observation?: string; } export interface ResetUserInput { @@ -2706,6 +2706,7 @@ export interface ResetUserInput { } export interface ResultDistribution { + id: string; label: string; /** @format int32 */ value: number; diff --git a/openbas-model/src/main/java/io/openbas/database/model/Payload.java b/openbas-model/src/main/java/io/openbas/database/model/Payload.java index a5e21d3e20..f4747bc1f2 100644 --- a/openbas-model/src/main/java/io/openbas/database/model/Payload.java +++ b/openbas-model/src/main/java/io/openbas/database/model/Payload.java @@ -117,18 +117,20 @@ public enum PAYLOAD_STATUS { @JsonProperty("payload_external_id") private String externalId; - @Queryable(filterable = true, sortable = true) @Setter + @Queryable(filterable = true, sortable = true) @Column(name = "payload_source") @Enumerated(EnumType.STRING) @JsonProperty("payload_source") + @NotNull private PAYLOAD_SOURCE source; - @Queryable(filterable = true) @Setter + @Queryable(filterable = true) @Column(name = "payload_status") @Enumerated(EnumType.STRING) @JsonProperty("payload_status") + @NotNull private PAYLOAD_STATUS status; // -- COLLECTOR --