diff options
author | metamuffin <metamuffin@disroot.org> | 2023-10-01 00:38:29 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2023-10-01 00:38:29 +0200 |
commit | fc5e13ae525cb74e77a5bc51204f44476115cea9 (patch) | |
tree | a20b6d296d67735a2c8d42a0dc31b44c0bb53cb7 /common | |
parent | d546caa3f5053ade763430490911fefd6257af9f (diff) | |
download | jellything-fc5e13ae525cb74e77a5bc51204f44476115cea9.tar jellything-fc5e13ae525cb74e77a5bc51204f44476115cea9.tar.bz2 jellything-fc5e13ae525cb74e77a5bc51204f44476115cea9.tar.zst |
draft for permission framework
Diffstat (limited to 'common')
-rw-r--r-- | common/src/config.rs | 3 | ||||
-rw-r--r-- | common/src/lib.rs | 3 | ||||
-rw-r--r-- | common/src/user.rs | 30 |
3 files changed, 35 insertions, 1 deletions
diff --git a/common/src/config.rs b/common/src/config.rs index da1cfb5..467dc02 100644 --- a/common/src/config.rs +++ b/common/src/config.rs @@ -7,6 +7,8 @@ use serde::{Deserialize, Serialize}; use std::{collections::HashMap, path::PathBuf}; +use crate::user::PermissionSet; + #[rustfmt::skip] #[derive(Debug, Deserialize, Serialize, Default)] pub struct GlobalConfig { @@ -22,6 +24,7 @@ pub struct GlobalConfig { #[serde(default)] pub session_key: Option<String>, #[serde(default = "default::login_expire")] pub login_expire: i64, #[serde(default)] pub remote_credentials: HashMap<String, (String, String, bool)>, + #[serde(default)] pub default_permission_set: PermissionSet, } #[rustfmt::skip] diff --git a/common/src/lib.rs b/common/src/lib.rs index ec6e0df..c842924 100644 --- a/common/src/lib.rs +++ b/common/src/lib.rs @@ -6,8 +6,9 @@ pub mod config; pub mod helpers; pub mod r#impl; -pub mod stream; pub mod seek_index; +pub mod stream; +pub mod user; #[cfg(feature = "rocket")] use rocket::{FromFormField, UriDisplayQuery}; diff --git a/common/src/user.rs b/common/src/user.rs new file mode 100644 index 0000000..543162c --- /dev/null +++ b/common/src/user.rs @@ -0,0 +1,30 @@ +use serde::{Deserialize, Serialize}; +use std::collections::HashMap; + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct User { + pub name: String, + pub display_name: String, + pub password: Vec<u8>, + pub admin: bool, + pub permissions: PermissionSet, +} + +#[derive(Debug, Clone, Serialize, Deserialize, Default)] +pub struct PermissionSet(pub HashMap<UserPermission, bool>); + +#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, Hash)] +#[serde(rename_all = "snake_case")] +pub enum UserPermission { + OriginalStream, + Transcode, + ManageUsers, + GenerateInvite, +} + +impl UserPermission { + pub fn default_value(&self) -> bool { + use UserPermission::*; + matches!(self, Transcode) + } +} |