chore(monorepo): delta, january, quark

This commit is contained in:
Paul Makles
2022-06-02 00:04:22 +01:00
parent 5d8432e267
commit 5120b071d1
232 changed files with 18094 additions and 554 deletions

View File

@@ -0,0 +1,93 @@
mod permission;
mod user;
use bson::Bson;
pub use permission::*;
pub use user::*;
use serde::{Deserialize, Serialize};
/// Holds a permission value to manipulate.
#[derive(Debug)]
pub struct PermissionValue(u64);
/// Representation of a single permission override
#[derive(Deserialize, JsonSchema, Debug, Clone, Copy)]
pub struct Override {
/// Allow bit flags
allow: u64,
/// Disallow bit flags
deny: u64,
}
/// Representation of a single permission override
/// as it appears on models and in the database
#[derive(Serialize, Deserialize, JsonSchema, Debug, Clone, Copy, Default)]
pub struct OverrideField {
/// Allow bit flags
a: i64,
/// Disallow bit flags
d: i64,
}
impl Override {
/// Into allows
pub fn allows(&self) -> u64 {
self.allow
}
/// Into denies
pub fn denies(&self) -> u64 {
self.deny
}
}
impl PermissionValue {
/// Apply a given override to this value
pub fn apply(&mut self, v: Override) {
self.0 |= v.allow;
self.0 &= !v.deny;
}
}
impl From<Override> for OverrideField {
fn from(v: Override) -> Self {
Self {
a: v.allow as i64,
d: v.deny as i64,
}
}
}
impl From<OverrideField> for Override {
fn from(v: OverrideField) -> Self {
Self {
allow: v.a as u64,
deny: v.d as u64,
}
}
}
impl From<OverrideField> for Bson {
fn from(v: OverrideField) -> Self {
Self::Document(bson::to_document(&v).unwrap())
}
}
impl From<i64> for PermissionValue {
fn from(v: i64) -> Self {
Self(v as u64)
}
}
impl From<u64> for PermissionValue {
fn from(v: u64) -> Self {
Self(v as u64)
}
}
impl From<PermissionValue> for u64 {
fn from(v: PermissionValue) -> Self {
v.0
}
}