use crate::CONF; use anyhow::anyhow; use jellycommon::user::{PermissionSet, UserPermission}; pub trait PermissionSetExt { fn check(&self, perm: UserPermission) -> bool; fn assert(&self, perm: UserPermission) -> Result<(), anyhow::Error>; } impl PermissionSetExt for PermissionSet { fn check(&self, perm: UserPermission) -> bool { *self .0 .get(&perm) .or(CONF.default_permission_set.0.get(&perm)) .unwrap_or(&perm.default_value()) } 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." )) } } }