mirror of
https://github.com/lldap/lldap.git
synced 2026-03-31 15:07:48 +01:00
1b26859141
Preparation for using basic type definitions in other upcoming modules, in particular for plugins.
73 lines
1.8 KiB
Rust
73 lines
1.8 KiB
Rust
use sea_orm::entity::prelude::*;
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
use lldap_domain::types::{AttributeName, AttributeValue, 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 {}
|
|
|
|
impl From<Model> for AttributeValue {
|
|
fn from(
|
|
Model {
|
|
user_id: _,
|
|
attribute_name,
|
|
value,
|
|
}: Model,
|
|
) -> Self {
|
|
Self {
|
|
name: attribute_name,
|
|
value,
|
|
}
|
|
}
|
|
}
|