Remove PersonInsertForm builder (#4779)

* Update session_middleware.rs

* Update private_message_report_view.rs

* Update session_middleware.rs

* Update private_message_view.rs

* Update private_message.rs

* Update registration_application_view.rs

* Update actor_language.rs

* Update vote_view.rs

* Update code_migrations.rs

* Update comment_aggregates.rs

* Update person_view.rs

* Update user_settings_backup.rs

* Update person.rs

* Update create.rs

* Update comment_view.rs

* Update moderator.rs

* Update site_aggregates.rs

* Update claims.rs

* Update community_aggregates.rs

* Update post_report.rs

* Update person_mention_view.rs

* Update community_view.rs

* Update comment_report_view.rs

* Update post_report_view.rs

* Update community_moderators.rs

* Update comment.rs

* Update person_aggregates.rs

* Update comment_reply_view.rs

* Update password_reset_request.rs

* Update post_aggregates.rs

* Update community.rs

* Update main.rs

* Update post.rs

* Update person.rs

* Update person.rs

* Update claims.rs

* Update person.rs

* Update create.rs

* Update user_settings_backup.rs

* Update community_moderators.rs

* Update main.rs

* Update comment_aggregates.rs

* Update community_aggregates.rs

* Update person.rs

* Update Cargo.toml

* Update Cargo.toml

* Update person.rs

* fix

* Update code_migrations.rs

* fix submodule

* Update person.rs
pull/4787/head
dullbananas 2024-06-06 05:29:18 -07:00 committed by GitHub
parent fda5ce4482
commit 79e6dbf0de
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
36 changed files with 125 additions and 311 deletions

12
Cargo.lock generated
View File

@ -1423,6 +1423,17 @@ dependencies = [
"syn 1.0.109", "syn 1.0.109",
] ]
[[package]]
name = "derive-new"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d150dea618e920167e5973d70ae6ece4385b7164e0d799fe7c122dd0a5d912ad"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.65",
]
[[package]] [[package]]
name = "derive_builder" name = "derive_builder"
version = "0.20.0" version = "0.20.0"
@ -2850,6 +2861,7 @@ dependencies = [
"bcrypt", "bcrypt",
"chrono", "chrono",
"deadpool 0.12.1", "deadpool 0.12.1",
"derive-new",
"diesel", "diesel",
"diesel-async", "diesel-async",
"diesel-derive-enum", "diesel-derive-enum",

View File

@ -167,6 +167,7 @@ moka = { version = "0.12.7", features = ["future"] }
i-love-jesus = { version = "0.1.0" } i-love-jesus = { version = "0.1.0" }
clap = { version = "4.5.4", features = ["derive", "env"] } clap = { version = "4.5.4", features = ["derive", "env"] }
pretty_assertions = "1.4.0" pretty_assertions = "1.4.0"
derive-new = "0.6.0"
[dependencies] [dependencies]
lemmy_api = { workspace = true } lemmy_api = { workspace = true }

View File

@ -112,11 +112,7 @@ mod tests {
.await .await
.unwrap(); .unwrap();
let new_person = PersonInsertForm::builder() let new_person = PersonInsertForm::test_form(inserted_instance.id, "Gerry9812");
.name("Gerry9812".into())
.public_key("pubkey".to_string())
.instance_id(inserted_instance.id)
.build();
let inserted_person = Person::create(pool, &new_person).await.unwrap(); let inserted_person = Person::create(pool, &new_person).await.unwrap();

View File

@ -112,15 +112,17 @@ pub async fn register(
// We have to create both a person, and local_user // We have to create both a person, and local_user
// Register the new person // Register the new person
let person_form = PersonInsertForm::builder() let person_form = PersonInsertForm {
.name(data.username.clone()) actor_id: Some(actor_id.clone()),
.actor_id(Some(actor_id.clone())) inbox_url: Some(generate_inbox_url(&actor_id)?),
.private_key(Some(actor_keypair.private_key)) shared_inbox_url: Some(generate_shared_inbox_url(context.settings())?),
.public_key(actor_keypair.public_key) private_key: Some(actor_keypair.private_key),
.inbox_url(Some(generate_inbox_url(&actor_id)?)) ..PersonInsertForm::new(
.shared_inbox_url(Some(generate_shared_inbox_url(context.settings())?)) data.username.clone(),
.instance_id(site_view.site.instance_id) actor_keypair.public_key,
.build(); site_view.site.instance_id,
)
};
// insert the person // insert the person
let inserted_person = Person::create(&mut context.pool(), &person_form) let inserted_person = Person::create(&mut context.pool(), &person_form)

View File

@ -338,13 +338,11 @@ mod tests {
context: &Data<LemmyContext>, context: &Data<LemmyContext>,
) -> LemmyResult<LocalUserView> { ) -> LemmyResult<LocalUserView> {
let instance = Instance::read_or_create(&mut context.pool(), "example.com".to_string()).await?; let instance = Instance::read_or_create(&mut context.pool(), "example.com".to_string()).await?;
let person_form = PersonInsertForm::builder() let person_form = PersonInsertForm {
.name(name.clone()) display_name: Some(name.clone()),
.display_name(Some(name.clone())) bio,
.bio(bio) ..PersonInsertForm::test_form(instance.id, &name)
.public_key("asd".to_string()) };
.instance_id(instance.id)
.build();
let person = Person::create(&mut context.pool(), &person_form).await?; let person = Person::create(&mut context.pool(), &person_form).await?;
let user_form = LocalUserInsertForm::builder() let user_form = LocalUserInsertForm::builder()

View File

@ -129,11 +129,7 @@ mod tests {
let inserted_instance = let inserted_instance =
Instance::read_or_create(&mut context.pool(), "my_domain.tld".to_string()).await?; Instance::read_or_create(&mut context.pool(), "my_domain.tld".to_string()).await?;
let old_mod = PersonInsertForm::builder() let old_mod = PersonInsertForm::test_form(inserted_instance.id, "holly");
.name("holly".into())
.public_key("pubkey".to_string())
.instance_id(inserted_instance.id)
.build();
let old_mod = Person::create(&mut context.pool(), &old_mod).await?; let old_mod = Person::create(&mut context.pool(), &old_mod).await?;
let community_moderator_form = CommunityModeratorForm { let community_moderator_form = CommunityModeratorForm {

View File

@ -72,11 +72,7 @@ async fn try_main() -> LemmyResult<()> {
println!("🫃 creating {} people", args.people); println!("🫃 creating {} people", args.people);
let mut person_ids = vec![]; let mut person_ids = vec![];
for i in 0..args.people.get() { for i in 0..args.people.get() {
let form = PersonInsertForm::builder() let form = PersonInsertForm::test_form(instance.id, &format!("p{i}"));
.name(format!("p{i}"))
.public_key("pubkey".to_owned())
.instance_id(instance.id)
.build();
person_ids.push(Person::create(&mut conn.into(), &form).await?.id); person_ids.push(Person::create(&mut conn.into(), &form).await?.id);
} }

View File

@ -81,6 +81,7 @@ uuid = { workspace = true, features = ["v4"] }
i-love-jesus = { workspace = true, optional = true } i-love-jesus = { workspace = true, optional = true }
anyhow = { workspace = true } anyhow = { workspace = true }
moka.workspace = true moka.workspace = true
derive-new.workspace = true
[dev-dependencies] [dev-dependencies]
serial_test = { workspace = true } serial_test = { workspace = true }

View File

@ -64,19 +64,11 @@ mod tests {
.await .await
.unwrap(); .unwrap();
let new_person = PersonInsertForm::builder() let new_person = PersonInsertForm::test_form(inserted_instance.id, "thommy_comment_agg");
.name("thommy_comment_agg".into())
.public_key("pubkey".into())
.instance_id(inserted_instance.id)
.build();
let inserted_person = Person::create(pool, &new_person).await.unwrap(); let inserted_person = Person::create(pool, &new_person).await.unwrap();
let another_person = PersonInsertForm::builder() let another_person = PersonInsertForm::test_form(inserted_instance.id, "jerry_comment_agg");
.name("jerry_comment_agg".into())
.public_key("pubkey".into())
.instance_id(inserted_instance.id)
.build();
let another_inserted_person = Person::create(pool, &another_person).await.unwrap(); let another_inserted_person = Person::create(pool, &another_person).await.unwrap();

View File

@ -65,19 +65,11 @@ mod tests {
.await .await
.unwrap(); .unwrap();
let new_person = PersonInsertForm::builder() let new_person = PersonInsertForm::test_form(inserted_instance.id, "thommy_community_agg");
.name("thommy_community_agg".into())
.public_key("pubkey".to_string())
.instance_id(inserted_instance.id)
.build();
let inserted_person = Person::create(pool, &new_person).await.unwrap(); let inserted_person = Person::create(pool, &new_person).await.unwrap();
let another_person = PersonInsertForm::builder() let another_person = PersonInsertForm::test_form(inserted_instance.id, "jerry_community_agg");
.name("jerry_community_agg".into())
.public_key("pubkey".to_string())
.instance_id(inserted_instance.id)
.build();
let another_inserted_person = Person::create(pool, &another_person).await.unwrap(); let another_inserted_person = Person::create(pool, &another_person).await.unwrap();

View File

@ -49,19 +49,11 @@ mod tests {
.await .await
.unwrap(); .unwrap();
let new_person = PersonInsertForm::builder() let new_person = PersonInsertForm::test_form(inserted_instance.id, "thommy_user_agg");
.name("thommy_user_agg".into())
.public_key("pubkey".to_string())
.instance_id(inserted_instance.id)
.build();
let inserted_person = Person::create(pool, &new_person).await.unwrap(); let inserted_person = Person::create(pool, &new_person).await.unwrap();
let another_person = PersonInsertForm::builder() let another_person = PersonInsertForm::test_form(inserted_instance.id, "jerry_user_agg");
.name("jerry_user_agg".into())
.public_key("pubkey".to_string())
.instance_id(inserted_instance.id)
.build();
let another_inserted_person = Person::create(pool, &another_person).await.unwrap(); let another_inserted_person = Person::create(pool, &another_person).await.unwrap();

View File

@ -83,19 +83,11 @@ mod tests {
.await .await
.unwrap(); .unwrap();
let new_person = PersonInsertForm::builder() let new_person = PersonInsertForm::test_form(inserted_instance.id, "thommy_community_agg");
.name("thommy_community_agg".into())
.public_key("pubkey".to_string())
.instance_id(inserted_instance.id)
.build();
let inserted_person = Person::create(pool, &new_person).await.unwrap(); let inserted_person = Person::create(pool, &new_person).await.unwrap();
let another_person = PersonInsertForm::builder() let another_person = PersonInsertForm::test_form(inserted_instance.id, "jerry_community_agg");
.name("jerry_community_agg".into())
.public_key("pubkey".to_string())
.instance_id(inserted_instance.id)
.build();
let another_inserted_person = Person::create(pool, &another_person).await.unwrap(); let another_inserted_person = Person::create(pool, &another_person).await.unwrap();
@ -229,11 +221,7 @@ mod tests {
.await .await
.unwrap(); .unwrap();
let new_person = PersonInsertForm::builder() let new_person = PersonInsertForm::test_form(inserted_instance.id, "thommy_community_agg");
.name("thommy_community_agg".into())
.public_key("pubkey".to_string())
.instance_id(inserted_instance.id)
.build();
let inserted_person = Person::create(pool, &new_person).await.unwrap(); let inserted_person = Person::create(pool, &new_person).await.unwrap();

View File

@ -42,11 +42,7 @@ mod tests {
.await .await
.unwrap(); .unwrap();
let new_person = PersonInsertForm::builder() let new_person = PersonInsertForm::test_form(inserted_instance.id, "thommy_site_agg");
.name("thommy_site_agg".into())
.public_key("pubkey".to_string())
.instance_id(inserted_instance.id)
.build();
let inserted_person = Person::create(pool, &new_person).await.unwrap(); let inserted_person = Person::create(pool, &new_person).await.unwrap();

View File

@ -531,11 +531,7 @@ mod tests {
let (site, instance) = create_test_site(pool).await; let (site, instance) = create_test_site(pool).await;
let person_form = PersonInsertForm::builder() let person_form = PersonInsertForm::test_form(instance.id, "my test person");
.name("my test person".to_string())
.public_key("pubkey".to_string())
.instance_id(instance.id)
.build();
let person = Person::create(pool, &person_form).await.unwrap(); let person = Person::create(pool, &person_form).await.unwrap();
let local_user_form = LocalUserInsertForm::builder() let local_user_form = LocalUserInsertForm::builder()
.person_id(person.id) .person_id(person.id)
@ -647,11 +643,7 @@ mod tests {
.await .await
.unwrap(); .unwrap();
let person_form = PersonInsertForm::builder() let person_form = PersonInsertForm::test_form(instance.id, "my test person");
.name("my test person".to_string())
.public_key("pubkey".to_string())
.instance_id(instance.id)
.build();
let person = Person::create(pool, &person_form).await.unwrap(); let person = Person::create(pool, &person_form).await.unwrap();
let local_user_form = LocalUserInsertForm::builder() let local_user_form = LocalUserInsertForm::builder()
.person_id(person.id) .person_id(person.id)

View File

@ -233,11 +233,7 @@ mod tests {
.await .await
.unwrap(); .unwrap();
let new_person = PersonInsertForm::builder() let new_person = PersonInsertForm::test_form(inserted_instance.id, "terry");
.name("terry".into())
.public_key("pubkey".to_string())
.instance_id(inserted_instance.id)
.build();
let inserted_person = Person::create(pool, &new_person).await.unwrap(); let inserted_person = Person::create(pool, &new_person).await.unwrap();

View File

@ -434,11 +434,7 @@ mod tests {
.await .await
.unwrap(); .unwrap();
let new_person = PersonInsertForm::builder() let new_person = PersonInsertForm::test_form(inserted_instance.id, "bobbee");
.name("bobbee".into())
.public_key("pubkey".to_string())
.instance_id(inserted_instance.id)
.build();
let inserted_person = Person::create(pool, &new_person).await.unwrap(); let inserted_person = Person::create(pool, &new_person).await.unwrap();

View File

@ -513,19 +513,11 @@ mod tests {
.await .await
.unwrap(); .unwrap();
let new_mod = PersonInsertForm::builder() let new_mod = PersonInsertForm::test_form(inserted_instance.id, "the mod");
.name("the mod".into())
.public_key("pubkey".to_string())
.instance_id(inserted_instance.id)
.build();
let inserted_mod = Person::create(pool, &new_mod).await.unwrap(); let inserted_mod = Person::create(pool, &new_mod).await.unwrap();
let new_person = PersonInsertForm::builder() let new_person = PersonInsertForm::test_form(inserted_instance.id, "jim2");
.name("jim2".into())
.public_key("pubkey".to_string())
.instance_id(inserted_instance.id)
.build();
let inserted_person = Person::create(pool, &new_person).await.unwrap(); let inserted_person = Person::create(pool, &new_person).await.unwrap();

View File

@ -70,11 +70,7 @@ mod tests {
// Setup // Setup
let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string()).await?; let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string()).await?;
let new_person = PersonInsertForm::builder() let new_person = PersonInsertForm::test_form(inserted_instance.id, "thommy prw");
.name("thommy prw".into())
.public_key("pubkey".to_string())
.instance_id(inserted_instance.id)
.build();
let inserted_person = Person::create(pool, &new_person).await?; let inserted_person = Person::create(pool, &new_person).await?;
let new_local_user = LocalUserInsertForm::builder() let new_local_user = LocalUserInsertForm::builder()
.person_id(inserted_person.id) .person_id(inserted_person.id)

View File

@ -125,11 +125,7 @@ impl Person {
impl PersonInsertForm { impl PersonInsertForm {
pub fn test_form(instance_id: InstanceId, name: &str) -> Self { pub fn test_form(instance_id: InstanceId, name: &str) -> Self {
Self::builder() Self::new(name.to_owned(), "pubkey".to_string(), instance_id)
.name(name.to_owned())
.public_key("pubkey".to_string())
.instance_id(instance_id)
.build()
} }
} }
@ -249,11 +245,7 @@ mod tests {
.await .await
.unwrap(); .unwrap();
let new_person = PersonInsertForm::builder() let new_person = PersonInsertForm::test_form(inserted_instance.id, "holly");
.name("holly".into())
.public_key("nada".to_owned())
.instance_id(inserted_instance.id)
.build();
let inserted_person = Person::create(pool, &new_person).await.unwrap(); let inserted_person = Person::create(pool, &new_person).await.unwrap();
@ -272,7 +264,7 @@ mod tests {
local: true, local: true,
bot_account: false, bot_account: false,
private_key: None, private_key: None,
public_key: "nada".to_owned(), public_key: "pubkey".to_owned(),
last_refreshed_at: inserted_person.published, last_refreshed_at: inserted_person.published,
inbox_url: inserted_person.inbox_url.clone(), inbox_url: inserted_person.inbox_url.clone(),
shared_inbox_url: None, shared_inbox_url: None,
@ -312,17 +304,9 @@ mod tests {
.await .await
.unwrap(); .unwrap();
let person_form_1 = PersonInsertForm::builder() let person_form_1 = PersonInsertForm::test_form(inserted_instance.id, "erich");
.name("erich".into())
.public_key("pubkey".to_string())
.instance_id(inserted_instance.id)
.build();
let person_1 = Person::create(pool, &person_form_1).await.unwrap(); let person_1 = Person::create(pool, &person_form_1).await.unwrap();
let person_form_2 = PersonInsertForm::builder() let person_form_2 = PersonInsertForm::test_form(inserted_instance.id, "michele");
.name("michele".into())
.public_key("pubkey".to_string())
.instance_id(inserted_instance.id)
.build();
let person_2 = Person::create(pool, &person_form_2).await.unwrap(); let person_2 = Person::create(pool, &person_form_2).await.unwrap();
let follow_form = PersonFollowerForm { let follow_form = PersonFollowerForm {

View File

@ -401,11 +401,7 @@ mod tests {
.await .await
.unwrap(); .unwrap();
let new_person = PersonInsertForm::builder() let new_person = PersonInsertForm::test_form(inserted_instance.id, "jim");
.name("jim".into())
.public_key("pubkey".to_string())
.instance_id(inserted_instance.id)
.build();
let inserted_person = Person::create(pool, &new_person).await.unwrap(); let inserted_person = Person::create(pool, &new_person).await.unwrap();

View File

@ -101,11 +101,7 @@ mod tests {
let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string()) let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string())
.await .await
.unwrap(); .unwrap();
let person_form = PersonInsertForm::builder() let person_form = PersonInsertForm::test_form(inserted_instance.id, "jim");
.name("jim".into())
.public_key("pubkey".to_string())
.instance_id(inserted_instance.id)
.build();
let person = Person::create(pool, &person_form).await.unwrap(); let person = Person::create(pool, &person_form).await.unwrap();
let community_form = CommunityInsertForm::builder() let community_form = CommunityInsertForm::builder()

View File

@ -111,19 +111,11 @@ mod tests {
.await .await
.unwrap(); .unwrap();
let creator_form = PersonInsertForm::builder() let creator_form = PersonInsertForm::test_form(inserted_instance.id, "creator_pm");
.name("creator_pm".into())
.public_key("pubkey".to_string())
.instance_id(inserted_instance.id)
.build();
let inserted_creator = Person::create(pool, &creator_form).await.unwrap(); let inserted_creator = Person::create(pool, &creator_form).await.unwrap();
let recipient_form = PersonInsertForm::builder() let recipient_form = PersonInsertForm::test_form(inserted_instance.id, "recipient_pm");
.name("recipient_pm".into())
.public_key("pubkey".to_string())
.instance_id(inserted_instance.id)
.build();
let inserted_recipient = Person::create(pool, &recipient_form).await.unwrap(); let inserted_recipient = Person::create(pool, &recipient_form).await.unwrap();

View File

@ -10,7 +10,6 @@ use serde::{Deserialize, Serialize};
use serde_with::skip_serializing_none; use serde_with::skip_serializing_none;
#[cfg(feature = "full")] #[cfg(feature = "full")]
use ts_rs::TS; use ts_rs::TS;
use typed_builder::TypedBuilder;
#[skip_serializing_none] #[skip_serializing_none]
#[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)] #[derive(Clone, PartialEq, Eq, Debug, Serialize, Deserialize)]
@ -60,33 +59,46 @@ pub struct Person {
pub instance_id: InstanceId, pub instance_id: InstanceId,
} }
#[derive(Clone, TypedBuilder)] #[derive(Clone, derive_new::new)]
#[builder(field_defaults(default))]
#[cfg_attr(feature = "full", derive(Insertable, AsChangeset))] #[cfg_attr(feature = "full", derive(Insertable, AsChangeset))]
#[cfg_attr(feature = "full", diesel(table_name = person))] #[cfg_attr(feature = "full", diesel(table_name = person))]
pub struct PersonInsertForm { pub struct PersonInsertForm {
#[builder(!default)]
pub name: String, pub name: String,
#[builder(!default)]
pub public_key: String, pub public_key: String,
#[builder(!default)]
pub instance_id: InstanceId, pub instance_id: InstanceId,
#[new(default)]
pub display_name: Option<String>, pub display_name: Option<String>,
#[new(default)]
pub avatar: Option<DbUrl>, pub avatar: Option<DbUrl>,
#[new(default)]
pub banned: Option<bool>, pub banned: Option<bool>,
#[new(default)]
pub published: Option<DateTime<Utc>>, pub published: Option<DateTime<Utc>>,
#[new(default)]
pub updated: Option<DateTime<Utc>>, pub updated: Option<DateTime<Utc>>,
#[new(default)]
pub actor_id: Option<DbUrl>, pub actor_id: Option<DbUrl>,
#[new(default)]
pub bio: Option<String>, pub bio: Option<String>,
#[new(default)]
pub local: Option<bool>, pub local: Option<bool>,
#[new(default)]
pub private_key: Option<String>, pub private_key: Option<String>,
#[new(default)]
pub last_refreshed_at: Option<DateTime<Utc>>, pub last_refreshed_at: Option<DateTime<Utc>>,
#[new(default)]
pub banner: Option<DbUrl>, pub banner: Option<DbUrl>,
#[new(default)]
pub deleted: Option<bool>, pub deleted: Option<bool>,
#[new(default)]
pub inbox_url: Option<DbUrl>, pub inbox_url: Option<DbUrl>,
#[new(default)]
pub shared_inbox_url: Option<DbUrl>, pub shared_inbox_url: Option<DbUrl>,
#[new(default)]
pub matrix_user_id: Option<String>, pub matrix_user_id: Option<String>,
#[new(default)]
pub bot_account: Option<bool>, pub bot_account: Option<bool>,
#[new(default)]
pub ban_expires: Option<DateTime<Utc>>, pub ban_expires: Option<DateTime<Utc>>,
} }

View File

@ -297,11 +297,7 @@ mod tests {
.await .await
.unwrap(); .unwrap();
let new_person = PersonInsertForm::builder() let new_person = PersonInsertForm::test_form(inserted_instance.id, "timmy_crv");
.name("timmy_crv".into())
.public_key("pubkey".to_string())
.instance_id(inserted_instance.id)
.build();
let inserted_timmy = Person::create(pool, &new_person).await.unwrap(); let inserted_timmy = Person::create(pool, &new_person).await.unwrap();
@ -319,20 +315,12 @@ mod tests {
counts: Default::default(), counts: Default::default(),
}; };
let new_person_2 = PersonInsertForm::builder() let new_person_2 = PersonInsertForm::test_form(inserted_instance.id, "sara_crv");
.name("sara_crv".into())
.public_key("pubkey".to_string())
.instance_id(inserted_instance.id)
.build();
let inserted_sara = Person::create(pool, &new_person_2).await.unwrap(); let inserted_sara = Person::create(pool, &new_person_2).await.unwrap();
// Add a third person, since new ppl can only report something once. // Add a third person, since new ppl can only report something once.
let new_person_3 = PersonInsertForm::builder() let new_person_3 = PersonInsertForm::test_form(inserted_instance.id, "jessica_crv");
.name("jessica_crv".into())
.public_key("pubkey".to_string())
.instance_id(inserted_instance.id)
.build();
let inserted_jessica = Person::create(pool, &new_person_3).await.unwrap(); let inserted_jessica = Person::create(pool, &new_person_3).await.unwrap();

View File

@ -488,11 +488,7 @@ mod tests {
async fn init_data(pool: &mut DbPool<'_>) -> LemmyResult<Data> { async fn init_data(pool: &mut DbPool<'_>) -> LemmyResult<Data> {
let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string()).await?; let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string()).await?;
let timmy_person_form = PersonInsertForm::builder() let timmy_person_form = PersonInsertForm::test_form(inserted_instance.id, "timmy");
.name("timmy".into())
.public_key("pubkey".to_string())
.instance_id(inserted_instance.id)
.build();
let inserted_timmy_person = Person::create(pool, &timmy_person_form).await?; let inserted_timmy_person = Person::create(pool, &timmy_person_form).await?;
let timmy_local_user_form = LocalUserInsertForm::builder() let timmy_local_user_form = LocalUserInsertForm::builder()
.person_id(inserted_timmy_person.id) .person_id(inserted_timmy_person.id)
@ -501,11 +497,7 @@ mod tests {
.build(); .build();
let inserted_timmy_local_user = LocalUser::create(pool, &timmy_local_user_form, vec![]).await?; let inserted_timmy_local_user = LocalUser::create(pool, &timmy_local_user_form, vec![]).await?;
let sara_person_form = PersonInsertForm::builder() let sara_person_form = PersonInsertForm::test_form(inserted_instance.id, "sara");
.name("sara".into())
.public_key("pubkey".to_string())
.instance_id(inserted_instance.id)
.build();
let inserted_sara_person = Person::create(pool, &sara_person_form).await?; let inserted_sara_person = Person::create(pool, &sara_person_form).await?;
let new_community = CommunityInsertForm::builder() let new_community = CommunityInsertForm::builder()

View File

@ -319,11 +319,7 @@ mod tests {
.await .await
.unwrap(); .unwrap();
let new_person = PersonInsertForm::builder() let new_person = PersonInsertForm::test_form(inserted_instance.id, "timmy_prv");
.name("timmy_prv".into())
.public_key("pubkey".to_string())
.instance_id(inserted_instance.id)
.build();
let inserted_timmy = Person::create(pool, &new_person).await.unwrap(); let inserted_timmy = Person::create(pool, &new_person).await.unwrap();
@ -341,20 +337,12 @@ mod tests {
counts: Default::default(), counts: Default::default(),
}; };
let new_person_2 = PersonInsertForm::builder() let new_person_2 = PersonInsertForm::test_form(inserted_instance.id, "sara_prv");
.name("sara_prv".into())
.public_key("pubkey".to_string())
.instance_id(inserted_instance.id)
.build();
let inserted_sara = Person::create(pool, &new_person_2).await.unwrap(); let inserted_sara = Person::create(pool, &new_person_2).await.unwrap();
// Add a third person, since new ppl can only report something once. // Add a third person, since new ppl can only report something once.
let new_person_3 = PersonInsertForm::builder() let new_person_3 = PersonInsertForm::test_form(inserted_instance.id, "jessica_prv");
.name("jessica_prv".into())
.public_key("pubkey".to_string())
.instance_id(inserted_instance.id)
.build();
let inserted_jessica = Person::create(pool, &new_person_3).await.unwrap(); let inserted_jessica = Person::create(pool, &new_person_3).await.unwrap();

View File

@ -140,18 +140,10 @@ mod tests {
.await .await
.unwrap(); .unwrap();
let new_person_1 = PersonInsertForm::builder() let new_person_1 = PersonInsertForm::test_form(inserted_instance.id, "timmy_mrv");
.name("timmy_mrv".into())
.public_key("pubkey".to_string())
.instance_id(inserted_instance.id)
.build();
let inserted_timmy = Person::create(pool, &new_person_1).await.unwrap(); let inserted_timmy = Person::create(pool, &new_person_1).await.unwrap();
let new_person_2 = PersonInsertForm::builder() let new_person_2 = PersonInsertForm::test_form(inserted_instance.id, "jessica_mrv");
.name("jessica_mrv".into())
.public_key("pubkey".to_string())
.instance_id(inserted_instance.id)
.build();
let inserted_jessica = Person::create(pool, &new_person_2).await.unwrap(); let inserted_jessica = Person::create(pool, &new_person_2).await.unwrap();
// timmy sends private message to jessica // timmy sends private message to jessica
@ -184,11 +176,7 @@ mod tests {
assert_eq!(pm_report.reason, reports[0].private_message_report.reason); assert_eq!(pm_report.reason, reports[0].private_message_report.reason);
assert_eq!(pm.content, reports[0].private_message.content); assert_eq!(pm.content, reports[0].private_message.content);
let new_person_3 = PersonInsertForm::builder() let new_person_3 = PersonInsertForm::test_form(inserted_instance.id, "admin_mrv");
.name("admin_mrv".into())
.public_key("pubkey".to_string())
.instance_id(inserted_instance.id)
.build();
let inserted_admin = Person::create(pool, &new_person_3).await.unwrap(); let inserted_admin = Person::create(pool, &new_person_3).await.unwrap();
// admin resolves the report (after taking appropriate action) // admin resolves the report (after taking appropriate action)

View File

@ -209,27 +209,15 @@ mod tests {
.await .await
.unwrap(); .unwrap();
let timmy_form = PersonInsertForm::builder() let timmy_form = PersonInsertForm::test_form(instance.id, "timmy_rav");
.name("timmy_rav".into())
.public_key("pubkey".to_string())
.instance_id(instance.id)
.build();
let timmy = Person::create(pool, &timmy_form).await.unwrap(); let timmy = Person::create(pool, &timmy_form).await.unwrap();
let sara_form = PersonInsertForm::builder() let sara_form = PersonInsertForm::test_form(instance.id, "sara_rav");
.name("sara_rav".into())
.public_key("pubkey".to_string())
.instance_id(instance.id)
.build();
let sara = Person::create(pool, &sara_form).await.unwrap(); let sara = Person::create(pool, &sara_form).await.unwrap();
let jess_form = PersonInsertForm::builder() let jess_form = PersonInsertForm::test_form(instance.id, "jess_rav");
.name("jess_rav".into())
.public_key("pubkey".to_string())
.instance_id(instance.id)
.build();
let jess = Person::create(pool, &jess_form).await.unwrap(); let jess = Person::create(pool, &jess_form).await.unwrap();

View File

@ -163,11 +163,7 @@ mod tests {
.await .await
.unwrap(); .unwrap();
let timmy_person_form = PersonInsertForm::builder() let timmy_person_form = PersonInsertForm::test_form(inserted_instance.id, "timmy_rav");
.name("timmy_rav".into())
.public_key("pubkey".to_string())
.instance_id(inserted_instance.id)
.build();
let inserted_timmy_person = Person::create(pool, &timmy_person_form).await.unwrap(); let inserted_timmy_person = Person::create(pool, &timmy_person_form).await.unwrap();
@ -181,11 +177,7 @@ mod tests {
.await .await
.unwrap(); .unwrap();
let sara_person_form = PersonInsertForm::builder() let sara_person_form = PersonInsertForm::test_form(inserted_instance.id, "sara_rav");
.name("sara_rav".into())
.public_key("pubkey".to_string())
.instance_id(inserted_instance.id)
.build();
let inserted_sara_person = Person::create(pool, &sara_person_form).await.unwrap(); let inserted_sara_person = Person::create(pool, &sara_person_form).await.unwrap();
@ -213,11 +205,7 @@ mod tests {
.unwrap() .unwrap()
.unwrap(); .unwrap();
let jess_person_form = PersonInsertForm::builder() let jess_person_form = PersonInsertForm::test_form(inserted_instance.id, "jess_rav");
.name("jess_rav".into())
.public_key("pubkey".to_string())
.instance_id(inserted_instance.id)
.build();
let inserted_jess_person = Person::create(pool, &jess_person_form).await.unwrap(); let inserted_jess_person = Person::create(pool, &jess_person_form).await.unwrap();

View File

@ -112,19 +112,11 @@ mod tests {
.await .await
.unwrap(); .unwrap();
let new_person = PersonInsertForm::builder() let new_person = PersonInsertForm::test_form(inserted_instance.id, "timmy_vv");
.name("timmy_vv".into())
.public_key("pubkey".to_string())
.instance_id(inserted_instance.id)
.build();
let inserted_timmy = Person::create(pool, &new_person).await.unwrap(); let inserted_timmy = Person::create(pool, &new_person).await.unwrap();
let new_person_2 = PersonInsertForm::builder() let new_person_2 = PersonInsertForm::test_form(inserted_instance.id, "sara_vv");
.name("sara_vv".into())
.public_key("pubkey".to_string())
.instance_id(inserted_instance.id)
.build();
let inserted_sara = Person::create(pool, &new_person_2).await.unwrap(); let inserted_sara = Person::create(pool, &new_person_2).await.unwrap();

View File

@ -334,19 +334,13 @@ mod tests {
let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string()).await?; let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string()).await?;
let terry_form = PersonInsertForm::builder() let terry_form = PersonInsertForm::test_form(inserted_instance.id, "terrylake");
.name("terrylake".into())
.public_key("pubkey".to_string())
.instance_id(inserted_instance.id)
.build();
let inserted_terry = Person::create(pool, &terry_form).await?; let inserted_terry = Person::create(pool, &terry_form).await?;
let recipient_form = PersonInsertForm::builder() let recipient_form = PersonInsertForm {
.name("terrylakes recipient".into()) local: Some(true),
.public_key("pubkey".to_string()) ..PersonInsertForm::test_form(inserted_instance.id, "terrylakes recipient")
.instance_id(inserted_instance.id) };
.local(Some(true))
.build();
let inserted_recipient = Person::create(pool, &recipient_form).await?; let inserted_recipient = Person::create(pool, &recipient_form).await?;
let recipient_id = inserted_recipient.id; let recipient_id = inserted_recipient.id;

View File

@ -286,11 +286,7 @@ mod tests {
let person_name = "tegan".to_string(); let person_name = "tegan".to_string();
let new_person = PersonInsertForm::builder() let new_person = PersonInsertForm::test_form(inserted_instance.id, &person_name);
.name(person_name.clone())
.public_key("pubkey".to_string())
.instance_id(inserted_instance.id)
.build();
let inserted_person = Person::create(pool, &new_person).await.unwrap(); let inserted_person = Person::create(pool, &new_person).await.unwrap();

View File

@ -334,19 +334,11 @@ mod tests {
let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string()).await?; let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string()).await?;
let new_person = PersonInsertForm::builder() let new_person = PersonInsertForm::test_form(inserted_instance.id, "terrylake");
.name("terrylake".into())
.public_key("pubkey".to_string())
.instance_id(inserted_instance.id)
.build();
let inserted_person = Person::create(pool, &new_person).await?; let inserted_person = Person::create(pool, &new_person).await?;
let recipient_form = PersonInsertForm::builder() let recipient_form = PersonInsertForm::test_form(inserted_instance.id, "terrylakes recipient");
.name("terrylakes recipient".into())
.public_key("pubkey".to_string())
.instance_id(inserted_instance.id)
.build();
let inserted_recipient = Person::create(pool, &recipient_form).await?; let inserted_recipient = Person::create(pool, &recipient_form).await?;
let recipient_id = inserted_recipient.id; let recipient_id = inserted_recipient.id;

View File

@ -191,12 +191,10 @@ mod tests {
async fn init_data(pool: &mut DbPool<'_>) -> LemmyResult<Data> { async fn init_data(pool: &mut DbPool<'_>) -> LemmyResult<Data> {
let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string()).await?; let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string()).await?;
let alice_form = PersonInsertForm::builder() let alice_form = PersonInsertForm {
.name("alice".to_string()) local: Some(true),
.public_key("pubkey".to_string()) ..PersonInsertForm::test_form(inserted_instance.id, "alice")
.instance_id(inserted_instance.id) };
.local(Some(true))
.build();
let alice = Person::create(pool, &alice_form).await?; let alice = Person::create(pool, &alice_form).await?;
let alice_local_user_form = LocalUserInsertForm::builder() let alice_local_user_form = LocalUserInsertForm::builder()
.person_id(alice.id) .person_id(alice.id)
@ -204,13 +202,11 @@ mod tests {
.build(); .build();
let alice_local_user = LocalUser::create(pool, &alice_local_user_form, vec![]).await?; let alice_local_user = LocalUser::create(pool, &alice_local_user_form, vec![]).await?;
let bob_form = PersonInsertForm::builder() let bob_form = PersonInsertForm {
.name("bob".to_string()) bot_account: Some(true),
.bot_account(Some(true)) local: Some(false),
.public_key("pubkey".to_string()) ..PersonInsertForm::test_form(inserted_instance.id, "bob")
.instance_id(inserted_instance.id) };
.local(Some(false))
.build();
let bob = Person::create(pool, &bob_form).await?; let bob = Person::create(pool, &bob_form).await?;
let bob_local_user_form = LocalUserInsertForm::builder() let bob_local_user_form = LocalUserInsertForm::builder()
.person_id(bob.id) .person_id(bob.id)

View File

@ -455,15 +455,17 @@ async fn initialize_local_site_2022_10_10(
)?; )?;
// Register the user if there's a site setup // Register the user if there's a site setup
let person_form = PersonInsertForm::builder() let person_form = PersonInsertForm {
.name(setup.admin_username.clone()) actor_id: Some(person_actor_id.clone()),
.instance_id(instance.id) inbox_url: Some(generate_inbox_url(&person_actor_id)?),
.actor_id(Some(person_actor_id.clone())) shared_inbox_url: Some(generate_shared_inbox_url(settings)?),
.private_key(Some(person_keypair.private_key)) private_key: Some(person_keypair.private_key),
.public_key(person_keypair.public_key) ..PersonInsertForm::new(
.inbox_url(Some(generate_inbox_url(&person_actor_id)?)) setup.admin_username.clone(),
.shared_inbox_url(Some(generate_shared_inbox_url(settings)?)) person_keypair.public_key,
.build(); instance.id,
)
};
let person_inserted = Person::create(pool, &person_form).await?; let person_inserted = Person::create(pool, &person_form).await?;
let local_user_form = LocalUserInsertForm::builder() let local_user_form = LocalUserInsertForm::builder()

View File

@ -142,11 +142,7 @@ mod tests {
.await .await
.unwrap(); .unwrap();
let new_person = PersonInsertForm::builder() let new_person = PersonInsertForm::test_form(inserted_instance.id, "Gerry9812");
.name("Gerry9812".into())
.public_key("pubkey".to_string())
.instance_id(inserted_instance.id)
.build();
let inserted_person = Person::create(pool, &new_person).await.unwrap(); let inserted_person = Person::create(pool, &new_person).await.unwrap();