@@ -25,6 +25,7 @@ pub struct DBDelphiReport {
2525 pub delphi_version : i32 ,
2626 pub artifact_url : String ,
2727 pub created : DateTime < Utc > ,
28+ pub severity : DelphiReportSeverity ,
2829}
2930
3031impl DBDelphiReport {
@@ -34,21 +35,35 @@ impl DBDelphiReport {
3435 ) -> Result < DelphiReportId , DatabaseError > {
3536 Ok ( DelphiReportId ( sqlx:: query_scalar!(
3637 "
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 )
3940 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
4142 RETURNING id
4243 " ,
4344 self . file_id as Option <DBFileId >,
4445 self . delphi_version,
4546 self . artifact_url,
47+ self . severity as DelphiReportSeverity ,
4648 )
4749 . fetch_one ( & mut * * transaction)
4850 . await ?) )
4951 }
5052}
5153
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+
5267/// An issue found in a Delphi report. Every issue belongs to a report,
5368/// and a report can have zero, one, or more issues attached to it.
5469#[ derive( Deserialize , Serialize ) ]
@@ -64,8 +79,7 @@ pub struct DBDelphiReportIssue {
6479 Deserialize , Serialize , Debug , Clone , Copy , PartialEq , Eq , Hash , sqlx:: Type ,
6580) ]
6681#[ 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" ) ]
6983pub enum DelphiReportIssueStatus {
7084 /// The issue is pending review by the moderation team.
7185 Pending ,
@@ -91,6 +105,8 @@ pub enum DelphiReportListOrder {
91105 CreatedAsc ,
92106 CreatedDesc ,
93107 PendingStatusFirst ,
108+ SeverityAsc ,
109+ SeverityDesc ,
94110}
95111
96112impl Display for DelphiReportListOrder {
@@ -146,9 +162,9 @@ impl DBDelphiReportIssue {
146162 SELECT
147163 delphi_report_issues.id AS "id", report_id,
148164 issue_type AS "issue_type: DelphiReportIssueType",
149- delphi_report_issues.status as "status: DelphiReportIssueStatus",
165+ delphi_report_issues.status AS "status: DelphiReportIssueStatus",
150166
151- file_id, delphi_version, artifact_url, created,
167+ file_id, delphi_version, artifact_url, created, severity AS "severity: DelphiReportSeverity",
152168 json_array(SELECT to_jsonb(delphi_report_issue_java_classes)
153169 FROM delphi_report_issue_java_classes
154170 WHERE issue_id = delphi_report_issues.id
@@ -165,7 +181,9 @@ impl DBDelphiReportIssue {
165181 ORDER BY
166182 CASE WHEN $3 = 'created_asc' THEN delphi_reports.created ELSE TO_TIMESTAMP(0) END ASC,
167183 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
169187 OFFSET $5
170188 LIMIT $4
171189 "# ,
@@ -188,6 +206,7 @@ impl DBDelphiReportIssue {
188206 delphi_version : row. delphi_version ,
189207 artifact_url : row. artifact_url ,
190208 created : row. created ,
209+ severity : row. severity ,
191210 } ,
192211 java_classes : row
193212 . classes
@@ -207,8 +226,7 @@ impl DBDelphiReportIssue {
207226 Deserialize , Serialize , Debug , Clone , Copy , PartialEq , Eq , Hash , sqlx:: Type ,
208227) ]
209228#[ 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" ) ]
212230pub enum DelphiReportIssueType {
213231 ReflectionIndirection ,
214232 XorObfuscation ,
0 commit comments