mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-13 21:42:34 +00:00
Add principal memberships to allow group accounts
This commit is contained in:
@@ -77,16 +77,23 @@ impl Resource for PrincipalResource {
|
|||||||
prop: &PrincipalPropWrapperName,
|
prop: &PrincipalPropWrapperName,
|
||||||
) -> Result<Self::Prop, Self::Error> {
|
) -> Result<Self::Prop, Self::Error> {
|
||||||
let principal_url = Self::get_url(rmap, vec![&self.principal]).unwrap();
|
let principal_url = Self::get_url(rmap, vec![&self.principal]).unwrap();
|
||||||
|
|
||||||
let home_set = CalendarHomeSet(
|
let home_set = CalendarHomeSet(
|
||||||
self.home_set
|
user.memberships()
|
||||||
.iter()
|
.into_iter()
|
||||||
.map(|&(home_name, _read_only)| format!("{}/{}", principal_url, home_name).into())
|
.map(|principal| Self::get_url(rmap, vec![principal]).unwrap())
|
||||||
|
.flat_map(|principal_url| {
|
||||||
|
self.home_set.iter().map(move |&(home_name, _read_only)| {
|
||||||
|
HrefElement::new(format!("{}/{}", &principal_url, home_name))
|
||||||
|
})
|
||||||
|
})
|
||||||
.collect(),
|
.collect(),
|
||||||
);
|
);
|
||||||
|
|
||||||
Ok(match prop {
|
Ok(match prop {
|
||||||
PrincipalPropWrapperName::Principal(prop) => {
|
PrincipalPropWrapperName::Principal(prop) => {
|
||||||
PrincipalPropWrapper::Principal(match prop {
|
PrincipalPropWrapper::Principal(match prop {
|
||||||
|
// TODO: principal types
|
||||||
PrincipalPropName::CalendarUserType => {
|
PrincipalPropName::CalendarUserType => {
|
||||||
PrincipalProp::CalendarUserType("INDIVIDUAL")
|
PrincipalProp::CalendarUserType("INDIVIDUAL")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ pub struct User {
|
|||||||
pub password: Option<String>,
|
pub password: Option<String>,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub app_tokens: Vec<String>,
|
pub app_tokens: Vec<String>,
|
||||||
|
#[serde(default)]
|
||||||
|
pub memberships: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl User {
|
impl User {
|
||||||
@@ -25,7 +27,16 @@ impl User {
|
|||||||
if self.id == principal {
|
if self.id == principal {
|
||||||
return true;
|
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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -35,6 +35,10 @@ pub fn cmd_gen_config(_args: GenConfigArgs) -> anyhow::Result<()> {
|
|||||||
app_tokens: vec![
|
app_tokens: vec![
|
||||||
"generate an app token hash with rustical pwhash --algorithm pbkdf2".to_owned(),
|
"generate an app token hash with rustical pwhash --algorithm pbkdf2".to_owned(),
|
||||||
],
|
],
|
||||||
|
memberships: vec![
|
||||||
|
"Here you can specify other principals this principal should be a member of"
|
||||||
|
.to_owned(),
|
||||||
|
],
|
||||||
}],
|
}],
|
||||||
}),
|
}),
|
||||||
data_store: DataStoreConfig::Sqlite(SqliteDataStoreConfig {
|
data_store: DataStoreConfig::Sqlite(SqliteDataStoreConfig {
|
||||||
|
|||||||
Reference in New Issue
Block a user