Add member search to user store

This commit is contained in:
Lennart
2025-06-12 19:50:32 +02:00
parent 41d5c72e4e
commit feb8b3ff09
2 changed files with 15 additions and 0 deletions

View File

@@ -24,6 +24,7 @@ pub trait AuthenticationProvider: Send + Sync + 'static {
async fn add_membership(&self, principal: &str, member_of: &str) -> Result<(), Error>; async fn add_membership(&self, principal: &str, member_of: &str) -> Result<(), Error>;
async fn remove_membership(&self, principal: &str, member_of: &str) -> Result<(), Error>; async fn remove_membership(&self, principal: &str, member_of: &str) -> Result<(), Error>;
async fn list_members(&self, principal: &str) -> Result<Vec<String>, Error>;
} }
pub use middleware::AuthenticationMiddleware; pub use middleware::AuthenticationMiddleware;

View File

@@ -249,4 +249,18 @@ impl AuthenticationProvider for SqlitePrincipalStore {
.map_err(crate::Error::from)?; .map_err(crate::Error::from)?;
Ok(()) Ok(())
} }
#[instrument]
async fn list_members(&self, principal: &str) -> Result<Vec<String>, Error> {
Ok(sqlx::query!(
r#"SELECT principal FROM memberships WHERE member_of = ?"#,
principal
)
.fetch_all(&self.db)
.await
.map_err(crate::Error::from)?
.into_iter()
.map(|record| record.principal)
.collect())
}
} }