mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-13 22:52:22 +00:00
Add principal memberships to allow group accounts
This commit is contained in:
@@ -15,6 +15,8 @@ pub struct User {
|
||||
pub password: Option<String>,
|
||||
#[serde(default)]
|
||||
pub app_tokens: Vec<String>,
|
||||
#[serde(default)]
|
||||
pub memberships: Vec<String>,
|
||||
}
|
||||
|
||||
impl User {
|
||||
@@ -25,7 +27,16 @@ impl User {
|
||||
if self.id == principal {
|
||||
return true;
|
||||
}
|
||||
false
|
||||
self.memberships
|
||||
.iter()
|
||||
.any(|membership| membership == principal)
|
||||
}
|
||||
|
||||
/// Returns all principals the user implements
|
||||
pub fn memberships(&self) -> Vec<&str> {
|
||||
let mut memberships: Vec<_> = self.memberships.iter().map(String::as_ref).collect();
|
||||
memberships.push(self.id.as_str());
|
||||
memberships
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user