diff --git a/giterated-daemon/src/backend/git.rs b/giterated-daemon/src/backend/git.rs index c0a25e6..c5b2768 100644 --- a/giterated-daemon/src/backend/git.rs +++ b/giterated-daemon/src/backend/git.rs @@ -297,6 +297,7 @@ impl RepositoryBackend for GitBackend { .into()); } } else if matches!(repository.visibility, RepositoryVisibility::Private) { + info!("Unauthenticated"); // Unauthenticated users can never view private repositories return Err(Box::new(GitBackendError::RepositoryNotFound { diff --git a/giterated-daemon/src/message.rs b/giterated-daemon/src/message.rs index 86410cc..67d8205 100644 --- a/giterated-daemon/src/message.rs +++ b/giterated-daemon/src/message.rs @@ -108,7 +108,7 @@ impl FromMessage for AuthenticatedInstance { network_message: &NetworkMessage, state: &ConnectionState, ) -> Result { - let message: Authenticated = + let message: Authenticated> = serde_json::from_slice(&network_message).map_err(|e| Error::from(e))?; let (instance, signature) = message diff --git a/giterated-models/src/messages/user.rs b/giterated-models/src/messages/user.rs index 291368c..edc6214 100644 --- a/giterated-models/src/messages/user.rs +++ b/giterated-models/src/messages/user.rs @@ -1,8 +1,8 @@ use std::collections::HashMap; -use serde::{Deserialize, Serialize}; +use serde::{de::DeserializeOwned, Deserialize, Serialize}; -use crate::model::{repository::RepositorySummary, user::User}; +use crate::model::{repository::RepositorySummary, settings::Setting, user::User}; #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct UserDisplayNameRequest { @@ -54,12 +54,42 @@ pub struct UserSettingsResponse { pub settings: HashMap, } +impl UserSettingsResponse { + pub fn try_get(&self) -> Option { + let setting_member = self + .settings + .iter() + .filter(|(key, _)| key.as_str() == S::name()) + .next()?; + + serde_json::from_value(setting_member.1.clone()).ok() + } +} + #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct UserWriteSettingsRequest { pub user: User, pub settings: Vec<(String, serde_json::Value)>, } +impl UserWriteSettingsRequest { + pub fn set(&mut self, setting: S) { + self.settings.push(( + S::name().to_string(), + serde_json::to_value(setting).unwrap(), + )); + } + pub fn try_get(&self) -> Option { + let setting_member = self + .settings + .iter() + .filter(|(key, _)| key.as_str() == S::name()) + .next()?; + + serde_json::from_value(setting_member.1.clone()).ok() + } +} + #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct UserWriteSettingsResponse { // IDK? diff --git a/giterated-models/src/model/settings.rs b/giterated-models/src/model/settings.rs index a3ea173..701c091 100644 --- a/giterated-models/src/model/settings.rs +++ b/giterated-models/src/model/settings.rs @@ -1,14 +1,14 @@ use serde::{Deserialize, Serialize}; pub trait Setting: Serialize { - fn name(&self) -> &'static str; + fn name() -> &'static str; } #[derive(Debug, Serialize, Deserialize)] pub struct UserBio(pub String); impl Setting for UserBio { - fn name(&self) -> &'static str { + fn name() -> &'static str { "Bio" } } @@ -17,7 +17,7 @@ impl Setting for UserBio { pub struct UserDisplayName(pub String); impl Setting for UserDisplayName { - fn name(&self) -> &'static str { + fn name() -> &'static str { "Display Name" } }