diff --git a/.sqlx/query-0bd1ca98418a7ef4993fb664b34b33e0236dee4e3453051fe9f310a4233139d4.json b/.sqlx/query-0bd1ca98418a7ef4993fb664b34b33e0236dee4e3453051fe9f310a4233139d4.json deleted file mode 100644 index e8d1b34..0000000 --- a/.sqlx/query-0bd1ca98418a7ef4993fb664b34b33e0236dee4e3453051fe9f310a4233139d4.json +++ /dev/null @@ -1,79 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "INSERT INTO repositories VALUES ($1, $2, $3, $4, $5, $6) RETURNING username, instance_url, name, description, visibility as \"visibility: _\", default_branch", - "describe": { - "columns": [ - { - "ordinal": 0, - "name": "username", - "type_info": "Text" - }, - { - "ordinal": 1, - "name": "instance_url", - "type_info": "Text" - }, - { - "ordinal": 2, - "name": "name", - "type_info": "Text" - }, - { - "ordinal": 3, - "name": "description", - "type_info": "Text" - }, - { - "ordinal": 4, - "name": "visibility: _", - "type_info": { - "Custom": { - "name": "visibility", - "kind": { - "Enum": [ - "public", - "unlisted", - "private" - ] - } - } - } - }, - { - "ordinal": 5, - "name": "default_branch", - "type_info": "Text" - } - ], - "parameters": { - "Left": [ - "Text", - "Text", - "Text", - "Text", - { - "Custom": { - "name": "visibility", - "kind": { - "Enum": [ - "public", - "unlisted", - "private" - ] - } - } - }, - "Text" - ] - }, - "nullable": [ - false, - false, - false, - true, - false, - false - ] - }, - "hash": "0bd1ca98418a7ef4993fb664b34b33e0236dee4e3453051fe9f310a4233139d4" -} diff --git a/.sqlx/query-3f9c634ce803bbdf38b2079ede3ba7b006b839d916154a924ab23ee6afad4a1c.json b/.sqlx/query-3f9c634ce803bbdf38b2079ede3ba7b006b839d916154a924ab23ee6afad4a1c.json new file mode 100644 index 0000000..e2efbca --- /dev/null +++ b/.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/.sqlx/query-5f9e3dd381486d725dbb7d6a8b9fd195b3fdf030f17c308c36122f2bd04340a2.json b/.sqlx/query-5f9e3dd381486d725dbb7d6a8b9fd195b3fdf030f17c308c36122f2bd04340a2.json deleted file mode 100644 index dbceeba..0000000 --- a/.sqlx/query-5f9e3dd381486d725dbb7d6a8b9fd195b3fdf030f17c308c36122f2bd04340a2.json +++ /dev/null @@ -1,63 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "SELECT instance_url, username, name, description, visibility as \"visibility: _\", default_branch FROM repositories WHERE name = $1", - "describe": { - "columns": [ - { - "ordinal": 0, - "name": "instance_url", - "type_info": "Text" - }, - { - "ordinal": 1, - "name": "username", - "type_info": "Text" - }, - { - "ordinal": 2, - "name": "name", - "type_info": "Text" - }, - { - "ordinal": 3, - "name": "description", - "type_info": "Text" - }, - { - "ordinal": 4, - "name": "visibility: _", - "type_info": { - "Custom": { - "name": "visibility", - "kind": { - "Enum": [ - "public", - "unlisted", - "private" - ] - } - } - } - }, - { - "ordinal": 5, - "name": "default_branch", - "type_info": "Text" - } - ], - "parameters": { - "Left": [ - "Text" - ] - }, - "nullable": [ - false, - false, - false, - true, - false, - false - ] - }, - "hash": "5f9e3dd381486d725dbb7d6a8b9fd195b3fdf030f17c308c36122f2bd04340a2" -} diff --git a/.sqlx/query-606364c79e0990deb07dfbe6c32b3d302d083ec5333f3a5ce04113c38a041100.json b/.sqlx/query-606364c79e0990deb07dfbe6c32b3d302d083ec5333f3a5ce04113c38a041100.json new file mode 100644 index 0000000..054209e --- /dev/null +++ b/.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": "display_name", + "type_info": "Text" + }, + { + "ordinal": 2, + "name": "image_url", + "type_info": "Text" + }, + { + "ordinal": 3, + "name": "bio", + "type_info": "Text" + }, + { + "ordinal": 4, + "name": "email", + "type_info": "Text" + }, + { + "ordinal": 5, + "name": "password", + "type_info": "Text" + } + ], + "parameters": { + "Left": [ + "Text" + ] + }, + "nullable": [ + false, + true, + false, + true, + true, + false + ] + }, + "hash": "606364c79e0990deb07dfbe6c32b3d302d083ec5333f3a5ce04113c38a041100" +} diff --git a/.sqlx/query-b131bee47923bdcde91f9cfcafca60ef6394edd4af563bb23313f767077ac9eb.json b/.sqlx/query-b131bee47923bdcde91f9cfcafca60ef6394edd4af563bb23313f767077ac9eb.json deleted file mode 100644 index 10aef34..0000000 --- a/.sqlx/query-b131bee47923bdcde91f9cfcafca60ef6394edd4af563bb23313f767077ac9eb.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "DELETE FROM repositories WHERE instance_url = $1 AND username = $2 AND name = $3", - "describe": { - "columns": [], - "parameters": { - "Left": [ - "Text", - "Text", - "Text" - ] - }, - "nullable": [] - }, - "hash": "b131bee47923bdcde91f9cfcafca60ef6394edd4af563bb23313f767077ac9eb" -} diff --git a/.sqlx/query-bbd782d2ea06a991db7e2cddbab3796cf695dbe9e645d969598d9de8153f80b6.json b/.sqlx/query-bbd782d2ea06a991db7e2cddbab3796cf695dbe9e645d969598d9de8153f80b6.json new file mode 100644 index 0000000..2c92c0e --- /dev/null +++ b/.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/.sqlx/query-df2100447de87e6200a2d9af6b1adacf9892d51abe3ea588c975cc37c3a6825f.json b/.sqlx/query-df2100447de87e6200a2d9af6b1adacf9892d51abe3ea588c975cc37c3a6825f.json new file mode 100644 index 0000000..747040f --- /dev/null +++ b/.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/migrations/20230829104151_create_users.sql b/migrations/20230829104151_create_users.sql index c0071ef..86224aa 100644 --- a/migrations/20230829104151_create_users.sql +++ b/migrations/20230829104151_create_users.sql @@ -8,6 +8,6 @@ CREATE TABLE IF NOT EXISTS users bio TEXT, email TEXT, password TEXT NOT NULL -) +); CREATE UNIQUE INDEX unique_username ON users (username); \ No newline at end of file diff --git a/src/backend/git.rs b/src/backend/git.rs index e90b994..754ef79 100644 --- a/src/backend/git.rs +++ b/src/backend/git.rs @@ -299,7 +299,8 @@ impl RepositoryBackend for GitBackend { async fn repository_info( &mut self, - raw_request: &UserAuthenticated, + // TODO: Allow non-authenticated??? + raw_request: &ValidatedUserAuthenticated, ) -> Result> { let request = raw_request.inner().await; @@ -316,13 +317,11 @@ impl RepositoryBackend for GitBackend { }; if !repository.can_user_view_repository( - request.owner.instance.url.as_str(), - Some(request.owner.username.as_str()), + Some(&raw_request.user), ) { return Err(Box::new(GitBackendError::RepositoryNotFound { - instance_url: request.owner.instance.url.clone(), - username: request.owner.username.clone(), - name: request.name.clone(), + owner_user: request.repository.owner.to_string(), + name: request.repository.name.clone(), })); } @@ -458,34 +457,26 @@ impl RepositoryBackend for GitBackend { } } + impl IssuesBackend for GitBackend { fn issues_count( &mut self, - _request: &ValidatedUserAuthenticated, + request: &ValidatedUserAuthenticated, ) -> Result> { todo!() } fn issue_labels( &mut self, - _request: &ValidatedUserAuthenticated, + request: &ValidatedUserAuthenticated, ) -> Result> { todo!() } fn issues( &mut self, - _request: &ValidatedUserAuthenticated, + request: &ValidatedUserAuthenticated, ) -> Result> { todo!() } -} - -async fn public_key(instance: &Instance) -> Result> { - let key = reqwest::get(format!("https://{}/.giterated/pubkey.pem", instance.url)) - .await? - .text() - .await?; - - Ok(key) -} +} \ No newline at end of file diff --git a/src/backend/user.rs b/src/backend/user.rs index 6753f42..b440e3f 100644 --- a/src/backend/user.rs +++ b/src/backend/user.rs @@ -30,7 +30,8 @@ impl UserBackend for UserAuth { r#"SELECT * FROM users WHERE username = $1"#, request.user.username ) - .await?; + .fetch_one(&self.pg_pool.clone()) + .await.unwrap(); Ok(UserDisplayNameResponse { display_name: db_row.display_name, @@ -46,7 +47,8 @@ impl UserBackend for UserAuth { r#"SELECT * FROM users WHERE username = $1"#, request.user.username ) - .await?; + .fetch_one(&self.pg_pool.clone()) + .await.unwrap(); Ok(UserDisplayImageResponse { image_url: db_row.image_url, @@ -62,7 +64,8 @@ impl UserBackend for UserAuth { r#"SELECT * FROM users WHERE username = $1"#, request.user.username ) - .await?; + .fetch_one(&self.pg_pool.clone()) + .await.unwrap(); Ok(UserBioResponse { bio: db_row.bio }) } @@ -82,6 +85,7 @@ impl AuthBackend for UserAuth { #[derive(Debug, sqlx::FromRow)] struct UserRow { pub username: String, + pub image_url: Option, pub display_name: Option, pub bio: Option, pub email: Option, diff --git a/src/messages/user.rs b/src/messages/user.rs index 36a3d5f..bfcd5c4 100644 --- a/src/messages/user.rs +++ b/src/messages/user.rs @@ -35,7 +35,7 @@ pub struct UserDisplayNameRequest { #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct UserDisplayNameResponse { - pub display_name: String, + pub display_name: Option, } #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] @@ -45,7 +45,7 @@ pub struct UserDisplayImageRequest { #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct UserDisplayImageResponse { - pub image_url: String, + pub image_url: Option, } #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] @@ -55,5 +55,5 @@ pub struct UserBioRequest { #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct UserBioResponse { - pub bio: String, + pub bio: Option, }