From ae635c752aaa0d11d3cb317c612180a835aa65f2 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Fri, 19 Mar 2021 15:57:56 -0400 Subject: [PATCH 1/9] Try to remove cargo home changing to fix release. --- .drone.yml | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/.drone.yml b/.drone.yml index 5c68e2ccb..bb27984f9 100644 --- a/.drone.yml +++ b/.drone.yml @@ -21,13 +21,7 @@ steps: - name: cargo clippy image: ekidd/rust-musl-builder:1.50.0 - environment: - CARGO_HOME: /drone/src/.cargo commands: - - whoami - - ls -la ~/.cargo - - mv ~/.cargo . - - ls -la .cargo - cargo clippy --workspace --tests --all-targets --all-features -- -D warnings -D deprecated -D clippy::perf -D clippy::complexity -D clippy::dbg_macro - cargo clippy --workspace -- -D clippy::unwrap_used @@ -37,7 +31,6 @@ steps: LEMMY_DATABASE_URL: postgres://lemmy:password@database:5432/lemmy RUST_BACKTRACE: 1 RUST_TEST_THREADS: 1 - CARGO_HOME: /drone/src/.cargo commands: - sudo apt-get update - sudo apt-get -y install --no-install-recommends espeak postgresql-client @@ -45,8 +38,6 @@ steps: - name: cargo build image: ekidd/rust-musl-builder:1.50.0 - environment: - CARGO_HOME: /drone/src/.cargo commands: - cargo build - mv target/x86_64-unknown-linux-musl/debug/lemmy_server target/lemmy_server @@ -118,7 +109,6 @@ steps: LEMMY_DATABASE_URL: postgres://lemmy:password@database:5432/lemmy RUST_BACKTRACE: 1 RUST_TEST_THREADS: 1 - CARGO_HOME: /drone/src/.cargo commands: - apt-get update - apt-get -y install --no-install-recommends espeak postgresql-client libssl-dev pkg-config libpq-dev @@ -128,8 +118,6 @@ steps: # Using Debian here because there seems to be no official Alpine-based Rust docker image for ARM. - name: cargo build image: rust:1.50-slim-buster - environment: - CARGO_HOME: /drone/src/.cargo commands: - apt-get update - apt-get -y install --no-install-recommends libssl-dev pkg-config libpq-dev From e9eca35816b2125ddcca73ceef62409fbb749c3c Mon Sep 17 00:00:00 2001 From: Dessalines Date: Fri, 19 Mar 2021 15:58:24 -0400 Subject: [PATCH 2/9] Version 0.10.0-rc.8 --- ansible/VERSION | 2 +- crates/utils/src/version.rs | 2 +- docker/dev/docker-compose.yml | 2 +- docker/federation/docker-compose.yml | 10 +++++----- docker/prod/docker-compose.yml | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/ansible/VERSION b/ansible/VERSION index 69843acd5..90bed77d8 100644 --- a/ansible/VERSION +++ b/ansible/VERSION @@ -1 +1 @@ -0.10.0-rc.7 +0.10.0-rc.8 diff --git a/crates/utils/src/version.rs b/crates/utils/src/version.rs index ad718a725..51afdfbc4 100644 --- a/crates/utils/src/version.rs +++ b/crates/utils/src/version.rs @@ -1 +1 @@ -pub const VERSION: &str = "0.10.0-rc.7"; +pub const VERSION: &str = "0.10.0-rc.8"; diff --git a/docker/dev/docker-compose.yml b/docker/dev/docker-compose.yml index e4c2a10f3..a0e59ddf4 100644 --- a/docker/dev/docker-compose.yml +++ b/docker/dev/docker-compose.yml @@ -17,7 +17,7 @@ services: - iframely lemmy-ui: - image: dessalines/lemmy-ui:0.10.0-rc.7 + image: dessalines/lemmy-ui:0.10.0-rc.8 ports: - "1235:1234" restart: always diff --git a/docker/federation/docker-compose.yml b/docker/federation/docker-compose.yml index b3a10c142..77bb53fa6 100644 --- a/docker/federation/docker-compose.yml +++ b/docker/federation/docker-compose.yml @@ -29,7 +29,7 @@ services: - ./volumes/pictrs_alpha:/mnt lemmy-alpha-ui: - image: dessalines/lemmy-ui:0.10.0-rc.7 + image: dessalines/lemmy-ui:0.10.0-rc.8 environment: - LEMMY_INTERNAL_HOST=lemmy-alpha:8541 - LEMMY_EXTERNAL_HOST=localhost:8541 @@ -58,7 +58,7 @@ services: - ./volumes/postgres_alpha:/var/lib/postgresql/data lemmy-beta-ui: - image: dessalines/lemmy-ui:0.10.0-rc.7 + image: dessalines/lemmy-ui:0.10.0-rc.8 environment: - LEMMY_INTERNAL_HOST=lemmy-beta:8551 - LEMMY_EXTERNAL_HOST=localhost:8551 @@ -87,7 +87,7 @@ services: - ./volumes/postgres_beta:/var/lib/postgresql/data lemmy-gamma-ui: - image: dessalines/lemmy-ui:0.10.0-rc.7 + image: dessalines/lemmy-ui:0.10.0-rc.8 environment: - LEMMY_INTERNAL_HOST=lemmy-gamma:8561 - LEMMY_EXTERNAL_HOST=localhost:8561 @@ -117,7 +117,7 @@ services: # An instance with only an allowlist for beta lemmy-delta-ui: - image: dessalines/lemmy-ui:0.10.0-rc.7 + image: dessalines/lemmy-ui:0.10.0-rc.8 environment: - LEMMY_INTERNAL_HOST=lemmy-delta:8571 - LEMMY_EXTERNAL_HOST=localhost:8571 @@ -147,7 +147,7 @@ services: # An instance who has a blocklist, with lemmy-alpha blocked lemmy-epsilon-ui: - image: dessalines/lemmy-ui:0.10.0-rc.7 + image: dessalines/lemmy-ui:0.10.0-rc.8 environment: - LEMMY_INTERNAL_HOST=lemmy-epsilon:8581 - LEMMY_EXTERNAL_HOST=localhost:8581 diff --git a/docker/prod/docker-compose.yml b/docker/prod/docker-compose.yml index 2d2d75722..ec37ed98f 100644 --- a/docker/prod/docker-compose.yml +++ b/docker/prod/docker-compose.yml @@ -12,7 +12,7 @@ services: restart: always lemmy: - image: dessalines/lemmy:0.10.0-rc.7 + image: dessalines/lemmy:0.10.0-rc.8 ports: - "127.0.0.1:8536:8536" restart: always @@ -26,7 +26,7 @@ services: - iframely lemmy-ui: - image: dessalines/lemmy-ui:0.10.0-rc.7 + image: dessalines/lemmy-ui:0.10.0-rc.8 ports: - "127.0.0.1:1235:1234" restart: always From 1745b64cebf3599a41599f67d19cea5d53fa3573 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Sat, 20 Mar 2021 15:21:51 -0400 Subject: [PATCH 3/9] Moving matrix_user_id to person table. #1438 --- crates/api/src/lib.rs | 2 +- crates/api/src/local_user.rs | 4 ++-- crates/apub/src/objects/person.rs | 1 + .../src/aggregates/comment_aggregates.rs | 2 ++ .../src/aggregates/community_aggregates.rs | 2 ++ .../db_queries/src/aggregates/person_aggregates.rs | 2 ++ .../db_queries/src/aggregates/post_aggregates.rs | 2 ++ .../db_queries/src/aggregates/site_aggregates.rs | 1 + crates/db_queries/src/source/activity.rs | 1 + crates/db_queries/src/source/comment.rs | 1 + crates/db_queries/src/source/community.rs | 1 + crates/db_queries/src/source/local_user.rs | 2 -- crates/db_queries/src/source/moderator.rs | 2 ++ .../src/source/password_reset_request.rs | 2 +- crates/db_queries/src/source/person.rs | 14 ++++++++++---- crates/db_queries/src/source/person_mention.rs | 2 ++ crates/db_queries/src/source/post.rs | 1 + crates/db_queries/src/source/private_message.rs | 2 ++ crates/db_schema/src/schema.rs | 4 +++- crates/db_schema/src/source/local_user.rs | 3 --- crates/db_schema/src/source/person.rs | 7 +++++++ crates/db_views/src/comment_view.rs | 2 ++ crates/db_views/src/post_view.rs | 2 ++ .../down.sql | 8 ++++++++ .../up.sql | 8 ++++++++ src/code_migrations.rs | 1 + 26 files changed, 65 insertions(+), 14 deletions(-) create mode 100644 migrations/2021-03-20-185321_move_matrix_id_to_person/down.sql create mode 100644 migrations/2021-03-20-185321_move_matrix_id_to_person/up.sql diff --git a/crates/api/src/lib.rs b/crates/api/src/lib.rs index 529a13cfd..8c6fe8a52 100644 --- a/crates/api/src/lib.rs +++ b/crates/api/src/lib.rs @@ -543,6 +543,7 @@ mod tests { last_refreshed_at: None, inbox_url: None, shared_inbox_url: None, + matrix_user_id: None, }; let inserted_person = Person::create(&conn, &new_person).unwrap(); @@ -550,7 +551,6 @@ mod tests { let local_user_form = LocalUserForm { person_id: inserted_person.id, email: None, - matrix_user_id: None, password_encrypted: "123456".to_string(), admin: None, show_nsfw: None, diff --git a/crates/api/src/local_user.rs b/crates/api/src/local_user.rs index 266d28eec..c43db39cf 100644 --- a/crates/api/src/local_user.rs +++ b/crates/api/src/local_user.rs @@ -214,6 +214,7 @@ impl Perform for Register { last_refreshed_at: None, inbox_url: Some(generate_inbox_url(&actor_id)?), shared_inbox_url: Some(Some(generate_shared_inbox_url(&actor_id)?)), + matrix_user_id: None, }; // insert the person @@ -232,7 +233,6 @@ impl Perform for Register { let local_user_form = LocalUserForm { person_id: inserted_person.id, email: Some(data.email.to_owned()), - matrix_user_id: None, password_encrypted: data.password.to_owned(), admin: Some(no_admins), show_nsfw: Some(data.show_nsfw), @@ -477,6 +477,7 @@ impl Perform for SaveUserSettings { public_key: None, last_refreshed_at: None, shared_inbox_url: None, + matrix_user_id, }; let person_res = blocking(context.pool(), move |conn| { @@ -493,7 +494,6 @@ impl Perform for SaveUserSettings { let local_user_form = LocalUserForm { person_id, email, - matrix_user_id, password_encrypted, admin: None, show_nsfw: data.show_nsfw, diff --git a/crates/apub/src/objects/person.rs b/crates/apub/src/objects/person.rs index de45aedd3..d1eb67071 100644 --- a/crates/apub/src/objects/person.rs +++ b/crates/apub/src/objects/person.rs @@ -187,6 +187,7 @@ impl FromApubToForm for PersonForm { last_refreshed_at: Some(naive_now()), inbox_url: Some(person.inner.inbox()?.to_owned().into()), shared_inbox_url: Some(shared_inbox), + matrix_user_id: None, // TODO }) } } diff --git a/crates/db_queries/src/aggregates/comment_aggregates.rs b/crates/db_queries/src/aggregates/comment_aggregates.rs index c55fef0ca..d3e925244 100644 --- a/crates/db_queries/src/aggregates/comment_aggregates.rs +++ b/crates/db_queries/src/aggregates/comment_aggregates.rs @@ -59,6 +59,7 @@ mod tests { last_refreshed_at: None, inbox_url: None, shared_inbox_url: None, + matrix_user_id: None, }; let inserted_person = Person::create(&conn, &new_person).unwrap(); @@ -80,6 +81,7 @@ mod tests { last_refreshed_at: None, inbox_url: None, shared_inbox_url: None, + matrix_user_id: None, }; let another_inserted_person = Person::create(&conn, &another_person).unwrap(); diff --git a/crates/db_queries/src/aggregates/community_aggregates.rs b/crates/db_queries/src/aggregates/community_aggregates.rs index bbe751ae5..ad90f20f6 100644 --- a/crates/db_queries/src/aggregates/community_aggregates.rs +++ b/crates/db_queries/src/aggregates/community_aggregates.rs @@ -63,6 +63,7 @@ mod tests { last_refreshed_at: None, inbox_url: None, shared_inbox_url: None, + matrix_user_id: None, }; let inserted_person = Person::create(&conn, &new_person).unwrap(); @@ -84,6 +85,7 @@ mod tests { last_refreshed_at: None, inbox_url: None, shared_inbox_url: None, + matrix_user_id: None, }; let another_inserted_person = Person::create(&conn, &another_person).unwrap(); diff --git a/crates/db_queries/src/aggregates/person_aggregates.rs b/crates/db_queries/src/aggregates/person_aggregates.rs index c1082c4b6..f6a6cd1ba 100644 --- a/crates/db_queries/src/aggregates/person_aggregates.rs +++ b/crates/db_queries/src/aggregates/person_aggregates.rs @@ -59,6 +59,7 @@ mod tests { last_refreshed_at: None, inbox_url: None, shared_inbox_url: None, + matrix_user_id: None, }; let inserted_person = Person::create(&conn, &new_person).unwrap(); @@ -80,6 +81,7 @@ mod tests { last_refreshed_at: None, inbox_url: None, shared_inbox_url: None, + matrix_user_id: None, }; let another_inserted_person = Person::create(&conn, &another_person).unwrap(); diff --git a/crates/db_queries/src/aggregates/post_aggregates.rs b/crates/db_queries/src/aggregates/post_aggregates.rs index aa5e774e0..a32b9da66 100644 --- a/crates/db_queries/src/aggregates/post_aggregates.rs +++ b/crates/db_queries/src/aggregates/post_aggregates.rs @@ -63,6 +63,7 @@ mod tests { last_refreshed_at: None, inbox_url: None, shared_inbox_url: None, + matrix_user_id: None, }; let inserted_person = Person::create(&conn, &new_person).unwrap(); @@ -84,6 +85,7 @@ mod tests { last_refreshed_at: None, inbox_url: None, shared_inbox_url: None, + matrix_user_id: None, }; let another_inserted_person = Person::create(&conn, &another_person).unwrap(); diff --git a/crates/db_queries/src/aggregates/site_aggregates.rs b/crates/db_queries/src/aggregates/site_aggregates.rs index a685ad0da..67cb04a7e 100644 --- a/crates/db_queries/src/aggregates/site_aggregates.rs +++ b/crates/db_queries/src/aggregates/site_aggregates.rs @@ -57,6 +57,7 @@ mod tests { last_refreshed_at: None, inbox_url: None, shared_inbox_url: None, + matrix_user_id: None, }; let inserted_person = Person::create(&conn, &new_person).unwrap(); diff --git a/crates/db_queries/src/source/activity.rs b/crates/db_queries/src/source/activity.rs index 1ec9b8d16..5d345db69 100644 --- a/crates/db_queries/src/source/activity.rs +++ b/crates/db_queries/src/source/activity.rs @@ -153,6 +153,7 @@ mod tests { last_refreshed_at: None, inbox_url: None, shared_inbox_url: None, + matrix_user_id: None, }; let inserted_creator = Person::create(&conn, &creator_form).unwrap(); diff --git a/crates/db_queries/src/source/comment.rs b/crates/db_queries/src/source/comment.rs index 69ac4c081..47965d3b4 100644 --- a/crates/db_queries/src/source/comment.rs +++ b/crates/db_queries/src/source/comment.rs @@ -261,6 +261,7 @@ mod tests { last_refreshed_at: None, inbox_url: None, shared_inbox_url: None, + matrix_user_id: None, }; let inserted_person = Person::create(&conn, &new_person).unwrap(); diff --git a/crates/db_queries/src/source/community.rs b/crates/db_queries/src/source/community.rs index 5b7fc92c8..a0038c9d3 100644 --- a/crates/db_queries/src/source/community.rs +++ b/crates/db_queries/src/source/community.rs @@ -371,6 +371,7 @@ mod tests { last_refreshed_at: None, inbox_url: None, shared_inbox_url: None, + matrix_user_id: None, }; let inserted_person = Person::create(&conn, &new_person).unwrap(); diff --git a/crates/db_queries/src/source/local_user.rs b/crates/db_queries/src/source/local_user.rs index eabd067d3..7e84011b4 100644 --- a/crates/db_queries/src/source/local_user.rs +++ b/crates/db_queries/src/source/local_user.rs @@ -25,7 +25,6 @@ mod safe_settings_type { lang, show_avatars, send_notifications_to_email, - matrix_user_id, validator_time, ); @@ -46,7 +45,6 @@ mod safe_settings_type { lang, show_avatars, send_notifications_to_email, - matrix_user_id, validator_time, ) } diff --git a/crates/db_queries/src/source/moderator.rs b/crates/db_queries/src/source/moderator.rs index 526fc2bd8..3b6d25445 100644 --- a/crates/db_queries/src/source/moderator.rs +++ b/crates/db_queries/src/source/moderator.rs @@ -224,6 +224,7 @@ mod tests { last_refreshed_at: None, inbox_url: None, shared_inbox_url: None, + matrix_user_id: None, }; let inserted_mod = Person::create(&conn, &new_mod).unwrap(); @@ -245,6 +246,7 @@ mod tests { last_refreshed_at: None, inbox_url: None, shared_inbox_url: None, + matrix_user_id: None, }; let inserted_person = Person::create(&conn, &new_person).unwrap(); diff --git a/crates/db_queries/src/source/password_reset_request.rs b/crates/db_queries/src/source/password_reset_request.rs index 89c375058..654dabf65 100644 --- a/crates/db_queries/src/source/password_reset_request.rs +++ b/crates/db_queries/src/source/password_reset_request.rs @@ -110,6 +110,7 @@ mod tests { last_refreshed_at: None, inbox_url: None, shared_inbox_url: None, + matrix_user_id: None, }; let inserted_person = Person::create(&conn, &new_person).unwrap(); @@ -118,7 +119,6 @@ mod tests { person_id: inserted_person.id, password_encrypted: "pass".to_string(), email: None, - matrix_user_id: None, admin: None, show_nsfw: None, theme: None, diff --git a/crates/db_queries/src/source/person.rs b/crates/db_queries/src/source/person.rs index f9979c970..40adab3df 100644 --- a/crates/db_queries/src/source/person.rs +++ b/crates/db_queries/src/source/person.rs @@ -27,6 +27,7 @@ mod safe_type { deleted, inbox_url, shared_inbox_url, + matrix_user_id, ); impl ToSafe for Person { @@ -47,6 +48,7 @@ mod safe_type { deleted, inbox_url, shared_inbox_url, + matrix_user_id, ) } } @@ -71,6 +73,7 @@ mod safe_type_alias_1 { deleted, inbox_url, shared_inbox_url, + matrix_user_id, ); impl ToSafe for PersonAlias1 { @@ -91,6 +94,7 @@ mod safe_type_alias_1 { deleted, inbox_url, shared_inbox_url, + matrix_user_id, ) } } @@ -115,6 +119,7 @@ mod safe_type_alias_2 { deleted, inbox_url, shared_inbox_url, + matrix_user_id, ); impl ToSafe for PersonAlias2 { @@ -135,6 +140,7 @@ mod safe_type_alias_2 { deleted, inbox_url, shared_inbox_url, + matrix_user_id, ) } } @@ -212,16 +218,14 @@ impl Person_ for Person { // Set the local user info to none diesel::update(local_user::table.filter(local_user::person_id.eq(person_id))) - .set(( - local_user::email.eq::>(None), - local_user::matrix_user_id.eq::>(None), - )) + .set((local_user::email.eq::>(None),)) .execute(conn)?; diesel::update(person.find(person_id)) .set(( preferred_username.eq::>(None), bio.eq::>(None), + matrix_user_id.eq::>(None), deleted.eq(true), updated.eq(naive_now()), )) @@ -254,6 +258,7 @@ mod tests { last_refreshed_at: None, inbox_url: None, shared_inbox_url: None, + matrix_user_id: None, }; let inserted_person = Person::create(&conn, &new_person).unwrap(); @@ -276,6 +281,7 @@ mod tests { last_refreshed_at: inserted_person.published, inbox_url: inserted_person.inbox_url.to_owned(), shared_inbox_url: None, + matrix_user_id: None, }; let read_person = Person::read(&conn, inserted_person.id).unwrap(); diff --git a/crates/db_queries/src/source/person_mention.rs b/crates/db_queries/src/source/person_mention.rs index dfd626cba..a6a86e788 100644 --- a/crates/db_queries/src/source/person_mention.rs +++ b/crates/db_queries/src/source/person_mention.rs @@ -105,6 +105,7 @@ mod tests { last_refreshed_at: None, inbox_url: None, shared_inbox_url: None, + matrix_user_id: None, }; let inserted_person = Person::create(&conn, &new_person).unwrap(); @@ -126,6 +127,7 @@ mod tests { last_refreshed_at: None, inbox_url: None, shared_inbox_url: None, + matrix_user_id: None, }; let inserted_recipient = Person::create(&conn, &recipient_form).unwrap(); diff --git a/crates/db_queries/src/source/post.rs b/crates/db_queries/src/source/post.rs index d6492e130..b1f6b7c2b 100644 --- a/crates/db_queries/src/source/post.rs +++ b/crates/db_queries/src/source/post.rs @@ -288,6 +288,7 @@ mod tests { last_refreshed_at: None, inbox_url: None, shared_inbox_url: None, + matrix_user_id: None, }; let inserted_person = Person::create(&conn, &new_person).unwrap(); diff --git a/crates/db_queries/src/source/private_message.rs b/crates/db_queries/src/source/private_message.rs index fe2456890..cd663093c 100644 --- a/crates/db_queries/src/source/private_message.rs +++ b/crates/db_queries/src/source/private_message.rs @@ -165,6 +165,7 @@ mod tests { last_refreshed_at: None, inbox_url: None, shared_inbox_url: None, + matrix_user_id: None, }; let inserted_creator = Person::create(&conn, &creator_form).unwrap(); @@ -186,6 +187,7 @@ mod tests { last_refreshed_at: None, inbox_url: None, shared_inbox_url: None, + matrix_user_id: None, }; let inserted_recipient = Person::create(&conn, &recipient_form).unwrap(); diff --git a/crates/db_schema/src/schema.rs b/crates/db_schema/src/schema.rs index 9bb3fe2d6..4c990ec03 100644 --- a/crates/db_schema/src/schema.rs +++ b/crates/db_schema/src/schema.rs @@ -154,7 +154,6 @@ table! { lang -> Varchar, show_avatars -> Bool, send_notifications_to_email -> Bool, - matrix_user_id -> Nullable, validator_time -> Timestamp, } } @@ -287,6 +286,7 @@ table! { deleted -> Bool, inbox_url -> Varchar, shared_inbox_url -> Nullable, + matrix_user_id -> Nullable, } } @@ -485,6 +485,7 @@ table! { deleted -> Bool, inbox_url -> Varchar, shared_inbox_url -> Nullable, + matrix_user_id -> Nullable, } } @@ -507,6 +508,7 @@ table! { deleted -> Bool, inbox_url -> Varchar, shared_inbox_url -> Nullable, + matrix_user_id -> Nullable, } } diff --git a/crates/db_schema/src/source/local_user.rs b/crates/db_schema/src/source/local_user.rs index 11dac6c9c..d902e6b4d 100644 --- a/crates/db_schema/src/source/local_user.rs +++ b/crates/db_schema/src/source/local_user.rs @@ -16,7 +16,6 @@ pub struct LocalUser { pub lang: String, pub show_avatars: bool, pub send_notifications_to_email: bool, - pub matrix_user_id: Option, pub validator_time: chrono::NaiveDateTime, } @@ -35,7 +34,6 @@ pub struct LocalUserForm { pub lang: Option, pub show_avatars: Option, pub send_notifications_to_email: Option, - pub matrix_user_id: Option>, } /// A local user view that removes password encrypted @@ -53,6 +51,5 @@ pub struct LocalUserSettings { pub lang: String, pub show_avatars: bool, pub send_notifications_to_email: bool, - pub matrix_user_id: Option, pub validator_time: chrono::NaiveDateTime, } diff --git a/crates/db_schema/src/source/person.rs b/crates/db_schema/src/source/person.rs index f669f0c55..8c66b1a8e 100644 --- a/crates/db_schema/src/source/person.rs +++ b/crates/db_schema/src/source/person.rs @@ -25,6 +25,7 @@ pub struct Person { pub deleted: bool, pub inbox_url: DbUrl, pub shared_inbox_url: Option, + pub matrix_user_id: Option, } /// A safe representation of person, without the sensitive info @@ -45,6 +46,7 @@ pub struct PersonSafe { pub deleted: bool, pub inbox_url: DbUrl, pub shared_inbox_url: Option, + pub matrix_user_id: Option, } #[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)] @@ -67,6 +69,7 @@ pub struct PersonAlias1 { pub deleted: bool, pub inbox_url: DbUrl, pub shared_inbox_url: Option, + pub matrix_user_id: Option, } #[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)] @@ -86,6 +89,7 @@ pub struct PersonSafeAlias1 { pub deleted: bool, pub inbox_url: DbUrl, pub shared_inbox_url: Option, + pub matrix_user_id: Option, } #[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)] @@ -108,6 +112,7 @@ pub struct PersonAlias2 { pub deleted: bool, pub inbox_url: DbUrl, pub shared_inbox_url: Option, + pub matrix_user_id: Option, } #[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)] @@ -127,6 +132,7 @@ pub struct PersonSafeAlias2 { pub deleted: bool, pub inbox_url: DbUrl, pub shared_inbox_url: Option, + pub matrix_user_id: Option, } #[derive(Insertable, AsChangeset, Clone)] @@ -148,4 +154,5 @@ pub struct PersonForm { pub deleted: Option, pub inbox_url: Option, pub shared_inbox_url: Option>, + pub matrix_user_id: Option>, } diff --git a/crates/db_views/src/comment_view.rs b/crates/db_views/src/comment_view.rs index 6c5850ad3..478a906f2 100644 --- a/crates/db_views/src/comment_view.rs +++ b/crates/db_views/src/comment_view.rs @@ -469,6 +469,7 @@ mod tests { last_refreshed_at: None, inbox_url: None, shared_inbox_url: None, + matrix_user_id: None, }; let inserted_person = Person::create(&conn, &new_person).unwrap(); @@ -581,6 +582,7 @@ mod tests { updated: None, inbox_url: inserted_person.inbox_url.to_owned(), shared_inbox_url: None, + matrix_user_id: None, }, recipient: None, post: Post { diff --git a/crates/db_views/src/post_view.rs b/crates/db_views/src/post_view.rs index fe852e376..08d889d18 100644 --- a/crates/db_views/src/post_view.rs +++ b/crates/db_views/src/post_view.rs @@ -469,6 +469,7 @@ mod tests { last_refreshed_at: None, inbox_url: None, shared_inbox_url: None, + matrix_user_id: None, }; let inserted_person = Person::create(&conn, &new_person).unwrap(); @@ -596,6 +597,7 @@ mod tests { updated: None, inbox_url: inserted_person.inbox_url.to_owned(), shared_inbox_url: None, + matrix_user_id: None, }, creator_banned_from_community: false, community: CommunitySafe { diff --git a/migrations/2021-03-20-185321_move_matrix_id_to_person/down.sql b/migrations/2021-03-20-185321_move_matrix_id_to_person/down.sql new file mode 100644 index 000000000..ce4eb4ad8 --- /dev/null +++ b/migrations/2021-03-20-185321_move_matrix_id_to_person/down.sql @@ -0,0 +1,8 @@ +alter table local_user add column matrix_user_id text; + +update local_user lu +set matrix_user_id = p.matrix_user_id +from person p +where p.id = lu.person_id; + +alter table person drop column matrix_user_id; diff --git a/migrations/2021-03-20-185321_move_matrix_id_to_person/up.sql b/migrations/2021-03-20-185321_move_matrix_id_to_person/up.sql new file mode 100644 index 000000000..f8c577c92 --- /dev/null +++ b/migrations/2021-03-20-185321_move_matrix_id_to_person/up.sql @@ -0,0 +1,8 @@ +alter table person add column matrix_user_id text; + +update person p +set matrix_user_id = lu.matrix_user_id +from local_user lu +where p.id = lu.person_id; + +alter table local_user drop column matrix_user_id; diff --git a/src/code_migrations.rs b/src/code_migrations.rs index bd67fe699..e9b43356a 100644 --- a/src/code_migrations.rs +++ b/src/code_migrations.rs @@ -70,6 +70,7 @@ fn user_updates_2020_04_02(conn: &PgConnection) -> Result<(), LemmyError> { last_refreshed_at: Some(naive_now()), inbox_url: None, shared_inbox_url: None, + matrix_user_id: None, }; Person::update(&conn, cperson.id, &form)?; From 53ea383b4e139ebbe8c81ea9b1a4acd6faa47f9d Mon Sep 17 00:00:00 2001 From: Dessalines Date: Sat, 20 Mar 2021 16:32:52 -0400 Subject: [PATCH 4/9] Forgot to regenerate person_alias views --- .../2021-03-20-185321_move_matrix_id_to_person/down.sql | 5 +++++ migrations/2021-03-20-185321_move_matrix_id_to_person/up.sql | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/migrations/2021-03-20-185321_move_matrix_id_to_person/down.sql b/migrations/2021-03-20-185321_move_matrix_id_to_person/down.sql index ce4eb4ad8..70cbe9bfa 100644 --- a/migrations/2021-03-20-185321_move_matrix_id_to_person/down.sql +++ b/migrations/2021-03-20-185321_move_matrix_id_to_person/down.sql @@ -5,4 +5,9 @@ set matrix_user_id = p.matrix_user_id from person p where p.id = lu.person_id; +drop view person_alias_1, person_alias_2; alter table person drop column matrix_user_id; + +-- Regenerate the person_alias views +create view person_alias_1 as select * from person; +create view person_alias_2 as select * from person; diff --git a/migrations/2021-03-20-185321_move_matrix_id_to_person/up.sql b/migrations/2021-03-20-185321_move_matrix_id_to_person/up.sql index f8c577c92..92f20c6cb 100644 --- a/migrations/2021-03-20-185321_move_matrix_id_to_person/up.sql +++ b/migrations/2021-03-20-185321_move_matrix_id_to_person/up.sql @@ -6,3 +6,8 @@ from local_user lu where p.id = lu.person_id; alter table local_user drop column matrix_user_id; + +-- Regenerate the person_alias views +drop view person_alias_1, person_alias_2; +create view person_alias_1 as select * from person; +create view person_alias_2 as select * from person; From c884510173f4af7bf25cd952b601e495e00a9492 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Sat, 20 Mar 2021 16:59:07 -0400 Subject: [PATCH 5/9] Creating default DB forms. Fixes #1511 --- crates/api/src/comment.rs | 8 +- crates/api/src/community.rs | 21 +--- crates/api/src/lib.rs | 27 +---- crates/api/src/local_user.rs | 29 +---- crates/api/src/post.rs | 21 +--- crates/api_structs/src/community.rs | 4 +- crates/apub/src/objects/comment.rs | 2 +- crates/apub/src/objects/community.rs | 4 +- crates/apub/src/objects/post.rs | 2 +- crates/apub/src/objects/private_message.rs | 2 +- .../src/aggregates/comment_aggregates.rs | 84 ++------------- .../src/aggregates/community_aggregates.rs | 101 ++---------------- .../src/aggregates/person_aggregates.rs | 84 ++------------- .../src/aggregates/post_aggregates.rs | 84 ++------------- .../src/aggregates/site_aggregates.rs | 67 +----------- crates/db_queries/src/source/activity.rs | 21 +--- crates/db_queries/src/source/comment.rs | 67 +----------- crates/db_queries/src/source/community.rs | 34 +----- crates/db_queries/src/source/moderator.rs | 76 +------------ .../src/source/password_reset_request.rs | 27 +---- crates/db_queries/src/source/person.rs | 17 +-- .../db_queries/src/source/person_mention.rs | 76 +------------ crates/db_queries/src/source/post.rs | 50 +-------- .../db_queries/src/source/private_message.rs | 41 +------ crates/db_schema/src/lib.rs | 12 ++- crates/db_schema/src/source/activity.rs | 2 +- crates/db_schema/src/source/comment.rs | 4 +- crates/db_schema/src/source/community.rs | 6 +- crates/db_schema/src/source/local_user.rs | 2 +- crates/db_schema/src/source/person.rs | 2 +- crates/db_schema/src/source/post.rs | 4 +- .../db_schema/src/source/private_message.rs | 4 +- crates/db_views/src/comment_view.rs | 59 +--------- crates/db_views/src/post_view.rs | 50 +-------- src/code_migrations.rs | 17 +-- 35 files changed, 110 insertions(+), 1001 deletions(-) diff --git a/crates/api/src/comment.rs b/crates/api/src/comment.rs index 4fd3f7b2c..61f9a7040 100644 --- a/crates/api/src/comment.rs +++ b/crates/api/src/comment.rs @@ -85,13 +85,7 @@ impl Perform for CreateComment { parent_id: data.parent_id.to_owned(), post_id: data.post_id, creator_id: local_user_view.person.id, - removed: None, - deleted: None, - read: None, - published: None, - updated: None, - ap_id: None, - local: true, + ..CommentForm::default() }; // Create the comment diff --git a/crates/api/src/community.rs b/crates/api/src/community.rs index f6ecbf125..cce4dfbcc 100644 --- a/crates/api/src/community.rs +++ b/crates/api/src/community.rs @@ -168,19 +168,14 @@ impl Perform for CreateCommunity { icon, banner, creator_id: local_user_view.person.id, - removed: None, - deleted: None, nsfw: data.nsfw, - updated: None, actor_id: Some(community_actor_id.to_owned()), - local: true, private_key: Some(keypair.private_key), public_key: Some(keypair.public_key), - last_refreshed_at: None, - published: None, followers_url: Some(generate_followers_url(&community_actor_id)?), inbox_url: Some(generate_inbox_url(&community_actor_id)?), shared_inbox_url: Some(Some(generate_shared_inbox_url(&community_actor_id)?)), + ..CommunityForm::default() }; let inserted_community = match blocking(context.pool(), move |conn| { @@ -263,23 +258,13 @@ impl Perform for EditCommunity { let community_form = CommunityForm { name: read_community.name, title: data.title.to_owned(), + creator_id: read_community.creator_id, description: data.description.to_owned(), icon, banner, - creator_id: read_community.creator_id, - removed: Some(read_community.removed), - deleted: Some(read_community.deleted), nsfw: data.nsfw, updated: Some(naive_now()), - actor_id: Some(read_community.actor_id), - local: read_community.local, - private_key: read_community.private_key, - public_key: read_community.public_key, - last_refreshed_at: None, - published: None, - followers_url: None, - inbox_url: None, - shared_inbox_url: None, + ..CommunityForm::default() }; let community_id = data.community_id; diff --git a/crates/api/src/lib.rs b/crates/api/src/lib.rs index 8c6fe8a52..fc258d6a1 100644 --- a/crates/api/src/lib.rs +++ b/crates/api/src/lib.rs @@ -528,38 +528,15 @@ mod tests { let new_person = PersonForm { name: "Gerry9812".into(), - preferred_username: None, - avatar: None, - banner: None, - banned: None, - deleted: None, - published: None, - updated: None, - actor_id: None, - bio: None, - local: None, - private_key: None, - public_key: None, - last_refreshed_at: None, - inbox_url: None, - shared_inbox_url: None, - matrix_user_id: None, + ..PersonForm::default() }; let inserted_person = Person::create(&conn, &new_person).unwrap(); let local_user_form = LocalUserForm { person_id: inserted_person.id, - email: None, password_encrypted: "123456".to_string(), - admin: None, - show_nsfw: None, - theme: None, - default_sort_type: None, - default_listing_type: None, - lang: None, - show_avatars: None, - send_notifications_to_email: None, + ..LocalUserForm::default() }; let inserted_local_user = LocalUser::create(&conn, &local_user_form).unwrap(); diff --git a/crates/api/src/local_user.rs b/crates/api/src/local_user.rs index c43db39cf..f7072b6e6 100644 --- a/crates/api/src/local_user.rs +++ b/crates/api/src/local_user.rs @@ -199,22 +199,12 @@ impl Perform for Register { // Register the new person let person_form = PersonForm { name: data.username.to_owned(), - avatar: None, - banner: None, - preferred_username: None, - published: None, - updated: None, - banned: None, - deleted: None, actor_id: Some(actor_id.clone()), - bio: None, - local: Some(true), private_key: Some(Some(actor_keypair.private_key)), public_key: Some(Some(actor_keypair.public_key)), - last_refreshed_at: None, inbox_url: Some(generate_inbox_url(&actor_id)?), shared_inbox_url: Some(Some(generate_shared_inbox_url(&actor_id)?)), - matrix_user_id: None, + ..PersonForm::default() }; // insert the person @@ -285,22 +275,14 @@ impl Perform for Register { name: default_community_name.to_string(), title: "The Default Community".to_string(), description: Some("The Default Community".to_string()), - nsfw: false, creator_id: inserted_person.id, - removed: None, - deleted: None, - updated: None, actor_id: Some(actor_id.to_owned()), - local: true, private_key: Some(main_community_keypair.private_key), public_key: Some(main_community_keypair.public_key), - last_refreshed_at: None, - published: None, - icon: None, - banner: None, followers_url: Some(generate_followers_url(&actor_id)?), inbox_url: Some(generate_inbox_url(&actor_id)?), shared_inbox_url: Some(Some(generate_shared_inbox_url(&actor_id)?)), + ..CommunityForm::default() }; blocking(context.pool(), move |conn| { Community::create(conn, &community_form) @@ -1101,12 +1083,7 @@ impl Perform for CreatePrivateMessage { content: content_slurs_removed.to_owned(), creator_id: local_user_view.person.id, recipient_id: data.recipient_id, - deleted: None, - read: None, - updated: None, - ap_id: None, - local: true, - published: None, + ..PrivateMessageForm::default() }; let inserted_private_message = match blocking(context.pool(), move |conn| { diff --git a/crates/api/src/post.rs b/crates/api/src/post.rs index 9911f6722..48153a86b 100644 --- a/crates/api/src/post.rs +++ b/crates/api/src/post.rs @@ -82,19 +82,12 @@ impl Perform for CreatePost { body: data.body.to_owned(), community_id: data.community_id, creator_id: local_user_view.person.id, - removed: None, - deleted: None, nsfw: data.nsfw, - locked: None, - stickied: None, - updated: None, embed_title: iframely_title, embed_description: iframely_description, embed_html: iframely_html, thumbnail_url: pictrs_thumbnail.map(|u| u.into()), - ap_id: None, - local: true, - published: None, + ..PostForm::default() }; let inserted_post = @@ -399,24 +392,18 @@ impl Perform for EditPost { fetch_iframely_and_pictrs_data(context.client(), data_url).await; let post_form = PostForm { + creator_id: orig_post.creator_id.to_owned(), + community_id: orig_post.community_id, name: data.name.trim().to_owned(), url: data_url.map(|u| u.to_owned().into()), body: data.body.to_owned(), nsfw: data.nsfw, - creator_id: orig_post.creator_id.to_owned(), - community_id: orig_post.community_id, - removed: Some(orig_post.removed), - deleted: Some(orig_post.deleted), - locked: Some(orig_post.locked), - stickied: Some(orig_post.stickied), updated: Some(naive_now()), embed_title: iframely_title, embed_description: iframely_description, embed_html: iframely_html, thumbnail_url: pictrs_thumbnail.map(|u| u.into()), - ap_id: Some(orig_post.ap_id), - local: orig_post.local, - published: None, + ..PostForm::default() }; let post_id = data.post_id; diff --git a/crates/api_structs/src/community.rs b/crates/api_structs/src/community.rs index bd0e129dc..a03440447 100644 --- a/crates/api_structs/src/community.rs +++ b/crates/api_structs/src/community.rs @@ -28,7 +28,7 @@ pub struct CreateCommunity { pub description: Option, pub icon: Option, pub banner: Option, - pub nsfw: bool, + pub nsfw: Option, pub auth: String, } @@ -88,7 +88,7 @@ pub struct EditCommunity { pub description: Option, pub icon: Option, pub banner: Option, - pub nsfw: bool, + pub nsfw: Option, pub auth: String, } diff --git a/crates/apub/src/objects/comment.rs b/crates/apub/src/objects/comment.rs index cc1d9f036..b09d4f42d 100644 --- a/crates/apub/src/objects/comment.rs +++ b/crates/apub/src/objects/comment.rs @@ -181,7 +181,7 @@ impl FromApubToForm for CommentForm { updated: note.updated().map(|u| u.to_owned().naive_local()), deleted: None, ap_id: Some(check_object_domain(note, expected_domain)?), - local: false, + local: Some(false), }) } } diff --git a/crates/apub/src/objects/community.rs b/crates/apub/src/objects/community.rs index 936938130..a4c0d6c34 100644 --- a/crates/apub/src/objects/community.rs +++ b/crates/apub/src/objects/community.rs @@ -205,9 +205,9 @@ impl FromApubToForm for CommunityForm { published: group.inner.published().map(|u| u.to_owned().naive_local()), updated: group.inner.updated().map(|u| u.to_owned().naive_local()), deleted: None, - nsfw: group.ext_one.sensitive.unwrap_or(false), + nsfw: Some(group.ext_one.sensitive.unwrap_or(false)), actor_id: Some(check_object_domain(group, expected_domain)?), - local: false, + local: Some(false), private_key: None, public_key: Some(group.ext_two.to_owned().public_key.public_key_pem), last_refreshed_at: Some(naive_now()), diff --git a/crates/apub/src/objects/post.rs b/crates/apub/src/objects/post.rs index 776946cbd..8f01218a9 100644 --- a/crates/apub/src/objects/post.rs +++ b/crates/apub/src/objects/post.rs @@ -217,7 +217,7 @@ impl FromApubToForm for PostForm { embed_html: iframely_html, thumbnail_url: pictrs_thumbnail.map(|u| u.into()), ap_id: Some(check_object_domain(page, expected_domain)?), - local: false, + local: Some(false), }) } } diff --git a/crates/apub/src/objects/private_message.rs b/crates/apub/src/objects/private_message.rs index d8c0077cf..b332446f5 100644 --- a/crates/apub/src/objects/private_message.rs +++ b/crates/apub/src/objects/private_message.rs @@ -121,7 +121,7 @@ impl FromApubToForm for PrivateMessageForm { deleted: None, read: None, ap_id: Some(check_object_domain(note, expected_domain)?), - local: false, + local: Some(false), }) } } diff --git a/crates/db_queries/src/aggregates/comment_aggregates.rs b/crates/db_queries/src/aggregates/comment_aggregates.rs index d3e925244..a2bea11ef 100644 --- a/crates/db_queries/src/aggregates/comment_aggregates.rs +++ b/crates/db_queries/src/aggregates/comment_aggregates.rs @@ -44,44 +44,14 @@ mod tests { let new_person = PersonForm { name: "thommy_comment_agg".into(), - preferred_username: None, - avatar: None, - banner: None, - banned: None, - deleted: None, - published: None, - updated: None, - actor_id: None, - bio: None, - local: None, - private_key: None, - public_key: None, - last_refreshed_at: None, - inbox_url: None, - shared_inbox_url: None, - matrix_user_id: None, + ..PersonForm::default() }; let inserted_person = Person::create(&conn, &new_person).unwrap(); let another_person = PersonForm { name: "jerry_comment_agg".into(), - preferred_username: None, - avatar: None, - banner: None, - banned: None, - deleted: None, - published: None, - updated: None, - actor_id: None, - bio: None, - local: None, - private_key: None, - public_key: None, - last_refreshed_at: None, - inbox_url: None, - shared_inbox_url: None, - matrix_user_id: None, + ..PersonForm::default() }; let another_inserted_person = Person::create(&conn, &another_person).unwrap(); @@ -90,45 +60,16 @@ mod tests { name: "TIL_comment_agg".into(), creator_id: inserted_person.id, title: "nada".to_owned(), - description: None, - nsfw: false, - removed: None, - deleted: None, - updated: None, - actor_id: None, - local: true, - private_key: None, - public_key: None, - last_refreshed_at: None, - published: None, - icon: None, - banner: None, - followers_url: None, - inbox_url: None, - shared_inbox_url: None, + ..CommunityForm::default() }; let inserted_community = Community::create(&conn, &new_community).unwrap(); let new_post = PostForm { name: "A test post".into(), - url: None, - body: None, creator_id: inserted_person.id, community_id: inserted_community.id, - removed: None, - deleted: None, - locked: None, - stickied: None, - nsfw: false, - updated: None, - embed_title: None, - embed_description: None, - embed_html: None, - thumbnail_url: None, - ap_id: None, - local: true, - published: None, + ..PostForm::default() }; let inserted_post = Post::create(&conn, &new_post).unwrap(); @@ -137,14 +78,7 @@ mod tests { content: "A test comment".into(), creator_id: inserted_person.id, post_id: inserted_post.id, - removed: None, - deleted: None, - read: None, - parent_id: None, - published: None, - updated: None, - ap_id: None, - local: true, + ..CommentForm::default() }; let inserted_comment = Comment::create(&conn, &comment_form).unwrap(); @@ -153,14 +87,8 @@ mod tests { content: "A test comment".into(), creator_id: inserted_person.id, post_id: inserted_post.id, - removed: None, - deleted: None, - read: None, parent_id: Some(inserted_comment.id), - published: None, - updated: None, - ap_id: None, - local: true, + ..CommentForm::default() }; let _inserted_child_comment = Comment::create(&conn, &child_comment_form).unwrap(); diff --git a/crates/db_queries/src/aggregates/community_aggregates.rs b/crates/db_queries/src/aggregates/community_aggregates.rs index ad90f20f6..25c0b394e 100644 --- a/crates/db_queries/src/aggregates/community_aggregates.rs +++ b/crates/db_queries/src/aggregates/community_aggregates.rs @@ -48,44 +48,14 @@ mod tests { let new_person = PersonForm { name: "thommy_community_agg".into(), - preferred_username: None, - avatar: None, - banner: None, - banned: None, - deleted: None, - published: None, - updated: None, - actor_id: None, - bio: None, - local: None, - private_key: None, - public_key: None, - last_refreshed_at: None, - inbox_url: None, - shared_inbox_url: None, - matrix_user_id: None, + ..PersonForm::default() }; let inserted_person = Person::create(&conn, &new_person).unwrap(); let another_person = PersonForm { name: "jerry_community_agg".into(), - preferred_username: None, - avatar: None, - banner: None, - banned: None, - deleted: None, - published: None, - updated: None, - actor_id: None, - bio: None, - local: None, - private_key: None, - public_key: None, - last_refreshed_at: None, - inbox_url: None, - shared_inbox_url: None, - matrix_user_id: None, + ..PersonForm::default() }; let another_inserted_person = Person::create(&conn, &another_person).unwrap(); @@ -94,22 +64,7 @@ mod tests { name: "TIL_community_agg".into(), creator_id: inserted_person.id, title: "nada".to_owned(), - description: None, - nsfw: false, - removed: None, - deleted: None, - updated: None, - actor_id: None, - local: true, - private_key: None, - public_key: None, - last_refreshed_at: None, - published: None, - icon: None, - banner: None, - followers_url: None, - inbox_url: None, - shared_inbox_url: None, + ..CommunityForm::default() }; let inserted_community = Community::create(&conn, &new_community).unwrap(); @@ -118,22 +73,7 @@ mod tests { name: "TIL_community_agg_2".into(), creator_id: inserted_person.id, title: "nada".to_owned(), - description: None, - nsfw: false, - removed: None, - deleted: None, - updated: None, - actor_id: None, - local: true, - private_key: None, - public_key: None, - last_refreshed_at: None, - published: None, - icon: None, - banner: None, - followers_url: None, - inbox_url: None, - shared_inbox_url: None, + ..CommunityForm::default() }; let another_inserted_community = Community::create(&conn, &another_community).unwrap(); @@ -164,23 +104,9 @@ mod tests { let new_post = PostForm { name: "A test post".into(), - url: None, - body: None, creator_id: inserted_person.id, community_id: inserted_community.id, - removed: None, - deleted: None, - locked: None, - stickied: None, - nsfw: false, - updated: None, - embed_title: None, - embed_description: None, - embed_html: None, - thumbnail_url: None, - ap_id: None, - local: true, - published: None, + ..PostForm::default() }; let inserted_post = Post::create(&conn, &new_post).unwrap(); @@ -189,14 +115,7 @@ mod tests { content: "A test comment".into(), creator_id: inserted_person.id, post_id: inserted_post.id, - removed: None, - deleted: None, - read: None, - parent_id: None, - published: None, - updated: None, - ap_id: None, - local: true, + ..CommentForm::default() }; let inserted_comment = Comment::create(&conn, &comment_form).unwrap(); @@ -205,14 +124,8 @@ mod tests { content: "A test comment".into(), creator_id: inserted_person.id, post_id: inserted_post.id, - removed: None, - deleted: None, - read: None, parent_id: Some(inserted_comment.id), - published: None, - updated: None, - ap_id: None, - local: true, + ..CommentForm::default() }; let _inserted_child_comment = Comment::create(&conn, &child_comment_form).unwrap(); diff --git a/crates/db_queries/src/aggregates/person_aggregates.rs b/crates/db_queries/src/aggregates/person_aggregates.rs index f6a6cd1ba..953f74ee7 100644 --- a/crates/db_queries/src/aggregates/person_aggregates.rs +++ b/crates/db_queries/src/aggregates/person_aggregates.rs @@ -44,44 +44,14 @@ mod tests { let new_person = PersonForm { name: "thommy_user_agg".into(), - preferred_username: None, - avatar: None, - banner: None, - banned: None, - deleted: None, - published: None, - updated: None, - actor_id: None, - bio: None, - local: None, - private_key: None, - public_key: None, - last_refreshed_at: None, - inbox_url: None, - shared_inbox_url: None, - matrix_user_id: None, + ..PersonForm::default() }; let inserted_person = Person::create(&conn, &new_person).unwrap(); let another_person = PersonForm { name: "jerry_user_agg".into(), - preferred_username: None, - avatar: None, - banner: None, - banned: None, - deleted: None, - published: None, - updated: None, - actor_id: None, - bio: None, - local: None, - private_key: None, - public_key: None, - last_refreshed_at: None, - inbox_url: None, - shared_inbox_url: None, - matrix_user_id: None, + ..PersonForm::default() }; let another_inserted_person = Person::create(&conn, &another_person).unwrap(); @@ -90,45 +60,16 @@ mod tests { name: "TIL_site_agg".into(), creator_id: inserted_person.id, title: "nada".to_owned(), - description: None, - nsfw: false, - removed: None, - deleted: None, - updated: None, - actor_id: None, - local: true, - private_key: None, - public_key: None, - last_refreshed_at: None, - published: None, - icon: None, - banner: None, - followers_url: None, - inbox_url: None, - shared_inbox_url: None, + ..CommunityForm::default() }; let inserted_community = Community::create(&conn, &new_community).unwrap(); let new_post = PostForm { name: "A test post".into(), - url: None, - body: None, creator_id: inserted_person.id, community_id: inserted_community.id, - removed: None, - deleted: None, - locked: None, - stickied: None, - nsfw: false, - updated: None, - embed_title: None, - embed_description: None, - embed_html: None, - thumbnail_url: None, - ap_id: None, - local: true, - published: None, + ..PostForm::default() }; let inserted_post = Post::create(&conn, &new_post).unwrap(); @@ -145,14 +86,7 @@ mod tests { content: "A test comment".into(), creator_id: inserted_person.id, post_id: inserted_post.id, - removed: None, - deleted: None, - read: None, - parent_id: None, - published: None, - updated: None, - ap_id: None, - local: true, + ..CommentForm::default() }; let inserted_comment = Comment::create(&conn, &comment_form).unwrap(); @@ -170,14 +104,8 @@ mod tests { content: "A test comment".into(), creator_id: inserted_person.id, post_id: inserted_post.id, - removed: None, - deleted: None, - read: None, parent_id: Some(inserted_comment.id), - published: None, - updated: None, - ap_id: None, - local: true, + ..CommentForm::default() }; let inserted_child_comment = Comment::create(&conn, &child_comment_form).unwrap(); diff --git a/crates/db_queries/src/aggregates/post_aggregates.rs b/crates/db_queries/src/aggregates/post_aggregates.rs index a32b9da66..fe7381316 100644 --- a/crates/db_queries/src/aggregates/post_aggregates.rs +++ b/crates/db_queries/src/aggregates/post_aggregates.rs @@ -48,44 +48,14 @@ mod tests { let new_person = PersonForm { name: "thommy_community_agg".into(), - preferred_username: None, - avatar: None, - banner: None, - banned: None, - deleted: None, - published: None, - updated: None, - actor_id: None, - bio: None, - local: None, - private_key: None, - public_key: None, - last_refreshed_at: None, - inbox_url: None, - shared_inbox_url: None, - matrix_user_id: None, + ..PersonForm::default() }; let inserted_person = Person::create(&conn, &new_person).unwrap(); let another_person = PersonForm { name: "jerry_community_agg".into(), - preferred_username: None, - avatar: None, - banner: None, - banned: None, - deleted: None, - published: None, - updated: None, - actor_id: None, - bio: None, - local: None, - private_key: None, - public_key: None, - last_refreshed_at: None, - inbox_url: None, - shared_inbox_url: None, - matrix_user_id: None, + ..PersonForm::default() }; let another_inserted_person = Person::create(&conn, &another_person).unwrap(); @@ -94,45 +64,16 @@ mod tests { name: "TIL_community_agg".into(), creator_id: inserted_person.id, title: "nada".to_owned(), - description: None, - nsfw: false, - removed: None, - deleted: None, - updated: None, - actor_id: None, - local: true, - private_key: None, - public_key: None, - last_refreshed_at: None, - published: None, - icon: None, - banner: None, - followers_url: None, - inbox_url: None, - shared_inbox_url: None, + ..CommunityForm::default() }; let inserted_community = Community::create(&conn, &new_community).unwrap(); let new_post = PostForm { name: "A test post".into(), - url: None, - body: None, creator_id: inserted_person.id, community_id: inserted_community.id, - removed: None, - deleted: None, - locked: None, - stickied: None, - nsfw: false, - updated: None, - embed_title: None, - embed_description: None, - embed_html: None, - thumbnail_url: None, - ap_id: None, - local: true, - published: None, + ..PostForm::default() }; let inserted_post = Post::create(&conn, &new_post).unwrap(); @@ -141,14 +82,7 @@ mod tests { content: "A test comment".into(), creator_id: inserted_person.id, post_id: inserted_post.id, - removed: None, - deleted: None, - read: None, - parent_id: None, - published: None, - updated: None, - ap_id: None, - local: true, + ..CommentForm::default() }; let inserted_comment = Comment::create(&conn, &comment_form).unwrap(); @@ -157,14 +91,8 @@ mod tests { content: "A test comment".into(), creator_id: inserted_person.id, post_id: inserted_post.id, - removed: None, - deleted: None, - read: None, parent_id: Some(inserted_comment.id), - published: None, - updated: None, - ap_id: None, - local: true, + ..CommentForm::default() }; let _inserted_child_comment = Comment::create(&conn, &child_comment_form).unwrap(); diff --git a/crates/db_queries/src/aggregates/site_aggregates.rs b/crates/db_queries/src/aggregates/site_aggregates.rs index 67cb04a7e..64fbdf7df 100644 --- a/crates/db_queries/src/aggregates/site_aggregates.rs +++ b/crates/db_queries/src/aggregates/site_aggregates.rs @@ -42,22 +42,7 @@ mod tests { let new_person = PersonForm { name: "thommy_site_agg".into(), - preferred_username: None, - avatar: None, - banner: None, - banned: None, - deleted: None, - published: None, - updated: None, - actor_id: None, - bio: None, - local: None, - private_key: None, - public_key: None, - last_refreshed_at: None, - inbox_url: None, - shared_inbox_url: None, - matrix_user_id: None, + ..PersonForm::default() }; let inserted_person = Person::create(&conn, &new_person).unwrap(); @@ -80,45 +65,16 @@ mod tests { name: "TIL_site_agg".into(), creator_id: inserted_person.id, title: "nada".to_owned(), - description: None, - nsfw: false, - removed: None, - deleted: None, - updated: None, - actor_id: None, - local: true, - private_key: None, - public_key: None, - last_refreshed_at: None, - published: None, - icon: None, - banner: None, - followers_url: None, - inbox_url: None, - shared_inbox_url: None, + ..CommunityForm::default() }; let inserted_community = Community::create(&conn, &new_community).unwrap(); let new_post = PostForm { name: "A test post".into(), - url: None, - body: None, creator_id: inserted_person.id, community_id: inserted_community.id, - removed: None, - deleted: None, - locked: None, - stickied: None, - nsfw: false, - updated: None, - embed_title: None, - embed_description: None, - embed_html: None, - thumbnail_url: None, - ap_id: None, - local: true, - published: None, + ..PostForm::default() }; // Insert two of those posts @@ -129,14 +85,7 @@ mod tests { content: "A test comment".into(), creator_id: inserted_person.id, post_id: inserted_post.id, - removed: None, - deleted: None, - read: None, - parent_id: None, - published: None, - updated: None, - ap_id: None, - local: true, + ..CommentForm::default() }; // Insert two of those comments @@ -146,14 +95,8 @@ mod tests { content: "A test comment".into(), creator_id: inserted_person.id, post_id: inserted_post.id, - removed: None, - deleted: None, - read: None, parent_id: Some(inserted_comment.id), - published: None, - updated: None, - ap_id: None, - local: true, + ..CommentForm::default() }; let _inserted_child_comment = Comment::create(&conn, &child_comment_form).unwrap(); diff --git a/crates/db_queries/src/source/activity.rs b/crates/db_queries/src/source/activity.rs index 5d345db69..d1fc0622f 100644 --- a/crates/db_queries/src/source/activity.rs +++ b/crates/db_queries/src/source/activity.rs @@ -74,7 +74,7 @@ impl Activity_ for Activity { let activity_form = ActivityForm { ap_id, data: serde_json::to_value(&data)?, - local, + local: Some(local), sensitive, updated: None, }; @@ -138,22 +138,7 @@ mod tests { let creator_form = PersonForm { name: "activity_creator_pm".into(), - preferred_username: None, - avatar: None, - banner: None, - banned: None, - deleted: None, - published: None, - updated: None, - actor_id: None, - bio: None, - local: None, - private_key: None, - public_key: None, - last_refreshed_at: None, - inbox_url: None, - shared_inbox_url: None, - matrix_user_id: None, + ..PersonForm::default() }; let inserted_creator = Person::create(&conn, &creator_form).unwrap(); @@ -180,7 +165,7 @@ mod tests { let activity_form = ActivityForm { ap_id: ap_id.clone(), data: test_json.to_owned(), - local: true, + local: Some(true), sensitive: false, updated: None, }; diff --git a/crates/db_queries/src/source/comment.rs b/crates/db_queries/src/source/comment.rs index 47965d3b4..8d77626aa 100644 --- a/crates/db_queries/src/source/comment.rs +++ b/crates/db_queries/src/source/comment.rs @@ -246,22 +246,7 @@ mod tests { let new_person = PersonForm { name: "terry".into(), - preferred_username: None, - avatar: None, - banner: None, - banned: None, - deleted: None, - published: None, - updated: None, - actor_id: None, - bio: None, - local: None, - private_key: None, - public_key: None, - last_refreshed_at: None, - inbox_url: None, - shared_inbox_url: None, - matrix_user_id: None, + ..PersonForm::default() }; let inserted_person = Person::create(&conn, &new_person).unwrap(); @@ -269,23 +254,8 @@ mod tests { let new_community = CommunityForm { name: "test community".to_string(), title: "nada".to_owned(), - description: None, creator_id: inserted_person.id, - removed: None, - deleted: None, - updated: None, - nsfw: false, - actor_id: None, - local: true, - private_key: None, - public_key: None, - last_refreshed_at: None, - published: None, - banner: None, - icon: None, - inbox_url: None, - shared_inbox_url: None, - followers_url: None, + ..CommunityForm::default() }; let inserted_community = Community::create(&conn, &new_community).unwrap(); @@ -293,22 +263,8 @@ mod tests { let new_post = PostForm { name: "A test post".into(), creator_id: inserted_person.id, - url: None, - body: None, community_id: inserted_community.id, - removed: None, - deleted: None, - locked: None, - stickied: None, - updated: None, - nsfw: false, - embed_title: None, - embed_description: None, - embed_html: None, - thumbnail_url: None, - ap_id: None, - local: true, - published: None, + ..PostForm::default() }; let inserted_post = Post::create(&conn, &new_post).unwrap(); @@ -317,14 +273,7 @@ mod tests { content: "A test comment".into(), creator_id: inserted_person.id, post_id: inserted_post.id, - removed: None, - deleted: None, - read: None, - parent_id: None, - published: None, - updated: None, - ap_id: None, - local: true, + ..CommentForm::default() }; let inserted_comment = Comment::create(&conn, &comment_form).unwrap(); @@ -349,13 +298,7 @@ mod tests { creator_id: inserted_person.id, post_id: inserted_post.id, parent_id: Some(inserted_comment.id), - removed: None, - deleted: None, - read: None, - published: None, - updated: None, - ap_id: None, - local: true, + ..CommentForm::default() }; let inserted_child_comment = Comment::create(&conn, &child_comment_form).unwrap(); diff --git a/crates/db_queries/src/source/community.rs b/crates/db_queries/src/source/community.rs index a0038c9d3..1970eef88 100644 --- a/crates/db_queries/src/source/community.rs +++ b/crates/db_queries/src/source/community.rs @@ -356,22 +356,7 @@ mod tests { let new_person = PersonForm { name: "bobbee".into(), - preferred_username: None, - avatar: None, - banner: None, - banned: None, - deleted: None, - published: None, - updated: None, - actor_id: None, - bio: None, - local: None, - private_key: None, - public_key: None, - last_refreshed_at: None, - inbox_url: None, - shared_inbox_url: None, - matrix_user_id: None, + ..PersonForm::default() }; let inserted_person = Person::create(&conn, &new_person).unwrap(); @@ -380,22 +365,7 @@ mod tests { name: "TIL".into(), creator_id: inserted_person.id, title: "nada".to_owned(), - description: None, - nsfw: false, - removed: None, - deleted: None, - updated: None, - actor_id: None, - local: true, - private_key: None, - public_key: None, - last_refreshed_at: None, - published: None, - icon: None, - banner: None, - followers_url: None, - inbox_url: None, - shared_inbox_url: None, + ..CommunityForm::default() }; let inserted_community = Community::create(&conn, &new_community).unwrap(); diff --git a/crates/db_queries/src/source/moderator.rs b/crates/db_queries/src/source/moderator.rs index 3b6d25445..c641fffc7 100644 --- a/crates/db_queries/src/source/moderator.rs +++ b/crates/db_queries/src/source/moderator.rs @@ -209,44 +209,14 @@ mod tests { let new_mod = PersonForm { name: "the mod".into(), - preferred_username: None, - avatar: None, - banner: None, - banned: None, - deleted: None, - published: None, - updated: None, - actor_id: None, - bio: None, - local: None, - private_key: None, - public_key: None, - last_refreshed_at: None, - inbox_url: None, - shared_inbox_url: None, - matrix_user_id: None, + ..PersonForm::default() }; let inserted_mod = Person::create(&conn, &new_mod).unwrap(); let new_person = PersonForm { name: "jim2".into(), - preferred_username: None, - avatar: None, - banner: None, - banned: None, - deleted: None, - published: None, - updated: None, - actor_id: None, - bio: None, - local: None, - private_key: None, - public_key: None, - last_refreshed_at: None, - inbox_url: None, - shared_inbox_url: None, - matrix_user_id: None, + ..PersonForm::default() }; let inserted_person = Person::create(&conn, &new_person).unwrap(); @@ -254,46 +224,17 @@ mod tests { let new_community = CommunityForm { name: "mod_community".to_string(), title: "nada".to_owned(), - description: None, creator_id: inserted_person.id, - removed: None, - deleted: None, - updated: None, - nsfw: false, - actor_id: None, - local: true, - private_key: None, - public_key: None, - last_refreshed_at: None, - published: None, - icon: None, - banner: None, - followers_url: None, - inbox_url: None, - shared_inbox_url: None, + ..CommunityForm::default() }; let inserted_community = Community::create(&conn, &new_community).unwrap(); let new_post = PostForm { name: "A test post thweep".into(), - url: None, - body: None, creator_id: inserted_person.id, community_id: inserted_community.id, - removed: None, - deleted: None, - locked: None, - stickied: None, - updated: None, - nsfw: false, - embed_title: None, - embed_description: None, - embed_html: None, - thumbnail_url: None, - ap_id: None, - local: true, - published: None, + ..PostForm::default() }; let inserted_post = Post::create(&conn, &new_post).unwrap(); @@ -302,14 +243,7 @@ mod tests { content: "A test comment".into(), creator_id: inserted_person.id, post_id: inserted_post.id, - removed: None, - deleted: None, - read: None, - parent_id: None, - published: None, - updated: None, - ap_id: None, - local: true, + ..CommentForm::default() }; let inserted_comment = Comment::create(&conn, &comment_form).unwrap(); diff --git a/crates/db_queries/src/source/password_reset_request.rs b/crates/db_queries/src/source/password_reset_request.rs index 654dabf65..6fe4ee3a5 100644 --- a/crates/db_queries/src/source/password_reset_request.rs +++ b/crates/db_queries/src/source/password_reset_request.rs @@ -95,22 +95,7 @@ mod tests { let new_person = PersonForm { name: "thommy prw".into(), - preferred_username: None, - avatar: None, - banner: None, - banned: None, - deleted: None, - published: None, - updated: None, - actor_id: None, - bio: None, - local: None, - private_key: None, - public_key: None, - last_refreshed_at: None, - inbox_url: None, - shared_inbox_url: None, - matrix_user_id: None, + ..PersonForm::default() }; let inserted_person = Person::create(&conn, &new_person).unwrap(); @@ -118,15 +103,7 @@ mod tests { let new_local_user = LocalUserForm { person_id: inserted_person.id, password_encrypted: "pass".to_string(), - email: None, - admin: None, - show_nsfw: None, - theme: None, - default_sort_type: None, - default_listing_type: None, - lang: None, - show_avatars: None, - send_notifications_to_email: None, + ..LocalUserForm::default() }; let inserted_local_user = LocalUser::create(&conn, &new_local_user).unwrap(); diff --git a/crates/db_queries/src/source/person.rs b/crates/db_queries/src/source/person.rs index 40adab3df..6d5ad9b4d 100644 --- a/crates/db_queries/src/source/person.rs +++ b/crates/db_queries/src/source/person.rs @@ -243,22 +243,7 @@ mod tests { let new_person = PersonForm { name: "holly".into(), - preferred_username: None, - avatar: None, - banner: None, - banned: None, - deleted: None, - published: None, - updated: None, - actor_id: None, - bio: None, - local: None, - private_key: None, - public_key: None, - last_refreshed_at: None, - inbox_url: None, - shared_inbox_url: None, - matrix_user_id: None, + ..PersonForm::default() }; let inserted_person = Person::create(&conn, &new_person).unwrap(); diff --git a/crates/db_queries/src/source/person_mention.rs b/crates/db_queries/src/source/person_mention.rs index a6a86e788..5a3a7ea61 100644 --- a/crates/db_queries/src/source/person_mention.rs +++ b/crates/db_queries/src/source/person_mention.rs @@ -90,44 +90,14 @@ mod tests { let new_person = PersonForm { name: "terrylake".into(), - preferred_username: None, - avatar: None, - banner: None, - banned: None, - deleted: None, - published: None, - updated: None, - actor_id: None, - bio: None, - local: None, - private_key: None, - public_key: None, - last_refreshed_at: None, - inbox_url: None, - shared_inbox_url: None, - matrix_user_id: None, + ..PersonForm::default() }; let inserted_person = Person::create(&conn, &new_person).unwrap(); let recipient_form = PersonForm { name: "terrylakes recipient".into(), - preferred_username: None, - avatar: None, - banner: None, - banned: None, - deleted: None, - published: None, - updated: None, - actor_id: None, - bio: None, - local: None, - private_key: None, - public_key: None, - last_refreshed_at: None, - inbox_url: None, - shared_inbox_url: None, - matrix_user_id: None, + ..PersonForm::default() }; let inserted_recipient = Person::create(&conn, &recipient_form).unwrap(); @@ -135,23 +105,8 @@ mod tests { let new_community = CommunityForm { name: "test community lake".to_string(), title: "nada".to_owned(), - description: None, creator_id: inserted_person.id, - removed: None, - deleted: None, - updated: None, - nsfw: false, - actor_id: None, - local: true, - private_key: None, - public_key: None, - last_refreshed_at: None, - published: None, - icon: None, - banner: None, - followers_url: None, - inbox_url: None, - shared_inbox_url: None, + ..CommunityForm::default() }; let inserted_community = Community::create(&conn, &new_community).unwrap(); @@ -159,22 +114,8 @@ mod tests { let new_post = PostForm { name: "A test post".into(), creator_id: inserted_person.id, - url: None, - body: None, community_id: inserted_community.id, - removed: None, - deleted: None, - locked: None, - stickied: None, - updated: None, - nsfw: false, - embed_title: None, - embed_description: None, - embed_html: None, - thumbnail_url: None, - ap_id: None, - local: true, - published: None, + ..PostForm::default() }; let inserted_post = Post::create(&conn, &new_post).unwrap(); @@ -183,14 +124,7 @@ mod tests { content: "A test comment".into(), creator_id: inserted_person.id, post_id: inserted_post.id, - removed: None, - deleted: None, - read: None, - parent_id: None, - published: None, - updated: None, - ap_id: None, - local: true, + ..CommentForm::default() }; let inserted_comment = Comment::create(&conn, &comment_form).unwrap(); diff --git a/crates/db_queries/src/source/post.rs b/crates/db_queries/src/source/post.rs index b1f6b7c2b..169ca18ef 100644 --- a/crates/db_queries/src/source/post.rs +++ b/crates/db_queries/src/source/post.rs @@ -273,22 +273,7 @@ mod tests { let new_person = PersonForm { name: "jim".into(), - preferred_username: None, - avatar: None, - banner: None, - banned: None, - deleted: None, - published: None, - updated: None, - actor_id: None, - bio: None, - local: None, - private_key: None, - public_key: None, - last_refreshed_at: None, - inbox_url: None, - shared_inbox_url: None, - matrix_user_id: None, + ..PersonForm::default() }; let inserted_person = Person::create(&conn, &new_person).unwrap(); @@ -296,46 +281,17 @@ mod tests { let new_community = CommunityForm { name: "test community_3".to_string(), title: "nada".to_owned(), - description: None, creator_id: inserted_person.id, - removed: None, - deleted: None, - updated: None, - nsfw: false, - actor_id: None, - local: true, - private_key: None, - public_key: None, - last_refreshed_at: None, - published: None, - icon: None, - banner: None, - followers_url: None, - inbox_url: None, - shared_inbox_url: None, + ..CommunityForm::default() }; let inserted_community = Community::create(&conn, &new_community).unwrap(); let new_post = PostForm { name: "A test post".into(), - url: None, - body: None, creator_id: inserted_person.id, community_id: inserted_community.id, - removed: None, - deleted: None, - locked: None, - stickied: None, - nsfw: false, - updated: None, - embed_title: None, - embed_description: None, - embed_html: None, - thumbnail_url: None, - ap_id: None, - local: true, - published: None, + ..PostForm::default() }; let inserted_post = Post::create(&conn, &new_post).unwrap(); diff --git a/crates/db_queries/src/source/private_message.rs b/crates/db_queries/src/source/private_message.rs index cd663093c..98c8e08ce 100644 --- a/crates/db_queries/src/source/private_message.rs +++ b/crates/db_queries/src/source/private_message.rs @@ -150,44 +150,14 @@ mod tests { let creator_form = PersonForm { name: "creator_pm".into(), - preferred_username: None, - avatar: None, - banner: None, - banned: None, - deleted: None, - published: None, - updated: None, - actor_id: None, - bio: None, - local: None, - private_key: None, - public_key: None, - last_refreshed_at: None, - inbox_url: None, - shared_inbox_url: None, - matrix_user_id: None, + ..PersonForm::default() }; let inserted_creator = Person::create(&conn, &creator_form).unwrap(); let recipient_form = PersonForm { name: "recipient_pm".into(), - preferred_username: None, - avatar: None, - banner: None, - banned: None, - deleted: None, - published: None, - updated: None, - actor_id: None, - bio: None, - local: None, - private_key: None, - public_key: None, - last_refreshed_at: None, - inbox_url: None, - shared_inbox_url: None, - matrix_user_id: None, + ..PersonForm::default() }; let inserted_recipient = Person::create(&conn, &recipient_form).unwrap(); @@ -196,12 +166,7 @@ mod tests { content: "A test private message".into(), creator_id: inserted_creator.id, recipient_id: inserted_recipient.id, - deleted: None, - read: None, - published: None, - updated: None, - ap_id: None, - local: true, + ..PrivateMessageForm::default() }; let inserted_private_message = PrivateMessage::create(&conn, &private_message_form).unwrap(); diff --git a/crates/db_schema/src/lib.rs b/crates/db_schema/src/lib.rs index 6b07e5cee..4efa983fe 100644 --- a/crates/db_schema/src/lib.rs +++ b/crates/db_schema/src/lib.rs @@ -22,7 +22,9 @@ use url::Url; pub mod schema; pub mod source; -#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, DieselNewType)] +#[derive( + Debug, Copy, Clone, Hash, Eq, PartialEq, Default, Serialize, Deserialize, DieselNewType, +)] pub struct PostId(pub i32); impl fmt::Display for PostId { @@ -31,7 +33,9 @@ impl fmt::Display for PostId { } } -#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, DieselNewType)] +#[derive( + Debug, Copy, Clone, Hash, Eq, PartialEq, Default, Serialize, Deserialize, DieselNewType, +)] pub struct PersonId(pub i32); #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, DieselNewType)] @@ -43,7 +47,9 @@ impl fmt::Display for CommentId { } } -#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, DieselNewType)] +#[derive( + Debug, Copy, Clone, Hash, Eq, PartialEq, Default, Serialize, Deserialize, DieselNewType, +)] pub struct CommunityId(pub i32); #[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Serialize, Deserialize, DieselNewType)] diff --git a/crates/db_schema/src/source/activity.rs b/crates/db_schema/src/source/activity.rs index 7b7f4aba3..ced8f3be4 100644 --- a/crates/db_schema/src/source/activity.rs +++ b/crates/db_schema/src/source/activity.rs @@ -18,7 +18,7 @@ pub struct Activity { #[table_name = "activity"] pub struct ActivityForm { pub data: Value, - pub local: bool, + pub local: Option, pub updated: Option, pub ap_id: DbUrl, pub sensitive: bool, diff --git a/crates/db_schema/src/source/comment.rs b/crates/db_schema/src/source/comment.rs index 8a91f601e..fba61f463 100644 --- a/crates/db_schema/src/source/comment.rs +++ b/crates/db_schema/src/source/comment.rs @@ -51,7 +51,7 @@ pub struct CommentAlias1 { pub local: bool, } -#[derive(Insertable, AsChangeset, Clone)] +#[derive(Insertable, AsChangeset, Clone, Default)] #[table_name = "comment"] pub struct CommentForm { pub creator_id: PersonId, @@ -64,7 +64,7 @@ pub struct CommentForm { pub updated: Option, pub deleted: Option, pub ap_id: Option, - pub local: bool, + pub local: Option, } #[derive(Identifiable, Queryable, Associations, PartialEq, Debug, Clone)] diff --git a/crates/db_schema/src/source/community.rs b/crates/db_schema/src/source/community.rs index 81789ecdf..427510270 100644 --- a/crates/db_schema/src/source/community.rs +++ b/crates/db_schema/src/source/community.rs @@ -51,7 +51,7 @@ pub struct CommunitySafe { pub banner: Option, } -#[derive(Insertable, AsChangeset, Debug)] +#[derive(Insertable, AsChangeset, Debug, Default)] #[table_name = "community"] pub struct CommunityForm { pub name: String, @@ -62,9 +62,9 @@ pub struct CommunityForm { pub published: Option, pub updated: Option, pub deleted: Option, - pub nsfw: bool, + pub nsfw: Option, pub actor_id: Option, - pub local: bool, + pub local: Option, pub private_key: Option, pub public_key: Option, pub last_refreshed_at: Option, diff --git a/crates/db_schema/src/source/local_user.rs b/crates/db_schema/src/source/local_user.rs index d902e6b4d..2f4a9fc2b 100644 --- a/crates/db_schema/src/source/local_user.rs +++ b/crates/db_schema/src/source/local_user.rs @@ -20,7 +20,7 @@ pub struct LocalUser { } // TODO redo these, check table defaults -#[derive(Insertable, AsChangeset, Clone)] +#[derive(Insertable, AsChangeset, Clone, Default)] #[table_name = "local_user"] pub struct LocalUserForm { pub person_id: PersonId, diff --git a/crates/db_schema/src/source/person.rs b/crates/db_schema/src/source/person.rs index 8c66b1a8e..f5f10ac46 100644 --- a/crates/db_schema/src/source/person.rs +++ b/crates/db_schema/src/source/person.rs @@ -135,7 +135,7 @@ pub struct PersonSafeAlias2 { pub matrix_user_id: Option, } -#[derive(Insertable, AsChangeset, Clone)] +#[derive(Insertable, AsChangeset, Clone, Default)] #[table_name = "person"] pub struct PersonForm { pub name: String, diff --git a/crates/db_schema/src/source/post.rs b/crates/db_schema/src/source/post.rs index 34b889d46..87681e010 100644 --- a/crates/db_schema/src/source/post.rs +++ b/crates/db_schema/src/source/post.rs @@ -31,7 +31,7 @@ pub struct Post { pub local: bool, } -#[derive(Insertable, AsChangeset)] +#[derive(Insertable, AsChangeset, Default)] #[table_name = "post"] pub struct PostForm { pub name: String, @@ -51,7 +51,7 @@ pub struct PostForm { pub embed_html: Option, pub thumbnail_url: Option, pub ap_id: Option, - pub local: bool, + pub local: Option, } #[derive(Identifiable, Queryable, Associations, PartialEq, Debug)] diff --git a/crates/db_schema/src/source/private_message.rs b/crates/db_schema/src/source/private_message.rs index 6d46c0129..6710c2dcf 100644 --- a/crates/db_schema/src/source/private_message.rs +++ b/crates/db_schema/src/source/private_message.rs @@ -16,7 +16,7 @@ pub struct PrivateMessage { pub local: bool, } -#[derive(Insertable, AsChangeset)] +#[derive(Insertable, AsChangeset, Default)] #[table_name = "private_message"] pub struct PrivateMessageForm { pub creator_id: PersonId, @@ -27,5 +27,5 @@ pub struct PrivateMessageForm { pub published: Option, pub updated: Option, pub ap_id: Option, - pub local: bool, + pub local: Option, } diff --git a/crates/db_views/src/comment_view.rs b/crates/db_views/src/comment_view.rs index 478a906f2..e44ddfef3 100644 --- a/crates/db_views/src/comment_view.rs +++ b/crates/db_views/src/comment_view.rs @@ -454,22 +454,7 @@ mod tests { let new_person = PersonForm { name: "timmy".into(), - preferred_username: None, - avatar: None, - banner: None, - banned: None, - deleted: None, - published: None, - updated: None, - actor_id: None, - bio: None, - local: None, - private_key: None, - public_key: None, - last_refreshed_at: None, - inbox_url: None, - shared_inbox_url: None, - matrix_user_id: None, + ..PersonForm::default() }; let inserted_person = Person::create(&conn, &new_person).unwrap(); @@ -477,23 +462,8 @@ mod tests { let new_community = CommunityForm { name: "test community 5".to_string(), title: "nada".to_owned(), - description: None, creator_id: inserted_person.id, - removed: None, - deleted: None, - updated: None, - nsfw: false, - actor_id: None, - local: true, - private_key: None, - public_key: None, - last_refreshed_at: None, - published: None, - icon: None, - banner: None, - followers_url: None, - inbox_url: None, - shared_inbox_url: None, + ..CommunityForm::default() }; let inserted_community = Community::create(&conn, &new_community).unwrap(); @@ -501,22 +471,8 @@ mod tests { let new_post = PostForm { name: "A test post 2".into(), creator_id: inserted_person.id, - url: None, - body: None, community_id: inserted_community.id, - removed: None, - deleted: None, - locked: None, - stickied: None, - updated: None, - nsfw: false, - embed_title: None, - embed_description: None, - embed_html: None, - thumbnail_url: None, - ap_id: None, - local: true, - published: None, + ..PostForm::default() }; let inserted_post = Post::create(&conn, &new_post).unwrap(); @@ -525,14 +481,7 @@ mod tests { content: "A test comment 32".into(), creator_id: inserted_person.id, post_id: inserted_post.id, - parent_id: None, - removed: None, - deleted: None, - read: None, - published: None, - updated: None, - ap_id: None, - local: true, + ..CommentForm::default() }; let inserted_comment = Comment::create(&conn, &comment_form).unwrap(); diff --git a/crates/db_views/src/post_view.rs b/crates/db_views/src/post_view.rs index 08d889d18..8e305b486 100644 --- a/crates/db_views/src/post_view.rs +++ b/crates/db_views/src/post_view.rs @@ -454,22 +454,7 @@ mod tests { let new_person = PersonForm { name: person_name.to_owned(), - preferred_username: None, - avatar: None, - banner: None, - banned: None, - deleted: None, - published: None, - updated: None, - actor_id: None, - bio: None, - local: None, - private_key: None, - public_key: None, - last_refreshed_at: None, - inbox_url: None, - shared_inbox_url: None, - matrix_user_id: None, + ..PersonForm::default() }; let inserted_person = Person::create(&conn, &new_person).unwrap(); @@ -477,46 +462,17 @@ mod tests { let new_community = CommunityForm { name: community_name.to_owned(), title: "nada".to_owned(), - description: None, creator_id: inserted_person.id, - removed: None, - deleted: None, - updated: None, - nsfw: false, - actor_id: None, - local: true, - private_key: None, - public_key: None, - last_refreshed_at: None, - published: None, - icon: None, - banner: None, - followers_url: None, - inbox_url: None, - shared_inbox_url: None, + ..CommunityForm::default() }; let inserted_community = Community::create(&conn, &new_community).unwrap(); let new_post = PostForm { name: post_name.to_owned(), - url: None, - body: None, creator_id: inserted_person.id, community_id: inserted_community.id, - removed: None, - deleted: None, - locked: None, - stickied: None, - updated: None, - nsfw: false, - embed_title: None, - embed_description: None, - embed_html: None, - thumbnail_url: None, - ap_id: None, - local: true, - published: None, + ..PostForm::default() }; let inserted_post = Post::create(&conn, &new_post).unwrap(); diff --git a/src/code_migrations.rs b/src/code_migrations.rs index e9b43356a..144c39f87 100644 --- a/src/code_migrations.rs +++ b/src/code_migrations.rs @@ -55,22 +55,11 @@ fn user_updates_2020_04_02(conn: &PgConnection) -> Result<(), LemmyError> { let form = PersonForm { name: cperson.name.to_owned(), - avatar: None, - banner: None, - preferred_username: None, - published: None, - updated: None, - banned: None, - deleted: None, actor_id: Some(generate_apub_endpoint(EndpointType::Person, &cperson.name)?), - bio: None, - local: None, private_key: Some(Some(keypair.private_key)), public_key: Some(Some(keypair.public_key)), last_refreshed_at: Some(naive_now()), - inbox_url: None, - shared_inbox_url: None, - matrix_user_id: None, + ..PersonForm::default() }; Person::update(&conn, cperson.id, &form)?; @@ -103,10 +92,10 @@ fn community_updates_2020_04_02(conn: &PgConnection) -> Result<(), LemmyError> { creator_id: ccommunity.creator_id, removed: None, deleted: None, - nsfw: ccommunity.nsfw, + nsfw: None, updated: None, actor_id: Some(community_actor_id.to_owned()), - local: ccommunity.local, + local: Some(ccommunity.local), private_key: Some(keypair.private_key), public_key: Some(keypair.public_key), last_refreshed_at: Some(naive_now()), From eb45bf2d0a8533c20ccd8c47b98ee0f6473e7715 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Mon, 22 Mar 2021 10:28:00 -0400 Subject: [PATCH 6/9] Moving admin to person table. Fixes #1515 --- crates/api/src/lib.rs | 2 +- crates/api/src/local_user.rs | 8 ++++---- crates/apub/src/objects/person.rs | 1 + crates/db_queries/src/source/local_user.rs | 10 ---------- crates/db_queries/src/source/person.rs | 14 ++++++++++++++ crates/db_schema/src/schema.rs | 4 +++- crates/db_schema/src/source/local_user.rs | 3 --- crates/db_schema/src/source/person.rs | 7 +++++++ crates/db_views/src/comment_view.rs | 1 + crates/db_views/src/post_view.rs | 1 + crates/db_views_actor/src/person_view.rs | 5 ++--- .../down.sql | 6 +++++- .../up.sql | 6 +++++- 13 files changed, 44 insertions(+), 24 deletions(-) diff --git a/crates/api/src/lib.rs b/crates/api/src/lib.rs index fc258d6a1..dacf46f2b 100644 --- a/crates/api/src/lib.rs +++ b/crates/api/src/lib.rs @@ -79,7 +79,7 @@ pub(crate) async fn is_mod_or_admin( } pub fn is_admin(local_user_view: &LocalUserView) -> Result<(), LemmyError> { - if !local_user_view.local_user.admin { + if !local_user_view.person.admin { return Err(ApiError::err("not_an_admin").into()); } Ok(()) diff --git a/crates/api/src/local_user.rs b/crates/api/src/local_user.rs index f7072b6e6..5fbbdeec4 100644 --- a/crates/api/src/local_user.rs +++ b/crates/api/src/local_user.rs @@ -204,6 +204,7 @@ impl Perform for Register { public_key: Some(Some(actor_keypair.public_key)), inbox_url: Some(generate_inbox_url(&actor_id)?), shared_inbox_url: Some(Some(generate_shared_inbox_url(&actor_id)?)), + admin: Some(no_admins), ..PersonForm::default() }; @@ -224,7 +225,6 @@ impl Perform for Register { person_id: inserted_person.id, email: Some(data.email.to_owned()), password_encrypted: data.password.to_owned(), - admin: Some(no_admins), show_nsfw: Some(data.show_nsfw), theme: Some("browser".into()), default_sort_type: Some(SortType::Active as i16), @@ -455,6 +455,7 @@ impl Perform for SaveUserSettings { actor_id: None, bio, local: None, + admin: None, private_key: None, public_key: None, last_refreshed_at: None, @@ -477,7 +478,6 @@ impl Perform for SaveUserSettings { person_id, email, password_encrypted, - admin: None, show_nsfw: data.show_nsfw, theme: data.theme.to_owned(), default_sort_type, @@ -638,7 +638,7 @@ impl Perform for AddAdmin { let added = data.added; let added_person_id = data.person_id; let added_admin = match blocking(context.pool(), move |conn| { - LocalUser::add_admin(conn, added_person_id, added) + Person::add_admin(conn, added_person_id, added) }) .await? { @@ -651,7 +651,7 @@ impl Perform for AddAdmin { // Mod tables let form = ModAddForm { mod_person_id: local_user_view.person.id, - other_person_id: added_admin.person_id, + other_person_id: added_admin.id, removed: Some(!data.added), }; diff --git a/crates/apub/src/objects/person.rs b/crates/apub/src/objects/person.rs index d1eb67071..c8e3a3501 100644 --- a/crates/apub/src/objects/person.rs +++ b/crates/apub/src/objects/person.rs @@ -182,6 +182,7 @@ impl FromApubToForm for PersonForm { actor_id: Some(check_object_domain(person, expected_domain)?), bio: Some(bio), local: Some(false), + admin: Some(false), private_key: None, public_key: Some(Some(person.ext_one.public_key.to_owned().public_key_pem)), last_refreshed_at: Some(naive_now()), diff --git a/crates/db_queries/src/source/local_user.rs b/crates/db_queries/src/source/local_user.rs index 7e84011b4..18720ceba 100644 --- a/crates/db_queries/src/source/local_user.rs +++ b/crates/db_queries/src/source/local_user.rs @@ -6,7 +6,6 @@ use lemmy_db_schema::{ schema::local_user::dsl::*, source::local_user::{LocalUser, LocalUserForm}, LocalUserId, - PersonId, }; mod safe_settings_type { @@ -17,7 +16,6 @@ mod safe_settings_type { id, person_id, email, - admin, show_nsfw, theme, default_sort_type, @@ -37,7 +35,6 @@ mod safe_settings_type { id, person_id, email, - admin, show_nsfw, theme, default_sort_type, @@ -58,7 +55,6 @@ pub trait LocalUser_ { local_user_id: LocalUserId, new_password: &str, ) -> Result; - fn add_admin(conn: &PgConnection, person_id: PersonId, added: bool) -> Result; } impl LocalUser_ for LocalUser { @@ -85,12 +81,6 @@ impl LocalUser_ for LocalUser { )) .get_result::(conn) } - - fn add_admin(conn: &PgConnection, for_person_id: PersonId, added: bool) -> Result { - diesel::update(local_user.filter(person_id.eq(for_person_id))) - .set(admin.eq(added)) - .get_result::(conn) - } } impl Crud for LocalUser { diff --git a/crates/db_queries/src/source/person.rs b/crates/db_queries/src/source/person.rs index 6d5ad9b4d..35ed540c0 100644 --- a/crates/db_queries/src/source/person.rs +++ b/crates/db_queries/src/source/person.rs @@ -28,6 +28,7 @@ mod safe_type { inbox_url, shared_inbox_url, matrix_user_id, + admin, ); impl ToSafe for Person { @@ -49,6 +50,7 @@ mod safe_type { inbox_url, shared_inbox_url, matrix_user_id, + admin, ) } } @@ -74,6 +76,7 @@ mod safe_type_alias_1 { inbox_url, shared_inbox_url, matrix_user_id, + admin, ); impl ToSafe for PersonAlias1 { @@ -95,6 +98,7 @@ mod safe_type_alias_1 { inbox_url, shared_inbox_url, matrix_user_id, + admin, ) } } @@ -120,6 +124,7 @@ mod safe_type_alias_2 { inbox_url, shared_inbox_url, matrix_user_id, + admin, ); impl ToSafe for PersonAlias2 { @@ -141,6 +146,7 @@ mod safe_type_alias_2 { inbox_url, shared_inbox_url, matrix_user_id, + admin, ) } } @@ -187,6 +193,7 @@ impl ApubObject for Person { pub trait Person_ { fn ban_person(conn: &PgConnection, person_id: PersonId, ban: bool) -> Result; + fn add_admin(conn: &PgConnection, person_id: PersonId, added: bool) -> Result; fn find_by_name(conn: &PgConnection, name: &str) -> Result; fn mark_as_updated(conn: &PgConnection, person_id: PersonId) -> Result; fn delete_account(conn: &PgConnection, person_id: PersonId) -> Result; @@ -199,6 +206,12 @@ impl Person_ for Person { .get_result::(conn) } + fn add_admin(conn: &PgConnection, person_id: PersonId, added: bool) -> Result { + diesel::update(person.find(person_id)) + .set(admin.eq(added)) + .get_result::(conn) + } + fn find_by_name(conn: &PgConnection, from_name: &str) -> Result { person .filter(deleted.eq(false)) @@ -261,6 +274,7 @@ mod tests { actor_id: inserted_person.actor_id.to_owned(), bio: None, local: true, + admin: false, private_key: None, public_key: None, last_refreshed_at: inserted_person.published, diff --git a/crates/db_schema/src/schema.rs b/crates/db_schema/src/schema.rs index 4c990ec03..5bc55f529 100644 --- a/crates/db_schema/src/schema.rs +++ b/crates/db_schema/src/schema.rs @@ -146,7 +146,6 @@ table! { person_id -> Int4, password_encrypted -> Text, email -> Nullable, - admin -> Bool, show_nsfw -> Bool, theme -> Varchar, default_sort_type -> Int2, @@ -287,6 +286,7 @@ table! { inbox_url -> Varchar, shared_inbox_url -> Nullable, matrix_user_id -> Nullable, + admin -> Bool, } } @@ -486,6 +486,7 @@ table! { inbox_url -> Varchar, shared_inbox_url -> Nullable, matrix_user_id -> Nullable, + admin -> Bool, } } @@ -509,6 +510,7 @@ table! { inbox_url -> Varchar, shared_inbox_url -> Nullable, matrix_user_id -> Nullable, + admin -> Bool, } } diff --git a/crates/db_schema/src/source/local_user.rs b/crates/db_schema/src/source/local_user.rs index 2f4a9fc2b..6f28a8fbc 100644 --- a/crates/db_schema/src/source/local_user.rs +++ b/crates/db_schema/src/source/local_user.rs @@ -8,7 +8,6 @@ pub struct LocalUser { pub person_id: PersonId, pub password_encrypted: String, pub email: Option, - pub admin: bool, pub show_nsfw: bool, pub theme: String, pub default_sort_type: i16, @@ -26,7 +25,6 @@ pub struct LocalUserForm { pub person_id: PersonId, pub password_encrypted: String, pub email: Option>, - pub admin: Option, pub show_nsfw: Option, pub theme: Option, pub default_sort_type: Option, @@ -43,7 +41,6 @@ pub struct LocalUserSettings { pub id: LocalUserId, pub person_id: PersonId, pub email: Option, - pub admin: bool, pub show_nsfw: bool, pub theme: String, pub default_sort_type: i16, diff --git a/crates/db_schema/src/source/person.rs b/crates/db_schema/src/source/person.rs index f5f10ac46..2c0e7e8b7 100644 --- a/crates/db_schema/src/source/person.rs +++ b/crates/db_schema/src/source/person.rs @@ -26,6 +26,7 @@ pub struct Person { pub inbox_url: DbUrl, pub shared_inbox_url: Option, pub matrix_user_id: Option, + pub admin: bool, } /// A safe representation of person, without the sensitive info @@ -47,6 +48,7 @@ pub struct PersonSafe { pub inbox_url: DbUrl, pub shared_inbox_url: Option, pub matrix_user_id: Option, + pub admin: bool, } #[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)] @@ -70,6 +72,7 @@ pub struct PersonAlias1 { pub inbox_url: DbUrl, pub shared_inbox_url: Option, pub matrix_user_id: Option, + pub admin: bool, } #[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)] @@ -90,6 +93,7 @@ pub struct PersonSafeAlias1 { pub inbox_url: DbUrl, pub shared_inbox_url: Option, pub matrix_user_id: Option, + pub admin: bool, } #[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)] @@ -113,6 +117,7 @@ pub struct PersonAlias2 { pub inbox_url: DbUrl, pub shared_inbox_url: Option, pub matrix_user_id: Option, + pub admin: bool, } #[derive(Clone, Queryable, Identifiable, PartialEq, Debug, Serialize)] @@ -133,6 +138,7 @@ pub struct PersonSafeAlias2 { pub inbox_url: DbUrl, pub shared_inbox_url: Option, pub matrix_user_id: Option, + pub admin: bool, } #[derive(Insertable, AsChangeset, Clone, Default)] @@ -155,4 +161,5 @@ pub struct PersonForm { pub inbox_url: Option, pub shared_inbox_url: Option>, pub matrix_user_id: Option>, + pub admin: Option, } diff --git a/crates/db_views/src/comment_view.rs b/crates/db_views/src/comment_view.rs index e44ddfef3..6b13103c0 100644 --- a/crates/db_views/src/comment_view.rs +++ b/crates/db_views/src/comment_view.rs @@ -526,6 +526,7 @@ mod tests { local: true, banned: false, deleted: false, + admin: false, bio: None, banner: None, updated: None, diff --git a/crates/db_views/src/post_view.rs b/crates/db_views/src/post_view.rs index 8e305b486..df67d3693 100644 --- a/crates/db_views/src/post_view.rs +++ b/crates/db_views/src/post_view.rs @@ -546,6 +546,7 @@ mod tests { avatar: None, actor_id: inserted_person.actor_id.to_owned(), local: true, + admin: false, banned: false, deleted: false, bio: None, diff --git a/crates/db_views_actor/src/person_view.rs b/crates/db_views_actor/src/person_view.rs index a44a468c4..8e292c3fc 100644 --- a/crates/db_views_actor/src/person_view.rs +++ b/crates/db_views_actor/src/person_view.rs @@ -9,7 +9,7 @@ use lemmy_db_queries::{ ViewToVec, }; use lemmy_db_schema::{ - schema::{local_user, person, person_aggregates}, + schema::{person, person_aggregates}, source::person::{Person, PersonSafe}, PersonId, }; @@ -36,9 +36,8 @@ impl PersonViewSafe { pub fn admins(conn: &PgConnection) -> Result, Error> { let admins = person::table .inner_join(person_aggregates::table) - .inner_join(local_user::table) .select((Person::safe_columns_tuple(), person_aggregates::all_columns)) - .filter(local_user::admin.eq(true)) + .filter(person::admin.eq(true)) .order_by(person::published) .load::(conn)?; diff --git a/migrations/2021-03-20-185321_move_matrix_id_to_person/down.sql b/migrations/2021-03-20-185321_move_matrix_id_to_person/down.sql index 70cbe9bfa..990d8fe97 100644 --- a/migrations/2021-03-20-185321_move_matrix_id_to_person/down.sql +++ b/migrations/2021-03-20-185321_move_matrix_id_to_person/down.sql @@ -1,12 +1,16 @@ alter table local_user add column matrix_user_id text; +alter table local_user add column admin boolean default false not null; update local_user lu -set matrix_user_id = p.matrix_user_id +set + matrix_user_id = p.matrix_user_id, + admin = p.admin from person p where p.id = lu.person_id; drop view person_alias_1, person_alias_2; alter table person drop column matrix_user_id; +alter table person drop column admin; -- Regenerate the person_alias views create view person_alias_1 as select * from person; diff --git a/migrations/2021-03-20-185321_move_matrix_id_to_person/up.sql b/migrations/2021-03-20-185321_move_matrix_id_to_person/up.sql index 92f20c6cb..d9ba3dd9c 100644 --- a/migrations/2021-03-20-185321_move_matrix_id_to_person/up.sql +++ b/migrations/2021-03-20-185321_move_matrix_id_to_person/up.sql @@ -1,11 +1,15 @@ alter table person add column matrix_user_id text; +alter table person add column admin boolean default false not null; update person p -set matrix_user_id = lu.matrix_user_id +set + matrix_user_id = lu.matrix_user_id, + admin = lu.admin from local_user lu where p.id = lu.person_id; alter table local_user drop column matrix_user_id; +alter table local_user drop column admin; -- Regenerate the person_alias views drop view person_alias_1, person_alias_2; From 6758922a632331fe9948791312f160bcadfc9562 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Tue, 23 Mar 2021 14:17:44 -0400 Subject: [PATCH 7/9] Version 0.10.0-rc.9 --- crates/utils/src/version.rs | 2 +- docker/dev/docker-compose.yml | 2 +- docker/federation/docker-compose.yml | 10 +++++----- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/crates/utils/src/version.rs b/crates/utils/src/version.rs index ad718a725..97c4a30f3 100644 --- a/crates/utils/src/version.rs +++ b/crates/utils/src/version.rs @@ -1 +1 @@ -pub const VERSION: &str = "0.10.0-rc.7"; +pub const VERSION: &str = "0.10.0-rc.9"; diff --git a/docker/dev/docker-compose.yml b/docker/dev/docker-compose.yml index b8dcac91e..4f95d528b 100644 --- a/docker/dev/docker-compose.yml +++ b/docker/dev/docker-compose.yml @@ -17,7 +17,7 @@ services: - iframely lemmy-ui: - image: dessalines/lemmy-ui:0.9.9 + image: dessalines/lemmy-ui:0.10.0-rc.9 ports: - "1235:1234" restart: always diff --git a/docker/federation/docker-compose.yml b/docker/federation/docker-compose.yml index 03355aa49..4274aff59 100644 --- a/docker/federation/docker-compose.yml +++ b/docker/federation/docker-compose.yml @@ -29,7 +29,7 @@ services: - ./volumes/pictrs_alpha:/mnt lemmy-alpha-ui: - image: dessalines/lemmy-ui:0.9.9 + image: dessalines/lemmy-ui:0.10.0-rc.9 environment: - LEMMY_INTERNAL_HOST=lemmy-alpha:8541 - LEMMY_EXTERNAL_HOST=localhost:8541 @@ -58,7 +58,7 @@ services: - ./volumes/postgres_alpha:/var/lib/postgresql/data lemmy-beta-ui: - image: dessalines/lemmy-ui:0.9.9 + image: dessalines/lemmy-ui:0.10.0-rc.9 environment: - LEMMY_INTERNAL_HOST=lemmy-beta:8551 - LEMMY_EXTERNAL_HOST=localhost:8551 @@ -87,7 +87,7 @@ services: - ./volumes/postgres_beta:/var/lib/postgresql/data lemmy-gamma-ui: - image: dessalines/lemmy-ui:0.9.9 + image: dessalines/lemmy-ui:0.10.0-rc.9 environment: - LEMMY_INTERNAL_HOST=lemmy-gamma:8561 - LEMMY_EXTERNAL_HOST=localhost:8561 @@ -117,7 +117,7 @@ services: # An instance with only an allowlist for beta lemmy-delta-ui: - image: dessalines/lemmy-ui:0.9.9 + image: dessalines/lemmy-ui:0.10.0-rc.9 environment: - LEMMY_INTERNAL_HOST=lemmy-delta:8571 - LEMMY_EXTERNAL_HOST=localhost:8571 @@ -147,7 +147,7 @@ services: # An instance who has a blocklist, with lemmy-alpha blocked lemmy-epsilon-ui: - image: dessalines/lemmy-ui:0.9.9 + image: dessalines/lemmy-ui:0.10.0-rc.9 environment: - LEMMY_INTERNAL_HOST=lemmy-epsilon:8581 - LEMMY_EXTERNAL_HOST=localhost:8581 From 7051207495e62a26d2e21894ec62ea4d1e6fa5ab Mon Sep 17 00:00:00 2001 From: Dessalines Date: Tue, 23 Mar 2021 14:46:18 -0400 Subject: [PATCH 8/9] Version 0.10.0-rc.10 --- crates/utils/src/version.rs | 2 +- docker/dev/docker-compose.yml | 2 +- docker/federation/docker-compose.yml | 10 +++++----- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/crates/utils/src/version.rs b/crates/utils/src/version.rs index 97c4a30f3..67580d9ed 100644 --- a/crates/utils/src/version.rs +++ b/crates/utils/src/version.rs @@ -1 +1 @@ -pub const VERSION: &str = "0.10.0-rc.9"; +pub const VERSION: &str = "0.10.0-rc.10"; diff --git a/docker/dev/docker-compose.yml b/docker/dev/docker-compose.yml index a0e59ddf4..fccfc2bc7 100644 --- a/docker/dev/docker-compose.yml +++ b/docker/dev/docker-compose.yml @@ -17,7 +17,7 @@ services: - iframely lemmy-ui: - image: dessalines/lemmy-ui:0.10.0-rc.8 + image: dessalines/lemmy-ui:0.10.0-rc.10 ports: - "1235:1234" restart: always diff --git a/docker/federation/docker-compose.yml b/docker/federation/docker-compose.yml index 77bb53fa6..28a2188ce 100644 --- a/docker/federation/docker-compose.yml +++ b/docker/federation/docker-compose.yml @@ -29,7 +29,7 @@ services: - ./volumes/pictrs_alpha:/mnt lemmy-alpha-ui: - image: dessalines/lemmy-ui:0.10.0-rc.8 + image: dessalines/lemmy-ui:0.10.0-rc.10 environment: - LEMMY_INTERNAL_HOST=lemmy-alpha:8541 - LEMMY_EXTERNAL_HOST=localhost:8541 @@ -58,7 +58,7 @@ services: - ./volumes/postgres_alpha:/var/lib/postgresql/data lemmy-beta-ui: - image: dessalines/lemmy-ui:0.10.0-rc.8 + image: dessalines/lemmy-ui:0.10.0-rc.10 environment: - LEMMY_INTERNAL_HOST=lemmy-beta:8551 - LEMMY_EXTERNAL_HOST=localhost:8551 @@ -87,7 +87,7 @@ services: - ./volumes/postgres_beta:/var/lib/postgresql/data lemmy-gamma-ui: - image: dessalines/lemmy-ui:0.10.0-rc.8 + image: dessalines/lemmy-ui:0.10.0-rc.10 environment: - LEMMY_INTERNAL_HOST=lemmy-gamma:8561 - LEMMY_EXTERNAL_HOST=localhost:8561 @@ -117,7 +117,7 @@ services: # An instance with only an allowlist for beta lemmy-delta-ui: - image: dessalines/lemmy-ui:0.10.0-rc.8 + image: dessalines/lemmy-ui:0.10.0-rc.10 environment: - LEMMY_INTERNAL_HOST=lemmy-delta:8571 - LEMMY_EXTERNAL_HOST=localhost:8571 @@ -147,7 +147,7 @@ services: # An instance who has a blocklist, with lemmy-alpha blocked lemmy-epsilon-ui: - image: dessalines/lemmy-ui:0.10.0-rc.8 + image: dessalines/lemmy-ui:0.10.0-rc.10 environment: - LEMMY_INTERNAL_HOST=lemmy-epsilon:8581 - LEMMY_EXTERNAL_HOST=localhost:8581 From 34bdf4c7c5267d7756de5d769c84eb1d28b5de32 Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Wed, 24 Mar 2021 17:43:18 +0100 Subject: [PATCH 9/9] Federate Matrix ID (fixes #1438) --- crates/apub/src/extensions/context.rs | 6 +++- ...group_extensions.rs => group_extension.rs} | 0 crates/apub/src/extensions/mod.rs | 3 +- .../apub/src/extensions/person_extension.rs | 36 +++++++++++++++++++ crates/apub/src/lib.rs | 5 +-- crates/apub/src/objects/community.rs | 2 +- crates/apub/src/objects/person.rs | 11 +++--- 7 files changed, 53 insertions(+), 10 deletions(-) rename crates/apub/src/extensions/{group_extensions.rs => group_extension.rs} (100%) create mode 100644 crates/apub/src/extensions/person_extension.rs diff --git a/crates/apub/src/extensions/context.rs b/crates/apub/src/extensions/context.rs index a36b84899..041ca4bf0 100644 --- a/crates/apub/src/extensions/context.rs +++ b/crates/apub/src/extensions/context.rs @@ -14,7 +14,11 @@ pub(crate) fn lemmy_context() -> Result, LemmyError> { "type": "sc:Boolean", "id": "pt:commentsEnabled" }, - "moderators": "as:moderators" + "moderators": "as:moderators", + "matrixUserId": { + "type": "sc:Text", + "id": "as:alsoKnownAs" + }, }))?; Ok(vec![ AnyBase::from(context()), diff --git a/crates/apub/src/extensions/group_extensions.rs b/crates/apub/src/extensions/group_extension.rs similarity index 100% rename from crates/apub/src/extensions/group_extensions.rs rename to crates/apub/src/extensions/group_extension.rs diff --git a/crates/apub/src/extensions/mod.rs b/crates/apub/src/extensions/mod.rs index 4b4c08664..2f7df8211 100644 --- a/crates/apub/src/extensions/mod.rs +++ b/crates/apub/src/extensions/mod.rs @@ -1,4 +1,5 @@ pub(crate) mod context; -pub(crate) mod group_extensions; +pub(crate) mod group_extension; pub(crate) mod page_extension; +pub(crate) mod person_extension; pub(crate) mod signatures; diff --git a/crates/apub/src/extensions/person_extension.rs b/crates/apub/src/extensions/person_extension.rs new file mode 100644 index 000000000..248adcc43 --- /dev/null +++ b/crates/apub/src/extensions/person_extension.rs @@ -0,0 +1,36 @@ +use activitystreams::unparsed::UnparsedMutExt; +use activitystreams_ext::UnparsedExtension; +use lemmy_utils::LemmyError; +use serde::{Deserialize, Serialize}; + +/// Activitystreams extension to allow (de)serializing additional Person field +/// `also_known_as` (used for Matrix profile link). +#[derive(Clone, Debug, Default, Deserialize, Serialize)] +#[serde(rename_all = "camelCase")] +pub struct PersonExtension { + pub matrix_user_id: Option, +} + +impl PersonExtension { + pub fn new(matrix_user_id: Option) -> Result { + Ok(PersonExtension { matrix_user_id }) + } +} + +impl UnparsedExtension for PersonExtension +where + U: UnparsedMutExt, +{ + type Error = serde_json::Error; + + fn try_from_unparsed(unparsed_mut: &mut U) -> Result { + Ok(PersonExtension { + matrix_user_id: unparsed_mut.remove("matrix_user_id")?, + }) + } + + fn try_into_unparsed(self, unparsed_mut: &mut U) -> Result<(), Self::Error> { + unparsed_mut.insert("matrix_user_id", self.matrix_user_id)?; + Ok(()) + } +} diff --git a/crates/apub/src/lib.rs b/crates/apub/src/lib.rs index 74d4cbef3..0e2c826ad 100644 --- a/crates/apub/src/lib.rs +++ b/crates/apub/src/lib.rs @@ -11,8 +11,9 @@ pub mod objects; pub mod routes; use crate::extensions::{ - group_extensions::GroupExtension, + group_extension::GroupExtension, page_extension::PageExtension, + person_extension::PersonExtension, signatures::{PublicKey, PublicKeyExtension}, }; use activitystreams::{ @@ -46,7 +47,7 @@ use url::{ParseError, Url}; /// Activitystreams type for community type GroupExt = Ext2>, GroupExtension, PublicKeyExtension>; /// Activitystreams type for person -type PersonExt = Ext1>, PublicKeyExtension>; +type PersonExt = Ext2>, PersonExtension, PublicKeyExtension>; /// Activitystreams type for post type PageExt = Ext1, PageExtension>; type NoteExt = ApObject; diff --git a/crates/apub/src/objects/community.rs b/crates/apub/src/objects/community.rs index a73febceb..9667031c7 100644 --- a/crates/apub/src/objects/community.rs +++ b/crates/apub/src/objects/community.rs @@ -1,5 +1,5 @@ use crate::{ - extensions::{context::lemmy_context, group_extensions::GroupExtension}, + extensions::{context::lemmy_context, group_extension::GroupExtension}, fetcher::{community::fetch_community_mods, person::get_or_fetch_and_upsert_person}, generate_moderators_url, objects::{ diff --git a/crates/apub/src/objects/person.rs b/crates/apub/src/objects/person.rs index cc45fd7ed..662871dc1 100644 --- a/crates/apub/src/objects/person.rs +++ b/crates/apub/src/objects/person.rs @@ -1,5 +1,5 @@ use crate::{ - extensions::context::lemmy_context, + extensions::{context::lemmy_context, person_extension::PersonExtension}, objects::{ check_object_domain, get_source_markdown_value, @@ -16,7 +16,7 @@ use activitystreams::{ object::{ApObject, Image, Tombstone}, prelude::*, }; -use activitystreams_ext::Ext1; +use activitystreams_ext::Ext2; use anyhow::Context; use lemmy_api_structs::blocking; use lemmy_db_queries::{ApubObject, DbPool}; @@ -77,7 +77,8 @@ impl ToApub for DbPerson { ..Default::default() }); - Ok(Ext1::new(ap_actor, self.get_public_key_ext()?)) + let person_ext = PersonExtension::new(self.matrix_user_id.to_owned())?; + Ok(Ext2::new(ap_actor, person_ext, self.get_public_key_ext()?)) } fn to_tombstone(&self) -> Result { unimplemented!() @@ -192,11 +193,11 @@ impl FromApubToForm for PersonForm { local: Some(false), admin: Some(false), private_key: None, - public_key: Some(Some(person.ext_one.public_key.to_owned().public_key_pem)), + public_key: Some(Some(person.ext_two.public_key.to_owned().public_key_pem)), last_refreshed_at: Some(naive_now()), inbox_url: Some(person.inner.inbox()?.to_owned().into()), shared_inbox_url: Some(shared_inbox), - matrix_user_id: None, // TODO + matrix_user_id: Some(person.ext_one.matrix_user_id.to_owned()), }) } }