Add set-description to group tooling ()

This commit is contained in:
Firstyear 2025-03-18 21:54:20 +10:00 committed by GitHub
parent 1e91f244a2
commit b13951a79b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 47 additions and 1 deletions
libs/client/src
tools/cli/src
cli/group
opt

View file

@ -195,4 +195,20 @@ impl KanidmClient {
self.perform_get_request(&format!("/v1/group/{}/_attr/mail", id))
.await
}
pub async fn idm_group_purge_description(&self, id: &str) -> Result<(), ClientError> {
self.idm_group_purge_attr(id, "description").await
}
pub async fn idm_group_set_description(
&self,
id: &str,
description: &str,
) -> Result<(), ClientError> {
self.perform_put_request(
&format!("/v1/group/{}/_attr/description", id),
&[description],
)
.await
}
}

View file

@ -16,7 +16,9 @@ impl GroupOpt {
GroupOpt::RemoveMembers(gcopt) => gcopt.copt.debug,
GroupOpt::SetMembers(gcopt) => gcopt.copt.debug,
GroupOpt::PurgeMembers(gcopt) => gcopt.copt.debug,
GroupOpt::Rename { copt, .. } | GroupOpt::SetMail { copt, .. } => copt.debug,
GroupOpt::SetDescription { copt, .. }
| GroupOpt::Rename { copt, .. }
| GroupOpt::SetMail { copt, .. } => copt.debug,
GroupOpt::Posix { commands } => match commands {
GroupPosix::Show(gcopt) => gcopt.copt.debug,
GroupPosix::Set(gcopt) => gcopt.copt.debug,
@ -178,6 +180,26 @@ impl GroupOpt {
Ok(_) => println!("Successfully set mail for group {}", name.as_str()),
}
}
GroupOpt::SetDescription {
copt,
name,
description,
} => {
let client = copt.to_client(OpType::Write).await;
let result = if let Some(description) = description {
client
.idm_group_set_description(name.as_str(), description.as_str())
.await
} else {
client.idm_group_purge_description(name.as_str()).await
};
match result {
Err(e) => handle_client_error(e, copt.output_mode),
Ok(_) => println!("Successfully set description for group {}", name.as_str()),
}
}
GroupOpt::Rename {
copt,
name,

View file

@ -348,6 +348,14 @@ pub enum GroupOpt {
name: String,
mail: Vec<String>,
},
/// Set the description of this group. If no description is provided, the value is cleared
#[clap(name = "set-description")]
SetDescription {
#[clap(flatten)]
copt: CommonOpt,
name: String,
description: Option<String>,
},
/// Set a new entry-managed-by for this group.
#[clap(name = "set-entry-manager")]
SetEntryManagedBy {