close members

This commit is contained in:
yggverse 2025-01-23 16:47:19 +02:00
parent 054c30b238
commit f495453c84
2 changed files with 27 additions and 29 deletions

View file

@ -63,9 +63,10 @@ impl Item {
// Extract certificate details from PEM string // Extract certificate details from PEM string
Ok(ref pem) => match TlsCertificate::from_pem(pem) { Ok(ref pem) => match TlsCertificate::from_pem(pem) {
// Collect certificate scopes for item // Collect certificate scopes for item
Ok(ref certificate) => match scope(profile, profile_identity_id) { Ok(ref certificate) => {
// Ready to build `Item` GObject let scope = &profile.identity.auth.scope(profile_identity_id);
Ok(ref scope) => Ok(Object::builder()
Ok(Object::builder()
.property("value", profile_identity_id) .property("value", profile_identity_id)
.property("title", title::new_for_profile_identity_id(certificate)) .property("title", title::new_for_profile_identity_id(certificate))
.property( .property(
@ -84,9 +85,8 @@ impl Item {
auth_url, auth_url,
), ),
) )
.build()), .build())
Err(_) => todo!(), }
},
Err(e) => Err(Error::TlsCertificate(e)), Err(e) => Err(Error::TlsCertificate(e)),
}, },
Err(_) => todo!(), Err(_) => todo!(),
@ -106,7 +106,7 @@ impl Item {
Ok(ref pem) => match TlsCertificate::from_pem(pem) { Ok(ref pem) => match TlsCertificate::from_pem(pem) {
Ok(ref certificate) => { Ok(ref certificate) => {
// Get current scope // Get current scope
let scope = &scope(profile, profile_identity_id)?; let scope = &profile.identity.auth.scope(profile_identity_id);
// Update properties // Update properties
self.set_title(title::new_for_profile_identity_id(certificate)); self.set_title(title::new_for_profile_identity_id(certificate));
@ -153,22 +153,3 @@ impl Item {
} }
} }
} }
// Tools
/// Collect certificate scope vector from `Profile` database for `profile_identity_id`
fn scope(profile: &Rc<Profile>, profile_identity_id: i64) -> Result<Vec<String>, Error> {
match profile.identity.auth.database.records_scope(None) {
Ok(result) => {
let mut scope = Vec::new();
for auth in result
.iter()
.filter(|this| this.profile_identity_id == profile_identity_id)
{
scope.push(auth.scope.clone())
}
Ok(scope)
}
Err(_) => todo!(),
}
}

View file

@ -11,10 +11,10 @@ use memory::Memory;
use sqlite::{Connection, Transaction}; use sqlite::{Connection, Transaction};
use std::{rc::Rc, sync::RwLock}; use std::{rc::Rc, sync::RwLock};
/// API for `profile_identity_id` + `scope` auth pairs operations /// Auth pair operations
pub struct Auth { pub struct Auth {
pub database: Rc<Database>, database: Rc<Database>,
pub memory: Rc<Memory>, memory: Rc<Memory>,
} }
impl Auth { impl Auth {
@ -124,6 +124,23 @@ impl Auth {
.is_some_and(|auth| auth.profile_identity_id == profile_identity_id) .is_some_and(|auth| auth.profile_identity_id == profile_identity_id)
} }
/// Collect certificate scope vector from `Profile` database for `profile_identity_id`
pub fn scope(&self, profile_identity_id: i64) -> Vec<String> {
let mut scope = Vec::new();
match self.database.records_scope(None) {
Ok(result) => {
for auth in result
.iter()
.filter(|this| this.profile_identity_id == profile_identity_id)
{
scope.push(auth.scope.clone())
}
}
Err(_) => todo!(),
}
scope
}
/// Get memory item string match request /// Get memory item string match request
pub fn get(&self, request: &str) -> Option<memory::Auth> { pub fn get(&self, request: &str) -> Option<memory::Auth> {
self.memory.match_scope(&filter_scope(request)) self.memory.match_scope(&filter_scope(request))