add: audit log and reports table

TODO: audit log/reports UIs
This commit is contained in:
trisua 2025-04-01 23:16:09 -04:00
parent 9a9b72bdbb
commit b2df2739a7
16 changed files with 387 additions and 6 deletions

View file

@ -70,7 +70,7 @@ impl Community {
}
}
#[derive(Serialize, Deserialize)]
#[derive(Debug, Serialize, Deserialize)]
pub struct CommunityContext {
pub display_name: String,
pub description: String,
@ -86,7 +86,7 @@ impl Default for CommunityContext {
}
/// Who can read a [`Community`].
#[derive(Serialize, Deserialize, PartialEq, Eq)]
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq)]
pub enum CommunityReadAccess {
/// Everybody can view the community.
Everybody,
@ -101,7 +101,7 @@ impl Default for CommunityReadAccess {
}
/// Who can write to a [`Community`].
#[derive(Serialize, Deserialize, PartialEq, Eq)]
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq)]
pub enum CommunityWriteAccess {
/// Everybody.
Everybody,
@ -120,7 +120,7 @@ impl Default for CommunityWriteAccess {
}
/// Who can join a [`Community`].
#[derive(Serialize, Deserialize, PartialEq, Eq)]
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq)]
pub enum CommunityJoinAccess {
/// Joins are closed. Nobody can join the community.
Nobody,
@ -136,7 +136,7 @@ impl Default for CommunityJoinAccess {
}
}
#[derive(Clone, Serialize, Deserialize)]
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CommunityMembership {
pub id: usize,
pub created: usize,
@ -161,7 +161,7 @@ impl CommunityMembership {
}
}
#[derive(Serialize, Deserialize)]
#[derive(Debug, Serialize, Deserialize)]
pub struct PostContext {
pub comments_enabled: bool,
}

View file

@ -1,6 +1,7 @@
pub mod auth;
pub mod communities;
pub mod communities_permissions;
pub mod moderation;
pub mod permissions;
pub mod reactions;

View file

@ -0,0 +1,54 @@
use serde::{Deserialize, Serialize};
use tetratto_shared::{snow::AlmostSnowflake, unix_epoch_timestamp};
use super::reactions::AssetType;
#[derive(Serialize, Deserialize)]
pub struct AuditLogEntry {
pub id: usize,
pub created: usize,
pub moderator: usize,
pub content: String,
}
impl AuditLogEntry {
/// Create a new [`AuditLogEntry`].
pub fn new(moderator: usize, content: String) -> Self {
Self {
id: AlmostSnowflake::new(1234567890)
.to_string()
.parse::<usize>()
.unwrap(),
created: unix_epoch_timestamp() as usize,
moderator,
content,
}
}
}
#[derive(Serialize, Deserialize)]
pub struct Report {
pub id: usize,
pub created: usize,
pub owner: usize,
pub content: String,
pub asset: usize,
pub asset_type: AssetType,
}
impl Report {
/// Create a new [`Report`].
pub fn new(owner: usize, content: String, asset: usize, asset_type: AssetType) -> Self {
Self {
id: AlmostSnowflake::new(1234567890)
.to_string()
.parse::<usize>()
.unwrap(),
created: unix_epoch_timestamp() as usize,
owner,
content,
asset,
asset_type,
}
}
}

View file

@ -23,6 +23,8 @@ bitflags! {
const MANAGE_REACTIONS = 1 << 12;
const MANAGE_FOLLOWS = 1 << 13;
const MANAGE_VERIFIED = 1 << 14;
const MANAGE_AUDITLOG = 1 << 15;
const MANAGE_REPORTS = 1 << 16;
const _ = !0;
}