use sea_orm::entity::prelude::*; use serde::{Deserialize, Serialize}; use time::OffsetDateTime; use uuid::Uuid; #[derive( Debug, Clone, Copy, PartialEq, Eq, EnumIter, DeriveActiveEnum, Serialize, Deserialize, utoipa::ToSchema, )] #[serde(rename_all = "lowercase")] #[sea_orm(rs_type = "String", db_type = "String(StringLen::N(8))")] pub enum AccessKeyScope { #[sea_orm(string_value = "read")] Read, #[sea_orm(string_value = "write")] Write, } impl AccessKeyScope { pub const fn allows(self, want_write: bool) -> bool { match self { Self::Write => true, Self::Read => !want_write, } } } #[sea_orm::model] #[derive(Clone, Debug, PartialEq, DeriveEntityModel)] #[sea_orm(table_name = "user_access_key")] pub struct Model { #[sea_orm(primary_key, auto_increment = false)] pub id: Uuid, #[sea_orm(unique_key = "user_name")] pub user_id: Uuid, #[sea_orm(belongs_to, from = "user_id", to = "uid")] pub user: BelongsTo, #[sea_orm(unique_key = "user_name")] pub name: String, #[sea_orm(unique)] pub token_hash: String, pub token_salt: String, pub token_last_eight: String, pub scope: AccessKeyScope, pub version: i32, pub created_at: OffsetDateTime, pub updated_at: OffsetDateTime, pub expires_at: Option, pub last_used_at: Option, } impl ActiveModelBehavior for ActiveModel {}