merge changes
parent: tbd commit: 5213bdc
Showing 11 changed files with 218 insertions and 184 deletions
.sqlx/query-3f9c634ce803bbdf38b2079ede3ba7b006b839d916154a924ab23ee6afad4a1c.json
@@ -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 | } |
.sqlx/query-606364c79e0990deb07dfbe6c32b3d302d083ec5333f3a5ce04113c38a041100.json
@@ -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": "display_name", | |
14 | "type_info": "Text" | |
15 | }, | |
16 | { | |
17 | "ordinal": 2, | |
18 | "name": "image_url", | |
19 | "type_info": "Text" | |
20 | }, | |
21 | { | |
22 | "ordinal": 3, | |
23 | "name": "bio", | |
24 | "type_info": "Text" | |
25 | }, | |
26 | { | |
27 | "ordinal": 4, | |
28 | "name": "email", | |
29 | "type_info": "Text" | |
30 | }, | |
31 | { | |
32 | "ordinal": 5, | |
33 | "name": "password", | |
34 | "type_info": "Text" | |
35 | } | |
36 | ], | |
37 | "parameters": { | |
38 | "Left": [ | |
39 | "Text" | |
40 | ] | |
41 | }, | |
42 | "nullable": [ | |
43 | false, | |
44 | true, | |
45 | false, | |
46 | true, | |
47 | true, | |
48 | false | |
49 | ] | |
50 | }, | |
51 | "hash": "606364c79e0990deb07dfbe6c32b3d302d083ec5333f3a5ce04113c38a041100" | |
52 | } |
.sqlx/query-bbd782d2ea06a991db7e2cddbab3796cf695dbe9e645d969598d9de8153f80b6.json
@@ -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 | } |
.sqlx/query-df2100447de87e6200a2d9af6b1adacf9892d51abe3ea588c975cc37c3a6825f.json
@@ -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 | } |
migrations/20230829104151_create_users.sql
@@ -8,6 +8,6 @@ CREATE TABLE IF NOT EXISTS users | ||
8 | 8 | bio TEXT, |
9 | 9 | email TEXT, |
10 | 10 | password TEXT NOT NULL |
11 | ) | |
11 | ); | |
12 | 12 | |
13 | 13 | CREATE UNIQUE INDEX unique_username ON users (username); |
13 | 13 | \ No newline at end of file |
src/backend/git.rs
@@ -299,7 +299,8 @@ impl RepositoryBackend for GitBackend { | ||
299 | 299 | |
300 | 300 | async fn repository_info( |
301 | 301 | &mut self, |
302 | raw_request: &UserAuthenticated<RepositoryInfoRequest>, | |
302 | // TODO: Allow non-authenticated??? | |
303 | raw_request: &ValidatedUserAuthenticated<RepositoryInfoRequest>, | |
303 | 304 | ) -> Result<RepositoryView, Box<dyn Error + Send>> { |
304 | 305 | let request = raw_request.inner().await; |
305 | 306 | |
@@ -316,13 +317,11 @@ impl RepositoryBackend for GitBackend { | ||
316 | 317 | }; |
317 | 318 | |
318 | 319 | if !repository.can_user_view_repository( |
319 | request.owner.instance.url.as_str(), | |
320 | Some(request.owner.username.as_str()), | |
320 | Some(&raw_request.user), | |
321 | 321 | ) { |
322 | 322 | return Err(Box::new(GitBackendError::RepositoryNotFound { |
323 | instance_url: request.owner.instance.url.clone(), | |
324 | username: request.owner.username.clone(), | |
325 | name: request.name.clone(), | |
323 | owner_user: request.repository.owner.to_string(), | |
324 | name: request.repository.name.clone(), | |
326 | 325 | })); |
327 | 326 | } |
328 | 327 | |
@@ -458,34 +457,26 @@ impl RepositoryBackend for GitBackend { | ||
458 | 457 | } |
459 | 458 | } |
460 | 459 | |
460 | ||
461 | 461 | impl IssuesBackend for GitBackend { |
462 | 462 | fn issues_count( |
463 | 463 | &mut self, |
464 | _request: &ValidatedUserAuthenticated<RepositoryIssuesCountRequest>, | |
464 | request: &ValidatedUserAuthenticated<RepositoryIssuesCountRequest>, | |
465 | 465 | ) -> Result<RepositoryIssuesCountResponse, Box<dyn Error + Send>> { |
466 | 466 | todo!() |
467 | 467 | } |
468 | 468 | |
469 | 469 | fn issue_labels( |
470 | 470 | &mut self, |
471 | _request: &ValidatedUserAuthenticated<RepositoryIssueLabelsRequest>, | |
471 | request: &ValidatedUserAuthenticated<RepositoryIssueLabelsRequest>, | |
472 | 472 | ) -> Result<RepositoryIssueLabelsResponse, Box<dyn Error + Send>> { |
473 | 473 | todo!() |
474 | 474 | } |
475 | 475 | |
476 | 476 | fn issues( |
477 | 477 | &mut self, |
478 | _request: &ValidatedUserAuthenticated<RepositoryIssuesRequest>, | |
478 | request: &ValidatedUserAuthenticated<RepositoryIssuesRequest>, | |
479 | 479 | ) -> Result<RepositoryIssuesResponse, Box<dyn Error + Send>> { |
480 | 480 | todo!() |
481 | 481 | } |
482 | } | |
483 | ||
484 | async fn public_key(instance: &Instance) -> Result<String, Box<dyn Error>> { | |
485 | let key = reqwest::get(format!("https://{}/.giterated/pubkey.pem", instance.url)) | |
486 | .await? | |
487 | .text() | |
488 | .await?; | |
489 | ||
490 | Ok(key) | |
491 | } | |
482 | } | |
482 | \ No newline at end of file |
src/backend/user.rs
@@ -30,7 +30,8 @@ impl UserBackend for UserAuth { | ||
30 | 30 | r#"SELECT * FROM users WHERE username = $1"#, |
31 | 31 | request.user.username |
32 | 32 | ) |
33 | .await?; | |
33 | .fetch_one(&self.pg_pool.clone()) | |
34 | .await.unwrap(); | |
34 | 35 | |
35 | 36 | Ok(UserDisplayNameResponse { |
36 | 37 | display_name: db_row.display_name, |
@@ -46,7 +47,8 @@ impl UserBackend for UserAuth { | ||
46 | 47 | r#"SELECT * FROM users WHERE username = $1"#, |
47 | 48 | request.user.username |
48 | 49 | ) |
49 | .await?; | |
50 | .fetch_one(&self.pg_pool.clone()) | |
51 | .await.unwrap(); | |
50 | 52 | |
51 | 53 | Ok(UserDisplayImageResponse { |
52 | 54 | image_url: db_row.image_url, |
@@ -62,7 +64,8 @@ impl UserBackend for UserAuth { | ||
62 | 64 | r#"SELECT * FROM users WHERE username = $1"#, |
63 | 65 | request.user.username |
64 | 66 | ) |
65 | .await?; | |
67 | .fetch_one(&self.pg_pool.clone()) | |
68 | .await.unwrap(); | |
66 | 69 | |
67 | 70 | Ok(UserBioResponse { bio: db_row.bio }) |
68 | 71 | } |
@@ -82,6 +85,7 @@ impl AuthBackend for UserAuth { | ||
82 | 85 | #[derive(Debug, sqlx::FromRow)] |
83 | 86 | struct UserRow { |
84 | 87 | pub username: String, |
88 | pub image_url: Option<String>, | |
85 | 89 | pub display_name: Option<String>, |
86 | 90 | pub bio: Option<String>, |
87 | 91 | pub email: Option<String>, |
src/messages/user.rs
@@ -35,7 +35,7 @@ pub struct UserDisplayNameRequest { | ||
35 | 35 | |
36 | 36 | #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] |
37 | 37 | pub struct UserDisplayNameResponse { |
38 | pub display_name: String, | |
38 | pub display_name: Option<String>, | |
39 | 39 | } |
40 | 40 | |
41 | 41 | #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] |
@@ -45,7 +45,7 @@ pub struct UserDisplayImageRequest { | ||
45 | 45 | |
46 | 46 | #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] |
47 | 47 | pub struct UserDisplayImageResponse { |
48 | pub image_url: String, | |
48 | pub image_url: Option<String>, | |
49 | 49 | } |
50 | 50 | |
51 | 51 | #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] |
@@ -55,5 +55,5 @@ pub struct UserBioRequest { | ||
55 | 55 | |
56 | 56 | #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] |
57 | 57 | pub struct UserBioResponse { |
58 | pub bio: String, | |
58 | pub bio: Option<String>, | |
59 | 59 | } |