Añade las entidades asociadas a roles y usuarios
This commit is contained in:
parent
4af6586003
commit
d07611d044
5 changed files with 156 additions and 11 deletions
|
|
@ -1 +1,4 @@
|
||||||
|
pub mod role;
|
||||||
|
pub mod role_permission;
|
||||||
pub mod user;
|
pub mod user;
|
||||||
|
pub mod user_role;
|
||||||
|
|
|
||||||
41
pagetop-user/src/entity/role.rs
Normal file
41
pagetop-user/src/entity/role.rs
Normal file
|
|
@ -0,0 +1,41 @@
|
||||||
|
use pagetop::db::entity::*;
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
|
||||||
|
#[sea_orm(table_name = "role")]
|
||||||
|
pub struct Model {
|
||||||
|
#[sea_orm(primary_key)]
|
||||||
|
pub rid : u32,
|
||||||
|
#[sea_orm(unique)]
|
||||||
|
pub name : String,
|
||||||
|
#[sea_orm(default_value = 0)]
|
||||||
|
pub weight: i32,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, Debug, EnumIter)]
|
||||||
|
pub enum Relation {
|
||||||
|
RolePermission,
|
||||||
|
UserRole,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl RelationTrait for Relation {
|
||||||
|
fn def(&self) -> RelationDef {
|
||||||
|
match self {
|
||||||
|
Self::RolePermission => Entity::has_many(super::role_permission::Entity).into(),
|
||||||
|
Self::UserRole => Entity::has_many(super::user_role::Entity).into(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Related<super::role_permission::Entity> for Entity {
|
||||||
|
fn to() -> RelationDef {
|
||||||
|
Relation::RolePermission.def()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Related<super::user_role::Entity> for Entity {
|
||||||
|
fn to() -> RelationDef {
|
||||||
|
Relation::UserRole.def()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ActiveModelBehavior for ActiveModel {}
|
||||||
35
pagetop-user/src/entity/role_permission.rs
Normal file
35
pagetop-user/src/entity/role_permission.rs
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
use pagetop::db::entity::*;
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
|
||||||
|
#[sea_orm(table_name = "role_permission")]
|
||||||
|
pub struct Model {
|
||||||
|
#[sea_orm(primary_key)]
|
||||||
|
pub rid : u32,
|
||||||
|
#[sea_orm(primary_key)]
|
||||||
|
pub permission: String,
|
||||||
|
pub module : String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, Debug, EnumIter)]
|
||||||
|
pub enum Relation {
|
||||||
|
Role,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl RelationTrait for Relation {
|
||||||
|
fn def(&self) -> RelationDef {
|
||||||
|
match self {
|
||||||
|
Self::Role => Entity::belongs_to(super::role::Entity)
|
||||||
|
.from(Column::Rid)
|
||||||
|
.to(super::role::Column::Rid)
|
||||||
|
.into(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Related<super::role::Entity> for Entity {
|
||||||
|
fn to() -> RelationDef {
|
||||||
|
Relation::Role.def()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ActiveModelBehavior for ActiveModel {}
|
||||||
|
|
@ -1,18 +1,39 @@
|
||||||
use crate::db::entity::*;
|
use pagetop::db::entity::*;
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Deserialize, Serialize)]
|
#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
|
||||||
#[sea_orm(table_name = "user")]
|
#[sea_orm(table_name = "user")]
|
||||||
pub struct Model {
|
pub struct Model {
|
||||||
#[sea_orm(primary_key)]
|
#[sea_orm(primary_key, auto_increment = false)]
|
||||||
#[serde(skip_deserializing)]
|
pub uid : u32,
|
||||||
pub id: i32,
|
#[sea_orm(unique)]
|
||||||
pub title: String,
|
pub name : String,
|
||||||
#[sea_orm(column_type = "Text")]
|
pub pass : String,
|
||||||
pub text: String,
|
pub mail : Option<String>,
|
||||||
|
pub created : DateTimeUtc,
|
||||||
|
pub changed : DateTimeUtc,
|
||||||
|
pub access : DateTimeUtc,
|
||||||
|
pub login : DateTimeUtc,
|
||||||
|
pub status : bool,
|
||||||
|
pub timezone: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
#[derive(Copy, Clone, Debug, EnumIter)]
|
||||||
pub enum Relation {}
|
pub enum Relation {
|
||||||
|
UserRole,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl RelationTrait for Relation {
|
||||||
|
fn def(&self) -> RelationDef {
|
||||||
|
match self {
|
||||||
|
Self::UserRole => Entity::has_many(super::user_role::Entity).into(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Related<super::user_role::Entity> for Entity {
|
||||||
|
fn to() -> RelationDef {
|
||||||
|
Relation::UserRole.def()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl ActiveModelBehavior for ActiveModel {}
|
impl ActiveModelBehavior for ActiveModel {}
|
||||||
|
|
|
||||||
45
pagetop-user/src/entity/user_role.rs
Normal file
45
pagetop-user/src/entity/user_role.rs
Normal file
|
|
@ -0,0 +1,45 @@
|
||||||
|
use pagetop::db::entity::*;
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
|
||||||
|
#[sea_orm(table_name = "user_role")]
|
||||||
|
pub struct Model {
|
||||||
|
#[sea_orm(primary_key)]
|
||||||
|
pub uid: u32,
|
||||||
|
#[sea_orm(primary_key)]
|
||||||
|
pub rid: u32,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, Debug, EnumIter)]
|
||||||
|
pub enum Relation {
|
||||||
|
User,
|
||||||
|
Role,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl RelationTrait for Relation {
|
||||||
|
fn def(&self) -> RelationDef {
|
||||||
|
match self {
|
||||||
|
Self::User => Entity::belongs_to(super::user::Entity)
|
||||||
|
.from(Column::Uid)
|
||||||
|
.to(super::user::Column::Uid)
|
||||||
|
.into(),
|
||||||
|
Self::Role => Entity::belongs_to(super::role::Entity)
|
||||||
|
.from(Column::Rid)
|
||||||
|
.to(super::role::Column::Rid)
|
||||||
|
.into(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Related<super::user::Entity> for Entity {
|
||||||
|
fn to() -> RelationDef {
|
||||||
|
Relation::User.def()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Related<super::role::Entity> for Entity {
|
||||||
|
fn to() -> RelationDef {
|
||||||
|
Relation::Role.def()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ActiveModelBehavior for ActiveModel {}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue