Moving matrix_user_id to person table. #1438

pull/1510/head
Dessalines 2021-03-20 15:21:51 -04:00
parent 4b92e35edc
commit 1745b64ceb
26 changed files with 65 additions and 14 deletions

View File

@ -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,

View File

@ -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,

View File

@ -187,6 +187,7 @@ impl FromApubToForm<PersonExt> 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
})
}
}

View File

@ -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();

View File

@ -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();

View File

@ -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();

View File

@ -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();

View File

@ -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();

View File

@ -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();

View File

@ -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();

View File

@ -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();

View File

@ -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,
)
}

View File

@ -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();

View File

@ -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,

View File

@ -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::<Option<String>>(None),
local_user::matrix_user_id.eq::<Option<String>>(None),
))
.set((local_user::email.eq::<Option<String>>(None),))
.execute(conn)?;
diesel::update(person.find(person_id))
.set((
preferred_username.eq::<Option<String>>(None),
bio.eq::<Option<String>>(None),
matrix_user_id.eq::<Option<String>>(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();

View File

@ -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();

View File

@ -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();

View File

@ -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();

View File

@ -154,7 +154,6 @@ table! {
lang -> Varchar,
show_avatars -> Bool,
send_notifications_to_email -> Bool,
matrix_user_id -> Nullable<Text>,
validator_time -> Timestamp,
}
}
@ -287,6 +286,7 @@ table! {
deleted -> Bool,
inbox_url -> Varchar,
shared_inbox_url -> Nullable<Varchar>,
matrix_user_id -> Nullable<Text>,
}
}
@ -485,6 +485,7 @@ table! {
deleted -> Bool,
inbox_url -> Varchar,
shared_inbox_url -> Nullable<Varchar>,
matrix_user_id -> Nullable<Text>,
}
}
@ -507,6 +508,7 @@ table! {
deleted -> Bool,
inbox_url -> Varchar,
shared_inbox_url -> Nullable<Varchar>,
matrix_user_id -> Nullable<Text>,
}
}

View File

@ -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<String>,
pub validator_time: chrono::NaiveDateTime,
}
@ -35,7 +34,6 @@ pub struct LocalUserForm {
pub lang: Option<String>,
pub show_avatars: Option<bool>,
pub send_notifications_to_email: Option<bool>,
pub matrix_user_id: Option<Option<String>>,
}
/// 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<String>,
pub validator_time: chrono::NaiveDateTime,
}

View File

@ -25,6 +25,7 @@ pub struct Person {
pub deleted: bool,
pub inbox_url: DbUrl,
pub shared_inbox_url: Option<DbUrl>,
pub matrix_user_id: Option<String>,
}
/// 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<DbUrl>,
pub matrix_user_id: Option<String>,
}
#[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<DbUrl>,
pub matrix_user_id: Option<String>,
}
#[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<DbUrl>,
pub matrix_user_id: Option<String>,
}
#[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<DbUrl>,
pub matrix_user_id: Option<String>,
}
#[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<DbUrl>,
pub matrix_user_id: Option<String>,
}
#[derive(Insertable, AsChangeset, Clone)]
@ -148,4 +154,5 @@ pub struct PersonForm {
pub deleted: Option<bool>,
pub inbox_url: Option<DbUrl>,
pub shared_inbox_url: Option<Option<DbUrl>>,
pub matrix_user_id: Option<Option<String>>,
}

View File

@ -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 {

View File

@ -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 {

View File

@ -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;

View File

@ -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;

View File

@ -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)?;