From c80bfccd6aaf8f7ef83e3c90080c45498c715af3 Mon Sep 17 00:00:00 2001 From: silverpill Date: Thu, 16 Mar 2023 22:04:36 +0000 Subject: [PATCH] Add "manually_approves_followers" column to actor_profile table --- ...ofile__add_manually_approves_followers.sql | 2 ++ migrations/schema.sql | 1 + src/activitypub/actors/helpers.rs | 2 ++ src/mastodon_api/accounts/types.rs | 2 ++ src/models/profiles/queries.rs | 30 +++++++++++++------ src/models/profiles/types.rs | 5 ++++ src/models/users/queries.rs | 1 + 7 files changed, 34 insertions(+), 9 deletions(-) create mode 100644 migrations/V0049__actor_profile__add_manually_approves_followers.sql diff --git a/migrations/V0049__actor_profile__add_manually_approves_followers.sql b/migrations/V0049__actor_profile__add_manually_approves_followers.sql new file mode 100644 index 0000000..def197a --- /dev/null +++ b/migrations/V0049__actor_profile__add_manually_approves_followers.sql @@ -0,0 +1,2 @@ +ALTER TABLE actor_profile ADD COLUMN manually_approves_followers BOOLEAN NOT NULL DEFAULT FALSE; +ALTER TABLE actor_profile ALTER COLUMN manually_approves_followers DROP DEFAULT; diff --git a/migrations/schema.sql b/migrations/schema.sql index 79e3201..9eb63e1 100644 --- a/migrations/schema.sql +++ b/migrations/schema.sql @@ -26,6 +26,7 @@ CREATE TABLE actor_profile ( bio_source TEXT, avatar JSONB, banner JSONB, + manually_approves_followers BOOLEAN NOT NULL, identity_proofs JSONB NOT NULL DEFAULT '[]', payment_options JSONB NOT NULL DEFAULT '[]', extra_fields JSONB NOT NULL DEFAULT '[]', diff --git a/src/activitypub/actors/helpers.rs b/src/activitypub/actors/helpers.rs index 9d731aa..6ce0516 100644 --- a/src/activitypub/actors/helpers.rs +++ b/src/activitypub/actors/helpers.rs @@ -149,6 +149,7 @@ pub async fn create_remote_profile( bio: actor.summary.clone(), avatar: maybe_avatar, banner: maybe_banner, + manually_approves_followers: actor.manually_approves_followers, identity_proofs, payment_options, extra_fields, @@ -204,6 +205,7 @@ pub async fn update_remote_profile( bio_source: actor.summary.clone(), avatar: maybe_avatar, banner: maybe_banner, + manually_approves_followers: actor.manually_approves_followers, identity_proofs, payment_options, extra_fields, diff --git a/src/mastodon_api/accounts/types.rs b/src/mastodon_api/accounts/types.rs index 225a025..812e453 100644 --- a/src/mastodon_api/accounts/types.rs +++ b/src/mastodon_api/accounts/types.rs @@ -132,6 +132,7 @@ impl Account { .map(|image| get_file_url(base_url, &image.file_name)); let header_url = profile.banner .map(|image| get_file_url(base_url, &image.file_name)); + // TODO: use profile.manually_approves_followers let is_locked = profile.actor_json .map(|actor| actor.manually_approves_followers) .unwrap_or(false); @@ -367,6 +368,7 @@ impl AccountUpdateData { bio_source: self.note, avatar, banner, + manually_approves_followers: false, identity_proofs, payment_options, extra_fields, diff --git a/src/models/profiles/queries.rs b/src/models/profiles/queries.rs index c20cfe7..8bca51f 100644 --- a/src/models/profiles/queries.rs +++ b/src/models/profiles/queries.rs @@ -133,12 +133,21 @@ pub async fn create_profile( transaction.execute( " INSERT INTO actor_profile ( - id, username, hostname, display_name, bio, bio_source, - avatar, banner, - identity_proofs, payment_options, extra_fields, + id, + username, + hostname, + display_name, + bio, + bio_source, + avatar, + banner, + manually_approves_followers, + identity_proofs, + payment_options, + extra_fields, actor_json ) - VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12) + VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13) RETURNING actor_profile ", &[ @@ -150,6 +159,7 @@ pub async fn create_profile( &profile_data.bio, &profile_data.avatar, &profile_data.banner, + &profile_data.manually_approves_followers, &IdentityProofs(profile_data.identity_proofs), &PaymentOptions(profile_data.payment_options), &ExtraFields(profile_data.extra_fields), @@ -184,12 +194,13 @@ pub async fn update_profile( bio_source = $3, avatar = $4, banner = $5, - identity_proofs = $6, - payment_options = $7, - extra_fields = $8, - actor_json = $9, + manually_approves_followers = $6, + identity_proofs = $7, + payment_options = $8, + extra_fields = $9, + actor_json = $10, updated_at = CURRENT_TIMESTAMP - WHERE id = $10 + WHERE id = $11 RETURNING actor_profile ", &[ @@ -198,6 +209,7 @@ pub async fn update_profile( &profile_data.bio_source, &profile_data.avatar, &profile_data.banner, + &profile_data.manually_approves_followers, &IdentityProofs(profile_data.identity_proofs), &PaymentOptions(profile_data.payment_options), &ExtraFields(profile_data.extra_fields), diff --git a/src/models/profiles/types.rs b/src/models/profiles/types.rs index 409a562..01f23b8 100644 --- a/src/models/profiles/types.rs +++ b/src/models/profiles/types.rs @@ -333,6 +333,7 @@ pub struct DbActorProfile { pub bio_source: Option, // plaintext or markdown pub avatar: Option, pub banner: Option, + pub manually_approves_followers: bool, pub identity_proofs: IdentityProofs, pub payment_options: PaymentOptions, pub extra_fields: ExtraFields, @@ -421,6 +422,7 @@ impl Default for DbActorProfile { bio_source: None, avatar: None, banner: None, + manually_approves_followers: false, identity_proofs: IdentityProofs(vec![]), payment_options: PaymentOptions(vec![]), extra_fields: ExtraFields(vec![]), @@ -446,6 +448,7 @@ pub struct ProfileCreateData { pub bio: Option, pub avatar: Option, pub banner: Option, + pub manually_approves_followers: bool, pub identity_proofs: Vec, pub payment_options: Vec, pub extra_fields: Vec, @@ -478,6 +481,7 @@ pub struct ProfileUpdateData { pub bio_source: Option, pub avatar: Option, pub banner: Option, + pub manually_approves_followers: bool, pub identity_proofs: Vec, pub payment_options: Vec, pub extra_fields: Vec, @@ -526,6 +530,7 @@ impl From<&DbActorProfile> for ProfileUpdateData { bio_source: profile.bio_source, avatar: profile.avatar, banner: profile.banner, + manually_approves_followers: profile.manually_approves_followers, identity_proofs: profile.identity_proofs.into_inner(), payment_options: profile.payment_options.into_inner(), extra_fields: profile.extra_fields.into_inner(), diff --git a/src/models/users/queries.rs b/src/models/users/queries.rs index 27a4836..3ad8adc 100644 --- a/src/models/users/queries.rs +++ b/src/models/users/queries.rs @@ -114,6 +114,7 @@ pub async fn create_user( bio: None, avatar: None, banner: None, + manually_approves_followers: false, identity_proofs: vec![], payment_options: vec![], extra_fields: vec![],