JavaScript is disabled, refresh for a better experience. ambee/giterated

ambee/giterated

Git repository hosting, collaboration, and discovery for the Fediverse.

Add API for manipulating settings requests

Amber - ⁨2⁩ years ago

parent: tbd commit: ⁨b5e5847

Showing ⁨⁨4⁩ changed files⁩ with ⁨⁨37⁩ insertions⁩ and ⁨⁨6⁩ deletions⁩

giterated-daemon/src/backend/git.rs

View file
@@ -297,6 +297,7 @@ impl RepositoryBackend for GitBackend {
297 297 .into());
298 298 }
299 299 } else if matches!(repository.visibility, RepositoryVisibility::Private) {
300 info!("Unauthenticated");
300 301 // Unauthenticated users can never view private repositories
301 302
302 303 return Err(Box::new(GitBackendError::RepositoryNotFound {

giterated-daemon/src/message.rs

View file
@@ -108,7 +108,7 @@ impl FromMessage<ConnectionState> for AuthenticatedInstance {
108 108 network_message: &NetworkMessage,
109 109 state: &ConnectionState,
110 110 ) -> Result<Self, Error> {
111 let message: Authenticated<Value> =
111 let message: Authenticated<HashMap<String, Value>> =
112 112 serde_json::from_slice(&network_message).map_err(|e| Error::from(e))?;
113 113
114 114 let (instance, signature) = message

giterated-models/src/messages/user.rs

View file
@@ -1,8 +1,8 @@
1 1 use std::collections::HashMap;
2 2
3 use serde::{Deserialize, Serialize};
3 use serde::{de::DeserializeOwned, Deserialize, Serialize};
4 4
5 use crate::model::{repository::RepositorySummary, user::User};
5 use crate::model::{repository::RepositorySummary, settings::Setting, user::User};
6 6
7 7 #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
8 8 pub struct UserDisplayNameRequest {
@@ -54,12 +54,42 @@ pub struct UserSettingsResponse {
54 54 pub settings: HashMap<String, serde_json::Value>,
55 55 }
56 56
57 impl UserSettingsResponse {
58 pub fn try_get<S: Setting + DeserializeOwned>(&self) -> Option<S> {
59 let setting_member = self
60 .settings
61 .iter()
62 .filter(|(key, _)| key.as_str() == S::name())
63 .next()?;
64
65 serde_json::from_value(setting_member.1.clone()).ok()
66 }
67 }
68
57 69 #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
58 70 pub struct UserWriteSettingsRequest {
59 71 pub user: User,
60 72 pub settings: Vec<(String, serde_json::Value)>,
61 73 }
62 74
75 impl UserWriteSettingsRequest {
76 pub fn set<S: Setting>(&mut self, setting: S) {
77 self.settings.push((
78 S::name().to_string(),
79 serde_json::to_value(setting).unwrap(),
80 ));
81 }
82 pub fn try_get<S: Setting + DeserializeOwned>(&self) -> Option<S> {
83 let setting_member = self
84 .settings
85 .iter()
86 .filter(|(key, _)| key.as_str() == S::name())
87 .next()?;
88
89 serde_json::from_value(setting_member.1.clone()).ok()
90 }
91 }
92
63 93 #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
64 94 pub struct UserWriteSettingsResponse {
65 95 // IDK?

giterated-models/src/model/settings.rs

View file
@@ -1,14 +1,14 @@
1 1 use serde::{Deserialize, Serialize};
2 2
3 3 pub trait Setting: Serialize {
4 fn name(&self) -> &'static str;
4 fn name() -> &'static str;
5 5 }
6 6
7 7 #[derive(Debug, Serialize, Deserialize)]
8 8 pub struct UserBio(pub String);
9 9
10 10 impl Setting for UserBio {
11 fn name(&self) -> &'static str {
11 fn name() -> &'static str {
12 12 "Bio"
13 13 }
14 14 }
@@ -17,7 +17,7 @@ impl Setting for UserBio {
17 17 pub struct UserDisplayName(pub String);
18 18
19 19 impl Setting for UserDisplayName {
20 fn name(&self) -> &'static str {
20 fn name() -> &'static str {
21 21 "Display Name"
22 22 }
23 23 }