Skip to content

Commit

Permalink
[backend/frontend] Fix filter order (#1478)
Browse files Browse the repository at this point in the history
  • Loading branch information
savacano28 authored Oct 11, 2024
1 parent 2a69c28 commit 9dfb5ce
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -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';");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,16 +183,13 @@ public Payload duplicate(@NotBlank final String payloadId) {
return duplicate;
}

private <T extends Payload> 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 <T extends Payload> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public static Predicate empty(Expression<String> 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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ const ScenarioDistributionByExercise: FunctionComponent<Props> = ({
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
13 changes: 7 additions & 6 deletions openbas-front/src/utils/api-types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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 {
Expand All @@ -2706,6 +2706,7 @@ export interface ResetUserInput {
}

export interface ResultDistribution {
id: string;
label: string;
/** @format int32 */
value: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 --
Expand Down

0 comments on commit 9dfb5ce

Please sign in to comment.