use lemmy_db_schema::{
schema::{local_user, person, registration_application},
source::{
- local_user::{LocalUser, LocalUserSettings},
- person::{Person, PersonSafe},
+ local_user::LocalUser,
+ person::Person,
registration_application::RegistrationApplication,
},
- traits::{ToSafe, ToSafeSettings, ViewToVec},
+ traits::JoinView,
utils::{get_conn, limit_and_offset, DbPool},
};
use typed_builder::TypedBuilder;
-type RegistrationApplicationViewTuple = (
- RegistrationApplication,
- LocalUserSettings,
- PersonSafe,
- Option<PersonSafe>,
-);
+type RegistrationApplicationViewTuple =
+ (RegistrationApplication, LocalUser, Person, Option<Person>);
impl RegistrationApplicationView {
- pub async fn read(pool: &DbPool, registration_application_id: i32) -> Result<Self, Error> {
+ pub async fn read(
+ pool: &mut DbPool<'_>,
+ registration_application_id: i32,
+ ) -> Result<Self, Error> {
let conn = &mut get_conn(pool).await?;
let person_alias_1 = diesel::alias!(person as person1);
.order_by(registration_application::published.desc())
.select((
registration_application::all_columns,
- LocalUser::safe_settings_columns_tuple(),
- Person::safe_columns_tuple(),
- person_alias_1
- .fields(Person::safe_columns_tuple())
- .nullable(),
+ local_user::all_columns,
+ person::all_columns,
+ person_alias_1.fields(person::all_columns).nullable(),
))
.first::<RegistrationApplicationViewTuple>(conn)
.await?;
}
/// Returns the current unread registration_application count
- pub async fn get_unread_count(pool: &DbPool, verified_email_only: bool) -> Result<i64, Error> {
+ pub async fn get_unread_count(
+ pool: &mut DbPool<'_>,
+ verified_email_only: bool,
+ ) -> Result<i64, Error> {
let conn = &mut get_conn(pool).await?;
let person_alias_1 = diesel::alias!(person as person1);
#[derive(TypedBuilder)]
#[builder(field_defaults(default))]
-pub struct RegistrationApplicationQuery<'a> {
+pub struct RegistrationApplicationQuery<'a, 'b: 'a> {
#[builder(!default)]
- pool: &'a DbPool,
+ pool: &'a mut DbPool<'b>,
unread_only: Option<bool>,
verified_email_only: Option<bool>,
page: Option<i64>,
limit: Option<i64>,
}
-impl<'a> RegistrationApplicationQuery<'a> {
+impl<'a, 'b: 'a> RegistrationApplicationQuery<'a, 'b> {
pub async fn list(self) -> Result<Vec<RegistrationApplicationView>, Error> {
let conn = &mut get_conn(self.pool).await?;
let person_alias_1 = diesel::alias!(person as person1);
.order_by(registration_application::published.desc())
.select((
registration_application::all_columns,
- LocalUser::safe_settings_columns_tuple(),
- Person::safe_columns_tuple(),
- person_alias_1
- .fields(Person::safe_columns_tuple())
- .nullable(),
+ local_user::all_columns,
+ person::all_columns,
+ person_alias_1.fields(person::all_columns).nullable(),
))
.into_boxed();
let res = query.load::<RegistrationApplicationViewTuple>(conn).await?;
- Ok(RegistrationApplicationView::from_tuple_to_vec(res))
+ Ok(
+ res
+ .into_iter()
+ .map(RegistrationApplicationView::from_tuple)
+ .collect(),
+ )
}
}
-impl ViewToVec for RegistrationApplicationView {
- type DbTuple = RegistrationApplicationViewTuple;
- fn from_tuple_to_vec(items: Vec<Self::DbTuple>) -> Vec<Self> {
- items
- .into_iter()
- .map(|a| Self {
- registration_application: a.0,
- creator_local_user: a.1,
- creator: a.2,
- admin: a.3,
- })
- .collect::<Vec<Self>>()
+impl JoinView for RegistrationApplicationView {
+ type JoinTuple = RegistrationApplicationViewTuple;
+ fn from_tuple(a: Self::JoinTuple) -> Self {
+ Self {
+ registration_application: a.0,
+ creator_local_user: a.1,
+ creator: a.2,
+ admin: a.3,
+ }
}
}
use lemmy_db_schema::{
source::{
instance::Instance,
- local_user::{LocalUser, LocalUserInsertForm, LocalUserSettings, LocalUserUpdateForm},
- person::{Person, PersonInsertForm, PersonSafe},
+ local_user::{LocalUser, LocalUserInsertForm, LocalUserUpdateForm},
+ person::{Person, PersonInsertForm},
registration_application::{
RegistrationApplication,
RegistrationApplicationInsertForm,
#[serial]
async fn test_crud() {
let pool = &build_db_pool_for_tests().await;
+ let pool = &mut pool.into();
let inserted_instance = Instance::read_or_create(pool, "my_domain.tld".to_string())
.await
let mut expected_sara_app_view = RegistrationApplicationView {
registration_application: sara_app.clone(),
- creator_local_user: LocalUserSettings {
+ creator_local_user: LocalUser {
id: inserted_sara_local_user.id,
person_id: inserted_sara_local_user.person_id,
email: inserted_sara_local_user.email,
show_new_post_notifs: inserted_sara_local_user.show_new_post_notifs,
email_verified: inserted_sara_local_user.email_verified,
accepted_application: inserted_sara_local_user.accepted_application,
+ totp_2fa_secret: inserted_sara_local_user.totp_2fa_secret,
+ totp_2fa_url: inserted_sara_local_user.totp_2fa_url,
+ password_encrypted: inserted_sara_local_user.password_encrypted,
+ open_links_in_new_tab: inserted_sara_local_user.open_links_in_new_tab,
},
- creator: PersonSafe {
+ creator: Person {
id: inserted_sara_person.id,
name: inserted_sara_person.name.clone(),
display_name: None,
shared_inbox_url: None,
matrix_user_id: None,
instance_id: inserted_instance.id,
+ private_key: inserted_sara_person.private_key,
+ public_key: inserted_sara_person.public_key,
+ last_refreshed_at: inserted_sara_person.last_refreshed_at,
},
admin: None,
};
.accepted_application = true;
expected_sara_app_view.registration_application.admin_id = Some(inserted_timmy_person.id);
- expected_sara_app_view.admin = Some(PersonSafe {
+ expected_sara_app_view.admin = Some(Person {
id: inserted_timmy_person.id,
name: inserted_timmy_person.name.clone(),
display_name: None,
shared_inbox_url: None,
matrix_user_id: None,
instance_id: inserted_instance.id,
+ private_key: inserted_timmy_person.private_key,
+ public_key: inserted_timmy_person.public_key,
+ last_refreshed_at: inserted_timmy_person.last_refreshed_at,
});
assert_eq!(read_sara_app_view_after_approve, expected_sara_app_view);