entities.rs 119 lignes · 4093 octets
//! SeaORM entity definitions backing the three guard tables.
//!
//! Each entity exposes a `Model` mapped 1-to-1 with the columns of
//! its table (see migration `m20260514_000001_fediverse_guard_schema`).
//! Conversion helpers translate between the persistence-layer `Model`
//! and the public types [`crate::events::GuardEvent`],
//! [`crate::store::BanEntry`], [`crate::store::AclEntry`].

/// SeaORM mapping of `fediverse_guard_events`.
pub mod event {
    use chrono::{DateTime, Utc};
    use sea_orm::entity::prelude::*;
    use uuid::Uuid;

    /// Row in `fediverse_guard_events`.
    #[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
    #[sea_orm(table_name = "fediverse_guard_events")]
    pub struct Model {
        /// Surrogate UUID primary key.
        #[sea_orm(primary_key, auto_increment = false)]
        pub id: Uuid,
        /// `GuardEventKind` serialised as `snake_case`.
        pub event_type: String,
        /// Lower-cased domain attributed.
        pub domain: String,
        /// Optional ActivityPub actor URI.
        pub actor_uri: Option<String>,
        /// Optional FK to `remote_identities.id`.
        pub remote_identity_id: Option<Uuid>,
        /// Severity hint.
        pub severity: String,
        /// HTTP status returned by the offending request.
        pub http_status: Option<i32>,
        /// Detector-specific JSON metadata.
        pub details: Option<Json>,
        /// Server-side timestamp.
        pub created_at: DateTime<Utc>,
    }

    /// SeaORM relations (none — events are leaf-only).
    #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
    pub enum Relation {}

    impl ActiveModelBehavior for ActiveModel {}
}

/// SeaORM mapping of `fediverse_guard_bans`.
pub mod ban {
    use chrono::{DateTime, Utc};
    use sea_orm::entity::prelude::*;
    use uuid::Uuid;

    /// Row in `fediverse_guard_bans`.
    #[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
    #[sea_orm(table_name = "fediverse_guard_bans")]
    pub struct Model {
        /// Surrogate UUID primary key.
        #[sea_orm(primary_key, auto_increment = false)]
        pub id: Uuid,
        /// Lower-cased domain the ban applies to.
        pub domain: String,
        /// Optional actor URI to narrow the ban.
        pub actor_uri: Option<String>,
        /// Free-form reason.
        pub reason: String,
        /// `"suspend"` / `"silence"` / `"rate_limit"`.
        pub severity: String,
        /// `"auto:<detector>"` or `"manual:<admin_uuid>"`.
        pub triggered_by: String,
        /// When the ban was applied.
        pub banned_at: DateTime<Utc>,
        /// `None` means permanent.
        pub expires_at: Option<DateTime<Utc>>,
        /// Set when the ban was lifted.
        pub lifted_at: Option<DateTime<Utc>>,
        /// Admin user that lifted the ban.
        pub lifted_by: Option<Uuid>,
    }

    /// SeaORM relations.
    #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
    pub enum Relation {}

    impl ActiveModelBehavior for ActiveModel {}
}

/// SeaORM mapping of `fediverse_guard_acl`.
pub mod acl {
    use chrono::{DateTime, Utc};
    use sea_orm::entity::prelude::*;
    use uuid::Uuid;

    /// Row in `fediverse_guard_acl`.
    #[derive(Clone, Debug, PartialEq, Eq, DeriveEntityModel)]
    #[sea_orm(table_name = "fediverse_guard_acl")]
    pub struct Model {
        /// Surrogate UUID primary key.
        #[sea_orm(primary_key, auto_increment = false)]
        pub id: Uuid,
        /// `"allow"` or `"deny"`.
        pub kind: String,
        /// Lower-cased domain.
        pub domain: String,
        /// Optional free-form reason.
        pub reason: Option<String>,
        /// FK to `users.id` of the admin that created the entry.
        pub created_by: Uuid,
        /// Created timestamp.
        pub created_at: DateTime<Utc>,
        /// Last update timestamp.
        pub updated_at: DateTime<Utc>,
    }

    /// SeaORM relations.
    #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
    pub enum Relation {}

    impl ActiveModelBehavior for ActiveModel {}
}