Compare commits
17
Commits
20230129-2
...
20230301-1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c09244039e | ||
|
|
bf9108408e | ||
|
|
304336d905 | ||
|
|
42b4906594 | ||
|
|
3038fb230f | ||
|
|
73af105feb | ||
|
|
2de37b23c1 | ||
|
|
0c75d8c8b3 | ||
|
|
be793b1570 | ||
|
|
5a3a97df34 | ||
|
|
0c072b01d7 | ||
|
|
056c0380b2 | ||
|
|
49598daf70 | ||
|
|
0445181d5b | ||
|
|
e780178cc0 | ||
|
|
c4b9884825 | ||
|
|
d74104fae4 |
@@ -59,6 +59,7 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
repository: revoltchat/api
|
repository: revoltchat/api
|
||||||
path: api
|
path: api
|
||||||
|
token: ${{ secrets.PAT }}
|
||||||
|
|
||||||
- name: Download OpenAPI specification
|
- name: Download OpenAPI specification
|
||||||
if: github.event_name != 'pull_request'
|
if: github.event_name != 'pull_request'
|
||||||
@@ -70,6 +71,6 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
cwd: "api"
|
cwd: "api"
|
||||||
add: "*.json"
|
add: "*.json"
|
||||||
|
author_name: Revolt CI
|
||||||
|
author_email: revolt-ci@users.noreply.github.com
|
||||||
message: "chore: generate OpenAPI specification"
|
message: "chore: generate OpenAPI specification"
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
|
|||||||
Generated
+3
-3
@@ -2792,7 +2792,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "revolt-bonfire"
|
name = "revolt-bonfire"
|
||||||
version = "0.5.7"
|
version = "0.5.10"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-std",
|
"async-std",
|
||||||
"async-tungstenite",
|
"async-tungstenite",
|
||||||
@@ -2808,7 +2808,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "revolt-delta"
|
name = "revolt-delta"
|
||||||
version = "0.5.7"
|
version = "0.5.10"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-channel",
|
"async-channel",
|
||||||
"async-std",
|
"async-std",
|
||||||
@@ -2848,7 +2848,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "revolt-quark"
|
name = "revolt-quark"
|
||||||
version = "0.5.7"
|
version = "0.5.10"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-lock",
|
"async-lock",
|
||||||
"async-recursion",
|
"async-recursion",
|
||||||
|
|||||||
Vendored
-2
@@ -1,2 +0,0 @@
|
|||||||
ko_fi: insertish
|
|
||||||
custom: https://insrt.uk/donate
|
|
||||||
-98
@@ -1,98 +0,0 @@
|
|||||||
name: Docker
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- "master"
|
|
||||||
tags:
|
|
||||||
- "*"
|
|
||||||
paths-ignore:
|
|
||||||
- ".github/**"
|
|
||||||
- "!.github/workflows/docker.yml"
|
|
||||||
- ".vscode/**"
|
|
||||||
- ".gitignore"
|
|
||||||
- ".gitlab-ci.yml"
|
|
||||||
- "LICENSE"
|
|
||||||
- "README"
|
|
||||||
pull_request:
|
|
||||||
branches:
|
|
||||||
- "master"
|
|
||||||
paths:
|
|
||||||
- "Dockerfile"
|
|
||||||
workflow_dispatch:
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
test:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
strategy:
|
|
||||||
matrix:
|
|
||||||
architecture: [linux/amd64]
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v2
|
|
||||||
with:
|
|
||||||
submodules: "recursive"
|
|
||||||
- name: Set up QEMU
|
|
||||||
uses: docker/setup-qemu-action@v1
|
|
||||||
- name: Set up Docker Buildx
|
|
||||||
uses: docker/setup-buildx-action@v1
|
|
||||||
- name: Cache Docker layers
|
|
||||||
uses: actions/cache@v2
|
|
||||||
with:
|
|
||||||
path: /tmp/.buildx-cache/${{ matrix.architecture }}
|
|
||||||
key: ${{ runner.os }}-buildx-${{ matrix.architecture }}-${{ github.sha }}
|
|
||||||
- name: Build
|
|
||||||
uses: docker/build-push-action@v2
|
|
||||||
with:
|
|
||||||
context: .
|
|
||||||
platforms: ${{ matrix.architecture }}
|
|
||||||
cache-from: type=local,src=/tmp/.buildx-cache/${{ matrix.architecture }}
|
|
||||||
cache-to: type=local,dest=/tmp/.buildx-cache-new/${{ matrix.architecture }},mode=max
|
|
||||||
- name: Move cache
|
|
||||||
run: |
|
|
||||||
rm -rf /tmp/.buildx-cache/${{ matrix.architecture }}
|
|
||||||
mv /tmp/.buildx-cache-new/${{ matrix.architecture }} /tmp/.buildx-cache/${{ matrix.architecture }}
|
|
||||||
|
|
||||||
publish_amd64:
|
|
||||||
needs: [test]
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
if: github.event_name != 'pull_request'
|
|
||||||
steps:
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v2
|
|
||||||
with:
|
|
||||||
submodules: "recursive"
|
|
||||||
- name: Set up QEMU
|
|
||||||
uses: docker/setup-qemu-action@v1
|
|
||||||
- name: Set up Docker Buildx
|
|
||||||
uses: docker/setup-buildx-action@v1
|
|
||||||
- name: Cache amd64 Docker layers
|
|
||||||
uses: actions/cache@v2
|
|
||||||
with:
|
|
||||||
path: /tmp/.buildx-cache/linux/amd64
|
|
||||||
key: ${{ runner.os }}-buildx-linux/amd64-${{ github.sha }}
|
|
||||||
- name: Docker meta
|
|
||||||
id: meta
|
|
||||||
uses: docker/metadata-action@v3
|
|
||||||
with:
|
|
||||||
images: ghcr.io/revoltchat/bonfire
|
|
||||||
- name: Login to Github Container Registry
|
|
||||||
uses: docker/login-action@v1
|
|
||||||
with:
|
|
||||||
registry: ghcr.io
|
|
||||||
username: ${{ github.actor }}
|
|
||||||
password: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
- name: Build and publish
|
|
||||||
uses: docker/build-push-action@v2
|
|
||||||
with:
|
|
||||||
context: .
|
|
||||||
push: true
|
|
||||||
platforms: linux/amd64
|
|
||||||
tags: ${{ steps.meta.outputs.tags }}
|
|
||||||
labels: ${{ steps.meta.outputs.labels }}
|
|
||||||
cache-from: type=local,src=/tmp/.buildx-cache/linux/amd64
|
|
||||||
cache-to: type=local,dest=/tmp/.buildx-cache-new,mode=max
|
|
||||||
- name: Move cache
|
|
||||||
run: |
|
|
||||||
rm -rf /tmp/.buildx-cache
|
|
||||||
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
|
|
||||||
-33
@@ -1,33 +0,0 @@
|
|||||||
name: Rust build and test
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches: [ master ]
|
|
||||||
pull_request:
|
|
||||||
branches: [ master ]
|
|
||||||
|
|
||||||
env:
|
|
||||||
CARGO_TERM_COLOR: always
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
check:
|
|
||||||
name: Rust project
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v2
|
|
||||||
- name: Install latest nightly
|
|
||||||
uses: actions-rs/toolchain@v1
|
|
||||||
with:
|
|
||||||
toolchain: nightly
|
|
||||||
override: true
|
|
||||||
components: rustfmt, clippy
|
|
||||||
|
|
||||||
- name: Run cargo build
|
|
||||||
uses: actions-rs/cargo@v1
|
|
||||||
with:
|
|
||||||
command: build
|
|
||||||
|
|
||||||
- name: Run cargo test
|
|
||||||
uses: actions-rs/cargo@v1
|
|
||||||
with:
|
|
||||||
command: test
|
|
||||||
@@ -1,49 +0,0 @@
|
|||||||
name: Add Issue to Board
|
|
||||||
|
|
||||||
on:
|
|
||||||
issues:
|
|
||||||
types: [opened]
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
track_issue:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Get project data
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.PAT }}
|
|
||||||
run: |
|
|
||||||
gh api graphql -f query='
|
|
||||||
query {
|
|
||||||
organization(login: "revoltchat"){
|
|
||||||
projectNext(number: 3) {
|
|
||||||
id
|
|
||||||
fields(first:20) {
|
|
||||||
nodes {
|
|
||||||
id
|
|
||||||
name
|
|
||||||
settings
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}' > project_data.json
|
|
||||||
|
|
||||||
echo 'PROJECT_ID='$(jq '.data.organization.projectNext.id' project_data.json) >> $GITHUB_ENV
|
|
||||||
echo 'STATUS_FIELD_ID='$(jq '.data.organization.projectNext.fields.nodes[] | select(.name== "Status") | .id' project_data.json) >> $GITHUB_ENV
|
|
||||||
echo 'TODO_OPTION_ID='$(jq '.data.organization.projectNext.fields.nodes[] | select(.name== "Status") |.settings | fromjson.options[] | select(.name=="Todo") |.id' project_data.json) >> $GITHUB_ENV
|
|
||||||
|
|
||||||
- name: Add issue to project
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.PAT }}
|
|
||||||
ISSUE_ID: ${{ github.event.issue.node_id }}
|
|
||||||
run: |
|
|
||||||
item_id="$( gh api graphql -f query='
|
|
||||||
mutation($project:ID!, $issue:ID!) {
|
|
||||||
addProjectNextItem(input: {projectId: $project, contentId: $issue}) {
|
|
||||||
projectNextItem {
|
|
||||||
id
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}' -f project=$PROJECT_ID -f issue=$ISSUE_ID --jq '.data.addProjectNextItem.projectNextItem.id')"
|
|
||||||
|
|
||||||
echo 'ITEM_ID='$item_id >> $GITHUB_ENV
|
|
||||||
-72
@@ -1,72 +0,0 @@
|
|||||||
name: Add PR to Board
|
|
||||||
|
|
||||||
on:
|
|
||||||
pull_request_target:
|
|
||||||
types: [opened, synchronize, ready_for_review, review_requested]
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
track_pr:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Get project data
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.PAT }}
|
|
||||||
run: |
|
|
||||||
gh api graphql -f query='
|
|
||||||
query {
|
|
||||||
organization(login: "revoltchat"){
|
|
||||||
projectNext(number: 3) {
|
|
||||||
id
|
|
||||||
fields(first:20) {
|
|
||||||
nodes {
|
|
||||||
id
|
|
||||||
name
|
|
||||||
settings
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}' > project_data.json
|
|
||||||
|
|
||||||
echo 'PROJECT_ID='$(jq '.data.organization.projectNext.id' project_data.json) >> $GITHUB_ENV
|
|
||||||
echo 'STATUS_FIELD_ID='$(jq '.data.organization.projectNext.fields.nodes[] | select(.name== "Status") | .id' project_data.json) >> $GITHUB_ENV
|
|
||||||
echo 'INCOMING_OPTION_ID='$(jq '.data.organization.projectNext.fields.nodes[] | select(.name== "Status") |.settings | fromjson.options[] | select(.name=="Incoming PRs") |.id' project_data.json) >> $GITHUB_ENV
|
|
||||||
|
|
||||||
- name: Add PR to project
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.PAT }}
|
|
||||||
PR_ID: ${{ github.event.pull_request.node_id }}
|
|
||||||
run: |
|
|
||||||
item_id="$( gh api graphql -f query='
|
|
||||||
mutation($project:ID!, $pr:ID!) {
|
|
||||||
addProjectNextItem(input: {projectId: $project, contentId: $pr}) {
|
|
||||||
projectNextItem {
|
|
||||||
id
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}' -f project=$PROJECT_ID -f pr=$PR_ID --jq '.data.addProjectNextItem.projectNextItem.id')"
|
|
||||||
|
|
||||||
echo 'ITEM_ID='$item_id >> $GITHUB_ENV
|
|
||||||
|
|
||||||
- name: Set fields
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.PAT }}
|
|
||||||
run: |
|
|
||||||
gh api graphql -f query='
|
|
||||||
mutation (
|
|
||||||
$project: ID!
|
|
||||||
$item: ID!
|
|
||||||
$status_field: ID!
|
|
||||||
$status_value: String!
|
|
||||||
) {
|
|
||||||
set_status: updateProjectNextItemField(input: {
|
|
||||||
projectId: $project
|
|
||||||
itemId: $item
|
|
||||||
fieldId: $status_field
|
|
||||||
value: $status_value
|
|
||||||
}) {
|
|
||||||
projectNextItem {
|
|
||||||
id
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}' -f project=$PROJECT_ID -f item=$ITEM_ID -f status_field=$STATUS_FIELD_ID -f status_value=${{ env.INCOMING_OPTION_ID }} --silent
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "revolt-bonfire"
|
name = "revolt-bonfire"
|
||||||
version = "0.5.7"
|
version = "0.5.10"
|
||||||
license = "AGPL-3.0-or-later"
|
license = "AGPL-3.0-or-later"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "revolt-delta"
|
name = "revolt-delta"
|
||||||
version = "0.5.7"
|
version = "0.5.10"
|
||||||
license = "AGPL-3.0-or-later"
|
license = "AGPL-3.0-or-later"
|
||||||
authors = ["Paul Makles <paulmakles@gmail.com>"]
|
authors = ["Paul Makles <paulmakles@gmail.com>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ mod invites;
|
|||||||
mod onboard;
|
mod onboard;
|
||||||
mod push;
|
mod push;
|
||||||
mod root;
|
mod root;
|
||||||
|
mod safety;
|
||||||
mod servers;
|
mod servers;
|
||||||
mod sync;
|
mod sync;
|
||||||
mod users;
|
mod users;
|
||||||
@@ -27,6 +28,7 @@ pub fn mount(mut rocket: Rocket<Build>) -> Rocket<Build> {
|
|||||||
"/servers" => servers::routes(),
|
"/servers" => servers::routes(),
|
||||||
"/invites" => invites::routes(),
|
"/invites" => invites::routes(),
|
||||||
"/custom" => customisation::routes(),
|
"/custom" => customisation::routes(),
|
||||||
|
"/safety" => safety::routes(),
|
||||||
"/auth/account" => rocket_authifier::routes::account::routes(),
|
"/auth/account" => rocket_authifier::routes::account::routes(),
|
||||||
"/auth/session" => rocket_authifier::routes::session::routes(),
|
"/auth/session" => rocket_authifier::routes::session::routes(),
|
||||||
"/auth/mfa" => rocket_authifier::routes::mfa::routes(),
|
"/auth/mfa" => rocket_authifier::routes::mfa::routes(),
|
||||||
@@ -105,6 +107,12 @@ fn custom_openapi_spec() -> OpenApi {
|
|||||||
"Emojis"
|
"Emojis"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "Platform Moderation",
|
||||||
|
"tags": [
|
||||||
|
"User Safety"
|
||||||
|
]
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "Authentication",
|
"name": "Authentication",
|
||||||
"tags": [
|
"tags": [
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
use revolt_quark::models::{Report, User};
|
||||||
|
use revolt_quark::{Db, Error, Result};
|
||||||
|
use rocket::serde::json::Json;
|
||||||
|
|
||||||
|
/// # Fetch Reports
|
||||||
|
///
|
||||||
|
/// Fetch all available reports
|
||||||
|
#[openapi(tag = "User Safety")]
|
||||||
|
#[get("/reports")]
|
||||||
|
pub async fn fetch_reports(db: &Db, user: User) -> Result<Json<Vec<Report>>> {
|
||||||
|
// Must be privileged for this route
|
||||||
|
if !user.privileged {
|
||||||
|
return Err(Error::NotPrivileged);
|
||||||
|
}
|
||||||
|
|
||||||
|
db.fetch_reports().await.map(Json)
|
||||||
|
}
|
||||||
@@ -0,0 +1,77 @@
|
|||||||
|
use std::collections::HashSet;
|
||||||
|
|
||||||
|
use revolt_quark::models::snapshot::{SnapshotContent, SnapshotWithContext};
|
||||||
|
use revolt_quark::models::{Channel, User};
|
||||||
|
use revolt_quark::{Db, Error, Result};
|
||||||
|
use rocket::serde::json::Json;
|
||||||
|
|
||||||
|
/// # Fetch Snapshot
|
||||||
|
///
|
||||||
|
/// Fetch a snapshot for a given report
|
||||||
|
#[openapi(tag = "User Safety")]
|
||||||
|
#[get("/snapshot/<report_id>")]
|
||||||
|
pub async fn fetch_snapshot(
|
||||||
|
db: &Db,
|
||||||
|
user: User,
|
||||||
|
report_id: String,
|
||||||
|
) -> Result<Json<SnapshotWithContext>> {
|
||||||
|
// Must be privileged for this route
|
||||||
|
if !user.privileged {
|
||||||
|
return Err(Error::NotPrivileged);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fetch snapshot
|
||||||
|
let snapshot = db.fetch_snapshot(&report_id).await?;
|
||||||
|
|
||||||
|
// Resolve and fetch IDs of associated content
|
||||||
|
let mut user_ids: HashSet<&str> = HashSet::new();
|
||||||
|
let mut channel_ids: HashSet<&str> = HashSet::new();
|
||||||
|
|
||||||
|
match &snapshot.content {
|
||||||
|
SnapshotContent::Message {
|
||||||
|
prior_context,
|
||||||
|
leading_context,
|
||||||
|
message,
|
||||||
|
} => {
|
||||||
|
for msg in prior_context {
|
||||||
|
user_ids.insert(&msg.author);
|
||||||
|
}
|
||||||
|
|
||||||
|
for msg in leading_context {
|
||||||
|
user_ids.insert(&msg.author);
|
||||||
|
}
|
||||||
|
|
||||||
|
user_ids.insert(&message.author);
|
||||||
|
channel_ids.insert(&message.channel);
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Collect user and channel IDs
|
||||||
|
let user_ids: Vec<String> = user_ids.into_iter().map(|s| s.to_owned()).collect();
|
||||||
|
let channel_ids: Vec<String> = channel_ids.into_iter().map(|s| s.to_owned()).collect();
|
||||||
|
|
||||||
|
// Fetch users and channels
|
||||||
|
let users = db.fetch_users(&user_ids).await?;
|
||||||
|
let channels = db.fetch_channels(&channel_ids).await?;
|
||||||
|
|
||||||
|
// Pull out first server from channels if possible
|
||||||
|
let server = if let Some(server_id) = channels.iter().find_map(|channel| match channel {
|
||||||
|
Channel::TextChannel { server, .. } => Some(server),
|
||||||
|
_ => None,
|
||||||
|
}) {
|
||||||
|
Some(db.fetch_server(server_id).await?)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
|
// Return snapshot with context
|
||||||
|
Ok(Json(SnapshotWithContext {
|
||||||
|
snapshot,
|
||||||
|
users,
|
||||||
|
channels,
|
||||||
|
server,
|
||||||
|
}))
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
use revolt_rocket_okapi::revolt_okapi::openapi3::OpenApi;
|
||||||
|
use rocket::Route;
|
||||||
|
|
||||||
|
mod fetch_reports;
|
||||||
|
mod report_content;
|
||||||
|
|
||||||
|
mod fetch_snapshot;
|
||||||
|
|
||||||
|
pub fn routes() -> (Vec<Route>, OpenApi) {
|
||||||
|
openapi_get_routes_spec![
|
||||||
|
// Reports
|
||||||
|
report_content::report_content,
|
||||||
|
fetch_reports::fetch_reports,
|
||||||
|
// Snapshots
|
||||||
|
fetch_snapshot::fetch_snapshot
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,160 @@
|
|||||||
|
use revolt_quark::events::client::EventV1;
|
||||||
|
use revolt_quark::models::report::{ReportStatus, ReportedContent};
|
||||||
|
use revolt_quark::models::snapshot::{Snapshot, SnapshotContent};
|
||||||
|
use revolt_quark::models::{Report, User};
|
||||||
|
use revolt_quark::{Db, Error, Result};
|
||||||
|
use serde::Deserialize;
|
||||||
|
use ulid::Ulid;
|
||||||
|
use validator::Validate;
|
||||||
|
|
||||||
|
use rocket::serde::json::Json;
|
||||||
|
|
||||||
|
/// # Report Data
|
||||||
|
#[derive(Validate, Deserialize, JsonSchema)]
|
||||||
|
pub struct DataReportContent {
|
||||||
|
/// Content being reported
|
||||||
|
content: ReportedContent,
|
||||||
|
/// Additional report description
|
||||||
|
#[validate(length(min = 0, max = 1000))]
|
||||||
|
#[serde(default)]
|
||||||
|
additional_context: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// # Report Content
|
||||||
|
///
|
||||||
|
/// Report a piece of content to the moderation team.
|
||||||
|
#[openapi(tag = "User Safety")]
|
||||||
|
#[post("/report", data = "<data>")]
|
||||||
|
pub async fn report_content(db: &Db, user: User, data: Json<DataReportContent>) -> Result<()> {
|
||||||
|
let data = data.into_inner();
|
||||||
|
data.validate()
|
||||||
|
.map_err(|error| Error::FailedValidation { error })?;
|
||||||
|
|
||||||
|
// Bots cannot create reports
|
||||||
|
if user.bot.is_some() {
|
||||||
|
return Err(Error::IsBot);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Find the content and create a snapshot of it
|
||||||
|
// Also retrieve any references to Files
|
||||||
|
let (content, files): (SnapshotContent, Vec<String>) = match &data.content {
|
||||||
|
ReportedContent::Message { id, .. } => {
|
||||||
|
let message = db.fetch_message(id).await?;
|
||||||
|
|
||||||
|
// Users cannot report themselves
|
||||||
|
if message.author == user.id {
|
||||||
|
return Err(Error::CannotReportYourself);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Collect message attachments
|
||||||
|
let files = message
|
||||||
|
.attachments
|
||||||
|
.as_ref()
|
||||||
|
.map(|attachments| attachments.iter().map(|x| x.id.to_string()).collect())
|
||||||
|
.unwrap_or_default();
|
||||||
|
|
||||||
|
// Collect prior context
|
||||||
|
let prior_context = db
|
||||||
|
.fetch_messages(
|
||||||
|
&message.channel,
|
||||||
|
Some(15),
|
||||||
|
Some(message.id.to_string()),
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
// Collect leading context
|
||||||
|
let leading_context = db
|
||||||
|
.fetch_messages(
|
||||||
|
&message.channel,
|
||||||
|
Some(15),
|
||||||
|
None,
|
||||||
|
Some(message.id.to_string()),
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
(
|
||||||
|
SnapshotContent::Message {
|
||||||
|
message,
|
||||||
|
prior_context,
|
||||||
|
leading_context,
|
||||||
|
},
|
||||||
|
files,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
ReportedContent::Server { id, .. } => {
|
||||||
|
let server = db.fetch_server(id).await?;
|
||||||
|
|
||||||
|
// Users cannot report their own server
|
||||||
|
if server.owner == user.id {
|
||||||
|
return Err(Error::CannotReportYourself);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Collect server's icon and banner
|
||||||
|
let files = [&server.icon, &server.banner]
|
||||||
|
.iter()
|
||||||
|
.filter_map(|x| x.as_ref().map(|x| x.id.to_string()))
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
(SnapshotContent::Server(server), files)
|
||||||
|
}
|
||||||
|
ReportedContent::User { id, .. } => {
|
||||||
|
let reported_user = db.fetch_user(id).await?;
|
||||||
|
|
||||||
|
// Users cannot report themselves
|
||||||
|
if reported_user.id == user.id {
|
||||||
|
return Err(Error::CannotReportYourself);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Collect user's avatar and profile background
|
||||||
|
let files = [
|
||||||
|
reported_user.avatar.as_ref(),
|
||||||
|
reported_user
|
||||||
|
.profile
|
||||||
|
.as_ref()
|
||||||
|
.and_then(|profile| profile.background.as_ref()),
|
||||||
|
]
|
||||||
|
.iter()
|
||||||
|
.filter_map(|x| x.as_ref().map(|x| x.id.to_string()))
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
(SnapshotContent::User(reported_user), files)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Mark all the attachments as reported
|
||||||
|
for file in files {
|
||||||
|
db.mark_attachment_as_reported(&file).await?;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Generate an id for the report
|
||||||
|
let id = Ulid::new().to_string();
|
||||||
|
|
||||||
|
// Save a snapshot of the content
|
||||||
|
let snapshot = Snapshot {
|
||||||
|
id: Ulid::new().to_string(),
|
||||||
|
report_id: id.to_string(),
|
||||||
|
content,
|
||||||
|
};
|
||||||
|
|
||||||
|
db.insert_snapshot(&snapshot).await?;
|
||||||
|
|
||||||
|
// Save the report
|
||||||
|
let report = Report {
|
||||||
|
id,
|
||||||
|
author_id: user.id,
|
||||||
|
content: data.content,
|
||||||
|
additional_context: data.additional_context,
|
||||||
|
status: ReportStatus::Created,
|
||||||
|
};
|
||||||
|
|
||||||
|
db.insert_report(&report).await?;
|
||||||
|
|
||||||
|
EventV1::ReportCreate(report).global().await;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
Vendored
-2
@@ -1,2 +0,0 @@
|
|||||||
ko_fi: insertish
|
|
||||||
custom: https://insrt.uk/donate
|
|
||||||
-33
@@ -1,33 +0,0 @@
|
|||||||
name: Rust build and test
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches: [ master ]
|
|
||||||
pull_request:
|
|
||||||
branches: [ master ]
|
|
||||||
|
|
||||||
env:
|
|
||||||
CARGO_TERM_COLOR: always
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
check:
|
|
||||||
name: Rust project
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v2
|
|
||||||
- name: Install latest nightly
|
|
||||||
uses: actions-rs/toolchain@v1
|
|
||||||
with:
|
|
||||||
toolchain: nightly
|
|
||||||
override: true
|
|
||||||
components: rustfmt, clippy
|
|
||||||
|
|
||||||
- name: Run cargo build
|
|
||||||
uses: actions-rs/cargo@v1
|
|
||||||
with:
|
|
||||||
command: build
|
|
||||||
|
|
||||||
- name: Run cargo test
|
|
||||||
uses: actions-rs/cargo@v1
|
|
||||||
with:
|
|
||||||
command: test
|
|
||||||
-49
@@ -1,49 +0,0 @@
|
|||||||
name: Add Issue to Board
|
|
||||||
|
|
||||||
on:
|
|
||||||
issues:
|
|
||||||
types: [opened]
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
track_issue:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Get project data
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.PAT }}
|
|
||||||
run: |
|
|
||||||
gh api graphql -f query='
|
|
||||||
query {
|
|
||||||
organization(login: "revoltchat"){
|
|
||||||
projectNext(number: 3) {
|
|
||||||
id
|
|
||||||
fields(first:20) {
|
|
||||||
nodes {
|
|
||||||
id
|
|
||||||
name
|
|
||||||
settings
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}' > project_data.json
|
|
||||||
|
|
||||||
echo 'PROJECT_ID='$(jq '.data.organization.projectNext.id' project_data.json) >> $GITHUB_ENV
|
|
||||||
echo 'STATUS_FIELD_ID='$(jq '.data.organization.projectNext.fields.nodes[] | select(.name== "Status") | .id' project_data.json) >> $GITHUB_ENV
|
|
||||||
echo 'TODO_OPTION_ID='$(jq '.data.organization.projectNext.fields.nodes[] | select(.name== "Status") |.settings | fromjson.options[] | select(.name=="Todo") |.id' project_data.json) >> $GITHUB_ENV
|
|
||||||
|
|
||||||
- name: Add issue to project
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.PAT }}
|
|
||||||
ISSUE_ID: ${{ github.event.issue.node_id }}
|
|
||||||
run: |
|
|
||||||
item_id="$( gh api graphql -f query='
|
|
||||||
mutation($project:ID!, $issue:ID!) {
|
|
||||||
addProjectNextItem(input: {projectId: $project, contentId: $issue}) {
|
|
||||||
projectNextItem {
|
|
||||||
id
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}' -f project=$PROJECT_ID -f issue=$ISSUE_ID --jq '.data.addProjectNextItem.projectNextItem.id')"
|
|
||||||
|
|
||||||
echo 'ITEM_ID='$item_id >> $GITHUB_ENV
|
|
||||||
-72
@@ -1,72 +0,0 @@
|
|||||||
name: Add PR to Board
|
|
||||||
|
|
||||||
on:
|
|
||||||
pull_request_target:
|
|
||||||
types: [opened, synchronize, ready_for_review, review_requested]
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
track_pr:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- name: Get project data
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.PAT }}
|
|
||||||
run: |
|
|
||||||
gh api graphql -f query='
|
|
||||||
query {
|
|
||||||
organization(login: "revoltchat"){
|
|
||||||
projectNext(number: 3) {
|
|
||||||
id
|
|
||||||
fields(first:20) {
|
|
||||||
nodes {
|
|
||||||
id
|
|
||||||
name
|
|
||||||
settings
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}' > project_data.json
|
|
||||||
|
|
||||||
echo 'PROJECT_ID='$(jq '.data.organization.projectNext.id' project_data.json) >> $GITHUB_ENV
|
|
||||||
echo 'STATUS_FIELD_ID='$(jq '.data.organization.projectNext.fields.nodes[] | select(.name== "Status") | .id' project_data.json) >> $GITHUB_ENV
|
|
||||||
echo 'INCOMING_OPTION_ID='$(jq '.data.organization.projectNext.fields.nodes[] | select(.name== "Status") |.settings | fromjson.options[] | select(.name=="Incoming PRs") |.id' project_data.json) >> $GITHUB_ENV
|
|
||||||
|
|
||||||
- name: Add PR to project
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.PAT }}
|
|
||||||
PR_ID: ${{ github.event.pull_request.node_id }}
|
|
||||||
run: |
|
|
||||||
item_id="$( gh api graphql -f query='
|
|
||||||
mutation($project:ID!, $pr:ID!) {
|
|
||||||
addProjectNextItem(input: {projectId: $project, contentId: $pr}) {
|
|
||||||
projectNextItem {
|
|
||||||
id
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}' -f project=$PROJECT_ID -f pr=$PR_ID --jq '.data.addProjectNextItem.projectNextItem.id')"
|
|
||||||
|
|
||||||
echo 'ITEM_ID='$item_id >> $GITHUB_ENV
|
|
||||||
|
|
||||||
- name: Set fields
|
|
||||||
env:
|
|
||||||
GITHUB_TOKEN: ${{ secrets.PAT }}
|
|
||||||
run: |
|
|
||||||
gh api graphql -f query='
|
|
||||||
mutation (
|
|
||||||
$project: ID!
|
|
||||||
$item: ID!
|
|
||||||
$status_field: ID!
|
|
||||||
$status_value: String!
|
|
||||||
) {
|
|
||||||
set_status: updateProjectNextItemField(input: {
|
|
||||||
projectId: $project
|
|
||||||
itemId: $item
|
|
||||||
fieldId: $status_field
|
|
||||||
value: $status_value
|
|
||||||
}) {
|
|
||||||
projectNextItem {
|
|
||||||
id
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}' -f project=$PROJECT_ID -f item=$ITEM_ID -f status_field=$STATUS_FIELD_ID -f status_value=${{ env.INCOMING_OPTION_ID }} --silent
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "revolt-quark"
|
name = "revolt-quark"
|
||||||
version = "0.5.7"
|
version = "0.5.10"
|
||||||
license = "AGPL-3.0-or-later"
|
license = "AGPL-3.0-or-later"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ use crate::models::message::{AppendMessage, PartialMessage};
|
|||||||
use crate::models::server::{FieldsRole, FieldsServer, PartialRole, PartialServer};
|
use crate::models::server::{FieldsRole, FieldsServer, PartialRole, PartialServer};
|
||||||
use crate::models::server_member::{FieldsMember, MemberCompositeKey, PartialMember};
|
use crate::models::server_member::{FieldsMember, MemberCompositeKey, PartialMember};
|
||||||
use crate::models::user::{FieldsUser, PartialUser, RelationshipStatus};
|
use crate::models::user::{FieldsUser, PartialUser, RelationshipStatus};
|
||||||
use crate::models::{Channel, Emoji, Member, Message, Server, User, UserSettings};
|
use crate::models::{Channel, Emoji, Member, Message, Report, Server, User, UserSettings};
|
||||||
use crate::Error;
|
use crate::Error;
|
||||||
|
|
||||||
/// WebSocket Client Errors
|
/// WebSocket Client Errors
|
||||||
@@ -213,6 +213,9 @@ pub enum EventV1 {
|
|||||||
/// Delete emoji
|
/// Delete emoji
|
||||||
EmojiDelete { id: String },
|
EmojiDelete { id: String },
|
||||||
|
|
||||||
|
/// New report
|
||||||
|
ReportCreate(Report),
|
||||||
|
|
||||||
/// Auth events
|
/// Auth events
|
||||||
Auth(AuthifierEvent),
|
Auth(AuthifierEvent),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,6 +28,11 @@ pub mod users {
|
|||||||
pub mod user_settings;
|
pub mod user_settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub mod safety {
|
||||||
|
pub mod report;
|
||||||
|
pub mod snapshot;
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct DummyDb;
|
pub struct DummyDb;
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
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(())
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn fetch_reports(&self) -> Result<Vec<Report>> {
|
||||||
|
Ok(vec![])
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
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(())
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn fetch_snapshot(&self, _report_id: &str) -> Result<Snapshot> {
|
||||||
|
todo!()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -57,6 +57,14 @@ pub async fn create_database(db: &MongoDb) {
|
|||||||
.await
|
.await
|
||||||
.expect("Failed to create user_settings collection.");
|
.expect("Failed to create user_settings collection.");
|
||||||
|
|
||||||
|
db.create_collection("safety_reports", None)
|
||||||
|
.await
|
||||||
|
.expect("Failed to create safety_reports collection.");
|
||||||
|
|
||||||
|
db.create_collection("safety_snapshots", None)
|
||||||
|
.await
|
||||||
|
.expect("Failed to create safety_snapshots collection.");
|
||||||
|
|
||||||
db.create_collection("bots", None)
|
db.create_collection("bots", None)
|
||||||
.await
|
.await
|
||||||
.expect("Failed to create bots collection.");
|
.expect("Failed to create bots collection.");
|
||||||
@@ -103,18 +111,18 @@ pub async fn create_database(db: &MongoDb) {
|
|||||||
},
|
},
|
||||||
"name": "content"
|
"name": "content"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"key": {
|
|
||||||
"channel": 1_i32
|
|
||||||
},
|
|
||||||
"name": "channel"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"key": {
|
"key": {
|
||||||
"channel": 1_i32,
|
"channel": 1_i32,
|
||||||
"_id": 1_i32
|
"_id": 1_i32
|
||||||
},
|
},
|
||||||
"name": "channel_id_compound"
|
"name": "channel_id_compound"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": {
|
||||||
|
"author": 1_i32
|
||||||
|
},
|
||||||
|
"name": "author"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ struct MigrationInfo {
|
|||||||
revision: i32,
|
revision: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const LATEST_REVISION: i32 = 18;
|
pub const LATEST_REVISION: i32 = 21;
|
||||||
|
|
||||||
pub async fn migrate_database(db: &MongoDb) {
|
pub async fn migrate_database(db: &MongoDb) {
|
||||||
let migrations = db.col::<Document>("migrations");
|
let migrations = db.col::<Document>("migrations");
|
||||||
@@ -661,6 +661,103 @@ pub async fn run_migrations(db: &MongoDb, revision: i32) -> i32 {
|
|||||||
.expect("Failed to update server members.");
|
.expect("Failed to update server members.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if revision <= 18 {
|
||||||
|
info!("Running migration [revision 18 / 27-02-2022]: Create author index on messages. Drop plain channel index if exists.");
|
||||||
|
|
||||||
|
if db
|
||||||
|
.db()
|
||||||
|
.run_command(
|
||||||
|
doc! {
|
||||||
|
"dropIndexes": "messages",
|
||||||
|
"index": ["channel"]
|
||||||
|
},
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.is_err()
|
||||||
|
{
|
||||||
|
info!("Failed to drop `messages.channel` index but this is ok since that means it's probably gone.");
|
||||||
|
}
|
||||||
|
|
||||||
|
db.db()
|
||||||
|
.run_command(
|
||||||
|
doc! {
|
||||||
|
"createIndexes": "messages",
|
||||||
|
"indexes": [
|
||||||
|
{
|
||||||
|
"key": {
|
||||||
|
"author": 1_i32,
|
||||||
|
},
|
||||||
|
"name": "author"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.expect("Failed to create messages author index.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if revision <= 19 {
|
||||||
|
info!("Running migration [revision 19 / 27-02-2023]: Create report / snapshot collections, migrate to new model if applicable.");
|
||||||
|
|
||||||
|
// TODO: make these fail once production is migrated
|
||||||
|
if db
|
||||||
|
.db()
|
||||||
|
.create_collection("safety_reports", None)
|
||||||
|
.await
|
||||||
|
.is_err()
|
||||||
|
{
|
||||||
|
info!("Failed to create safety_reports collection but this is expected in production.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if db
|
||||||
|
.db()
|
||||||
|
.create_collection("safety_snapshots", None)
|
||||||
|
.await
|
||||||
|
.is_err()
|
||||||
|
{
|
||||||
|
info!(
|
||||||
|
"Failed to create safety_snapshots collection but this is expected in production."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
db.col::<Document>("safety_reports")
|
||||||
|
.update_many(
|
||||||
|
doc! {},
|
||||||
|
doc! {
|
||||||
|
"$set": {
|
||||||
|
"status": "Created"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
if revision <= 20 {
|
||||||
|
info!("Running migration [revision 20 / 28-02-2023]: Add index `snapshot.report_id`.");
|
||||||
|
|
||||||
|
db.db()
|
||||||
|
.run_command(
|
||||||
|
doc! {
|
||||||
|
"createIndexes": "safety_snapshots",
|
||||||
|
"indexes": [
|
||||||
|
{
|
||||||
|
"key": {
|
||||||
|
"report_id": 1_i32
|
||||||
|
},
|
||||||
|
"name": "report_id"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
None,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.expect("Failed to create safety snapshot index.");
|
||||||
|
}
|
||||||
|
|
||||||
// Need to migrate fields on attachments, change `user_id`, `object_id`, etc to `parent`.
|
// Need to migrate fields on attachments, change `user_id`, `object_id`, etc to `parent`.
|
||||||
|
|
||||||
// Reminder to update LATEST_REVISION when adding new migrations.
|
// Reminder to update LATEST_REVISION when adding new migrations.
|
||||||
|
|||||||
@@ -39,6 +39,11 @@ pub mod users {
|
|||||||
pub mod user_settings;
|
pub mod user_settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub mod safety {
|
||||||
|
pub mod report;
|
||||||
|
pub mod snapshot;
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct MongoDb(pub mongodb::Client);
|
pub struct MongoDb(pub mongodb::Client);
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
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(|_| ())
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn fetch_reports(&self) -> Result<Vec<Report>> {
|
||||||
|
self.find(COL, doc! {}).await
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
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(|_| ())
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn fetch_snapshot(&self, report_id: &str) -> Result<Snapshot> {
|
||||||
|
self.find_one(
|
||||||
|
COL,
|
||||||
|
doc! {
|
||||||
|
"report_id": report_id
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -27,9 +27,15 @@ mod users {
|
|||||||
pub mod user_settings;
|
pub mod user_settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mod safety {
|
||||||
|
pub mod report;
|
||||||
|
pub mod snapshot;
|
||||||
|
}
|
||||||
|
|
||||||
pub use admin::*;
|
pub use admin::*;
|
||||||
pub use channels::*;
|
pub use channels::*;
|
||||||
pub use media::*;
|
pub use media::*;
|
||||||
|
pub use safety::*;
|
||||||
pub use servers::*;
|
pub use servers::*;
|
||||||
pub use users::*;
|
pub use users::*;
|
||||||
|
|
||||||
@@ -41,9 +47,11 @@ pub use channel_unread::ChannelUnread;
|
|||||||
pub use emoji::Emoji;
|
pub use emoji::Emoji;
|
||||||
pub use message::Message;
|
pub use message::Message;
|
||||||
pub use migrations::MigrationInfo;
|
pub use migrations::MigrationInfo;
|
||||||
|
pub use report::Report;
|
||||||
pub use server::Server;
|
pub use server::Server;
|
||||||
pub use server_ban::ServerBan;
|
pub use server_ban::ServerBan;
|
||||||
pub use server_member::Member;
|
pub use server_member::Member;
|
||||||
pub use simple::SimpleModel;
|
pub use simple::SimpleModel;
|
||||||
|
pub use snapshot::Snapshot;
|
||||||
pub use user::User;
|
pub use user::User;
|
||||||
pub use user_settings::UserSettings;
|
pub use user_settings::UserSettings;
|
||||||
|
|||||||
@@ -0,0 +1,103 @@
|
|||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
/// Reason for reporting content (message or server)
|
||||||
|
#[derive(Serialize, Deserialize, JsonSchema, Debug, Clone)]
|
||||||
|
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, Clone)]
|
||||||
|
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,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The content being reported
|
||||||
|
#[derive(Serialize, Deserialize, JsonSchema, Debug, Clone)]
|
||||||
|
#[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,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
/// 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 {
|
||||||
|
/// 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,
|
||||||
|
/// Status of the report
|
||||||
|
#[serde(flatten)]
|
||||||
|
pub status: ReportStatus,
|
||||||
|
}
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
use crate::models::{Channel, 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 {
|
||||||
|
/// Context before the message
|
||||||
|
#[serde(rename = "_prior_context", default)]
|
||||||
|
prior_context: Vec<Message>,
|
||||||
|
|
||||||
|
/// Context after the message
|
||||||
|
#[serde(rename = "_leading_context", default)]
|
||||||
|
leading_context: Vec<Message>,
|
||||||
|
|
||||||
|
/// Message
|
||||||
|
#[serde(flatten)]
|
||||||
|
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,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Snapshot of some content with required data to render
|
||||||
|
#[derive(Serialize, JsonSchema, Debug)]
|
||||||
|
pub struct SnapshotWithContext {
|
||||||
|
/// Snapshot itself
|
||||||
|
#[serde(flatten)]
|
||||||
|
pub snapshot: Snapshot,
|
||||||
|
/// Users involved in snapshot
|
||||||
|
#[serde(rename = "_users", skip_serializing_if = "Vec::is_empty")]
|
||||||
|
pub users: Vec<User>,
|
||||||
|
/// Channels involved in snapshot
|
||||||
|
#[serde(rename = "_channels", skip_serializing_if = "Vec::is_empty")]
|
||||||
|
pub channels: Vec<Channel>,
|
||||||
|
/// Server involved in snapshot
|
||||||
|
#[serde(rename = "_server", skip_serializing_if = "Option::is_none")]
|
||||||
|
pub server: Option<Server>,
|
||||||
|
}
|
||||||
@@ -26,6 +26,11 @@ mod users {
|
|||||||
pub mod user_settings;
|
pub mod user_settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mod safety {
|
||||||
|
pub mod report;
|
||||||
|
pub mod snapshot;
|
||||||
|
}
|
||||||
|
|
||||||
pub use admin::migrations::AbstractMigrations;
|
pub use admin::migrations::AbstractMigrations;
|
||||||
|
|
||||||
pub use media::attachment::AbstractAttachment;
|
pub use media::attachment::AbstractAttachment;
|
||||||
@@ -44,6 +49,9 @@ pub use users::bot::AbstractBot;
|
|||||||
pub use users::user::AbstractUser;
|
pub use users::user::AbstractUser;
|
||||||
pub use users::user_settings::AbstractUserSettings;
|
pub use users::user_settings::AbstractUserSettings;
|
||||||
|
|
||||||
|
pub use safety::report::AbstractReport;
|
||||||
|
pub use safety::snapshot::AbstractSnapshot;
|
||||||
|
|
||||||
pub trait AbstractDatabase:
|
pub trait AbstractDatabase:
|
||||||
Sync
|
Sync
|
||||||
+ Send
|
+ Send
|
||||||
@@ -60,5 +68,7 @@ pub trait AbstractDatabase:
|
|||||||
+ AbstractBot
|
+ AbstractBot
|
||||||
+ AbstractUser
|
+ AbstractUser
|
||||||
+ AbstractUserSettings
|
+ AbstractUserSettings
|
||||||
|
+ AbstractReport
|
||||||
|
+ AbstractSnapshot
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
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<()>;
|
||||||
|
|
||||||
|
/// Fetch reports
|
||||||
|
async fn fetch_reports(&self) -> Result<Vec<Report>>;
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
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<()>;
|
||||||
|
|
||||||
|
/// Fetch a snapshot by a report's id
|
||||||
|
async fn fetch_snapshot(&self, report_id: &str) -> Result<Snapshot>;
|
||||||
|
}
|
||||||
@@ -64,6 +64,9 @@ pub enum Error {
|
|||||||
IsBot,
|
IsBot,
|
||||||
BotIsPrivate,
|
BotIsPrivate,
|
||||||
|
|
||||||
|
// ? User safety related errors
|
||||||
|
CannotReportYourself,
|
||||||
|
|
||||||
// ? Permission errors
|
// ? Permission errors
|
||||||
MissingPermission {
|
MissingPermission {
|
||||||
permission: Permission,
|
permission: Permission,
|
||||||
@@ -72,6 +75,7 @@ pub enum Error {
|
|||||||
permission: UserPermission,
|
permission: UserPermission,
|
||||||
},
|
},
|
||||||
NotElevated,
|
NotElevated,
|
||||||
|
NotPrivileged,
|
||||||
CannotGiveMissingPermissions,
|
CannotGiveMissingPermissions,
|
||||||
NotOwner,
|
NotOwner,
|
||||||
|
|
||||||
@@ -166,9 +170,12 @@ impl<'r> Responder<'r, 'static> for Error {
|
|||||||
Error::IsBot => Status::BadRequest,
|
Error::IsBot => Status::BadRequest,
|
||||||
Error::BotIsPrivate => Status::Forbidden,
|
Error::BotIsPrivate => Status::Forbidden,
|
||||||
|
|
||||||
|
Error::CannotReportYourself => Status::BadRequest,
|
||||||
|
|
||||||
Error::MissingPermission { .. } => Status::Forbidden,
|
Error::MissingPermission { .. } => Status::Forbidden,
|
||||||
Error::MissingUserPermission { .. } => Status::Forbidden,
|
Error::MissingUserPermission { .. } => Status::Forbidden,
|
||||||
Error::NotElevated => Status::Forbidden,
|
Error::NotElevated => Status::Forbidden,
|
||||||
|
Error::NotPrivileged => Status::Forbidden,
|
||||||
Error::CannotGiveMissingPermissions => Status::Forbidden,
|
Error::CannotGiveMissingPermissions => Status::Forbidden,
|
||||||
Error::NotOwner => Status::Forbidden,
|
Error::NotOwner => Status::Forbidden,
|
||||||
|
|
||||||
|
|||||||
@@ -129,6 +129,8 @@ fn resolve_bucket<'r>(request: &'r rocket::Request<'_>) -> (&'r str, Option<&'r
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
("swagger", _) => ("swagger", None),
|
("swagger", _) => ("swagger", None),
|
||||||
|
("safety", Some("report")) => ("safety_report", Some("report")),
|
||||||
|
("safety", _) => ("safety", None),
|
||||||
_ => ("any", None),
|
_ => ("any", None),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -148,6 +150,8 @@ fn resolve_bucket_limit(bucket: &str) -> u8 {
|
|||||||
"auth_delete" => 255,
|
"auth_delete" => 255,
|
||||||
"default_avatar" => 255,
|
"default_avatar" => 255,
|
||||||
"swagger" => 100,
|
"swagger" => 100,
|
||||||
|
"safety" => 15,
|
||||||
|
"safety_report" => 3,
|
||||||
_ => 20,
|
_ => 20,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user