mirror of
https://github.com/lldap/lldap.git
synced 2026-03-31 15:07:48 +01:00
domain-model: move domain::model module to separate crate
This commit is contained in:
committed by
nitnelave
parent
3c0359eb8a
commit
d854ace89f
@@ -0,0 +1,50 @@
|
||||
[package]
|
||||
authors = ["Valentin Tolmer <valentin@tolmer.fr>"]
|
||||
name = "lldap_domain_model"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[features]
|
||||
test = []
|
||||
|
||||
[dependencies]
|
||||
base64 = "0.21"
|
||||
bincode = "1.3"
|
||||
orion = "0.17"
|
||||
serde = "1"
|
||||
serde_bytes = "0.11"
|
||||
thiserror = "1"
|
||||
|
||||
[dev-dependencies]
|
||||
pretty_assertions = "1"
|
||||
|
||||
[dependencies.chrono]
|
||||
features = ["serde"]
|
||||
version = "0.4"
|
||||
|
||||
[dependencies.derive_more]
|
||||
features = ["debug", "display", "from", "from_str"]
|
||||
default-features = false
|
||||
version = "1"
|
||||
|
||||
[dependencies.lldap_auth]
|
||||
path = "../auth"
|
||||
features = ["opaque_server", "opaque_client", "sea_orm"]
|
||||
|
||||
[dependencies.lldap_domain]
|
||||
path = "../domain"
|
||||
|
||||
[dependencies.sea-orm]
|
||||
version = "0.12"
|
||||
default-features = false
|
||||
features = [
|
||||
"macros",
|
||||
"with-chrono",
|
||||
"with-uuid",
|
||||
"sqlx-all",
|
||||
"runtime-actix-rustls",
|
||||
]
|
||||
|
||||
[dependencies.uuid]
|
||||
features = ["v1", "v3"]
|
||||
version = "1"
|
||||
@@ -0,0 +1,35 @@
|
||||
use thiserror::Error;
|
||||
|
||||
#[allow(clippy::enum_variant_names)]
|
||||
#[derive(Error, Debug)]
|
||||
pub enum DomainError {
|
||||
#[error("Authentication error {0}")]
|
||||
AuthenticationError(String),
|
||||
#[error("Database error: `{0}`")]
|
||||
DatabaseError(#[from] sea_orm::DbErr),
|
||||
#[error("Database transaction error: `{0}`")]
|
||||
DatabaseTransactionError(#[from] sea_orm::TransactionError<sea_orm::DbErr>),
|
||||
#[error("Authentication protocol error for `{0}`")]
|
||||
AuthenticationProtocolError(#[from] lldap_auth::opaque::AuthenticationError),
|
||||
#[error("Unknown crypto error: `{0}`")]
|
||||
UnknownCryptoError(#[from] orion::errors::UnknownCryptoError),
|
||||
#[error("Binary serialization error: `{0}`")]
|
||||
BinarySerializationError(#[from] bincode::Error),
|
||||
#[error("Invalid base64: `{0}`")]
|
||||
Base64DecodeError(#[from] base64::DecodeError),
|
||||
#[error("Entity not found: `{0}`")]
|
||||
EntityNotFound(String),
|
||||
#[error("Internal error: `{0}`")]
|
||||
InternalError(String),
|
||||
}
|
||||
|
||||
impl From<sea_orm::TransactionError<DomainError>> for DomainError {
|
||||
fn from(value: sea_orm::TransactionError<DomainError>) -> Self {
|
||||
match value {
|
||||
sea_orm::TransactionError::Connection(e) => e.into(),
|
||||
sea_orm::TransactionError::Transaction(e) => e,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub type Result<T> = std::result::Result<T, DomainError>;
|
||||
@@ -0,0 +1,2 @@
|
||||
pub mod error;
|
||||
pub mod model;
|
||||
@@ -0,0 +1,57 @@
|
||||
use crate::error::DomainError;
|
||||
use lldap_domain::{
|
||||
schema::AttributeList,
|
||||
types::{Attribute, AttributeName, AttributeType, AttributeValue, Cardinality, Serialized},
|
||||
};
|
||||
|
||||
// Value must be a serialized attribute value of the type denoted by typ,
|
||||
// and either a singleton or unbounded list, depending on is_list.
|
||||
pub fn deserialize_attribute_value(
|
||||
value: &Serialized,
|
||||
typ: AttributeType,
|
||||
is_list: bool,
|
||||
) -> AttributeValue {
|
||||
match (typ, is_list) {
|
||||
(AttributeType::String, false) => {
|
||||
AttributeValue::String(Cardinality::Singleton(value.unwrap()))
|
||||
}
|
||||
(AttributeType::String, true) => {
|
||||
AttributeValue::String(Cardinality::Unbounded(value.unwrap()))
|
||||
}
|
||||
(AttributeType::Integer, false) => {
|
||||
AttributeValue::Integer(Cardinality::Singleton(value.unwrap::<i64>()))
|
||||
}
|
||||
(AttributeType::Integer, true) => {
|
||||
AttributeValue::Integer(Cardinality::Unbounded(value.unwrap()))
|
||||
}
|
||||
(AttributeType::DateTime, false) => {
|
||||
AttributeValue::DateTime(Cardinality::Singleton(value.unwrap()))
|
||||
}
|
||||
(AttributeType::DateTime, true) => {
|
||||
AttributeValue::DateTime(Cardinality::Unbounded(value.unwrap()))
|
||||
}
|
||||
(AttributeType::JpegPhoto, false) => {
|
||||
AttributeValue::JpegPhoto(Cardinality::Singleton(value.unwrap()))
|
||||
}
|
||||
(AttributeType::JpegPhoto, true) => {
|
||||
AttributeValue::JpegPhoto(Cardinality::Unbounded(value.unwrap()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn deserialize_attribute(
|
||||
name: AttributeName,
|
||||
value: &Serialized,
|
||||
schema: &AttributeList,
|
||||
) -> Result<Attribute, DomainError> {
|
||||
match schema.get_attribute_type(&name) {
|
||||
Some((typ, is_list)) => Ok(Attribute {
|
||||
name,
|
||||
value: deserialize_attribute_value(value, typ, is_list),
|
||||
}),
|
||||
None => Err(DomainError::InternalError(format!(
|
||||
"Unable to find schema for attribute named '{}'",
|
||||
name.into_string()
|
||||
))),
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
use sea_orm::entity::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use lldap_domain::{
|
||||
schema::AttributeSchema,
|
||||
types::{AttributeName, AttributeType},
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
|
||||
#[sea_orm(table_name = "group_attribute_schema")]
|
||||
pub struct Model {
|
||||
#[sea_orm(
|
||||
primary_key,
|
||||
auto_increment = false,
|
||||
column_name = "group_attribute_schema_name"
|
||||
)]
|
||||
pub attribute_name: AttributeName,
|
||||
#[sea_orm(column_name = "group_attribute_schema_type")]
|
||||
pub attribute_type: AttributeType,
|
||||
#[sea_orm(column_name = "group_attribute_schema_is_list")]
|
||||
pub is_list: bool,
|
||||
#[sea_orm(column_name = "group_attribute_schema_is_group_visible")]
|
||||
pub is_group_visible: bool,
|
||||
#[sea_orm(column_name = "group_attribute_schema_is_group_editable")]
|
||||
pub is_group_editable: bool,
|
||||
#[sea_orm(column_name = "group_attribute_schema_is_hardcoded")]
|
||||
pub is_hardcoded: bool,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||
pub enum Relation {
|
||||
#[sea_orm(has_many = "super::group_attributes::Entity")]
|
||||
GroupAttributes,
|
||||
}
|
||||
|
||||
impl Related<super::GroupAttributes> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::GroupAttributes.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
||||
|
||||
impl From<Model> for AttributeSchema {
|
||||
fn from(value: Model) -> Self {
|
||||
Self {
|
||||
name: value.attribute_name,
|
||||
attribute_type: value.attribute_type,
|
||||
is_list: value.is_list,
|
||||
is_visible: value.is_group_visible,
|
||||
is_editable: value.is_group_editable,
|
||||
is_hardcoded: value.is_hardcoded,
|
||||
is_readonly: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
use sea_orm::entity::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use lldap_domain::types::{AttributeName, GroupId, Serialized};
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
|
||||
#[sea_orm(table_name = "group_attributes")]
|
||||
pub struct Model {
|
||||
#[sea_orm(
|
||||
primary_key,
|
||||
auto_increment = false,
|
||||
column_name = "group_attribute_group_id"
|
||||
)]
|
||||
pub group_id: GroupId,
|
||||
#[sea_orm(
|
||||
primary_key,
|
||||
auto_increment = false,
|
||||
column_name = "group_attribute_name"
|
||||
)]
|
||||
pub attribute_name: AttributeName,
|
||||
#[sea_orm(column_name = "group_attribute_value")]
|
||||
pub value: Serialized,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||
pub enum Relation {
|
||||
#[sea_orm(
|
||||
belongs_to = "super::groups::Entity",
|
||||
from = "Column::GroupId",
|
||||
to = "super::groups::Column::GroupId",
|
||||
on_update = "Cascade",
|
||||
on_delete = "Cascade"
|
||||
)]
|
||||
Groups,
|
||||
#[sea_orm(
|
||||
belongs_to = "super::group_attribute_schema::Entity",
|
||||
from = "Column::AttributeName",
|
||||
to = "super::group_attribute_schema::Column::AttributeName",
|
||||
on_update = "Cascade",
|
||||
on_delete = "Cascade"
|
||||
)]
|
||||
GroupAttributeSchema,
|
||||
}
|
||||
|
||||
impl Related<super::Group> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Groups.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl Related<super::GroupAttributeSchema> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::GroupAttributeSchema.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
||||
@@ -0,0 +1,23 @@
|
||||
use sea_orm::entity::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use lldap_domain::types::LdapObjectClass;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
|
||||
#[sea_orm(table_name = "group_object_classes")]
|
||||
pub struct Model {
|
||||
#[sea_orm(primary_key, auto_increment = false)]
|
||||
pub lower_object_class: String,
|
||||
pub object_class: LdapObjectClass,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||
pub enum Relation {}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
||||
|
||||
impl From<Model> for LdapObjectClass {
|
||||
fn from(value: Model) -> Self {
|
||||
value.object_class
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.10.3
|
||||
|
||||
use sea_orm::entity::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use lldap_domain::types::{GroupId, GroupName, Uuid};
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
|
||||
#[sea_orm(table_name = "groups")]
|
||||
pub struct Model {
|
||||
#[sea_orm(primary_key, auto_increment = false)]
|
||||
pub group_id: GroupId,
|
||||
pub display_name: GroupName,
|
||||
pub lowercase_display_name: String,
|
||||
pub creation_date: chrono::NaiveDateTime,
|
||||
pub uuid: Uuid,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||
pub enum Relation {
|
||||
#[sea_orm(has_many = "super::memberships::Entity")]
|
||||
Memberships,
|
||||
}
|
||||
|
||||
impl Related<super::memberships::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Memberships.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
||||
|
||||
impl From<Model> for lldap_domain::types::Group {
|
||||
fn from(group: Model) -> Self {
|
||||
Self {
|
||||
id: group.group_id,
|
||||
display_name: group.display_name,
|
||||
creation_date: group.creation_date,
|
||||
uuid: group.uuid,
|
||||
users: vec![],
|
||||
attributes: Vec::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Model> for lldap_domain::types::GroupDetails {
|
||||
fn from(group: Model) -> Self {
|
||||
Self {
|
||||
group_id: group.group_id,
|
||||
display_name: group.display_name,
|
||||
creation_date: group.creation_date,
|
||||
uuid: group.uuid,
|
||||
attributes: Vec::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.10.3
|
||||
|
||||
use sea_orm::entity::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use lldap_domain::types::UserId;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
|
||||
#[sea_orm(table_name = "jwt_refresh_storage")]
|
||||
pub struct Model {
|
||||
#[sea_orm(primary_key, auto_increment = false)]
|
||||
pub refresh_token_hash: i64,
|
||||
pub user_id: UserId,
|
||||
pub expiry_date: chrono::NaiveDateTime,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||
pub enum Relation {
|
||||
#[sea_orm(
|
||||
belongs_to = "super::users::Entity",
|
||||
from = "Column::UserId",
|
||||
to = "super::users::Column::UserId",
|
||||
on_update = "Cascade",
|
||||
on_delete = "Cascade"
|
||||
)]
|
||||
Users,
|
||||
}
|
||||
|
||||
impl Related<super::users::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Users.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
||||
@@ -0,0 +1,36 @@
|
||||
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.10.3
|
||||
|
||||
use sea_orm::entity::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use lldap_domain::types::UserId;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
|
||||
#[sea_orm(table_name = "jwt_storage")]
|
||||
pub struct Model {
|
||||
#[sea_orm(primary_key, auto_increment = false)]
|
||||
pub jwt_hash: i64,
|
||||
pub user_id: UserId,
|
||||
pub expiry_date: chrono::NaiveDateTime,
|
||||
pub blacklisted: bool,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||
pub enum Relation {
|
||||
#[sea_orm(
|
||||
belongs_to = "super::users::Entity",
|
||||
from = "Column::UserId",
|
||||
to = "super::users::Column::UserId",
|
||||
on_update = "Cascade",
|
||||
on_delete = "Cascade"
|
||||
)]
|
||||
Users,
|
||||
}
|
||||
|
||||
impl Related<super::users::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Users.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
||||
@@ -0,0 +1,73 @@
|
||||
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.10.3
|
||||
|
||||
use sea_orm::entity::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use lldap_domain::types::{GroupId, UserId};
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
|
||||
#[sea_orm(table_name = "memberships")]
|
||||
pub struct Model {
|
||||
#[sea_orm(primary_key)]
|
||||
pub user_id: UserId,
|
||||
#[sea_orm(primary_key)]
|
||||
pub group_id: GroupId,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||
pub enum Relation {
|
||||
#[sea_orm(
|
||||
belongs_to = "super::groups::Entity",
|
||||
from = "Column::GroupId",
|
||||
to = "super::groups::Column::GroupId",
|
||||
on_update = "Cascade",
|
||||
on_delete = "Cascade"
|
||||
)]
|
||||
Groups,
|
||||
#[sea_orm(
|
||||
belongs_to = "super::users::Entity",
|
||||
from = "Column::UserId",
|
||||
to = "super::users::Column::UserId",
|
||||
on_update = "Cascade",
|
||||
on_delete = "Cascade"
|
||||
)]
|
||||
Users,
|
||||
}
|
||||
|
||||
impl Related<super::groups::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Groups.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl Related<super::users::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Users.def()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct UserToGroup;
|
||||
impl Linked for UserToGroup {
|
||||
type FromEntity = super::User;
|
||||
|
||||
type ToEntity = super::Group;
|
||||
|
||||
fn link(&self) -> Vec<RelationDef> {
|
||||
vec![Relation::Users.def().rev(), Relation::Groups.def()]
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct GroupToUser;
|
||||
impl Linked for GroupToUser {
|
||||
type FromEntity = super::Group;
|
||||
|
||||
type ToEntity = super::User;
|
||||
|
||||
fn link(&self) -> Vec<RelationDef> {
|
||||
vec![Relation::Groups.def().rev(), Relation::Users.def()]
|
||||
}
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
||||
@@ -0,0 +1,19 @@
|
||||
pub mod prelude;
|
||||
|
||||
pub mod deserialize;
|
||||
pub mod groups;
|
||||
pub mod jwt_refresh_storage;
|
||||
pub mod jwt_storage;
|
||||
pub mod memberships;
|
||||
pub mod password_reset_tokens;
|
||||
pub mod users;
|
||||
|
||||
pub mod user_attribute_schema;
|
||||
pub mod user_attributes;
|
||||
pub mod user_object_classes;
|
||||
|
||||
pub mod group_attribute_schema;
|
||||
pub mod group_attributes;
|
||||
pub mod group_object_classes;
|
||||
|
||||
pub use prelude::*;
|
||||
@@ -0,0 +1,35 @@
|
||||
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.10.3
|
||||
|
||||
use sea_orm::entity::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use lldap_domain::types::UserId;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
|
||||
#[sea_orm(table_name = "password_reset_tokens")]
|
||||
pub struct Model {
|
||||
#[sea_orm(primary_key, auto_increment = false)]
|
||||
pub token: String,
|
||||
pub user_id: UserId,
|
||||
pub expiry_date: chrono::NaiveDateTime,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||
pub enum Relation {
|
||||
#[sea_orm(
|
||||
belongs_to = "super::users::Entity",
|
||||
from = "Column::UserId",
|
||||
to = "super::users::Column::UserId",
|
||||
on_update = "Cascade",
|
||||
on_delete = "Cascade"
|
||||
)]
|
||||
Users,
|
||||
}
|
||||
|
||||
impl Related<super::users::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Users.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
||||
@@ -0,0 +1,26 @@
|
||||
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.10.3
|
||||
|
||||
pub use super::group_attribute_schema::Column as GroupAttributeSchemaColumn;
|
||||
pub use super::group_attribute_schema::Entity as GroupAttributeSchema;
|
||||
pub use super::group_attributes::Column as GroupAttributesColumn;
|
||||
pub use super::group_attributes::Entity as GroupAttributes;
|
||||
pub use super::group_object_classes::Column as GroupObjectClassesColumn;
|
||||
pub use super::group_object_classes::Entity as GroupObjectClasses;
|
||||
pub use super::groups::Column as GroupColumn;
|
||||
pub use super::groups::Entity as Group;
|
||||
pub use super::jwt_refresh_storage::Column as JwtRefreshStorageColumn;
|
||||
pub use super::jwt_refresh_storage::Entity as JwtRefreshStorage;
|
||||
pub use super::jwt_storage::Column as JwtStorageColumn;
|
||||
pub use super::jwt_storage::Entity as JwtStorage;
|
||||
pub use super::memberships::Column as MembershipColumn;
|
||||
pub use super::memberships::Entity as Membership;
|
||||
pub use super::password_reset_tokens::Column as PasswordResetTokensColumn;
|
||||
pub use super::password_reset_tokens::Entity as PasswordResetTokens;
|
||||
pub use super::user_attribute_schema::Column as UserAttributeSchemaColumn;
|
||||
pub use super::user_attribute_schema::Entity as UserAttributeSchema;
|
||||
pub use super::user_attributes::Column as UserAttributesColumn;
|
||||
pub use super::user_attributes::Entity as UserAttributes;
|
||||
pub use super::user_object_classes::Column as UserObjectClassesColumn;
|
||||
pub use super::user_object_classes::Entity as UserObjectClasses;
|
||||
pub use super::users::Column as UserColumn;
|
||||
pub use super::users::Entity as User;
|
||||
@@ -0,0 +1,56 @@
|
||||
use sea_orm::entity::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use lldap_domain::{
|
||||
schema::AttributeSchema,
|
||||
types::{AttributeName, AttributeType},
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
|
||||
#[sea_orm(table_name = "user_attribute_schema")]
|
||||
pub struct Model {
|
||||
#[sea_orm(
|
||||
primary_key,
|
||||
auto_increment = false,
|
||||
column_name = "user_attribute_schema_name"
|
||||
)]
|
||||
pub attribute_name: AttributeName,
|
||||
#[sea_orm(column_name = "user_attribute_schema_type")]
|
||||
pub attribute_type: AttributeType,
|
||||
#[sea_orm(column_name = "user_attribute_schema_is_list")]
|
||||
pub is_list: bool,
|
||||
#[sea_orm(column_name = "user_attribute_schema_is_user_visible")]
|
||||
pub is_user_visible: bool,
|
||||
#[sea_orm(column_name = "user_attribute_schema_is_user_editable")]
|
||||
pub is_user_editable: bool,
|
||||
#[sea_orm(column_name = "user_attribute_schema_is_hardcoded")]
|
||||
pub is_hardcoded: bool,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||
pub enum Relation {
|
||||
#[sea_orm(has_many = "super::user_attributes::Entity")]
|
||||
UserAttributes,
|
||||
}
|
||||
|
||||
impl Related<super::UserAttributes> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::UserAttributes.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
||||
|
||||
impl From<Model> for AttributeSchema {
|
||||
fn from(value: Model) -> Self {
|
||||
Self {
|
||||
name: value.attribute_name,
|
||||
attribute_type: value.attribute_type,
|
||||
is_list: value.is_list,
|
||||
is_visible: value.is_user_visible,
|
||||
is_editable: value.is_user_editable,
|
||||
is_hardcoded: value.is_hardcoded,
|
||||
is_readonly: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
use sea_orm::entity::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use lldap_domain::types::{AttributeName, Serialized, UserId};
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
|
||||
#[sea_orm(table_name = "user_attributes")]
|
||||
pub struct Model {
|
||||
#[sea_orm(
|
||||
primary_key,
|
||||
auto_increment = false,
|
||||
column_name = "user_attribute_user_id"
|
||||
)]
|
||||
pub user_id: UserId,
|
||||
#[sea_orm(
|
||||
primary_key,
|
||||
auto_increment = false,
|
||||
column_name = "user_attribute_name"
|
||||
)]
|
||||
pub attribute_name: AttributeName,
|
||||
#[sea_orm(column_name = "user_attribute_value")]
|
||||
pub value: Serialized,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||
pub enum Relation {
|
||||
#[sea_orm(
|
||||
belongs_to = "super::users::Entity",
|
||||
from = "Column::UserId",
|
||||
to = "super::users::Column::UserId",
|
||||
on_update = "Cascade",
|
||||
on_delete = "Cascade"
|
||||
)]
|
||||
Users,
|
||||
#[sea_orm(
|
||||
belongs_to = "super::user_attribute_schema::Entity",
|
||||
from = "Column::AttributeName",
|
||||
to = "super::user_attribute_schema::Column::AttributeName",
|
||||
on_update = "Cascade",
|
||||
on_delete = "Cascade"
|
||||
)]
|
||||
UserAttributeSchema,
|
||||
}
|
||||
|
||||
impl Related<super::User> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Users.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl Related<super::UserAttributeSchema> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::UserAttributeSchema.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
||||
@@ -0,0 +1,23 @@
|
||||
use sea_orm::entity::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use lldap_domain::types::LdapObjectClass;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
|
||||
#[sea_orm(table_name = "user_object_classes")]
|
||||
pub struct Model {
|
||||
#[sea_orm(primary_key, auto_increment = false)]
|
||||
pub lower_object_class: String,
|
||||
pub object_class: LdapObjectClass,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||
pub enum Relation {}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
||||
|
||||
impl From<Model> for LdapObjectClass {
|
||||
fn from(value: Model) -> Self {
|
||||
value.object_class
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.10.3
|
||||
|
||||
use sea_orm::{entity::prelude::*, sea_query::BlobSize};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use lldap_domain::types::{Email, UserId, Uuid};
|
||||
|
||||
#[derive(Copy, Clone, Default, Debug, DeriveEntity)]
|
||||
pub struct Entity;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveModel, Eq, Serialize, Deserialize, DeriveActiveModel)]
|
||||
#[sea_orm(table_name = "users")]
|
||||
pub struct Model {
|
||||
#[sea_orm(primary_key, auto_increment = false)]
|
||||
pub user_id: UserId,
|
||||
pub email: Email,
|
||||
pub lowercase_email: String,
|
||||
pub display_name: Option<String>,
|
||||
pub creation_date: chrono::NaiveDateTime,
|
||||
pub password_hash: Option<Vec<u8>>,
|
||||
pub totp_secret: Option<String>,
|
||||
pub mfa_type: Option<String>,
|
||||
pub uuid: Uuid,
|
||||
}
|
||||
|
||||
impl EntityName for Entity {
|
||||
fn table_name(&self) -> &str {
|
||||
"users"
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveColumn, PartialEq, Eq, Serialize, Deserialize)]
|
||||
pub enum Column {
|
||||
UserId,
|
||||
Email,
|
||||
LowercaseEmail,
|
||||
DisplayName,
|
||||
CreationDate,
|
||||
PasswordHash,
|
||||
TotpSecret,
|
||||
MfaType,
|
||||
Uuid,
|
||||
}
|
||||
|
||||
impl ColumnTrait for Column {
|
||||
type EntityName = Entity;
|
||||
|
||||
fn def(&self) -> ColumnDef {
|
||||
match self {
|
||||
Column::UserId => ColumnType::String(Some(255)),
|
||||
Column::Email => ColumnType::String(Some(255)),
|
||||
Column::LowercaseEmail => ColumnType::String(Some(255)),
|
||||
Column::DisplayName => ColumnType::String(Some(255)),
|
||||
Column::CreationDate => ColumnType::DateTime,
|
||||
Column::PasswordHash => ColumnType::Binary(BlobSize::Medium),
|
||||
Column::TotpSecret => ColumnType::String(Some(64)),
|
||||
Column::MfaType => ColumnType::String(Some(64)),
|
||||
Column::Uuid => ColumnType::String(Some(36)),
|
||||
}
|
||||
.def()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||
pub enum Relation {
|
||||
#[sea_orm(has_many = "super::memberships::Entity")]
|
||||
Memberships,
|
||||
#[sea_orm(has_many = "super::jwt_refresh_storage::Entity")]
|
||||
JwtRefreshStorage,
|
||||
#[sea_orm(has_many = "super::jwt_storage::Entity")]
|
||||
JwtStorage,
|
||||
#[sea_orm(has_many = "super::password_reset_tokens::Entity")]
|
||||
PasswordResetTokens,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DerivePrimaryKey)]
|
||||
pub enum PrimaryKey {
|
||||
UserId,
|
||||
}
|
||||
|
||||
impl PrimaryKeyTrait for PrimaryKey {
|
||||
type ValueType = UserId;
|
||||
|
||||
fn auto_increment() -> bool {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
impl Related<super::memberships::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Memberships.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl Related<super::jwt_refresh_storage::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::JwtRefreshStorage.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl Related<super::jwt_storage::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::JwtStorage.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl Related<super::password_reset_tokens::Entity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::PasswordResetTokens.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
||||
|
||||
impl From<Model> for lldap_domain::types::User {
|
||||
fn from(user: Model) -> Self {
|
||||
Self {
|
||||
user_id: user.user_id,
|
||||
email: user.email,
|
||||
display_name: user.display_name,
|
||||
creation_date: user.creation_date,
|
||||
uuid: user.uuid,
|
||||
attributes: Vec::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user