From fc5e13ae525cb74e77a5bc51204f44476115cea9 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Sun, 1 Oct 2023 00:38:29 +0200 Subject: draft for permission framework --- common/src/config.rs | 3 +++ common/src/lib.rs | 3 ++- common/src/user.rs | 30 ++++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 common/src/user.rs (limited to 'common/src') 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, #[serde(default = "default::login_expire")] pub login_expire: i64, #[serde(default)] pub remote_credentials: HashMap, + #[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, + pub admin: bool, + pub permissions: PermissionSet, +} + +#[derive(Debug, Clone, Serialize, Deserialize, Default)] +pub struct PermissionSet(pub HashMap); + +#[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) + } +} -- cgit v1.2.3-70-g09d2