init
This commit is contained in:
+1
-20
@@ -1,6 +1,5 @@
|
||||
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.19
|
||||
|
||||
use crate::permissions::{ChannelPermission, PermissionSet, ServerPermission, VoicePermission};
|
||||
use sea_orm::entity::prelude::*;
|
||||
use sea_orm::prelude::async_trait::async_trait;
|
||||
use sea_orm::Set;
|
||||
@@ -15,11 +14,7 @@ pub struct Model {
|
||||
pub created_at: DateTimeUtc,
|
||||
pub updated_at: DateTimeUtc,
|
||||
pub is_default: bool,
|
||||
|
||||
/// Permissions serveur par défaut (stockées en i64, lues en u64)
|
||||
pub default_server_permissions: i64,
|
||||
pub default_channel_permissions: i64,
|
||||
pub default_voice_permissions: i64,
|
||||
pub owned_id: Uuid,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||
@@ -53,24 +48,10 @@ impl Related<super::server_user::Entity> for Entity {
|
||||
#[async_trait]
|
||||
impl ActiveModelBehavior for ActiveModel {
|
||||
fn new() -> Self {
|
||||
let default_perm = PermissionSet::DEFAULT;
|
||||
Self {
|
||||
id: Set(Uuid::new_v4()),
|
||||
is_default: Set(false),
|
||||
default_server_permissions: Set(default_perm.server.bits() as i64),
|
||||
default_channel_permissions: Set(default_perm.channel.bits() as i64),
|
||||
default_voice_permissions: Set(default_perm.voice.bits() as i64),
|
||||
..ActiveModelTrait::default()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Model {
|
||||
pub fn default_permissions(&self) -> PermissionSet {
|
||||
PermissionSet {
|
||||
server: ServerPermission::from_bits_truncate(self.default_server_permissions as u64),
|
||||
channel: ChannelPermission::from_bits_truncate(self.default_channel_permissions as u64),
|
||||
voice: VoicePermission::from_bits_truncate(self.default_voice_permissions as u64),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user