New perm concept, reference, and adding routes.

This commit is contained in:
Paul Makles
2020-12-29 13:02:04 +00:00
parent 798047625a
commit eb382fa1ec
14 changed files with 196 additions and 46 deletions

View File

@@ -0,0 +1,32 @@
use crate::database::entities::User;
use num_enum::TryFromPrimitive;
use std::ops;
#[derive(Debug, PartialEq, Eq, TryFromPrimitive, Copy, Clone)]
#[repr(u32)]
pub enum UserPermission {
Access = 1,
SendMessage = 2,
Invite = 4
}
bitfield! {
pub struct UserPermissions(MSB0 [u32]);
u32;
pub get_access, _: 31;
pub get_send_message, _: 30;
pub get_invite, _: 29;
}
impl_op_ex!(+ |a: &UserPermission, b: &UserPermission| -> u32 { *a + *b });
impl_op_ex!(+ |a: &u32, b: &UserPermission| -> u32 { *a + *b });
pub async fn temp_calc_perm(_user: &User, _target: &User) -> UserPermissions<[u32; 1]> {
// if friends; Access + Message + Invite
// if mutually know each other:
// and has DMs from users enabled -> Access + Message
// otherwise -> Access
// otherwise; None
UserPermissions([UserPermission::Access + UserPermission::SendMessage + UserPermission::Invite])
}