@@ -25,6 +25,7 @@ pub struct DBDelphiReport {
25
25
pub delphi_version : i32 ,
26
26
pub artifact_url : String ,
27
27
pub created : DateTime < Utc > ,
28
+ pub severity : DelphiReportSeverity ,
28
29
}
29
30
30
31
impl DBDelphiReport {
@@ -34,21 +35,35 @@ impl DBDelphiReport {
34
35
) -> Result < DelphiReportId , DatabaseError > {
35
36
Ok ( DelphiReportId ( sqlx:: query_scalar!(
36
37
"
37
- INSERT INTO delphi_reports (file_id, delphi_version, artifact_url)
38
- VALUES ($1, $2, $3)
38
+ INSERT INTO delphi_reports (file_id, delphi_version, artifact_url, severity )
39
+ VALUES ($1, $2, $3, $4 )
39
40
ON CONFLICT (file_id, delphi_version) DO UPDATE SET
40
- delphi_version = $2, artifact_url = $3, created = CURRENT_TIMESTAMP
41
+ delphi_version = $2, artifact_url = $3, created = CURRENT_TIMESTAMP, severity = $4
41
42
RETURNING id
42
43
" ,
43
44
self . file_id as Option <DBFileId >,
44
45
self . delphi_version,
45
46
self . artifact_url,
47
+ self . severity as DelphiReportSeverity ,
46
48
)
47
49
. fetch_one ( & mut * * transaction)
48
50
. await ?) )
49
51
}
50
52
}
51
53
54
+ /// A severity level for a Delphi report.
55
+ #[ derive(
56
+ Deserialize , Serialize , Debug , Clone , Copy , PartialEq , Eq , Hash , sqlx:: Type ,
57
+ ) ]
58
+ #[ serde( rename_all = "UPPERCASE" ) ]
59
+ #[ sqlx( type_name = "delphi_report_severity" , rename_all = "snake_case" ) ]
60
+ pub enum DelphiReportSeverity {
61
+ Low ,
62
+ Medium ,
63
+ High ,
64
+ Severe ,
65
+ }
66
+
52
67
/// An issue found in a Delphi report. Every issue belongs to a report,
53
68
/// and a report can have zero, one, or more issues attached to it.
54
69
#[ derive( Deserialize , Serialize ) ]
@@ -64,8 +79,7 @@ pub struct DBDelphiReportIssue {
64
79
Deserialize , Serialize , Debug , Clone , Copy , PartialEq , Eq , Hash , sqlx:: Type ,
65
80
) ]
66
81
#[ serde( rename_all = "snake_case" ) ]
67
- #[ sqlx( type_name = "delphi_report_issue_status" ) ]
68
- #[ sqlx( rename_all = "snake_case" ) ]
82
+ #[ sqlx( type_name = "delphi_report_issue_status" , rename_all = "snake_case" ) ]
69
83
pub enum DelphiReportIssueStatus {
70
84
/// The issue is pending review by the moderation team.
71
85
Pending ,
@@ -91,6 +105,8 @@ pub enum DelphiReportListOrder {
91
105
CreatedAsc ,
92
106
CreatedDesc ,
93
107
PendingStatusFirst ,
108
+ SeverityAsc ,
109
+ SeverityDesc ,
94
110
}
95
111
96
112
impl Display for DelphiReportListOrder {
@@ -146,9 +162,9 @@ impl DBDelphiReportIssue {
146
162
SELECT
147
163
delphi_report_issues.id AS "id", report_id,
148
164
issue_type AS "issue_type: DelphiReportIssueType",
149
- delphi_report_issues.status as "status: DelphiReportIssueStatus",
165
+ delphi_report_issues.status AS "status: DelphiReportIssueStatus",
150
166
151
- file_id, delphi_version, artifact_url, created,
167
+ file_id, delphi_version, artifact_url, created, severity AS "severity: DelphiReportSeverity",
152
168
json_array(SELECT to_jsonb(delphi_report_issue_java_classes)
153
169
FROM delphi_report_issue_java_classes
154
170
WHERE issue_id = delphi_report_issues.id
@@ -165,7 +181,9 @@ impl DBDelphiReportIssue {
165
181
ORDER BY
166
182
CASE WHEN $3 = 'created_asc' THEN delphi_reports.created ELSE TO_TIMESTAMP(0) END ASC,
167
183
CASE WHEN $3 = 'created_desc' THEN delphi_reports.created ELSE TO_TIMESTAMP(0) END DESC,
168
- CASE WHEN $3 = 'pending_status_first' THEN delphi_report_issues.status ELSE 'pending'::delphi_report_issue_status END ASC
184
+ CASE WHEN $3 = 'pending_status_first' THEN delphi_report_issues.status ELSE 'pending'::delphi_report_issue_status END ASC,
185
+ CASE WHEN $3 = 'severity_asc' THEN delphi_reports.severity ELSE 'low'::delphi_report_severity END ASC,
186
+ CASE WHEN $3 = 'severity_desc' THEN delphi_reports.severity ELSE 'low'::delphi_report_severity END DESC
169
187
OFFSET $5
170
188
LIMIT $4
171
189
"# ,
@@ -188,6 +206,7 @@ impl DBDelphiReportIssue {
188
206
delphi_version : row. delphi_version ,
189
207
artifact_url : row. artifact_url ,
190
208
created : row. created ,
209
+ severity : row. severity ,
191
210
} ,
192
211
java_classes : row
193
212
. classes
@@ -207,8 +226,7 @@ impl DBDelphiReportIssue {
207
226
Deserialize , Serialize , Debug , Clone , Copy , PartialEq , Eq , Hash , sqlx:: Type ,
208
227
) ]
209
228
#[ serde( rename_all = "snake_case" ) ]
210
- #[ sqlx( type_name = "delphi_report_issue_type" ) ]
211
- #[ sqlx( rename_all = "snake_case" ) ]
229
+ #[ sqlx( type_name = "delphi_report_issue_type" , rename_all = "snake_case" ) ]
212
230
pub enum DelphiReportIssueType {
213
231
ReflectionIndirection ,
214
232
XorObfuscation ,
0 commit comments