forked from jmug/stoatchat
feat(safety): implement report content API
This commit is contained in:
@@ -28,6 +28,11 @@ pub mod users {
|
||||
pub mod user_settings;
|
||||
}
|
||||
|
||||
pub mod safety {
|
||||
pub mod report;
|
||||
pub mod snapshot;
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct DummyDb;
|
||||
|
||||
|
||||
12
crates/quark/src/impl/dummy/safety/report.rs
Normal file
12
crates/quark/src/impl/dummy/safety/report.rs
Normal file
@@ -0,0 +1,12 @@
|
||||
use crate::models::Report;
|
||||
use crate::{AbstractReport, Result};
|
||||
|
||||
use super::super::DummyDb;
|
||||
|
||||
#[async_trait]
|
||||
impl AbstractReport for DummyDb {
|
||||
async fn insert_report(&self, report: &Report) -> Result<()> {
|
||||
info!("Insert {:?}", report);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
12
crates/quark/src/impl/dummy/safety/snapshot.rs
Normal file
12
crates/quark/src/impl/dummy/safety/snapshot.rs
Normal file
@@ -0,0 +1,12 @@
|
||||
use crate::models::Snapshot;
|
||||
use crate::{AbstractSnapshot, Result};
|
||||
|
||||
use super::super::DummyDb;
|
||||
|
||||
#[async_trait]
|
||||
impl AbstractSnapshot for DummyDb {
|
||||
async fn insert_snapshot(&self, snapshot: &Snapshot) -> Result<()> {
|
||||
info!("Insert {:?}", snapshot);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -39,6 +39,11 @@ pub mod users {
|
||||
pub mod user_settings;
|
||||
}
|
||||
|
||||
pub mod safety {
|
||||
pub mod report;
|
||||
pub mod snapshot;
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct MongoDb(pub mongodb::Client);
|
||||
|
||||
|
||||
13
crates/quark/src/impl/mongo/safety/report.rs
Normal file
13
crates/quark/src/impl/mongo/safety/report.rs
Normal file
@@ -0,0 +1,13 @@
|
||||
use crate::models::Report;
|
||||
use crate::{AbstractReport, Result};
|
||||
|
||||
use super::super::MongoDb;
|
||||
|
||||
static COL: &str = "safety_reports";
|
||||
|
||||
#[async_trait]
|
||||
impl AbstractReport for MongoDb {
|
||||
async fn insert_report(&self, report: &Report) -> Result<()> {
|
||||
self.insert_one(COL, report).await.map(|_| ())
|
||||
}
|
||||
}
|
||||
13
crates/quark/src/impl/mongo/safety/snapshot.rs
Normal file
13
crates/quark/src/impl/mongo/safety/snapshot.rs
Normal file
@@ -0,0 +1,13 @@
|
||||
use crate::models::Snapshot;
|
||||
use crate::{AbstractSnapshot, Result};
|
||||
|
||||
use super::super::MongoDb;
|
||||
|
||||
static COL: &str = "safety_snapshots";
|
||||
|
||||
#[async_trait]
|
||||
impl AbstractSnapshot for MongoDb {
|
||||
async fn insert_snapshot(&self, snapshot: &Snapshot) -> Result<()> {
|
||||
self.insert_one(COL, snapshot).await.map(|_| ())
|
||||
}
|
||||
}
|
||||
@@ -27,9 +27,15 @@ mod users {
|
||||
pub mod user_settings;
|
||||
}
|
||||
|
||||
mod safety {
|
||||
pub mod report;
|
||||
pub mod snapshot;
|
||||
}
|
||||
|
||||
pub use admin::*;
|
||||
pub use channels::*;
|
||||
pub use media::*;
|
||||
pub use safety::*;
|
||||
pub use servers::*;
|
||||
pub use users::*;
|
||||
|
||||
@@ -41,9 +47,11 @@ pub use channel_unread::ChannelUnread;
|
||||
pub use emoji::Emoji;
|
||||
pub use message::Message;
|
||||
pub use migrations::MigrationInfo;
|
||||
pub use report::Report;
|
||||
pub use server::Server;
|
||||
pub use server_ban::ServerBan;
|
||||
pub use server_member::Member;
|
||||
pub use simple::SimpleModel;
|
||||
pub use snapshot::Snapshot;
|
||||
pub use user::User;
|
||||
pub use user_settings::UserSettings;
|
||||
|
||||
85
crates/quark/src/models/safety/report.rs
Normal file
85
crates/quark/src/models/safety/report.rs
Normal file
@@ -0,0 +1,85 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
/// Reason for reporting content (message or server)
|
||||
#[derive(Serialize, Deserialize, JsonSchema, Debug)]
|
||||
pub enum ContentReportReason {
|
||||
/// No reason has been specified
|
||||
NoneSpecified,
|
||||
|
||||
/// Blatantly illegal content
|
||||
Illegal,
|
||||
|
||||
/// Content that promotes harm to others / self
|
||||
PromotesHarm,
|
||||
|
||||
/// Spam or platform abuse
|
||||
SpamAbuse,
|
||||
|
||||
/// Distribution of malware
|
||||
Malware,
|
||||
|
||||
/// Harassment or abuse targeted at another user
|
||||
Harassment,
|
||||
}
|
||||
|
||||
/// Reason for reporting a user
|
||||
#[derive(Serialize, Deserialize, JsonSchema, Debug)]
|
||||
pub enum UserReportReason {
|
||||
/// No reason has been specified
|
||||
NoneSpecified,
|
||||
|
||||
/// User is sending spam or otherwise abusing the platform
|
||||
SpamAbuse,
|
||||
|
||||
/// User's profile contains inappropriate content for a general audience
|
||||
InappropriateProfile,
|
||||
|
||||
/// User is impersonating another user
|
||||
Impersonation,
|
||||
|
||||
/// User is evading a ban
|
||||
BanEvasion,
|
||||
|
||||
/// User is not of minimum age to use the platform
|
||||
Underage,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, JsonSchema, Debug)]
|
||||
#[serde(tag = "type")]
|
||||
pub enum ReportedContent {
|
||||
/// Report a message
|
||||
Message {
|
||||
/// ID of the message
|
||||
id: String,
|
||||
/// Reason for reporting message
|
||||
report_reason: ContentReportReason,
|
||||
},
|
||||
/// Report a server
|
||||
Server {
|
||||
/// ID of the server
|
||||
id: String,
|
||||
/// Reason for reporting server
|
||||
report_reason: ContentReportReason,
|
||||
},
|
||||
/// Report a user
|
||||
User {
|
||||
/// ID of the user
|
||||
id: String,
|
||||
/// Reason for reporting a user
|
||||
report_reason: UserReportReason,
|
||||
},
|
||||
}
|
||||
|
||||
/// User-generated platform moderation report.
|
||||
#[derive(Serialize, Deserialize, JsonSchema, Debug)]
|
||||
pub struct Report {
|
||||
/// Unique Id
|
||||
#[serde(rename = "_id")]
|
||||
pub id: String,
|
||||
/// Id of the user creating this report
|
||||
pub author_id: String,
|
||||
/// Reported content
|
||||
pub content: ReportedContent,
|
||||
/// Additional report context
|
||||
pub additional_context: String,
|
||||
}
|
||||
25
crates/quark/src/models/safety/snapshot.rs
Normal file
25
crates/quark/src/models/safety/snapshot.rs
Normal file
@@ -0,0 +1,25 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::models::{Message, Server, User};
|
||||
|
||||
/// Enum to map into different models
|
||||
/// that can be saved in a snapshot
|
||||
#[derive(Serialize, Deserialize, JsonSchema, Debug)]
|
||||
#[serde(tag = "_type")]
|
||||
pub enum SnapshotContent {
|
||||
Message(Message),
|
||||
Server(Server),
|
||||
User(User),
|
||||
}
|
||||
|
||||
/// Snapshot of some content
|
||||
#[derive(Serialize, Deserialize, JsonSchema, Debug)]
|
||||
pub struct Snapshot {
|
||||
/// Unique Id
|
||||
#[serde(rename = "_id")]
|
||||
pub id: String,
|
||||
/// Report parent Id
|
||||
pub report_id: String,
|
||||
/// Snapshot of content
|
||||
pub content: SnapshotContent,
|
||||
}
|
||||
@@ -26,6 +26,11 @@ mod users {
|
||||
pub mod user_settings;
|
||||
}
|
||||
|
||||
mod safety {
|
||||
pub mod report;
|
||||
pub mod snapshot;
|
||||
}
|
||||
|
||||
pub use admin::migrations::AbstractMigrations;
|
||||
|
||||
pub use media::attachment::AbstractAttachment;
|
||||
@@ -44,6 +49,9 @@ pub use users::bot::AbstractBot;
|
||||
pub use users::user::AbstractUser;
|
||||
pub use users::user_settings::AbstractUserSettings;
|
||||
|
||||
pub use safety::report::AbstractReport;
|
||||
pub use safety::snapshot::AbstractSnapshot;
|
||||
|
||||
pub trait AbstractDatabase:
|
||||
Sync
|
||||
+ Send
|
||||
@@ -60,5 +68,7 @@ pub trait AbstractDatabase:
|
||||
+ AbstractBot
|
||||
+ AbstractUser
|
||||
+ AbstractUserSettings
|
||||
+ AbstractReport
|
||||
+ AbstractSnapshot
|
||||
{
|
||||
}
|
||||
|
||||
8
crates/quark/src/traits/safety/report.rs
Normal file
8
crates/quark/src/traits/safety/report.rs
Normal file
@@ -0,0 +1,8 @@
|
||||
use crate::models::Report;
|
||||
use crate::Result;
|
||||
|
||||
#[async_trait]
|
||||
pub trait AbstractReport: Sync + Send {
|
||||
/// Insert a new report into the database
|
||||
async fn insert_report(&self, report: &Report) -> Result<()>;
|
||||
}
|
||||
8
crates/quark/src/traits/safety/snapshot.rs
Normal file
8
crates/quark/src/traits/safety/snapshot.rs
Normal file
@@ -0,0 +1,8 @@
|
||||
use crate::models::Snapshot;
|
||||
use crate::Result;
|
||||
|
||||
#[async_trait]
|
||||
pub trait AbstractSnapshot: Sync + Send {
|
||||
/// Insert a new snapshot into the database
|
||||
async fn insert_snapshot(&self, snapshot: &Snapshot) -> Result<()>;
|
||||
}
|
||||
Reference in New Issue
Block a user