diff --git a/giterated-daemon/.sqlx/query-2888158ffe851e3cf90d585d03d98a336e1c0871fa395b50bfd8258183c9fccf.json b/giterated-daemon/.sqlx/query-2888158ffe851e3cf90d585d03d98a336e1c0871fa395b50bfd8258183c9fccf.json new file mode 100644 index 0000000..0f3e629 --- /dev/null +++ b/giterated-daemon/.sqlx/query-2888158ffe851e3cf90d585d03d98a336e1c0871fa395b50bfd8258183c9fccf.json @@ -0,0 +1,56 @@ +{ + "db_name": "PostgreSQL", + "query": "INSERT INTO users VALUES ($1, null, $2, $3, $4, $5) returning *", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "username", + "type_info": "Text" + }, + { + "ordinal": 1, + "name": "image_url", + "type_info": "Text" + }, + { + "ordinal": 2, + "name": "email", + "type_info": "Text" + }, + { + "ordinal": 3, + "name": "password", + "type_info": "Text" + }, + { + "ordinal": 4, + "name": "public_key", + "type_info": "Text" + }, + { + "ordinal": 5, + "name": "enc_private_key", + "type_info": "Text" + } + ], + "parameters": { + "Left": [ + "Text", + "Text", + "Text", + "Text", + "Text" + ] + }, + "nullable": [ + false, + false, + true, + false, + false, + false + ] + }, + "hash": "2888158ffe851e3cf90d585d03d98a336e1c0871fa395b50bfd8258183c9fccf" +} diff --git a/giterated-daemon/.sqlx/query-3f9c634ce803bbdf38b2079ede3ba7b006b839d916154a924ab23ee6afad4a1c.json b/giterated-daemon/.sqlx/query-3f9c634ce803bbdf38b2079ede3ba7b006b839d916154a924ab23ee6afad4a1c.json new file mode 100644 index 0000000..e2efbca --- /dev/null +++ b/giterated-daemon/.sqlx/query-3f9c634ce803bbdf38b2079ede3ba7b006b839d916154a924ab23ee6afad4a1c.json @@ -0,0 +1,15 @@ +{ + "db_name": "PostgreSQL", + "query": "DELETE FROM repositories WHERE owner_user = $1 AND name = $2", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Text", + "Text" + ] + }, + "nullable": [] + }, + "hash": "3f9c634ce803bbdf38b2079ede3ba7b006b839d916154a924ab23ee6afad4a1c" +} diff --git a/giterated-daemon/.sqlx/query-606364c79e0990deb07dfbe6c32b3d302d083ec5333f3a5ce04113c38a041100.json b/giterated-daemon/.sqlx/query-606364c79e0990deb07dfbe6c32b3d302d083ec5333f3a5ce04113c38a041100.json new file mode 100644 index 0000000..ce3dbde --- /dev/null +++ b/giterated-daemon/.sqlx/query-606364c79e0990deb07dfbe6c32b3d302d083ec5333f3a5ce04113c38a041100.json @@ -0,0 +1,52 @@ +{ + "db_name": "PostgreSQL", + "query": "SELECT * FROM users WHERE username = $1", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "username", + "type_info": "Text" + }, + { + "ordinal": 1, + "name": "image_url", + "type_info": "Text" + }, + { + "ordinal": 2, + "name": "email", + "type_info": "Text" + }, + { + "ordinal": 3, + "name": "password", + "type_info": "Text" + }, + { + "ordinal": 4, + "name": "public_key", + "type_info": "Text" + }, + { + "ordinal": 5, + "name": "enc_private_key", + "type_info": "Text" + } + ], + "parameters": { + "Left": [ + "Text" + ] + }, + "nullable": [ + false, + false, + true, + false, + false, + false + ] + }, + "hash": "606364c79e0990deb07dfbe6c32b3d302d083ec5333f3a5ce04113c38a041100" +} diff --git a/giterated-daemon/.sqlx/query-b56ee50882e7eae84981cbfc91b5a53b1150d57a2da8fad5eebb9b1a88d7ccab.json b/giterated-daemon/.sqlx/query-b56ee50882e7eae84981cbfc91b5a53b1150d57a2da8fad5eebb9b1a88d7ccab.json new file mode 100644 index 0000000..9832255 --- /dev/null +++ b/giterated-daemon/.sqlx/query-b56ee50882e7eae84981cbfc91b5a53b1150d57a2da8fad5eebb9b1a88d7ccab.json @@ -0,0 +1,16 @@ +{ + "db_name": "PostgreSQL", + "query": "INSERT INTO user_settings VALUES ($1, $2, $3) ON CONFLICT (username, name) DO UPDATE SET value = $3", + "describe": { + "columns": [], + "parameters": { + "Left": [ + "Text", + "Text", + "Text" + ] + }, + "nullable": [] + }, + "hash": "b56ee50882e7eae84981cbfc91b5a53b1150d57a2da8fad5eebb9b1a88d7ccab" +} diff --git a/giterated-daemon/.sqlx/query-bbd782d2ea06a991db7e2cddbab3796cf695dbe9e645d969598d9de8153f80b6.json b/giterated-daemon/.sqlx/query-bbd782d2ea06a991db7e2cddbab3796cf695dbe9e645d969598d9de8153f80b6.json new file mode 100644 index 0000000..2c92c0e --- /dev/null +++ b/giterated-daemon/.sqlx/query-bbd782d2ea06a991db7e2cddbab3796cf695dbe9e645d969598d9de8153f80b6.json @@ -0,0 +1,58 @@ +{ + "db_name": "PostgreSQL", + "query": "SELECT owner_user, name, description, visibility as \"visibility: _\", default_branch FROM repositories WHERE owner_user = $1 AND name = $2", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "owner_user", + "type_info": "Text" + }, + { + "ordinal": 1, + "name": "name", + "type_info": "Text" + }, + { + "ordinal": 2, + "name": "description", + "type_info": "Text" + }, + { + "ordinal": 3, + "name": "visibility: _", + "type_info": { + "Custom": { + "name": "visibility", + "kind": { + "Enum": [ + "public", + "unlisted", + "private" + ] + } + } + } + }, + { + "ordinal": 4, + "name": "default_branch", + "type_info": "Text" + } + ], + "parameters": { + "Left": [ + "Text", + "Text" + ] + }, + "nullable": [ + false, + false, + true, + false, + false + ] + }, + "hash": "bbd782d2ea06a991db7e2cddbab3796cf695dbe9e645d969598d9de8153f80b6" +} diff --git a/giterated-daemon/.sqlx/query-ca33818a5e95965aa6330d004be4de2d1d5786541a64fbe2afb7b8254ffbfbf0.json b/giterated-daemon/.sqlx/query-ca33818a5e95965aa6330d004be4de2d1d5786541a64fbe2afb7b8254ffbfbf0.json new file mode 100644 index 0000000..9cc89e3 --- /dev/null +++ b/giterated-daemon/.sqlx/query-ca33818a5e95965aa6330d004be4de2d1d5786541a64fbe2afb7b8254ffbfbf0.json @@ -0,0 +1,57 @@ +{ + "db_name": "PostgreSQL", + "query": "SELECT visibility as \"visibility: _\", owner_user, name, description, default_branch FROM repositories WHERE owner_user = $1", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "visibility: _", + "type_info": { + "Custom": { + "name": "visibility", + "kind": { + "Enum": [ + "public", + "unlisted", + "private" + ] + } + } + } + }, + { + "ordinal": 1, + "name": "owner_user", + "type_info": "Text" + }, + { + "ordinal": 2, + "name": "name", + "type_info": "Text" + }, + { + "ordinal": 3, + "name": "description", + "type_info": "Text" + }, + { + "ordinal": 4, + "name": "default_branch", + "type_info": "Text" + } + ], + "parameters": { + "Left": [ + "Text" + ] + }, + "nullable": [ + false, + false, + false, + true, + false + ] + }, + "hash": "ca33818a5e95965aa6330d004be4de2d1d5786541a64fbe2afb7b8254ffbfbf0" +} diff --git a/giterated-daemon/.sqlx/query-df2100447de87e6200a2d9af6b1adacf9892d51abe3ea588c975cc37c3a6825f.json b/giterated-daemon/.sqlx/query-df2100447de87e6200a2d9af6b1adacf9892d51abe3ea588c975cc37c3a6825f.json new file mode 100644 index 0000000..747040f --- /dev/null +++ b/giterated-daemon/.sqlx/query-df2100447de87e6200a2d9af6b1adacf9892d51abe3ea588c975cc37c3a6825f.json @@ -0,0 +1,72 @@ +{ + "db_name": "PostgreSQL", + "query": "INSERT INTO repositories VALUES ($1, $2, $3, $4, $5) RETURNING owner_user, name, description, visibility as \"visibility: _\", default_branch", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "owner_user", + "type_info": "Text" + }, + { + "ordinal": 1, + "name": "name", + "type_info": "Text" + }, + { + "ordinal": 2, + "name": "description", + "type_info": "Text" + }, + { + "ordinal": 3, + "name": "visibility: _", + "type_info": { + "Custom": { + "name": "visibility", + "kind": { + "Enum": [ + "public", + "unlisted", + "private" + ] + } + } + } + }, + { + "ordinal": 4, + "name": "default_branch", + "type_info": "Text" + } + ], + "parameters": { + "Left": [ + "Text", + "Text", + "Text", + { + "Custom": { + "name": "visibility", + "kind": { + "Enum": [ + "public", + "unlisted", + "private" + ] + } + } + }, + "Text" + ] + }, + "nullable": [ + false, + false, + true, + false, + false + ] + }, + "hash": "df2100447de87e6200a2d9af6b1adacf9892d51abe3ea588c975cc37c3a6825f" +} diff --git a/giterated-daemon/.sqlx/query-df25d6977ebaeea72c5f1648100fbbd30365d0e20194a80fd291f979e73d2e7c.json b/giterated-daemon/.sqlx/query-df25d6977ebaeea72c5f1648100fbbd30365d0e20194a80fd291f979e73d2e7c.json new file mode 100644 index 0000000..6fe8469 --- /dev/null +++ b/giterated-daemon/.sqlx/query-df25d6977ebaeea72c5f1648100fbbd30365d0e20194a80fd291f979e73d2e7c.json @@ -0,0 +1,34 @@ +{ + "db_name": "PostgreSQL", + "query": "SELECT * FROM user_settings WHERE username = $1", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "username", + "type_info": "Text" + }, + { + "ordinal": 1, + "name": "name", + "type_info": "Text" + }, + { + "ordinal": 2, + "name": "value", + "type_info": "Text" + } + ], + "parameters": { + "Left": [ + "Text" + ] + }, + "nullable": [ + false, + false, + false + ] + }, + "hash": "df25d6977ebaeea72c5f1648100fbbd30365d0e20194a80fd291f979e73d2e7c" +} diff --git a/giterated-daemon/migrations/20230905055314_modify_users.sql b/giterated-daemon/migrations/20230905055314_modify_users.sql new file mode 100644 index 0000000..f8c1e5d --- /dev/null +++ b/giterated-daemon/migrations/20230905055314_modify_users.sql @@ -0,0 +1,2 @@ +ALTER TABLE users DROP COLUMN bio; +ALTER TABLE users DROP COLUMN display_name; \ No newline at end of file diff --git a/giterated-daemon/src/backend/user.rs b/giterated-daemon/src/backend/user.rs index ea5569a..9662666 100644 --- a/giterated-daemon/src/backend/user.rs +++ b/giterated-daemon/src/backend/user.rs @@ -17,7 +17,11 @@ use giterated_models::{ UserDisplayNameRequest, UserDisplayNameResponse, }, }, - model::{instance::Instance, user::User, settings::{UserBio, Setting, UserDisplayName}}, + model::{ + instance::Instance, + settings::{Setting, UserBio, UserDisplayName}, + user::User, + }, }; use rsa::{ pkcs8::{EncodePrivateKey, EncodePublicKey}, @@ -60,12 +64,16 @@ impl UserBackend for UserAuth { ) -> Result { let settings = self.settings(&request.user).await?; - let name = settings.iter().find(|setting| &setting.0 == UserDisplayName::name()); + let name = settings + .iter() + .find(|setting| &setting.0 == UserDisplayName::name()); if let Some((_, name)) = name { let name: UserDisplayName = serde_json::from_value(name.clone()).unwrap(); - Ok(UserDisplayNameResponse { display_name: Some(name.0) }) + Ok(UserDisplayNameResponse { + display_name: Some(name.0), + }) } else { Ok(UserDisplayNameResponse { display_name: None }) } @@ -92,12 +100,14 @@ impl UserBackend for UserAuth { async fn bio(&mut self, request: UserBioRequest) -> Result { let settings = self.settings(&request.user).await?; - let bio = settings.iter().find(|setting| &setting.0 == UserBio::name()); + let bio = settings + .iter() + .find(|setting| &setting.0 == UserBio::name()); if let Some((_, bio)) = bio { let bio: UserBio = serde_json::from_value(bio.clone()).unwrap(); - Ok(UserBioResponse { bio: Some(bio.0)}) + Ok(UserBioResponse { bio: Some(bio.0) }) } else { Ok(UserBioResponse { bio: None }) } @@ -129,7 +139,7 @@ impl UserBackend for UserAuth { } }) .filter_map(|row| async move { - if let Ok(value) = serde_json::from_str(&format!("\"{}\"", row.value)) { + if let Ok(value) = serde_json::from_str(&row.value) { Some((row.name, value)) } else { None @@ -204,7 +214,7 @@ impl AuthBackend for UserAuth { let user = match sqlx::query_as!( UserRow, - r#"INSERT INTO users VALUES ($1, null, $2, null, null, $3, $4, $5) returning *"#, + r#"INSERT INTO users VALUES ($1, null, $2, $3, $4, $5) returning *"#, request.username, "example.com", password_hash, @@ -251,8 +261,6 @@ impl AuthBackend for UserAuth { struct UserRow { pub username: String, pub image_url: Option, - pub display_name: Option, - pub bio: Option, pub email: Option, pub password: String, pub public_key: String, diff --git a/giterated-daemon/src/connection/wrapper.rs b/giterated-daemon/src/connection/wrapper.rs index 926afc7..b0c3f74 100644 --- a/giterated-daemon/src/connection/wrapper.rs +++ b/giterated-daemon/src/connection/wrapper.rs @@ -81,11 +81,6 @@ pub async fn connection_wrapper( _ => continue, }; - info!( - "Received payload: {}", - std::str::from_utf8(&payload).unwrap() - ); - let message = NetworkMessage(payload.clone()); if !handshaked { diff --git a/giterated-daemon/src/message.rs b/giterated-daemon/src/message.rs index 6d9754a..c9ba2f9 100644 --- a/giterated-daemon/src/message.rs +++ b/giterated-daemon/src/message.rs @@ -1,4 +1,4 @@ -use std::{collections::HashMap, ops::Deref}; +use std::{collections::HashMap, fmt::Debug, ops::Deref}; use anyhow::Error; use futures_util::Future; @@ -240,12 +240,16 @@ where #[async_trait::async_trait] impl FromMessage for Message where - T: DeserializeOwned + Send + Sync + Serialize, + T: DeserializeOwned + Send + Sync + Serialize + Debug, S: Clone + Send + Sync, { async fn from_message(message: &NetworkMessage, _: &S) -> Result { let payload: AuthenticatedPayload = serde_json::from_slice(&message)?; - Ok(Message(bincode::deserialize(&payload.payload)?)) + let payload = bincode::deserialize(&payload.payload)?; + + info!("Deserialized payload: {:#?}", payload); + + Ok(Message(payload)) } }