diff options
author | metamuffin <metamuffin@disroot.org> | 2025-04-30 11:46:28 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2025-04-30 11:46:28 +0200 |
commit | 35ae80f183904466667af73c7921b4ade399569a (patch) | |
tree | 3a7eec95debbd9ba292436ff989742b8a9b1dff4 /base/src/permission.rs | |
parent | d6a039a10ac3c81d410beb9b648d29524ca1e278 (diff) | |
download | jellything-35ae80f183904466667af73c7921b4ade399569a.tar jellything-35ae80f183904466667af73c7921b4ade399569a.tar.bz2 jellything-35ae80f183904466667af73c7921b4ade399569a.tar.zst |
split base into asset_token and db
Diffstat (limited to 'base/src/permission.rs')
-rw-r--r-- | base/src/permission.rs | 64 |
1 files changed, 0 insertions, 64 deletions
diff --git a/base/src/permission.rs b/base/src/permission.rs deleted file mode 100644 index 7914f0b..0000000 --- a/base/src/permission.rs +++ /dev/null @@ -1,64 +0,0 @@ -/* - This file is part of jellything (https://codeberg.org/metamuffin/jellything) - which is licensed under the GNU Affero General Public License (version 3); see /COPYING. - Copyright (C) 2025 metamuffin <metamuffin.org> -*/ -use anyhow::anyhow; -use jellycommon::{ - user::{PermissionSet, UserPermission}, - Node, -}; - -pub trait PermissionSetExt { - fn check_explicit(&self, perm: &UserPermission) -> Option<bool>; - fn check(&self, perm: &UserPermission) -> bool { - self.check_explicit(perm).unwrap_or(perm.default_value()) - } - fn assert(&self, perm: &UserPermission) -> Result<(), anyhow::Error>; -} - -impl PermissionSetExt for PermissionSet { - fn check_explicit(&self, perm: &UserPermission) -> Option<bool> { - self.0 - .get(perm) - // .or(CONF.default_permission_set.0.get(perm)) - .copied() - } - fn assert(&self, perm: &UserPermission) -> Result<(), anyhow::Error> { - if self.check(perm) { - Ok(()) - } else { - Err(anyhow!( - "sorry, you need special permission {perm:?} for this action." - )) - } - } -} - -pub trait NodePermissionExt { - fn only_if_permitted(self, perms: &PermissionSet) -> Self; -} -impl NodePermissionExt for Option<Node> { - fn only_if_permitted(self, perms: &PermissionSet) -> Self { - self.and_then(|node| { - if check_node_permission(perms, &node) { - Some(node) - } else { - None - } - }) - } -} -fn check_node_permission(_perms: &PermissionSet, _node: &Node) -> bool { - // if let Some(v) = perms.check_explicit(&UserPermission::AccessNode(node.id.clone().unwrap())) { - // v - // } else { - // TODO - // for com in node.parents.clone().into_iter() { - // if let Some(v) = perms.check_explicit(&UserPermission::AccessNode(com.to_owned())) { - // return v; - // } - // } - true - // } -} |