This commit is contained in:
2026-07-13 01:38:36 +02:00
parent ede38cc042
commit 09cf5f37fb
16 changed files with 747 additions and 644 deletions
+65
View File
@@ -0,0 +1,65 @@
//! SeaORM Entity pour les permissions d'un rôle dans un canal.
use crate::permissions::ChannelPermission;
use sea_orm::entity::prelude::*;
use sea_orm::prelude::async_trait::async_trait;
use sea_orm::{NotSet, Set};
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
#[sea_orm(table_name = "channel_role_permission")]
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub id: Uuid,
pub channel_id: Uuid,
pub role_id: Uuid,
/// Bitmask des permissions accordées au rôle dans ce canal.
pub permission: i64,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(
belongs_to = "super::channel::Entity",
from = "Column::ChannelId",
to = "super::channel::Column::Id",
on_update = "NoAction",
on_delete = "Cascade"
)]
Channel,
#[sea_orm(
belongs_to = "super::role::Entity",
from = "Column::RoleId",
to = "super::role::Column::Id",
on_update = "NoAction",
on_delete = "Cascade"
)]
Role,
}
impl Related<super::channel::Entity> for Entity {
fn to() -> RelationDef {
Relation::Channel.def()
}
}
impl Related<super::role::Entity> for Entity {
fn to() -> RelationDef {
Relation::Role.def()
}
}
#[async_trait]
impl ActiveModelBehavior for ActiveModel {
fn new() -> Self {
Self {
id: Set(Uuid::new_v4()),
channel_id: NotSet,
role_id: NotSet,
permission: Set(ChannelPermission::empty().bits() as i64),
}
}
}
+65
View File
@@ -0,0 +1,65 @@
//! SeaORM Entity pour les permissions directes d'un utilisateur dans un canal.
use crate::permissions::ChannelPermission;
use sea_orm::entity::prelude::*;
use sea_orm::prelude::async_trait::async_trait;
use sea_orm::{NotSet, Set};
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
#[sea_orm(table_name = "channel_user_permission")]
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub id: Uuid,
pub channel_id: Uuid,
pub user_id: Uuid,
/// Bitmask des permissions accordées directement à l'utilisateur dans ce canal.
pub permission: i64,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(
belongs_to = "super::channel::Entity",
from = "Column::ChannelId",
to = "super::channel::Column::Id",
on_update = "NoAction",
on_delete = "Cascade"
)]
Channel,
#[sea_orm(
belongs_to = "super::user::Entity",
from = "Column::UserId",
to = "super::user::Column::Id",
on_update = "NoAction",
on_delete = "Cascade"
)]
User,
}
impl Related<super::channel::Entity> for Entity {
fn to() -> RelationDef {
Relation::Channel.def()
}
}
impl Related<super::user::Entity> for Entity {
fn to() -> RelationDef {
Relation::User.def()
}
}
#[async_trait]
impl ActiveModelBehavior for ActiveModel {
fn new() -> Self {
Self {
id: Set(Uuid::new_v4()),
channel_id: NotSet,
user_id: NotSet,
permission: Set(ChannelPermission::empty().bits() as i64),
}
}
}
+19 -3
View File
@@ -1,10 +1,12 @@
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.19
use async_trait::async_trait;
/// Permet de cache les permissions des utilisateurs pour éviter de recalculer les permissions à chaque fois qu'une requête est faite.
use sea_orm::entity::prelude::*;
use sea_orm::{NotSet, Set};
use serde::{Deserialize, Serialize};
use utoipa::ToSchema;
#[derive(
Debug, Clone, Copy, PartialEq, Eq, EnumIter, DeriveActiveEnum, Serialize, Deserialize, ToSchema,
)]
@@ -21,6 +23,8 @@ pub enum PermissionScopeType {
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
#[sea_orm(table_name = "computed_permission")]
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub id: Uuid,
/// L'utilisateur à qui appartiennent ces permissions
#[sea_orm(primary_key, auto_increment = false)]
pub user_id: Uuid,
@@ -35,7 +39,6 @@ pub struct Model {
/// Cache des permissions serveur (stocké en i64 pour SQL, utilisé en u64)
pub server_permissions: i64,
pub channel_permissions: i64,
pub voice_permissions: i64,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
@@ -56,4 +59,17 @@ impl Related<super::user::Entity> for Entity {
}
}
impl ActiveModelBehavior for ActiveModel {}
#[async_trait]
impl ActiveModelBehavior for ActiveModel {
fn new() -> Self {
Self {
id: Set(Uuid::new_v4()),
user_id: NotSet,
server_id: NotSet,
scope_type: NotSet,
resource_id: NotSet,
server_permissions: Set(0),
channel_permissions: Set(0),
}
}
}
-67
View File
@@ -1,67 +0,0 @@
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.19
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
use utoipa::ToSchema;
#[derive(
Debug, Clone, Copy, PartialEq, Eq, EnumIter, DeriveActiveEnum, Serialize, Deserialize, ToSchema,
)]
#[sea_orm(rs_type = "i32", db_type = "Integer")]
pub enum PermissionScopeType {
#[sea_orm(num_value = 0)]
Server,
#[sea_orm(num_value = 1)]
Category,
#[sea_orm(num_value = 2)]
Channel,
}
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
#[sea_orm(table_name = "group_permission")]
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub id: Uuid,
pub group_id: Uuid,
pub server_id: Uuid,
// L'ID du scope (soit un Uuid d'une Category, soit l'Uuid d'un Channel, soit l'Uuid du Server)
pub scope_type: PermissionScopeType,
pub scope_id: Uuid,
pub server_permissions: i64,
pub channel_permissions: i64,
pub voice_permissions: i64,
pub created_at: DateTimeUtc,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(
belongs_to = "super::group::Entity",
from = "Column::GroupId",
to = "super::group::Column::Id",
on_update = "NoAction",
on_delete = "Cascade"
)]
Group,
#[sea_orm(
belongs_to = "super::server::Entity",
from = "Column::ServerId",
to = "super::server::Column::Id",
on_update = "NoAction",
on_delete = "Cascade"
)]
Server,
}
impl Related<super::group::Entity> for Entity {
fn to() -> RelationDef {
Relation::Group.def()
}
}
impl Related<super::server::Entity> for Entity {
fn to() -> RelationDef {
Relation::Server.def()
}
}
impl ActiveModelBehavior for ActiveModel {}
+6 -4
View File
@@ -5,13 +5,15 @@ pub mod prelude;
pub mod attachment;
pub mod category;
pub mod channel;
pub mod channel_role_permission;
pub mod channel_user;
pub mod channel_user_permission;
pub mod computed_permission;
pub mod group;
pub mod group_member;
pub mod group_permission;
pub mod message;
pub mod role;
pub mod role_user;
pub mod server;
pub mod server_role_permission;
pub mod server_user;
pub mod server_user_permission;
pub mod user;
pub mod user_permission;
+4 -4
View File
@@ -5,11 +5,11 @@ pub use super::category::Entity as Category;
pub use super::channel::Entity as Channel;
pub use super::channel_user::Entity as ChannelUser;
pub use super::computed_permission::Entity as ComputedPermission;
pub use super::group::Entity as Group;
pub use super::group_member::Entity as GroupMember;
pub use super::group_permission::Entity as GroupPermission;
pub use super::message::Entity as Message;
pub use super::role::Entity as Group;
pub use super::role_user::Entity as GroupMember;
pub use super::server::Entity as Server;
pub use super::server_role_permission::Entity as ServerRolePermission;
pub use super::server_user::Entity as ServerUser;
pub use super::server_user_permission::Entity as ServerUserPermission;
pub use super::user::Entity as User;
pub use super::user_permission::Entity as UserPermission;
+5 -5
View File
@@ -5,7 +5,7 @@ use sea_orm::prelude::async_trait::async_trait;
use sea_orm::Set;
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
#[sea_orm(table_name = "group")]
#[sea_orm(table_name = "role")]
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub id: Uuid,
@@ -25,8 +25,8 @@ pub enum Relation {
on_delete = "Cascade"
)]
Server,
#[sea_orm(has_many = "super::group_member::Entity")]
GroupMember,
#[sea_orm(has_many = "super::role_user::Entity")]
RoleUser,
}
impl Related<super::server::Entity> for Entity {
@@ -35,9 +35,9 @@ impl Related<super::server::Entity> for Entity {
}
}
impl Related<super::group_member::Entity> for Entity {
impl Related<super::role_user::Entity> for Entity {
fn to() -> RelationDef {
Relation::GroupMember.def()
Relation::RoleUser.def()
}
}
@@ -3,10 +3,10 @@
use sea_orm::entity::prelude::*;
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
#[sea_orm(table_name = "group_member")]
#[sea_orm(table_name = "role_user")]
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub group_id: Uuid,
pub role_id: Uuid,
#[sea_orm(primary_key, auto_increment = false)]
pub user_id: Uuid,
}
@@ -14,9 +14,9 @@ pub struct Model {
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(
belongs_to = "super::group::Entity",
from = "Column::GroupId",
to = "super::group::Column::Id",
belongs_to = "super::role::Entity",
from = "Column::RoleId",
to = "super::role::Column::Id",
on_update = "NoAction",
on_delete = "Cascade"
)]
@@ -31,7 +31,7 @@ pub enum Relation {
User,
}
impl Related<super::group::Entity> for Entity {
impl Related<super::role::Entity> for Entity {
fn to() -> RelationDef {
Relation::Group.def()
}
+65
View File
@@ -0,0 +1,65 @@
use crate::permissions::ServerPermission;
use sea_orm::entity::prelude::*;
use sea_orm::prelude::async_trait::async_trait;
use sea_orm::{NotSet, Set};
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
#[sea_orm(table_name = "server_group_permission")]
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub id: Uuid,
#[sea_orm(primary_key, auto_increment = false)]
pub server_id: Uuid,
#[sea_orm(primary_key, auto_increment = false)]
pub role_id: Uuid,
/// Bitmask des permissions accordées directement à l'utilisateur.
pub permission: i64,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(
belongs_to = "super::server::Entity",
from = "Column::ServerId",
to = "super::server::Column::Id",
on_update = "NoAction",
on_delete = "Cascade"
)]
Server,
#[sea_orm(
belongs_to = "super::role::Entity",
from = "Column::RoleId",
to = "super::role::Column::Id",
on_update = "NoAction",
on_delete = "Cascade"
)]
Role,
}
impl Related<super::server::Entity> for Entity {
fn to() -> RelationDef {
Relation::Server.def()
}
}
impl Related<super::role::Entity> for Entity {
fn to() -> RelationDef {
Relation::Role.def()
}
}
#[async_trait]
impl ActiveModelBehavior for ActiveModel {
fn new() -> Self {
Self {
id: Set(Uuid::new_v4()),
server_id: NotSet,
role_id: NotSet,
permission: Set(ServerPermission::empty().bits() as i64),
}
}
}
@@ -1,47 +1,26 @@
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.19
use crate::permissions::ServerPermission;
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
use utoipa::ToSchema;
#[derive(
Debug, Clone, Copy, PartialEq, Eq, EnumIter, DeriveActiveEnum, Serialize, Deserialize, ToSchema,
)]
#[sea_orm(rs_type = "i32", db_type = "Integer")]
pub enum PermissionScopeType {
#[sea_orm(num_value = 0)]
Server,
#[sea_orm(num_value = 1)]
Category,
#[sea_orm(num_value = 2)]
Channel,
}
use sea_orm::prelude::async_trait::async_trait;
use sea_orm::{NotSet, Set};
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
#[sea_orm(table_name = "user_permission")]
#[sea_orm(table_name = "server_user_permission")]
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub id: Uuid,
pub user_id: Uuid,
#[sea_orm(primary_key, auto_increment = false)]
pub server_id: Uuid,
// L'ID du scope (soit un Uuid d'une Category, soit l'Uuid d'un Channel, soit l'Uuid du Server)
pub scope_type: PermissionScopeType,
pub scope_id: Uuid,
pub server_permissions: i64,
pub channel_permissions: i64,
pub voice_permissions: i64,
pub created_at: DateTimeUtc,
#[sea_orm(primary_key, auto_increment = false)]
pub user_id: Uuid,
/// Bitmask des permissions accordées directement à l'utilisateur.
pub permission: i64,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(
belongs_to = "super::user::Entity",
from = "Column::UserId",
to = "super::user::Column::Id",
on_update = "NoAction",
on_delete = "Cascade"
)]
User,
#[sea_orm(
belongs_to = "super::server::Entity",
from = "Column::ServerId",
@@ -50,12 +29,15 @@ pub enum Relation {
on_delete = "Cascade"
)]
Server,
}
impl Related<super::user::Entity> for Entity {
fn to() -> RelationDef {
Relation::User.def()
}
#[sea_orm(
belongs_to = "super::user::Entity",
from = "Column::UserId",
to = "super::user::Column::Id",
on_update = "NoAction",
on_delete = "Cascade"
)]
User,
}
impl Related<super::server::Entity> for Entity {
@@ -64,4 +46,20 @@ impl Related<super::server::Entity> for Entity {
}
}
impl ActiveModelBehavior for ActiveModel {}
impl Related<super::user::Entity> for Entity {
fn to() -> RelationDef {
Relation::User.def()
}
}
#[async_trait]
impl ActiveModelBehavior for ActiveModel {
fn new() -> Self {
Self {
id: Set(Uuid::new_v4()),
server_id: NotSet,
user_id: NotSet,
permission: Set(ServerPermission::empty().bits() as i64),
}
}
}