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

ambee/giterated

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

Move user settings to user settings

Amber - ⁨2⁩ years ago

parent: tbd commit: ⁨fd846f6

Showing ⁨⁨12⁩ changed files⁩ with ⁨⁨386⁩ insertions⁩ and ⁨⁨17⁩ deletions⁩

giterated-daemon/.sqlx/query-2888158ffe851e3cf90d585d03d98a336e1c0871fa395b50bfd8258183c9fccf.json

View file
@@ -0,0 +1,56 @@
1 {
2 "db_name": "PostgreSQL",
3 "query": "INSERT INTO users VALUES ($1, null, $2, $3, $4, $5) returning *",
4 "describe": {
5 "columns": [
6 {
7 "ordinal": 0,
8 "name": "username",
9 "type_info": "Text"
10 },
11 {
12 "ordinal": 1,
13 "name": "image_url",
14 "type_info": "Text"
15 },
16 {
17 "ordinal": 2,
18 "name": "email",
19 "type_info": "Text"
20 },
21 {
22 "ordinal": 3,
23 "name": "password",
24 "type_info": "Text"
25 },
26 {
27 "ordinal": 4,
28 "name": "public_key",
29 "type_info": "Text"
30 },
31 {
32 "ordinal": 5,
33 "name": "enc_private_key",
34 "type_info": "Text"
35 }
36 ],
37 "parameters": {
38 "Left": [
39 "Text",
40 "Text",
41 "Text",
42 "Text",
43 "Text"
44 ]
45 },
46 "nullable": [
47 false,
48 false,
49 true,
50 false,
51 false,
52 false
53 ]
54 },
55 "hash": "2888158ffe851e3cf90d585d03d98a336e1c0871fa395b50bfd8258183c9fccf"
56 }

giterated-daemon/.sqlx/query-3f9c634ce803bbdf38b2079ede3ba7b006b839d916154a924ab23ee6afad4a1c.json

View file
@@ -0,0 +1,15 @@
1 {
2 "db_name": "PostgreSQL",
3 "query": "DELETE FROM repositories WHERE owner_user = $1 AND name = $2",
4 "describe": {
5 "columns": [],
6 "parameters": {
7 "Left": [
8 "Text",
9 "Text"
10 ]
11 },
12 "nullable": []
13 },
14 "hash": "3f9c634ce803bbdf38b2079ede3ba7b006b839d916154a924ab23ee6afad4a1c"
15 }

giterated-daemon/.sqlx/query-606364c79e0990deb07dfbe6c32b3d302d083ec5333f3a5ce04113c38a041100.json

View file
@@ -0,0 +1,52 @@
1 {
2 "db_name": "PostgreSQL",
3 "query": "SELECT * FROM users WHERE username = $1",
4 "describe": {
5 "columns": [
6 {
7 "ordinal": 0,
8 "name": "username",
9 "type_info": "Text"
10 },
11 {
12 "ordinal": 1,
13 "name": "image_url",
14 "type_info": "Text"
15 },
16 {
17 "ordinal": 2,
18 "name": "email",
19 "type_info": "Text"
20 },
21 {
22 "ordinal": 3,
23 "name": "password",
24 "type_info": "Text"
25 },
26 {
27 "ordinal": 4,
28 "name": "public_key",
29 "type_info": "Text"
30 },
31 {
32 "ordinal": 5,
33 "name": "enc_private_key",
34 "type_info": "Text"
35 }
36 ],
37 "parameters": {
38 "Left": [
39 "Text"
40 ]
41 },
42 "nullable": [
43 false,
44 false,
45 true,
46 false,
47 false,
48 false
49 ]
50 },
51 "hash": "606364c79e0990deb07dfbe6c32b3d302d083ec5333f3a5ce04113c38a041100"
52 }

giterated-daemon/.sqlx/query-b56ee50882e7eae84981cbfc91b5a53b1150d57a2da8fad5eebb9b1a88d7ccab.json

View file
@@ -0,0 +1,16 @@
1 {
2 "db_name": "PostgreSQL",
3 "query": "INSERT INTO user_settings VALUES ($1, $2, $3) ON CONFLICT (username, name) DO UPDATE SET value = $3",
4 "describe": {
5 "columns": [],
6 "parameters": {
7 "Left": [
8 "Text",
9 "Text",
10 "Text"
11 ]
12 },
13 "nullable": []
14 },
15 "hash": "b56ee50882e7eae84981cbfc91b5a53b1150d57a2da8fad5eebb9b1a88d7ccab"
16 }

giterated-daemon/.sqlx/query-bbd782d2ea06a991db7e2cddbab3796cf695dbe9e645d969598d9de8153f80b6.json

View file
@@ -0,0 +1,58 @@
1 {
2 "db_name": "PostgreSQL",
3 "query": "SELECT owner_user, name, description, visibility as \"visibility: _\", default_branch FROM repositories WHERE owner_user = $1 AND name = $2",
4 "describe": {
5 "columns": [
6 {
7 "ordinal": 0,
8 "name": "owner_user",
9 "type_info": "Text"
10 },
11 {
12 "ordinal": 1,
13 "name": "name",
14 "type_info": "Text"
15 },
16 {
17 "ordinal": 2,
18 "name": "description",
19 "type_info": "Text"
20 },
21 {
22 "ordinal": 3,
23 "name": "visibility: _",
24 "type_info": {
25 "Custom": {
26 "name": "visibility",
27 "kind": {
28 "Enum": [
29 "public",
30 "unlisted",
31 "private"
32 ]
33 }
34 }
35 }
36 },
37 {
38 "ordinal": 4,
39 "name": "default_branch",
40 "type_info": "Text"
41 }
42 ],
43 "parameters": {
44 "Left": [
45 "Text",
46 "Text"
47 ]
48 },
49 "nullable": [
50 false,
51 false,
52 true,
53 false,
54 false
55 ]
56 },
57 "hash": "bbd782d2ea06a991db7e2cddbab3796cf695dbe9e645d969598d9de8153f80b6"
58 }

giterated-daemon/.sqlx/query-ca33818a5e95965aa6330d004be4de2d1d5786541a64fbe2afb7b8254ffbfbf0.json

View file
@@ -0,0 +1,57 @@
1 {
2 "db_name": "PostgreSQL",
3 "query": "SELECT visibility as \"visibility: _\", owner_user, name, description, default_branch FROM repositories WHERE owner_user = $1",
4 "describe": {
5 "columns": [
6 {
7 "ordinal": 0,
8 "name": "visibility: _",
9 "type_info": {
10 "Custom": {
11 "name": "visibility",
12 "kind": {
13 "Enum": [
14 "public",
15 "unlisted",
16 "private"
17 ]
18 }
19 }
20 }
21 },
22 {
23 "ordinal": 1,
24 "name": "owner_user",
25 "type_info": "Text"
26 },
27 {
28 "ordinal": 2,
29 "name": "name",
30 "type_info": "Text"
31 },
32 {
33 "ordinal": 3,
34 "name": "description",
35 "type_info": "Text"
36 },
37 {
38 "ordinal": 4,
39 "name": "default_branch",
40 "type_info": "Text"
41 }
42 ],
43 "parameters": {
44 "Left": [
45 "Text"
46 ]
47 },
48 "nullable": [
49 false,
50 false,
51 false,
52 true,
53 false
54 ]
55 },
56 "hash": "ca33818a5e95965aa6330d004be4de2d1d5786541a64fbe2afb7b8254ffbfbf0"
57 }

giterated-daemon/.sqlx/query-df2100447de87e6200a2d9af6b1adacf9892d51abe3ea588c975cc37c3a6825f.json

View file
@@ -0,0 +1,72 @@
1 {
2 "db_name": "PostgreSQL",
3 "query": "INSERT INTO repositories VALUES ($1, $2, $3, $4, $5) RETURNING owner_user, name, description, visibility as \"visibility: _\", default_branch",
4 "describe": {
5 "columns": [
6 {
7 "ordinal": 0,
8 "name": "owner_user",
9 "type_info": "Text"
10 },
11 {
12 "ordinal": 1,
13 "name": "name",
14 "type_info": "Text"
15 },
16 {
17 "ordinal": 2,
18 "name": "description",
19 "type_info": "Text"
20 },
21 {
22 "ordinal": 3,
23 "name": "visibility: _",
24 "type_info": {
25 "Custom": {
26 "name": "visibility",
27 "kind": {
28 "Enum": [
29 "public",
30 "unlisted",
31 "private"
32 ]
33 }
34 }
35 }
36 },
37 {
38 "ordinal": 4,
39 "name": "default_branch",
40 "type_info": "Text"
41 }
42 ],
43 "parameters": {
44 "Left": [
45 "Text",
46 "Text",
47 "Text",
48 {
49 "Custom": {
50 "name": "visibility",
51 "kind": {
52 "Enum": [
53 "public",
54 "unlisted",
55 "private"
56 ]
57 }
58 }
59 },
60 "Text"
61 ]
62 },
63 "nullable": [
64 false,
65 false,
66 true,
67 false,
68 false
69 ]
70 },
71 "hash": "df2100447de87e6200a2d9af6b1adacf9892d51abe3ea588c975cc37c3a6825f"
72 }

giterated-daemon/.sqlx/query-df25d6977ebaeea72c5f1648100fbbd30365d0e20194a80fd291f979e73d2e7c.json

View file
@@ -0,0 +1,34 @@
1 {
2 "db_name": "PostgreSQL",
3 "query": "SELECT * FROM user_settings WHERE username = $1",
4 "describe": {
5 "columns": [
6 {
7 "ordinal": 0,
8 "name": "username",
9 "type_info": "Text"
10 },
11 {
12 "ordinal": 1,
13 "name": "name",
14 "type_info": "Text"
15 },
16 {
17 "ordinal": 2,
18 "name": "value",
19 "type_info": "Text"
20 }
21 ],
22 "parameters": {
23 "Left": [
24 "Text"
25 ]
26 },
27 "nullable": [
28 false,
29 false,
30 false
31 ]
32 },
33 "hash": "df25d6977ebaeea72c5f1648100fbbd30365d0e20194a80fd291f979e73d2e7c"
34 }

giterated-daemon/migrations/20230905055314_modify_users.sql

View file
@@ -0,0 +1,2 @@
1 ALTER TABLE users DROP COLUMN bio;
2 ALTER TABLE users DROP COLUMN display_name;
2 \ No newline at end of file

giterated-daemon/src/backend/user.rs

View file
@@ -17,7 +17,11 @@ use giterated_models::{
17 17 UserDisplayNameRequest, UserDisplayNameResponse,
18 18 },
19 19 },
20 model::{instance::Instance, user::User, settings::{UserBio, Setting, UserDisplayName}},
20 model::{
21 instance::Instance,
22 settings::{Setting, UserBio, UserDisplayName},
23 user::User,
24 },
21 25 };
22 26 use rsa::{
23 27 pkcs8::{EncodePrivateKey, EncodePublicKey},
@@ -60,12 +64,16 @@ impl UserBackend for UserAuth {
60 64 ) -> Result<UserDisplayNameResponse, Error> {
61 65 let settings = self.settings(&request.user).await?;
62 66
63 let name = settings.iter().find(|setting| &setting.0 == UserDisplayName::name());
67 let name = settings
68 .iter()
69 .find(|setting| &setting.0 == UserDisplayName::name());
64 70
65 71 if let Some((_, name)) = name {
66 72 let name: UserDisplayName = serde_json::from_value(name.clone()).unwrap();
67 73
68 Ok(UserDisplayNameResponse { display_name: Some(name.0) })
74 Ok(UserDisplayNameResponse {
75 display_name: Some(name.0),
76 })
69 77 } else {
70 78 Ok(UserDisplayNameResponse { display_name: None })
71 79 }
@@ -92,12 +100,14 @@ impl UserBackend for UserAuth {
92 100 async fn bio(&mut self, request: UserBioRequest) -> Result<UserBioResponse, Error> {
93 101 let settings = self.settings(&request.user).await?;
94 102
95 let bio = settings.iter().find(|setting| &setting.0 == UserBio::name());
103 let bio = settings
104 .iter()
105 .find(|setting| &setting.0 == UserBio::name());
96 106
97 107 if let Some((_, bio)) = bio {
98 108 let bio: UserBio = serde_json::from_value(bio.clone()).unwrap();
99 109
100 Ok(UserBioResponse { bio: Some(bio.0)})
110 Ok(UserBioResponse { bio: Some(bio.0) })
101 111 } else {
102 112 Ok(UserBioResponse { bio: None })
103 113 }
@@ -129,7 +139,7 @@ impl UserBackend for UserAuth {
129 139 }
130 140 })
131 141 .filter_map(|row| async move {
132 if let Ok(value) = serde_json::from_str(&format!("\"{}\"", row.value)) {
142 if let Ok(value) = serde_json::from_str(&row.value) {
133 143 Some((row.name, value))
134 144 } else {
135 145 None
@@ -204,7 +214,7 @@ impl AuthBackend for UserAuth {
204 214
205 215 let user = match sqlx::query_as!(
206 216 UserRow,
207 r#"INSERT INTO users VALUES ($1, null, $2, null, null, $3, $4, $5) returning *"#,
217 r#"INSERT INTO users VALUES ($1, null, $2, $3, $4, $5) returning *"#,
208 218 request.username,
209 219 "example.com",
210 220 password_hash,
@@ -251,8 +261,6 @@ impl AuthBackend for UserAuth {
251 261 struct UserRow {
252 262 pub username: String,
253 263 pub image_url: Option<String>,
254 pub display_name: Option<String>,
255 pub bio: Option<String>,
256 264 pub email: Option<String>,
257 265 pub password: String,
258 266 pub public_key: String,

giterated-daemon/src/connection/wrapper.rs

View file
@@ -81,11 +81,6 @@ pub async fn connection_wrapper(
81 81 _ => continue,
82 82 };
83 83
84 info!(
85 "Received payload: {}",
86 std::str::from_utf8(&payload).unwrap()
87 );
88
89 84 let message = NetworkMessage(payload.clone());
90 85
91 86 if !handshaked {

giterated-daemon/src/message.rs

View file
@@ -1,4 +1,4 @@
1 use std::{collections::HashMap, ops::Deref};
1 use std::{collections::HashMap, fmt::Debug, ops::Deref};
2 2
3 3 use anyhow::Error;
4 4 use futures_util::Future;
@@ -240,12 +240,16 @@ where
240 240 #[async_trait::async_trait]
241 241 impl<T, S> FromMessage<S> for Message<T>
242 242 where
243 T: DeserializeOwned + Send + Sync + Serialize,
243 T: DeserializeOwned + Send + Sync + Serialize + Debug,
244 244 S: Clone + Send + Sync,
245 245 {
246 246 async fn from_message(message: &NetworkMessage, _: &S) -> Result<Self, Error> {
247 247 let payload: AuthenticatedPayload = serde_json::from_slice(&message)?;
248 Ok(Message(bincode::deserialize(&payload.payload)?))
248 let payload = bincode::deserialize(&payload.payload)?;
249
250 info!("Deserialized payload: {:#?}", payload);
251
252 Ok(Message(payload))
249 253 }
250 254 }
251 255