feat(safety): fetch reports and fetch snapshot API
This commit is contained in:
@@ -9,4 +9,8 @@ impl AbstractReport for DummyDb {
|
||||
info!("Insert {:?}", report);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn fetch_reports(&self) -> Result<Vec<Report>> {
|
||||
Ok(vec![])
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,4 +9,8 @@ impl AbstractSnapshot for DummyDb {
|
||||
info!("Insert {:?}", snapshot);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn fetch_snapshot(&self, _report_id: &str) -> Result<Snapshot> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,4 +10,8 @@ impl AbstractReport for MongoDb {
|
||||
async fn insert_report(&self, report: &Report) -> Result<()> {
|
||||
self.insert_one(COL, report).await.map(|_| ())
|
||||
}
|
||||
|
||||
async fn fetch_reports(&self) -> Result<Vec<Report>> {
|
||||
self.find(COL, doc! {}).await
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,4 +10,14 @@ impl AbstractSnapshot for MongoDb {
|
||||
async fn insert_snapshot(&self, snapshot: &Snapshot) -> Result<()> {
|
||||
self.insert_one(COL, snapshot).await.map(|_| ())
|
||||
}
|
||||
|
||||
async fn fetch_snapshot(&self, report_id: &str) -> Result<Snapshot> {
|
||||
self.find_one(
|
||||
COL,
|
||||
doc! {
|
||||
"report_id": report_id
|
||||
},
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,6 +44,7 @@ pub enum UserReportReason {
|
||||
Underage,
|
||||
}
|
||||
|
||||
/// The content being reported
|
||||
#[derive(Serialize, Deserialize, JsonSchema, Debug, Clone)]
|
||||
#[serde(tag = "type")]
|
||||
pub enum ReportedContent {
|
||||
@@ -70,6 +71,20 @@ pub enum ReportedContent {
|
||||
},
|
||||
}
|
||||
|
||||
/// Status of the report
|
||||
#[derive(Serialize, Deserialize, JsonSchema, Debug, Clone)]
|
||||
#[serde(tag = "status")]
|
||||
pub enum ReportStatus {
|
||||
/// Report is waiting for triage / action
|
||||
Created,
|
||||
|
||||
/// Report was rejected
|
||||
Rejected { rejection_reason: String },
|
||||
|
||||
/// Report was actioned and resolved
|
||||
Resolved,
|
||||
}
|
||||
|
||||
/// User-generated platform moderation report.
|
||||
#[derive(Serialize, Deserialize, JsonSchema, Debug, Clone)]
|
||||
pub struct Report {
|
||||
@@ -82,4 +97,7 @@ pub struct Report {
|
||||
pub content: ReportedContent,
|
||||
/// Additional report context
|
||||
pub additional_context: String,
|
||||
/// Status of the report
|
||||
#[serde(flatten)]
|
||||
pub status: ReportStatus,
|
||||
}
|
||||
|
||||
@@ -9,11 +9,11 @@ use crate::models::{Message, Server, User};
|
||||
pub enum SnapshotContent {
|
||||
Message {
|
||||
/// Context before the message
|
||||
#[serde(rename = "_prior_context")]
|
||||
#[serde(rename = "_prior_context", default)]
|
||||
prior_context: Vec<Message>,
|
||||
|
||||
/// Context after the message
|
||||
#[serde(rename = "_leading_context")]
|
||||
#[serde(rename = "_leading_context", default)]
|
||||
leading_context: Vec<Message>,
|
||||
|
||||
/// Message
|
||||
|
||||
@@ -5,4 +5,7 @@ use crate::Result;
|
||||
pub trait AbstractReport: Sync + Send {
|
||||
/// Insert a new report into the database
|
||||
async fn insert_report(&self, report: &Report) -> Result<()>;
|
||||
|
||||
/// Fetch reports
|
||||
async fn fetch_reports(&self) -> Result<Vec<Report>>;
|
||||
}
|
||||
|
||||
@@ -5,4 +5,7 @@ use crate::Result;
|
||||
pub trait AbstractSnapshot: Sync + Send {
|
||||
/// Insert a new snapshot into the database
|
||||
async fn insert_snapshot(&self, snapshot: &Snapshot) -> Result<()>;
|
||||
|
||||
/// Fetch a snapshot by a report's id
|
||||
async fn fetch_snapshot(&self, report_id: &str) -> Result<Snapshot>;
|
||||
}
|
||||
|
||||
@@ -75,6 +75,7 @@ pub enum Error {
|
||||
permission: UserPermission,
|
||||
},
|
||||
NotElevated,
|
||||
NotPrivileged,
|
||||
CannotGiveMissingPermissions,
|
||||
NotOwner,
|
||||
|
||||
@@ -174,6 +175,7 @@ impl<'r> Responder<'r, 'static> for Error {
|
||||
Error::MissingPermission { .. } => Status::Forbidden,
|
||||
Error::MissingUserPermission { .. } => Status::Forbidden,
|
||||
Error::NotElevated => Status::Forbidden,
|
||||
Error::NotPrivileged => Status::Forbidden,
|
||||
Error::CannotGiveMissingPermissions => Status::Forbidden,
|
||||
Error::NotOwner => Status::Forbidden,
|
||||
|
||||
|
||||
Reference in New Issue
Block a user